[PATCH] use a compile time assert to allow configure to work when cross compiling

Jim Radford radford at galvanix.net
Tue Oct 7 04:41:13 GMT 2008


This patch allows ./configure to run out of the box when cross
compiling samba-3.2.4 by using compile asserts instead of runtime
checks.

This technique has only been tested with gcc, so I added an assert for
the compile assert itself to catch compilers that it doesn't work
with.

-Jim

diff -ru samba-3.2.4.orig/source/configure.in samba-3.2.4/source/configure.in
--- samba-3.2.4.orig/source/configure.in	2008-10-06 21:12:35.000000000 -0700
+++ samba-3.2.4/source/configure.in	2008-10-06 21:36:10.000000000 -0700
@@ -275,6 +275,8 @@
 fi
 AC_SUBST(BROKEN_CC)
 
+AC_TRY_COMPILE([],[(void)sizeof(char[-1])],AC_MSG_ERROR([configure's compilation assert doesn't work with $CC]))
+
 dnl Check if the C compiler understands -Werror
 AC_CACHE_CHECK([that the C compiler understands -Werror],samba_cv_HAVE_Werror, [
  AC_TRY_RUN_STRICT([
@@ -325,25 +327,11 @@
 # a runtime test is needed here
 AC_SUBST(PIDL_ARGS)
 AC_CACHE_CHECK([that the C compiler understands negative enum values],samba_cv_CC_NEGATIVE_ENUM_VALUES, [
-    AC_TRY_RUN(
+    AC_TRY_COMPILE([],
 [
-	#include <stdio.h>
 	enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
-	int main(void) {
-		enum negative_values v1 = NEGATIVE_VALUE;
-		unsigned v2 = NEGATIVE_VALUE;
-
-		if (v1 != 0xFFFFFFFF) {
-			printf("%u != 0xFFFFFFFF\n", v1);
-			return 1;
-		}
-		if (v2 != 0xFFFFFFFF) {
-			printf("%u != 0xFFFFFFFF\n", v2);
-			return 1;
-		}
-
-		return 0;
-	}
+	(void)sizeof(char[1-2*(            (unsigned)NEGATIVE_VALUE != 0xFFFFFFFF)]);
+	(void)sizeof(char[1-2*((enum negative_values)NEGATIVE_VALUE != 0xFFFFFFFF)]);
 ],
 	samba_cv_CC_NEGATIVE_ENUM_VALUES=yes,samba_cv__CC_NEGATIVE_ENUM_VALUES=no)])
 if test x"$samba_cv_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
@@ -1187,22 +1175,12 @@
 case "$host_os" in
     *linux*)
        # glibc <= 2.3.2 has a broken getgrouplist
-       AC_TRY_RUN([
-#include <unistd.h>
+       AC_TRY_COMPILE([
 #include <sys/utsname.h>
-main() {
-       /* glibc up to 2.3 has a broken getgrouplist */
+],[
 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
-       int libc_major = __GLIBC__;
-       int libc_minor = __GLIBC_MINOR__;
-
-       if (libc_major < 2)
-              exit(1);
-       if ((libc_major == 2) && (libc_minor <= 3))
-              exit(1);
+       (void)sizeof(char[1-2*(__GLIBC__ < 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)]);
 #endif
-       exit(0);
-}
 ], [linux_getgrouplist_ok=yes], [linux_getgrouplist_ok=no])
        if test x"$linux_getgrouplist_ok" = x"yes"; then
           AC_DEFINE(HAVE_GETGROUPLIST, 1, [Have good getgrouplist])


More information about the samba-technical mailing list