Detect multiarch triplet and lddir from ldd output
authorThomas Preud'homme <robotux@celest.fr>
Wed, 13 Feb 2013 19:14:13 +0000 (13 20:14 +0100)
committerThomas Preud'homme <robotux@celest.fr>
Wed, 13 Feb 2013 19:14:13 +0000 (13 20:14 +0100)
configure
tcc.h

index 761c20c..425f719 100755 (executable)
--- a/configure
+++ b/configure
@@ -261,12 +261,12 @@ if $cc -o $TMPO $TMPC 2> /dev/null ; then
 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 -L $sysroot/usr/lib/crti.o ; then
-   use_multiarch="yes"
-  fi
+ libc_dir="$(ldd ./print_env_info | grep libc.so | sed 's|[^/]*/\(.*/\)[^/]*|\1|')"
+ multiarch_triplet=${libc_dir#*/}
+ multiarch_triplet=${multiarch_triplet%/}
+ lddir="${libc_dir%%/*}"
+ if test -n "$multiarch_triplet" ; then
+  lddir="$lddir/$multiarch_triplet"
  fi
 fi
 
@@ -501,8 +501,8 @@ 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
+if test -n "$multiarch_triplet" ; then
+  echo "#define CONFIG_MULTIARCHDIR \"$multiarch_triplet\"" >> $TMPH
 fi
 if test -n "$lddir" ; then
   echo "#define CONFIG_LDDIR \"$lddir\"" >> $TMPH
diff --git a/tcc.h b/tcc.h
index 3a9c0e8..e9ce802 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
-# else
-#  define CONFIG_LDDIR "lib"
-# endif
-#endif
-
 /* path to find crt1.o, crti.o and crtn.o */
 #ifndef CONFIG_TCC_CRTPREFIX
 # define CONFIG_TCC_CRTPREFIX CONFIG_SYSROOT "/usr/" CONFIG_LDDIR