Hi, here a patch to add this platform as a new target.
From 38196801851fa941258360e5786d1ed45078d2fd Mon Sep 17 00:00:00 2001
From: David Carlier <[email protected]>
Date: Sun, 20 Feb 2022 18:57:58 +0000
Subject: [PATCH] illumos/solaris improving support

---
 Makefile       |  3 +++
 configure      | 19 +++++++++++--------
 conftest.c     |  1 +
 tcc.c          |  2 ++
 tcc.h          |  3 +++
 tccpp.c        |  2 ++
 tccrun.c       |  8 ++++++--
 tests/Makefile |  2 ++
 8 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 9216b0d..9041808 100644
--- a/Makefile
+++ b/Makefile
@@ -90,6 +90,7 @@ NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
 NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64
 NATIVE_DEFINES_$(CONFIG_riscv64) += -DTCC_TARGET_RISCV64
 NATIVE_DEFINES_$(CONFIG_BSD) += -DTARGETOS_$(TARGETOS)
+NATIVE_DEFINES_$(CONFIG_SunOS) += -DTARGETOS_$(TARGETOS)
 NATIVE_DEFINES_$(CONFIG_pie) += -DCONFIG_TCC_PIE
 NATIVE_DEFINES_no_$(CONFIG_bcheck) += -DCONFIG_TCC_BCHECK=0
 NATIVE_DEFINES_no_$(CONFIG_backtrace) += -DCONFIG_TCC_BACKTRACE=0
@@ -98,6 +99,7 @@ NATIVE_DEFINES += $(NATIVE_DEFINES_yes) $(NATIVE_DEFINES_no_no)
 DEF-i386           = -DTCC_TARGET_I386
 DEF-i386-win32     = -DTCC_TARGET_I386 -DTCC_TARGET_PE
 DEF-i386-OpenBSD   = $(DEF-i386) -DTARGETOS_OpenBSD
+DEF-i386-SunOS     = $(DEF-i386) -DTARGETOS_SunOS
 DEF-x86_64         = -DTCC_TARGET_X86_64
 DEF-x86_64-win32   = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
 DEF-x86_64-osx     = -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO
@@ -119,6 +121,7 @@ DEF-c67            = -DTCC_TARGET_C67 -w # disable warnigs
 DEF-x86_64-FreeBSD = $(DEF-x86_64) -DTARGETOS_FreeBSD
 DEF-x86_64-NetBSD  = $(DEF-x86_64) -DTARGETOS_NetBSD
 DEF-x86_64-OpenBSD = $(DEF-x86_64) -DTARGETOS_OpenBSD
+DEF-x86_64-SunOS   = $(DEF-x86_64) -DTARGETOS_SunOS
 
 DEF-$(NATIVE_TARGET) = $(NATIVE_DEFINES)
 
diff --git a/configure b/configure
index f05b700..f34f89a 100755
--- a/configure
+++ b/configure
@@ -71,6 +71,9 @@ case $targetos in
   DragonFly|OpenBSD|FreeBSD|NetBSD)
     confvars="$confvars BSD ldl=no"
     ;;
+  SunOS)
+    confvars="$confvars SunOS"
+    ;;
   *)
     ;;
 esac
@@ -463,20 +466,20 @@ DLLSUF=$DLLSUF
 EOF
 
 print_inc() {
-  local v="$2"
-  if test -n "$v"; then
-    test "$3" = "num" || v="\"$v\""
+  vinc="$2"
+  if test -n "$vinc"; then
+    test "$3" = "num" || vinc="\"$vinc\""
     echo "#ifndef $1" >> $TMPH
-    echo "# define $1 $v" >> $TMPH
+    echo "# define $1 $vinc" >> $TMPH
     echo "#endif" >> $TMPH
   fi
 }
 
 print_mak() {
-  local v="$2"
-  if test -n "$v"; then
-    test "$3" = "num" || v="\"\\\"$v\\\"\""
-    echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
+  vmak="$2"
+  if test -n "$vmak"; then
+    test "$3" = "num" || vmak="\"\\\"$vmak\\\"\""
+    echo "NATIVE_DEFINES+=-D$1=$vmak" >> config.mak
   fi
 }
 
diff --git a/conftest.c b/conftest.c
index e8e1220..66181a0 100644
--- a/conftest.c
+++ b/conftest.c
@@ -20,6 +20,7 @@ const char *platform_macros[] = {
     "__FreeBSD_kernel__",   "TARGETOS_FreeBSD_kernel",
     "__OpenBSD__",          "TARGETOS_OpenBSD",
     "__NetBSD__",           "TARGETOS_NetBSD",
+    "__sun",                "TARGETOS_SunOS",
     "__linux__",            "TARGETOS_Linux",
     "__SIZEOF_POINTER__",   "PTR_SIZE",
     "__SIZEOF_LONG__",      "LONG_SIZE",
diff --git a/tcc.c b/tcc.c
index 42a251b..d60dc0b 100644
--- a/tcc.c
+++ b/tcc.c
@@ -185,6 +185,8 @@ static const char version[] =
         " OpenBSD"
 #elif TARGETOS_NetBSD
         " NetBSD"
+#elif TARGETOS_SunOS
+        " Solaris"
 #else
         " Linux"
 #endif
diff --git a/tcc.h b/tcc.h
index ef69ef5..db18f6f 100644
--- a/tcc.h
+++ b/tcc.h
@@ -23,6 +23,7 @@
 
 #define _GNU_SOURCE
 #define _DARWIN_C_SOURCE
+#define __EXTENSIONS__
 #include "config.h"
 
 #include <stdarg.h>
@@ -307,6 +308,8 @@ extern long double strtold (const char *__nptr, char **__endptr);
 #  define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.elf_so"
 # elif TARGETOS_OpenBSD
 #  define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.so"
+# elif TARGETOS_SunOS
+#  define CONFIG_TCC_ELFINTERP "/usr/lib/ld.so.1"
 # elif defined __GNU__
 #  define CONFIG_TCC_ELFINTERP "/lib/ld.so"
 # elif defined(TCC_TARGET_PE)
diff --git a/tccpp.c b/tccpp.c
index 6b828c9..6299751 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -3694,6 +3694,8 @@ static const char * const target_os_defs =
     "__NetBSD__\0"
 # elif TARGETOS_OpenBSD
     "__OpenBSD__\0"
+# elif TARGETOS_SunOS
+    "__sun\0"
 # else
     "__linux__\0"
     "__linux\0"
diff --git a/tccrun.c b/tccrun.c
index 9c9f4e0..be308ba 100644
--- a/tccrun.c
+++ b/tccrun.c
@@ -147,7 +147,7 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv)
 
 #if defined(__APPLE__) || defined(__FreeBSD__)
     char **envp = NULL;
-#elif defined(__OpenBSD__) || defined(__NetBSD__)
+#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__sun)
     extern char **environ;
     char **envp = environ;
 #else
@@ -647,7 +647,11 @@ static void rt_exit(int code)
 #ifndef _WIN32
 # include <signal.h>
 # ifndef __OpenBSD__
-#  include <sys/ucontext.h>
+#  ifdef __sun
+#    include <ucontext.h>
+#  else
+#    include <sys/ucontext.h>
+#  endif
 # endif
 #else
 # define ucontext_t CONTEXT
diff --git a/tests/Makefile b/tests/Makefile
index 8cc2e36..d3e6b95 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -285,12 +285,14 @@ CROSS-TGTS = \
  i386 \
  i386-win32 \
  i386-OpenBSD \
+ i386-SunOS \
  x86_64 \
  x86_64-win32 \
  x86_64-osx \
  x86_64-FreeBSD \
  x86_64-NetBSD \
  x86_64-OpenBSD \
+ x86_64-SunOS \
  arm-fpa \
  arm-eabihf \
  arm-NetBSD \
-- 
2.35.1

_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to