From 3c8ac8643a0d7c3c3ce972c0a0685d9d1c9de9bc Mon Sep 17 00:00:00 2001
From: wzx <wuzx1226@qq.com>
Date: Thu, 27 Oct 2022 11:27:23 +0800
Subject: [PATCH] Add sw64 architecture

Add sw64 architecture in file config.guess config.sub installplatform lib/rpmrc.c macros.in rpmrc.in and tools/elfdeps.c to support sw64 architecture.

Signed-off-by: wzx <wuzx1226@qq.com>
---
 build-aux/config.guess |  8 ++++++++
 build-aux/config.sub   |  1 +
 installplatform        |  6 ++++++
 lib/rpmrc.c            |  7 +++++++
 macros.in              |  1 +
 rpmrc.in               | 15 +++++++++++++++
 tools/elfdeps.c        |  1 +
 7 files changed, 39 insertions(+)

diff --git a/build-aux/config.guess b/build-aux/config.guess
index b33c9e8..69e3005 100755
--- a/build-aux/config.guess
+++ b/build-aux/config.guess
@@ -913,6 +913,14 @@ EOF
 	UNAME_MACHINE=aarch64_be
 	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
 	exit ;;
+    sw_64:Linux:*:*)
+	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+	  sw)   UNAME_MACHINE=sw_64 ;;
+	esac
+	objdump --private-headers /bin/sh | grep -q ld.so.1
+	if test "$?" = 0 ; then LIBC=gnulibc1 ; fi
+	echo "$UNAME_MACHINE"-sunway-linux-"$LIBC"
+	exit ;;
     alpha:Linux:*:*)
 	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
 	  EV5)   UNAME_MACHINE=alphaev5 ;;
diff --git a/build-aux/config.sub b/build-aux/config.sub
index b51fb8c..84a8688 100755
--- a/build-aux/config.sub
+++ b/build-aux/config.sub
@@ -1155,6 +1155,7 @@ case $cpu-$vendor in
 		case $cpu in
 			1750a | 580 \
 			| a29k \
+			| sw_64 \
 			| aarch64 | aarch64_be \
 			| abacus \
 			| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \
diff --git a/installplatform b/installplatform
index ca490e0..2700199 100755
--- a/installplatform
+++ b/installplatform
@@ -108,6 +108,12 @@ for ARCH in noarch `grep ^arch_canon $RPMRC | cut -d: -f2`; do
 	CANONARCH=arm
 	CANONCOLOR=0
 	;;
+    sw_64*)
+	ISANAME=sw_64
+	ISABITS=64
+	CANONARCH=sw_64
+	CANONCOLOR=0
+	;;
     alpha*)
 	ISANAME=alpha
 	ISABITS=64
diff --git a/lib/rpmrc.c b/lib/rpmrc.c
index 120777c..5d9507d 100644
--- a/lib/rpmrc.c
+++ b/lib/rpmrc.c
@@ -1268,6 +1268,13 @@ static void defaultMachine(rpmrcCtx ctx, const char ** arch, const char ** os)
 	}
 #	endif
 
+#       if defined(__GNUC__) && defined(__sw_64__)
+        {
+                strcpy(un.machine, "sw_64sw6b");
+        }
+#       endif
+
+
 #	if defined(__linux__) && defined(__i386__)
 	{
 	    char mclass = (char) (RPMClass() | '0');
diff --git a/macros.in b/macros.in
index 4dbf5b6..6722a74 100644
--- a/macros.in
+++ b/macros.in
@@ -1107,6 +1107,7 @@ package or when debugging this package.\
 #------------------------------------------------------------------------------
 # arch macro for all supported Alpha processors
 %alpha	alpha alphaev56 alphaev6 alphaev67
+%sw_64 sw_64 sw_64sw6b
 
 #------------------------------------------------------------------------------
 # arch macro for all supported PowerPC 64 processors
diff --git a/rpmrc.in b/rpmrc.in
index 3a48af4..8d70f91 100644
--- a/rpmrc.in
+++ b/rpmrc.in
@@ -25,6 +25,9 @@ optflags: x86_64 -O2 -g
 optflags: amd64 -O2 -g
 optflags: ia32e -O2 -g
 
+optflags: sw_64 -O2 -g -mieee
+optflags: sw_64sw6b -O2 -g -mieee -mtune=sw6b
+
 optflags: alpha -O2 -g -mieee
 optflags: alphaev5 -O2 -g -mieee -mtune=ev5
 optflags: alphaev56 -O2 -g -mieee -mtune=ev56
@@ -112,6 +115,7 @@ optflags: riscv64 -O2 -g
 archcolor: noarch 0
 archcolor: i386 1
 archcolor: alpha 2
+archcolor: sw_64 2
 archcolor: sparc 1
 archcolor: sparc64 2
 archcolor: sparcv9 2
@@ -176,6 +180,9 @@ arch_canon:	amd64:	amd64	1
 arch_canon:	ia32e:	ia32e	1
 arch_canon:	em64t:	em64t	1
 
+arch_canon:    sw_64:  sw_64   2
+arch_canon:    sw_64sw6b: sw_64sw6b    2
+
 arch_canon:	alpha:	alpha	2
 arch_canon:	alphaev5: alphaev5	2
 arch_canon:	alphaev56: alphaev56	2
@@ -315,6 +322,9 @@ buildarchtranslate: i586: i386
 buildarchtranslate: i486: i386
 buildarchtranslate: i386: i386
 
+buildarchtranslate: sw_64: sw_64
+buildarchtranslate: sw_64sw6b: sw_64
+
 buildarchtranslate: alphaev5: alpha
 buildarchtranslate: alphaev56: alpha
 buildarchtranslate: alphapca56: alpha
@@ -401,6 +411,8 @@ buildarchtranslate: riscv64: riscv64
 
 #########################################/####################
 # Architecture compatibility
+arch_compat: sw_64sw6b: sw_64
+arch_compat: sw_64: axp noarch
 
 arch_compat: alphaev67: alphaev6
 arch_compat: alphaev6: alphapca56
@@ -570,6 +582,9 @@ buildarch_compat: sparcv9: sparcv8
 buildarch_compat: sparcv8: sparc
 buildarch_compat: sparc: noarch
 
+buildarch_compat: sw_64sw6b: sw_64
+buildarch_compat: sw_64: noarch
+
 buildarch_compat: alphaev67: alphaev6
 buildarch_compat: alphaev6: alphapca56
 buildarch_compat: alphapca56: alphaev56
diff --git a/tools/elfdeps.c b/tools/elfdeps.c
index d205935..590021b 100644
--- a/tools/elfdeps.c
+++ b/tools/elfdeps.c
@@ -85,6 +85,7 @@ static const char *mkmarker(GElf_Ehdr *ehdr)
     if (ehdr->e_ident[EI_CLASS] == ELFCLASS64) {
 	switch (ehdr->e_machine) {
 	case EM_ALPHA:
+	case EM_SW_64:
 	case EM_FAKE_ALPHA:
 	    /* alpha doesn't traditionally have 64bit markers */
 	    break;
-- 
2.33.0

