Further fixes to RPM.
[fedora-riscv.git] / 0002-rpmrc-Convert-uname.machine-riscv-to-riscv32-riscv64.patch
diff --git a/0002-rpmrc-Convert-uname.machine-riscv-to-riscv32-riscv64.patch b/0002-rpmrc-Convert-uname.machine-riscv-to-riscv32-riscv64.patch
new file mode 100644 (file)
index 0000000..0c89ede
--- /dev/null
@@ -0,0 +1,46 @@
+From 331b0ac34a9767d1f0147daf3fd22b64e2e4e3af Mon Sep 17 00:00:00 2001
+From: "Richard W.M. Jones" <rjones@redhat.com>
+Date: Thu, 11 Aug 2016 11:38:18 +0100
+Subject: [PATCH 2/4] rpmrc: Convert uname.machine == "riscv" to
+ "riscv32"/"riscv64"/"riscv128".
+
+On RISC-V, the kernel returns uname.machine == "riscv" (for all bit
+sizes).  GNU is using "riscv64".  Convert the kernel uname machine
+type to a more suitable value.
+
+This conversion is supposed to be done by the arch_canon table.
+However the arch_canon table is not populated until after the
+defaultMachine function is called for the first time, making it a bit
+useless.  In any case, arch_canon cannot take into account the bit
+size of the architecture, but the C code here can.
+
+Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
+---
+ lib/rpmrc.c | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+diff --git a/lib/rpmrc.c b/lib/rpmrc.c
+index f2e0f48..eb136d8 100644
+--- a/lib/rpmrc.c
++++ b/lib/rpmrc.c
+@@ -1216,6 +1216,17 @@ static void defaultMachine(rpmrcCtx ctx, const char ** arch, const char ** os)
+       }
+ #     endif   /* arm*-linux */
++#     if defined(__linux__) && defined(__riscv__)
++      if (rstreq(un.machine, "riscv")) {
++              if (sizeof(long) == 4)
++                      strcpy(un.machine, "riscv32");
++              else if (sizeof(long) == 8)
++                      strcpy(un.machine, "riscv64");
++              else if (sizeof(long) == 16)
++                      strcpy(un.machine, "riscv128");
++      }
++#     endif   /* riscv */
++
+ #     if defined(__GNUC__) && defined(__alpha__)
+       {
+           unsigned long amask, implver;
+-- 
+2.7.4
+