+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.
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