Source: gcl
Version: 2.6.12-76
Tags: patch upstream
User: helm...@debian.org
Usertags: rebootstrap

gcl fails to cross build from source, because it uses AC_RUN_IFELSE a
lot. As it happens, AC_RUN_IFELSE does not work during cross compilation
at all (because you cannot run stuff). I'm attaching a patch that fixes
many instances:
 * Often AC_RUN_IFELSE can simply be replaced with AC_COMPILE_IFELSE as
   the property being tested manifests itself as a compile error, or it
   can be turned into a compile error e.g. using #error.
 * Consider using AC_CHECK_SIZEOF or AC_CHECK_TYPE where appropriate.
 * The _SC_CLK_TCK check is entirely broken and nobody ever noticed.
 * Don't run a bare "gcc" or "cpp". Always use variables such as $CC.

The attached patch does not fix all. Think of it more of a test: Is it
something that you can apply? It removes quite a bit of complexity and
thus improves maintainability.

Please close this bug if you fix most or all of the AC_RUN_IFELSE from
my patch. I'll look into writing another one then. If the patch is not
something you can take, please explain why.

Helmut
--- gcl-2.6.12.orig/configure.in
+++ gcl-2.6.12/configure.in
@@ -190,10 +190,9 @@
     AC_MSG_CHECKING([for CFLAG $1])
     CFLAGS_ORI=$CFLAGS
     CFLAGS="$CFLAGS -Werror $1 `echo $1|sed 's,-Wno-,-W,1'`"
-    AC_RUN_IFELSE(
+    AC_COMPILE_IFELSE(
 	[AC_LANG_PROGRAM([[]],[[]])],
 	[CFLAGS="$CFLAGS_ORI $1";AC_MSG_RESULT([yes]);return 0],
-	[AC_MSG_RESULT([no])],
 	[AC_MSG_RESULT([no])])
     CFLAGS=$CFLAGS_ORI
     return 1
@@ -218,10 +217,9 @@
     AC_MSG_CHECKING([for LDFLAG $1])
     LDFLAGS_ORI=$LDFLAGS
     LDFLAGS="$LDFLAGS -Werror $1"
-    AC_RUN_IFELSE(
+    AC_COMPILE_IFELSE(
 	[AC_LANG_PROGRAM([[]],[[]])],
 	[LDFLAGS="$LDFLAGS_ORI $1";AC_MSG_RESULT([yes]);return 0],
-	[AC_MSG_RESULT([no])],
 	[AC_MSG_RESULT([no])])
     LDFLAGS=$LDFLAGS_ORI
     return 1
@@ -267,16 +265,14 @@
 add_args_to_ldflags -no-pie -Wl,-z,lazy
 
 AC_MSG_CHECKING([for clang])
-AC_RUN_IFELSE(
+AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM([[
-			 #ifdef __clang__
-			 #define RET 0
-			 #else
-			 #define RET 1
+			 #ifndef __clang__
+			 #error not clang
 			 #endif
 		     ]],
 		     [[
-			 return RET;
+			 return 0;
 		     ]])],
     [AC_MSG_RESULT([yes])
      clang="yes"
@@ -486,45 +482,17 @@
 
 AC_CHECK_HEADERS(
     [setjmp.h],
-    [AC_MSG_CHECKING([sizeof jmp_buf])
-     AC_RUN_IFELSE(
-	 [AC_LANG_PROGRAM(
-		 [[
-		     #include <stdio.h>
-		     #include <setjmp.h>
-		 ]],
-		 [[
-		     FILE *fp=fopen("conftest1","w");
-		     fprintf(fp,"%lu\n",sizeof(jmp_buf));
-		     fclose(fp);
-		 ]])],
-	 [sizeof_jmp_buf=`cat conftest1`
-	  AC_MSG_RESULT($sizeof_jmp_buf)
-	  AC_DEFINE_UNQUOTED(SIZEOF_JMP_BUF,$sizeof_jmp_buf,[sizeof jmp_buf])],
-	 [AC_MSG_RESULT([no])])])
+    [AC_CHECK_SIZEOF([jmp_buf],,[#include <setjmp.h>])
+     sizeof_jmp_buf=$SIZEOF_jmp_buf
+     AS_IF([test "$sizeof_jmp_buf" = 0],,[
+	  AC_DEFINE_UNQUOTED(SIZEOF_JMP_BUF,$sizeof_jmp_buf,[sizeof jmp_buf])])])
 
 # sysconf
 AC_CHECK_HEADERS(
     [unistd.h],
     [AC_CHECK_LIB(
 	    [c],[sysconf],
-	    [AC_MSG_CHECKING([_SC_CLK_TCK])
-	     hz=0
-	     AC_RUN_IFELSE(
-		 [AC_LANG_PROGRAM(
-			 [[
-			     #include <unistd.h>
-			     #include <stdio.h>
-			 ]],
-			 [[
-			     FILE *fp=fopen("conftest1","w");
-			     fprintf(fp,"%lu\n",sysconf(_SC_CLK_TCK));
-			     fclose(fp);
-			 ]],
-			 [hz=`cat conftest1`
-			  AC_DEFINE_UNQUOTED(HZ,$hz,[time system constant])])])
-	     AC_MSG_RESULT($hz)])])
-
+	    AC_DEFINE_UNQUOTED([HZ],[0],[This has always been 0, because the check was long broken. Better not change.]))])
 
 rm -f makedefsafter
 
@@ -537,23 +505,21 @@
 	[AC_CHECK_LIB(
 		[gmp],[__gmpz_init],
 		[AC_MSG_CHECKING([for external gmp version])
-		 AC_RUN_IFELSE(
+		 AC_COMPILE_IFELSE(
 		     [AC_LANG_PROGRAM(
 			     [[
 				 #include <gmp.h>
 			     ]],
 			     [[
-				 #if __GNU_MP_VERSION > 3
-				 return 0;
-				 #else
-				 return -1;
+				 #if __GNU_MP_VERSION <= 3
+				 #error gmp too old
 				 #endif
 			     ]])],
 		     [AC_MSG_RESULT([good])
 		      TLIBS="$TLIBS -lgmp"
 		      echo "#include \"gmp.h\"" >foo.c
 		      echo "int main() {return 0;}" >>foo.c
-		      MP_INCLUDE=`cpp foo.c | $AWK '/(\/|\\\\)gmp.h/ {if (!i) print $3;i=1}' | tr -d '"'`
+		      MP_INCLUDE=`$CC -E foo.c | $AWK '/(\/|\\\\)gmp.h/ {if (!i) print $3;i=1}' | tr -d '"'`
 		      rm -f foo.c])])])
     
     if test "$MP_INCLUDE" = "" ; then
@@ -626,42 +592,29 @@
 fi
 rm -f foo.c foo.o foo map
 
-AC_MSG_CHECKING([for size of gmp limbs])
-AC_RUN_IFELSE([AC_LANG_PROGRAM([[
-				   #include <stdio.h>
-				   #include "$MP_INCLUDE"
-			       ]],
-			       [[
-				   FILE *fp=fopen("conftest1","w");
-				   fprintf(fp,"%u",sizeof(mp_limb_t));
-				   fclose(fp);
-			       ]])],[mpsize=`cat conftest1`],[AC_MSG_ERROR([Cannot determine mpsize])])
-AC_DEFINE_UNQUOTED(MP_LIMB_BYTES,$mpsize,[sizeof mp_limb in gmp library])
-AC_MSG_RESULT($mpsize) 
+AC_CHECK_SIZEOF([mp_limb_t],,[#include "$MP_INCLUDE"])
+AS_IF([test "$SIZEOF_mp_limb_t" = 0],[AC_MSG_ERROR([Cannot determine mpsize])])
+AC_DEFINE_UNQUOTED(MP_LIMB_BYTES,$SIZEOF_mp_limb_t,[sizeof mp_limb in gmp library])
 
 AC_MSG_CHECKING([_SHORT_LIMB])
-AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 				   #include <stdio.h>
 				   #include "$MP_INCLUDE"
 			       ]],
 			       [[
-				   #ifdef _SHORT_LIMB
-				   return 0;
-				   #else
-				   return 1;
+				   #ifndef _SHORT_LIMB
+				   #error no short gmp3 limbs
 				   #endif
 			       ]])],[AC_DEFINE(__SHORT_LIMB,1,[short gmp3 limbs]) AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])
 
 AC_MSG_CHECKING([_LONG_LONG_LIMB])
-AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 				   #include <stdio.h>
 				   #include "$MP_INCLUDE"
 			       ]],
 			       [[
-				   #ifdef _LONG_LONG_LIMB
-				   return 0;
-				   #else
-				   return 1;
+				   #ifndef _LONG_LONG_LIMB
+				   #error no long gmp3 limbs
 				   #endif
 			       ]])],[AC_DEFINE(__LONG_LONG_LIMB,1,[long gmp3 limbs]) AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])
 
@@ -717,31 +670,18 @@
 	    # Old binutils appear to need CONST defined to const
 	    #
 	    AC_MSG_CHECKING([need to define CONST for bfd])
-	    AC_RUN_IFELSE(
-		[AC_LANG_PROGRAM(
-			[[
-			    #define IN_GCC
-			    #include <bfd.h>
-			]],
-			[[
-			    symbol_info t;
-			]])],
-		AC_MSG_RESULT([no]),
-		AC_RUN_IFELSE(
-		    [AC_LANG_PROGRAM(
-			    [[
+	    AC_CHECK_TYPE([symbol_info],[AC_MSG_RESULT([no])],[
+		AC_CHECK_TYPE([symbol_info],[AC_DEFINE(NEED_CONST,1,[binutils requires CONST definition])
+			    ],[AC_MSG_ERROR([cannot use bfd])
+			    ],[[
 				#define CONST const
 				#define IN_GCC
 				#include <bfd.h>
-			    ]],
-			    [[
-				symbol_info t;
 			    ]])],
-		    AC_MSG_RESULT([yes]) 
-		    AC_DEFINE(NEED_CONST,1,[binutils requires CONST definition]),
-		    AC_MSG_ERROR([cannot use bfd]),
-		    AC_MSG_ERROR([cannot use bfd])),
-		AC_MSG_ERROR([cannot use bfd]))
+			[[
+			    #define IN_GCC
+			    #include <bfd.h>
+			]])
 	    ,,-liberty))
     
     AC_DEFINE(HAVE_LIBBFD,1,[use libbfd])
@@ -751,7 +691,7 @@
     #
     
     AC_MSG_CHECKING(for useable bfd_boolean)
-    AC_RUN_IFELSE(
+    AC_COMPILE_IFELSE(
 	[AC_LANG_PROGRAM(
 		[[
 		    #define IN_GCC
@@ -760,8 +700,7 @@
 		]],
 		[[]])],
 	[AC_MSG_RESULT(yes) 
-	 AC_DEFINE(HAVE_BFD_BOOLEAN,1,[bfd_boolean defined])],
-	[AC_MSG_RESULT(no)])
+	 AC_DEFINE(HAVE_BFD_BOOLEAN,1,[bfd_boolean defined])])
     
     #
     # bfd_link_info.output_bfd minimal configure change check

Reply via email to