Simon Josefsson wrote: > I merged this now, thank you! And here's the cross-compilation handling that I promised to add.
2024-10-31 Bruno Haible <br...@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. diff --git a/lib/crc-generate-table.c b/lib/crc-generate-table.c index 314bf000ee..83a99baca0 100644 --- a/lib/crc-generate-table.c +++ b/lib/crc-generate-table.c @@ -16,8 +16,6 @@ /* Written by Sam Russell. */ -#include <config.h> - #include <stdio.h> #include <stdlib.h> diff --git a/modules/crc b/modules/crc index d62650b28a..e8b0d91ea6 100644 --- a/modules/crc +++ b/modules/crc @@ -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