]> Savannah Git Hosting - gnulib.git/commitdiff
crc: Don't attempt to run a compiled C program when cross-compiling.
authorBruno Haible <bruno@clisp.org>
Thu, 31 Oct 2024 13:48:35 +0000 (14:48 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 31 Oct 2024 13:48:35 +0000 (14:48 +0100)
* lib/crc-generate-table.c: Don't include config.h.
* modules/crc (configure.ac): Define CROSS_COMPILING variable. Invoke
AC_PROG_MKDIR_P.
(Makefile.am): When cross-compiling, don't regenerate crc-sliceby8.h.
Don't use Gnulib modules while compiling the generator.

ChangeLog
lib/crc-generate-table.c
modules/crc

index cce8ccf7d06588ef0ff2fffb79e8ae735c1c8a0d..5c5fdc6e2adfe9cbde79d025011d960984c41565 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-10-31  Bruno Haible  <bruno@clisp.org>
+
+       crc: Don't attempt to run a compiled C program when cross-compiling.
+       * lib/crc-generate-table.c: Don't include config.h.
+       * modules/crc (configure.ac): Define CROSS_COMPILING variable. Invoke
+       AC_PROG_MKDIR_P.
+       (Makefile.am): When cross-compiling, don't regenerate crc-sliceby8.h.
+       Don't use Gnulib modules while compiling the generator.
+
 2024-10-31  Bruno Haible  <bruno@clisp.org>
 
        crc: Tweak generator.
index 314bf000ee8a322bc36a1634a38f9ae2f15bd761..83a99baca09d339d25c1702265da66edd70909b9 100644 (file)
@@ -16,8 +16,6 @@
 
 /* Written by Sam Russell. */
 
-#include <config.h>
-
 #include <stdio.h>
 #include <stdlib.h>
 
index d62650b28af8e0cc3bd21fcaa82dfaabc6061de0..e8b0d91ea6690950b36b0fd891aafb5a6ee54688 100644 (file)
@@ -13,17 +13,33 @@ endian
 
 configure.ac:
 AC_REQUIRE([gl_CRC_SLICE_BY_8])
+CROSS_COMPILING=$cross_compiling
+AC_SUBST([CROSS_COMPILING])
+AC_PROG_MKDIR_P
 
 Makefile.am:
 lib_SOURCES += crc.c
 
+# Generate crc-sliceby8.h.
+# Do so only when not cross-compiling.
+# Don't use any Gnulib modules (since libgnu.a will only be available after
+# this directory is built!).  Therefore, don't use any of the Automake variables
+# $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(AM_CFLAGS)
+# $(AM_LDFLAGS).  And do the compilation in a temporary directory, where
+# gnulib-generated stdio.h and stdlib.h files are not visible.
 $(srcdir)/crc-sliceby8.h: $(srcdir)/crc-generate-table.c
-       $(COMPILE) $(AM_LDFLAGS) $(LDFLAGS) -o crc-generate-table $(srcdir)/crc-generate-table.c \
-       && ./crc-generate-table $(srcdir)/crc-sliceby8.h-t \
-       && rm -f crc-generate-table \
-       && mv $(srcdir)/crc-sliceby8.h-t $(srcdir)/crc-sliceby8.h
+       if test @CROSS_COMPILING@ = no; then \
+         $(MKDIR_P) crc-tmp \
+         && abs_srcdir=`cd $(srcdir) && pwd` \
+         && (cd crc-tmp \
+             && $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o crc-generate-table $$abs_srcdir/crc-generate-table.c) \
+         && crc-tmp/crc-generate-table $(srcdir)/crc-sliceby8.h-t \
+         && rm -rf crc-tmp \
+         && mv $(srcdir)/crc-sliceby8.h-t $(srcdir)/crc-sliceby8.h; \
+       fi
 BUILT_SOURCES        += crc-sliceby8.h
-MOSTLYCLEANFILES     += crc-sliceby8.h-t crc-generate-table
+MOSTLYCLEANFILES     += crc-sliceby8.h-t crc-tmp/crc-generate-table
+MOSTLYCLEANDIRS      += crc-tmp
 MAINTAINERCLEANFILES += crc-sliceby8.h
 EXTRA_DIST           += crc-sliceby8.h