-From d34904540ecaabbcbfff8e99dc4c831b39f4ea32 Mon Sep 17 00:00:00 2001
+From 2b02641ebbfad717ef02f42c836b9b001a4269c9 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 9 Aug 2016 18:25:24 +0100
-Subject: [PATCH 2/2] RISCV 64-bit (riscv64) support.
+Subject: [PATCH 1/3] RISCV 64-bit (riscv64) support.
Based on Mark Salter's aarch64 support patch (commit 8e1ca16c58).
--- /dev/null
+From 85b9fa7d081f70bbc5ef6266fbdbd7480e7331dc Mon Sep 17 00:00:00 2001
+From: "Richard W.M. Jones" <rjones@redhat.com>
+Date: Wed, 10 Aug 2016 15:01:31 +0100
+Subject: [PATCH 2/3] build: fgetc returns int, not char.
+
+Returning the value into a char is a mistake on all platforms, but is
+particularly bad on RISC-V. On that platform (like ARM) char is
+unsigned. Therefore EOF (-1) is returned as 255, and the subsequent
+test 'c == EOF' ('255 == -1') fails causing an infinite loop.
+
+Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
+---
+ build/parseSpec.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/build/parseSpec.c b/build/parseSpec.c
+index 85b0ba3..28f00bc 100644
+--- a/build/parseSpec.c
++++ b/build/parseSpec.c
+@@ -323,7 +323,7 @@ retry:
+
+ /* Make sure we have something in the read buffer */
+ if (!(ofi->readPtr && *(ofi->readPtr))) {
+- char c;
++ int c;
+ int i = 0;
+
+ while((c = fgetc(ofi->fp)) != EOF) {
+--
+2.7.4
+
-From d6940aecfc237d215c3c067c16b386885ecd9ca8 Mon Sep 17 00:00:00 2001
+From 006666a5c9132bf0e580357fcbc671254724935a Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 9 Aug 2016 18:21:57 +0100
-Subject: [PATCH 1/2] HACKS TO GET RPM TO CROSS-COMPILE
+Subject: [PATCH 3/3] HACKS TO GET RPM TO CROSS-COMPILE
---
configure.ac | 28 ++++++++++++++++------------
tar -zxf rpm-$(RPM_SHORT_COMMIT).tar.gz
tar -zxf db-$(BDB_VERSION).tar.gz -C rpm-$(RPM_SHORT_COMMIT)
cd rpm-$(RPM_SHORT_COMMIT) && ln -s db-$(BDB_VERSION) db
- cd rpm-$(RPM_SHORT_COMMIT) && patch -p1 < ../0001-HACKS-TO-GET-RPM-TO-CROSS-COMPILE.patch
- cd rpm-$(RPM_SHORT_COMMIT) && patch -p1 < ../0002-RISCV-64-bit-riscv64-support.patch
+ cd rpm-$(RPM_SHORT_COMMIT) && \
+ patch -p1 < ../0001-RISCV-64-bit-riscv64-support.patch && \
+ patch -p1 < ../0002-build-fgetc-returns-int-not-char.patch && \
+ patch -p1 < ../0003-HACKS-TO-GET-RPM-TO-CROSS-COMPILE.patch
cd rpm-$(RPM_SHORT_COMMIT) && autoreconf -i
cd rpm-$(RPM_SHORT_COMMIT) && \
PATH=$(ROOT)/fixed-gcc:$$PATH \