Another attempt to "detect" multiarch
authorThomas Preud'homme <robotux@celest.fr>
Thu, 14 Feb 2013 14:39:35 +0000 (14 15:39 +0100)
committerThomas Preud'homme <robotux@celest.fr>
Thu, 14 Feb 2013 14:39:35 +0000 (14 15:39 +0100)
configure
conftest.c

index 1f4a17d..e2430db 100755 (executable)
--- a/configure
+++ b/configure
@@ -296,7 +296,13 @@ if test -z "$cross_prefix" ; then
     gcc_major="$($CONFTEST version)"
     gcc_minor="$($CONFTEST minor)"
     if test "$mingw32" = "no" ; then
-      libc_dir="$(ldd $CONFTEST | grep libc.so | sed 's|[^/]*/\(.*/\)[^/]*|\1|')"
+      triplet="$($CONFTEST triplet)"
+      if test -f "/usr/lib/$triplet/crti.o" ; then
+        tcc_lddir="lib/$triplet"
+        multiarch_triplet="$triplet"
+      elif test -f "usr/lib64/crti.o" ; then
+        tcc_lddir="lib64"
+      fi
 
 # gr: FIXME
 #  ldd $CONFTEST gives (ubuntu 8)
@@ -306,13 +312,13 @@ if test -z "$cross_prefix" ; then
 #  result is crap:
 #        CONFIG_LDDIR="lib/tls/i686/cmov"
 #        CONFIG_MUADIR="tls/i686/cmov"
-
-      multiarch_triplet=${libc_dir#*/}
-      multiarch_triplet=${multiarch_triplet%/}
-      tcc_lddir="${libc_dir%%/*}"
-      if test -n "$multiarch_triplet" ; then
-        tcc_lddir="$tcc_lddir/$multiarch_triplet"
-      fi
+#
+#      multiarch_triplet=${libc_dir#*/}
+#      multiarch_triplet=${multiarch_triplet%/}
+#      tcc_lddir="${libc_dir%%/*}"
+#      if test -n "$multiarch_triplet" ; then
+#        tcc_lddir="$tcc_lddir/$multiarch_triplet"
+#      fi
 
 # gr: maybe for after the release:
 #      tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
index a803bff..9eae11a 100644 (file)
@@ -1,27 +1,59 @@
 #include <stdio.h>
 
+/* Define architecture */
+#if defined(__i386__)
+# define TRIPLET_ARCH "i386"
+#elif defined(__x86_64__)
+# define TRIPLET_ARCH "x86_64"
+#elif defined(__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 TRIPLET TRIPLET_ARCH "-" TRIPLET_ABI
+#else
+# define TRIPLET TRIPLET_ARCH "-" TRIPLET_OS "-" TRIPLET_ABI
+#endif
+
 int main(int argc, char *argv[])
 {
     switch(argc == 2 ? argv[1][0] : 0) {
-#ifdef __GNUC__
-        case 'v':
-            printf("%d\n", __GNUC__);
+        case 'b':
+        {
+            volatile unsigned foo = 0x01234567;
+            puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes");
             break;
+        }
+#ifdef __GNUC__
         case 'm':
             printf("%d\n", __GNUC_MINOR__);
             break;
-#else
         case 'v':
+            printf("%d\n", __GNUC__);
+            break;
+#else
         case 'm':
+        case 'v':
             puts("0");
             break;
 #endif
-        case 'b':
-        {
-            volatile unsigned foo = 0x01234567;
-            puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes");
+        case 't':
+            puts(TRIPLET);
             break;
-        }
         case -1:
             /* to test -Wno-unused-result */
             fread(NULL, 1, 1, NULL);