From a4fb55ae3de789cf645d4939ed8af9dbaad242ce Mon Sep 17 00:00:00 2001
From: wuzx <wuzx1226@qq.com>
Date: Fri, 18 Nov 2022 02:53:10 +0800
Subject: [PATCH] Add sw64 architecture

Signed-off-by: wuzx <wuzx1226@qq.com>
---
 source/acinclude.m4                   |  6 ++
 source/config.guess                   |  8 +++
 source/config.sub                     |  2 +
 source/config/mh-sw_64-linux-cc       | 87 +++++++++++++++++++++++++++
 source/config/mh-sw_64-linux-gcc      | 85 ++++++++++++++++++++++++++
 source/configure                      |  8 ++-
 source/configure.ac                   |  2 +-
 source/i18n/double-conversion-utils.h |  2 +-
 8 files changed, 197 insertions(+), 3 deletions(-)
 create mode 100644 source/config/mh-sw_64-linux-cc
 create mode 100644 source/config/mh-sw_64-linux-gcc

diff --git a/source/acinclude.m4 b/source/acinclude.m4
index 507f41f..381a91f 100644
--- a/source/acinclude.m4
+++ b/source/acinclude.m4
@@ -21,6 +21,12 @@ case "${host}" in
 	else
 		icu_cv_host_frag=mh-solaris
 	fi ;;
+sw_64*-*-linux-gnu)
+	if test "$GCC" = yes; then
+		icu_cv_host_frag=mh-sw_64-linux-gcc
+	else
+		icu_cv_host_frag=mh-sw_64-linux-cc
+	fi ;;
 alpha*-*-linux-gnu)
 	if test "$GCC" = yes; then
 		icu_cv_host_frag=mh-alpha-linux-gcc
diff --git a/source/config.guess b/source/config.guess
index 31e01ef..1dfe5d5 100644
--- a/source/config.guess
+++ b/source/config.guess
@@ -894,6 +894,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/source/config.sub b/source/config.sub
index fb57947..07dc65e 100644
--- a/source/config.sub
+++ b/source/config.sub
@@ -244,6 +244,7 @@ case $basic_machine in
 	# Some are omitted here because they have special meanings below.
 	1750a | 580 \
 	| a29k \
+	| sw_64 \
 	| aarch64 | aarch64_be \
 	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
 	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
@@ -368,6 +369,7 @@ case $basic_machine in
 	# Recognize the basic CPU types with company name.
 	580-* \
 	| a29k-* \
+	| sw_64-* \
 	| aarch64-* | aarch64_be-* \
 	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
 	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
diff --git a/source/config/mh-sw_64-linux-cc b/source/config/mh-sw_64-linux-cc
new file mode 100644
index 0000000..f27259a
--- /dev/null
+++ b/source/config/mh-sw_64-linux-cc
@@ -0,0 +1,87 @@
+## -*-makefile-*-
+## Copyright (C) 2016 and later: Unicode, Inc. and others.
+## License & terms of use: http://www.unicode.org/copyright.html
+## Sw-64-Linux-specific setup
+## Copyright (c) 1999-2006, International Business Machines Corporation and
+## others. All Rights Reserved.
+
+## Commands to generate dependency files
+#GEN_DEPS.c=	$(CC) $(DEFS) $(CPPFLAGS) -MD -c -msg_quiet
+#GEN_DEPS.cc=	$(CXX) $(DEFS) $(CPPFLAGS) -D__USE_STD_IOSTREAM -c -MD -msg_quiet
+
+## Flags for position independent code
+SHAREDLIBCFLAGS = -fPIC
+SHAREDLIBCXXFLAGS = -fPIC
+SHAREDLIBCPPFLAGS = -DPIC
+
+## Additional flags when building libraries and with threads
+THREADSCPPFLAGS = -D_REENTRANT
+LIBCPPFLAGS =
+
+# The tests need complete IEEE floating point support
+CFLAGS += -ieee
+CXXFLAGS += -ieee
+
+## Commands to compile
+COMPILE.c=	$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS)  -c -signed -accept nogccinline
+COMPILE.cc=	$(CXX) $(DEFS) $(CPPFLAGS) $(CXXFLAGS) -c -signed -D__USE_STD_IOSTREAM -accept nogcc_inline
+
+
+## Commands to link
+LINK.c=		$(CC) -call_shared $(CFLAGS) $(LDFLAGS)
+LINK.cc=	$(CXX) -call_shared $(CXXFLAGS) $(LDFLAGS)
+
+## Compiler switch to embed a runtime search path
+LD_RPATH=
+LD_RPATH_PRE=	-Wl,-rpath,
+
+## Compiler switch to embed a library name
+LD_SONAME = -Wl,-soname -Wl,$(notdir $(MIDDLE_SO_TARGET))
+
+## Shared object suffix
+SO = so
+## Non-shared intermediate object suffix
+STATIC_O = ao
+
+## Compilation rules
+%.$(STATIC_O): $(srcdir)/%.c
+	$(COMPILE.c) $(STATICCPPFLAGS) $(STATICCFLAGS) -o $@ $<
+%.o: $(srcdir)/%.c
+	$(COMPILE.c) $(DYNAMICCPPFLAGS) $(DYNAMICCFLAGS) -o $@ $<
+
+%.$(STATIC_O): $(srcdir)/%.cpp
+	$(COMPILE.cc) $(STATICCPPFLAGS) $(STATICCXXFLAGS) -o $@ $<
+%.o: $(srcdir)/%.cpp
+	$(COMPILE.cc) $(DYNAMICCPPFLAGS) $(DYNAMICCXXFLAGS) -o $@ $<
+
+
+## Dependency rules
+#%.d: $(srcdir)/%.c
+#	@echo "generating dependency information for $<"
+#	@$(SHELL) -ec '$(GEN_DEPS.c) $< \
+#		| sed '\''s%\($*\)\.o[ :]*%\1.o $@ : %g'\'' > $@; \
+#		[ -s $@ ] || rm -f $@'
+
+#%.d: $(srcdir)/%.cpp
+#	@echo "generating dependency information for $<"
+#	@$(SHELL) -ec '$(GEN_DEPS.cc) $< \
+#		| sed '\''s%\($*\)\.o[ :]*%\1.o $@ : %g'\'' > $@; \
+#		[ -s $@ ] || rm -f $@'
+#
+## Versioned libraries rules
+
+%.$(SO).$(SO_TARGET_VERSION_MAJOR): %.$(SO).$(SO_TARGET_VERSION)
+	$(RM) $@ && ln -s ${<F} $@
+%.$(SO): %.$(SO).$(SO_TARGET_VERSION_MAJOR)
+	$(RM) $@ && ln -s ${*F}.$(SO).$(SO_TARGET_VERSION) $@
+
+##  Bind internal references
+
+# LDflags that pkgdata will use
+BIR_LDFLAGS= -Wl,-Bsymbolic
+
+# Dependencies [i.e. map files] for the final library
+BIR_DEPS=
+
+## End Linux-specific setup
+
diff --git a/source/config/mh-sw_64-linux-gcc b/source/config/mh-sw_64-linux-gcc
new file mode 100644
index 0000000..a3531d2
--- /dev/null
+++ b/source/config/mh-sw_64-linux-gcc
@@ -0,0 +1,85 @@
+## -*-makefile-*-
+## Copyright (C) 2016 and later: Unicode, Inc. and others.
+## License & terms of use: http://www.unicode.org/copyright.html
+## Linux-specific setup
+## Copyright (c) 1999-2009, International Business Machines Corporation and
+## others. All Rights Reserved.
+
+## Commands to generate dependency files
+GEN_DEPS.c=	$(CC) -E -MM $(DEFS) $(CPPFLAGS)
+GEN_DEPS.cc=	$(CXX) -E -MM $(DEFS) $(CPPFLAGS)
+
+## Flags for position independent code
+SHAREDLIBCFLAGS = -fPIC
+SHAREDLIBCXXFLAGS = -fPIC
+SHAREDLIBCPPFLAGS = -DPIC
+
+## Additional flags when building libraries and with threads
+THREADSCPPFLAGS = -D_REENTRANT
+LIBCPPFLAGS =
+
+# The tests need complete IEEE floating point support
+CFLAGS += -mieee
+CXXFLAGS += -mieee
+
+## Compiler switch to embed a runtime search path
+LD_RPATH=	
+LD_RPATH_PRE=	-Wl,-rpath,
+
+## Compiler switch to embed a library name
+LD_SONAME = -Wl,-soname -Wl,$(notdir $(MIDDLE_SO_TARGET))
+
+
+## Shared library options
+LD_SOOPTIONS= -Wl,-Bsymbolic
+
+## Shared object suffix
+SO = so
+## Non-shared intermediate object suffix
+STATIC_O = ao
+
+## Compilation rules
+%.$(STATIC_O): $(srcdir)/%.c
+	$(COMPILE.c) $(STATICCPPFLAGS) $(STATICCFLAGS) -o $@ $<
+%.o: $(srcdir)/%.c
+	$(COMPILE.c) $(DYNAMICCPPFLAGS) $(DYNAMICCFLAGS) -o $@ $<
+
+%.$(STATIC_O): $(srcdir)/%.cpp
+	$(COMPILE.cc) $(STATICCPPFLAGS) $(STATICCXXFLAGS) -o $@ $<
+%.o: $(srcdir)/%.cpp
+	$(COMPILE.cc) $(DYNAMICCPPFLAGS) $(DYNAMICCXXFLAGS) -o $@ $<
+
+
+## Dependency rules
+%.d: $(srcdir)/%.c
+	@echo "generating dependency information for $<"
+	@$(SHELL) -ec '$(GEN_DEPS.c) $< \
+		| sed '\''s%\($*\)\.o[ :]*%\1.o $@ : %g'\'' > $@; \
+		[ -s $@ ] || rm -f $@'
+
+%.d: $(srcdir)/%.cpp
+	@echo "generating dependency information for $<"
+	@$(SHELL) -ec '$(GEN_DEPS.cc) $< \
+		| sed '\''s%\($*\)\.o[ :]*%\1.o $@ : %g'\'' > $@; \
+		[ -s $@ ] || rm -f $@'
+
+## Versioned libraries rules
+
+%.$(SO).$(SO_TARGET_VERSION_MAJOR): %.$(SO).$(SO_TARGET_VERSION)
+	$(RM) $@ && ln -s ${<F} $@
+%.$(SO): %.$(SO).$(SO_TARGET_VERSION_MAJOR)
+	$(RM) $@ && ln -s ${*F}.$(SO).$(SO_TARGET_VERSION) $@
+
+# The type of assembly to write for generating an object file
+GENCCODE_ASSEMBLY=-a gcc
+
+##  Bind internal references
+
+# LDflags that pkgdata will use
+BIR_LDFLAGS= -Wl,-Bsymbolic
+
+# Dependencies [i.e. map files] for the final library
+BIR_DEPS=
+
+## End Linux-specific setup
+
diff --git a/source/configure b/source/configure
index a2ff7e4..a190250 100755
--- a/source/configure
+++ b/source/configure
@@ -5249,6 +5249,12 @@ case "${host}" in
 	else
 		icu_cv_host_frag=mh-solaris
 	fi ;;
+sw_64*-*-linux-gnu)
+	if test "$GCC" = yes; then
+		icu_cv_host_frag=mh-sw_64-linux-gcc
+	else
+		icu_cv_host_frag=mh-sw_64-linux-cc
+	fi ;;
 alpha*-*-linux-gnu)
 	if test "$GCC" = yes; then
 		icu_cv_host_frag=mh-alpha-linux-gcc
@@ -6511,7 +6517,7 @@ if test "$CC" = ccc; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: \"C compiler set to CCC ${CC}\" " >&5
 $as_echo "\"C compiler set to CCC ${CC}\" " >&6; }
  case "${host}" in
-        alpha*-*-*) U_HAVE_INTTYPES_H=0;
+        alpha*-*-* | sw_64*-*-*) U_HAVE_INTTYPES_H=0;
         CONFIG_CPPFLAGS="${CONFIG_CPPFLAGS} -DU_HAVE_INTTYPES_H=0"
  esac
 fi
diff --git a/source/configure.ac b/source/configure.ac
index 425fdc7..6acf133 100644
--- a/source/configure.ac
+++ b/source/configure.ac
@@ -685,7 +685,7 @@ fi
 if test "$CC" = ccc; then
  AC_MSG_RESULT("C compiler set to CCC ${CC}" )
  case "${host}" in
-        alpha*-*-*) U_HAVE_INTTYPES_H=0;
+        alpha*-*-* | sw_64*-*-*) U_HAVE_INTTYPES_H=0;
         CONFIG_CPPFLAGS="${CONFIG_CPPFLAGS} -DU_HAVE_INTTYPES_H=0"
  esac
 fi
diff --git a/source/i18n/double-conversion-utils.h b/source/i18n/double-conversion-utils.h
index c937463..7dcdbf8 100644
--- a/source/i18n/double-conversion-utils.h
+++ b/source/i18n/double-conversion-utils.h
@@ -122,7 +122,7 @@ int main(int argc, char** argv) {
     defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
     defined(_POWER) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \
     defined(__sparc__) || defined(__sparc) || defined(__s390__) || \
-    defined(__SH4__) || defined(__alpha__) || \
+    defined(__SH4__) || defined(__alpha__) || defined(__sw_64__) || \
     defined(_MIPS_ARCH_MIPS32R2) || defined(__ARMEB__) ||\
     defined(__AARCH64EL__) || defined(__aarch64__) || defined(__AARCH64EB__) || \
     defined(__riscv) || defined(__e2k__) || \
-- 
2.33.0

