Improve multiarch detection
authorThomas Preud'homme <robotux@celest.fr>
Wed, 13 Feb 2013 16:01:53 +0000 (13 17:01 +0100)
committerThomas Preud'homme <robotux@celest.fr>
Wed, 13 Feb 2013 16:03:30 +0000 (13 17:03 +0100)
* Detect multiarch at configure time
* Detect based on the place where crti.o is
* Define multiarch triplet in tcc.h

Makefile
configure
tcc.h

index f81f97d..4d09e42 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -35,16 +35,8 @@ endif
 
 ifeq ($(ARCH),i386)
 NATIVE_DEFINES=-DTCC_TARGET_I386
-NATIVE_DEFINES+=\
-  $(if $(wildcard /lib/i386-linux-gnu),-DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\",\
-  $(if $(wildcard /lib/i386-kfreebsd-gnu),-DCONFIG_MULTIARCHDIR=\"i386-kfreebsd-gnu\",\
-  $(if $(wildcard /lib/i386-gnu),-DCONFIG_MULTIARCHDIR=\"i386-gnu\")))
 else ifeq ($(ARCH),x86-64)
 NATIVE_DEFINES=-DTCC_TARGET_X86_64
-NATIVE_DEFINES+=\
-  $(if $(wildcard /usr/lib64),-DCONFIG_LDDIR=\"lib64\",\
-  $(if $(wildcard /lib/x86_64-linux-gnu),-DCONFIG_MULTIARCHDIR=\"x86_64-linux-gnu\",\
-  $(if $(wildcard /lib/x86_64-kfreebsd-gnu),-DCONFIG_MULTIARCHDIR=\"x86_64-kfreebsd-gnu\")))
 endif
 
 ifeq ($(ARCH),arm)
@@ -52,10 +44,8 @@ NATIVE_DEFINES=-DTCC_TARGET_ARM
 NATIVE_DEFINES+=-DWITHOUT_LIBTCC
 ifneq (,$(wildcard /lib/ld-linux-armhf.so.3 /lib/arm-linux-gnueabihf/ld-linux.so.3))
 NATIVE_DEFINES+=-DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
-NATIVE_DEFINES+=$(if $(wildcard /lib/arm-linux-gnueabihf),-DCONFIG_MULTIARCHDIR=\"arm-linux-gnueabihf\")
 else ifneq (,$(wildcard /lib/ld-linux.so.3))
 NATIVE_DEFINES+=-DTCC_ARM_EABI
-NATIVE_DEFINES+=$(if $(wildcard /lib/arm-linux-gnueabi), -DCONFIG_MULTIARCHDIR=\"arm-linux-gnueabi\")
 endif
 NATIVE_DEFINES+=$(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
 endif
index f8619a3..db991ca 100755 (executable)
--- a/configure
+++ b/configure
@@ -260,6 +260,16 @@ if $cc -o $TMPO $TMPC 2> /dev/null ; then
     gcc_major="4"
 fi
 
+if test -z "$cross_prefix" ; then
+ if test -f "/usr/lib64" ; then
+   lddir="lib64"
+ elif test -z "$tcc_crtprefix" ; then # check if system is multiarch
+  if ! test -f $sysroot/usr/lib/crti.o -o test -L $sysroot/usr/lib/crti.o ; then
+   use_multiarch="yes"
+  fi
+ fi
+fi
+
 if test x"$show_help" = "xyes" ; then
 cat << EOF
 Usage: configure [options]
@@ -491,6 +501,12 @@ if test "$have_selinux" = "yes" ; then
   echo "#define HAVE_SELINUX" >> $TMPH
   echo "HAVE_SELINUX=yes" >> config.mak
 fi
+if test "$use_multiarch" = "yes" ; then
+  echo "#define CONFIG_TCC_MULTIARCH" >> $TMPH
+fi
+if test -n "$lddir" ; then
+  echo "#define CONFIG_LDDIR \"$lddir\"" >> $TMPH
+fi
 
 version=`head $source_path/VERSION`
 echo "VERSION=$version" >>config.mak
diff --git a/tcc.h b/tcc.h
index fa09434..3a9c0e8 100644 (file)
--- a/tcc.h
+++ b/tcc.h
 # define CONFIG_SYSROOT ""
 #endif
 
+#if defined(CONFIG_TCC_MULTIARCH) && defined(TCC_IS_NATIVE)
+/* Define architecture */
+# if defined(TCC_TARGET_I386)
+#  define TRIPLET_ARCH "i386"
+# elif defined(TCC_TARGET_X86_64)
+#  define TRIPLET_ARCH "x86_64"
+# elif defined(TCC_TARGET_ARM)
+#  define TRIPLET_ARCH "arm"
+# else
+#  define TRIPLET_ARCH "unknown"
+# endif
+/* Define OS */
+# if defined (__linux__)
+#  define TRIPLET_OS "linux"
+# elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
+#  define TRIPLET_OS "kfreebsd"
+# elif !defined (__GNU__)
+#  define TRIPLET_OS "unknown"
+# endif
+/* Define calling convention and ABI */
+# define TRIPLET_ABI "gnu"
+# ifdef __GNU__
+#  define CONFIG_MULTIARCHDIR TRIPLET_ARCH "-" TRIPLET_ABI
+# else
+#  define CONFIG_MULTIARCHDIR TRIPLET_ARCH "-" TRIPLET_OS "-" TRIPLET_ABI
+# endif
+#endif
+
 #ifndef CONFIG_LDDIR
 # ifdef CONFIG_MULTIARCHDIR
 #  define CONFIG_LDDIR "lib/" CONFIG_MULTIARCHDIR