+2024-10-31 Bruno Haible <bruno@clisp.org>
+
+ crc: Support generating the tables also when cross-compiling.
+ * m4/build-cc.m4: New file.
+ * modules/crc (Files): Add it.
+ (configure.ac): Invoke gl_BUILD_CC. Don't set GL_CROSS_COMPILING.
+ (Makefile.am): Use $(BUILD_CC) etc. instead of $(CC) etc.
+
2024-10-31 Bruno Haible <bruno@clisp.org>
malloc-posix, realloc-posix: Fix incorrect expansion of AC_FUNC_MALLOC.
--- /dev/null
+# build-cc.m4
+# serial 1
+dnl Copyright (C) 2024 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl This file is offered as-is, without any warranty.
+
+dnl Written by Bruno Haible.
+
+dnl When the build environment ($build_os) is different from the target runtime
+dnl environment ($host_os), a build step that requires execution of the built
+dnl program must use a native compiler.
+dnl In order to specify this compiler, the user can specify the following
+dnl variables (as environment variables or as assignment arguments to
+dnl 'configure'):
+dnl - BUILD_CC - the C compiler
+dnl - BUILD_CPPFLAGS - compiler options used during preprocessing
+dnl - BUILD_CFLAGS - compiler options used during compilation to object code
+dnl - BUILD_LDFLAGS - compiler options used durint linking
+dnl These are the same conventions as used e.g. by glibc.
+dnl
+dnl gl_BUILD_CC provides these variables.
+dnl If not cross-compiling, the values are the same as those of
+dnl CC, CPPFLAGS, CFLAGS, LDFLAGS respectively (so that the user does not have
+dnl to specify them twice).
+dnl If no native compiler was found, BUILD_CC is set to empty.
+dnl
+dnl This macro is intentionally simple.
+dnl If you need things like BUILD_OBJEXT, BUILD_EXEEXT, etc., consider using
+dnl AX_PROG_CC_FOR_BUILD from the Autoconf Archive.
+
+AC_DEFUN_ONCE([gl_BUILD_CC],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ dnl $cross_compiling is 'yes' if executables created by the C compiler $CC
+ dnl can be run in the build environment, or 'no' otherwise.
+ if test $cross_compiling = yes; then
+ if test -z "$BUILD_CC"; then
+ dnl If the user has not specified BUILD_CC, try gcc, then cc.
+ AC_CHECK_PROGS([BUILD_CC], [gcc cc])
+ fi
+ else
+ BUILD_CC="$CC"
+ BUILD_CPPFLAGS="$CPPFLAGS"
+ BUILD_CFLAGS="$CFLAGS"
+ BUILD_LDFLAGS="$LDFLAGS"
+ fi
+ AC_SUBST([BUILD_CC])
+ AC_SUBST([BUILD_CPPFLAGS])
+ AC_SUBST([BUILD_CFLAGS])
+ AC_SUBST([BUILD_LDFLAGS])
+])
lib/crc.c
lib/crc-generate-table.c
m4/crc.m4
+m4/build-cc.m4
Depends-on:
stdint
configure.ac:
AC_REQUIRE([gl_CRC_SLICE_BY_8])
-# Set to 'yes' if executables created by the C compiler $CC can be run in the
-# build environment, or to 'no' otherwise.
-GL_CROSS_COMPILING=$cross_compiling
-AC_SUBST([GL_CROSS_COMPILING])
+gl_BUILD_CC
AC_PROG_MKDIR_P
Makefile.am:
lib_SOURCES += crc.c
# Generate crc-sliceby8.h.
-# Do so only when not cross-compiling.
+# Use a native compiler when 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
- if test @GL_CROSS_COMPILING@ = no; then \
+ if test -n '$(BUILD_CC)'; 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) \
+ && $(BUILD_CC) $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) $(BUILD_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; \