]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
build: support cross-compiling directly from git checkout
authorCollin Funk <collin.funk1@gmail.com>
Fri, 16 May 2025 05:02:26 +0000 (22:02 -0700)
committerPádraig Brady <P@draigBrady.com>
Sat, 17 May 2025 08:17:12 +0000 (09:17 +0100)
* src/local.mk: Compile the make-prime-list in a temporary directory
using $(BUILD_CC) so it can be run even when $(CC) is a cross-compiler.
Add some comments.
(noinst_PROGRAMS): Remove src/make-prime-list.
(src_make_prime_list_LDADD): Remove variable.
* src/make-prime-list.c: Don't include config.h and attributes.h.
Remove unnecessary #undefs
(ATTRIBUTE_CONST, ATTRIBUTE_MALLOC): Define for the host compiler.
Fixes https://bugs.gnu.org/78377

.gitignore
cfg.mk
src/local.mk
src/make-prime-list.c

index bafeb2bc51c8b91231689af367ce8b6cc7c3dfc5..ba7344994a98ae4b71d91f3f7f1ea956bb6254af 100644 (file)
 /src/fs-kernel-magic
 /src/fs-latest-magic.h
 /src/fs-magic
-/src/make-prime-list
 /src/primes.h
 /src/single-binary.mk
 /src/version.c
diff --git a/cfg.mk b/cfg.mk
index e147d4ae7da91db466f6e905a44795e3839df79a..fa032f52e56ff78eec5df163a8ad05b40e04dca4 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -869,7 +869,7 @@ exclude_file_name_regexp--sc_system_h_headers = \
   ^src/((system|copy|chown-core|find-mount-point)\.h|make-prime-list\.c)$$
 
 _src := (false|lbracket|chown-(chgrp|chown)
-_src := $(_src)|ls-(dir|ls|vdir)|tac-pipe|uname-(arch|uname))
+_src := $(_src)|ls-(dir|ls|vdir)|make-prime-list|tac-pipe|uname-(arch|uname))
 _gl_src = (xdecto.max|cl-strtold)
 exclude_file_name_regexp--sc_require_config_h_first = \
   (^lib/buffer-lcm\.c|gl/lib/$(_gl_src)\.c|src/$(_src)\.c)$$
@@ -921,8 +921,10 @@ exclude_file_name_regexp--sc_prohibit_operator_at_end_of_line = \
 exclude_file_name_regexp--sc_error_message_uppercase = ^src/factor\.c$$
 exclude_file_name_regexp--sc_prohibit_atoi_atof = ^src/make-prime-list\.c$$
 
-# Exception here as we don't want __attribute elided on non GCC
-exclude_file_name_regexp--sc_prohibit-gl-attributes = ^src/libstdbuf\.c$$
+# Exception here as we don't want __attribute elided on non GCC for stdbuf
+# and we don't want to depend on gnulib for make-prime-list
+exclude_file_name_regexp--sc_prohibit-gl-attributes = \
+  ^src/(make-prime-list|libstdbuf)\.c$$
 
 exclude_file_name_regexp--sc_prohibit_uppercase_id_est = \.diff$$
 exclude_file_name_regexp--sc_ensure_dblspace_after_dot_before_id_est = \.diff$$
index fd9dc81c278f76b097eb280098cdce35b12e404d..68c7db63a8565e7059530276220676d563c3f504 100644 (file)
@@ -36,8 +36,7 @@ pkglibexec_PROGRAMS = @pkglibexec_PROGRAMS@
 
 # Needed by the testsuite.
 noinst_PROGRAMS =              \
-  src/getlimits                        \
-  src/make-prime-list
+  src/getlimits
 
 noinst_HEADERS =               \
   src/chown.h                  \
@@ -150,11 +149,6 @@ src_ln_LDADD = $(LDADD)
 src_logname_LDADD = $(LDADD)
 src_ls_LDADD = $(LDADD)
 
-# This must *not* depend on anything in lib/, since it is used to generate
-# src/primes.h.  If it depended on libcoreutils.a, that would pull all lib/*.c
-# into BUILT_SOURCES.
-src_make_prime_list_LDADD =
-
 src_md5sum_LDADD = $(LDADD)
 src_mkdir_LDADD = $(LDADD)
 src_mkfifo_LDADD = $(LDADD)
@@ -556,15 +550,24 @@ $(top_srcdir)/src/dircolors.h: src/dcgen src/dircolors.hin
 # and it needs to be built on a widest-known-int architecture, so it's
 # built only if absent.  It is not cleaned because we don't want to
 # insist that maintainers must build on hosts that support the widest
-# known ints (currently 128-bit).
+# known ints (currently 128-bit).  It is built in a temporary directory
+# to avoid Gnulib and allow cross-compilers.  The BUILD_* definitions
+# come from Gnulib's gl_BUILD_CC which is invoked for the crc module.
 BUILT_SOURCES += $(top_srcdir)/src/primes.h
-$(top_srcdir)/src/primes.h:
-       $(AM_V_at)${MKDIR_P} src
-       $(MAKE) src/make-prime-list$(EXEEXT)
-       $(AM_V_GEN)rm -f $@ $@-t
-       $(AM_V_at)src/make-prime-list$(EXEEXT) 5000 > $@-t
-       $(AM_V_at)chmod a-w $@-t
-       $(AM_V_at)mv $@-t $@
+$(top_srcdir)/src/primes.h: $(top_srcdir)/src/make-prime-list.c
+       $(AM_V_GEN)if test -n '$(BUILD_CC)'; then \
+         $(MKDIR_P) $(top_srcdir)/src/primes-tmp \
+         && (cd $(top_srcdir)/src/primes-tmp \
+             && $(BUILD_CC) $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) \
+               $(BUILD_LDFLAGS) -o make-prime-list$(EXEEXT) \
+               $(abs_top_srcdir)/src/make-prime-list.c) \
+         && rm -f $@ $@-t \
+         && $(top_srcdir)/src/primes-tmp/make-prime-list$(EXEEXT) \
+           5000 > $@-t \
+         && chmod a-w $@-t \
+         && mv $@-t $@ \
+         && rm -rf $(top_srcdir)/src/primes-tmp; \
+       fi
 
 # false exits nonzero even with --help or --version.
 # test doesn't support --help or --version.
index 35cf3627c4647c5b5ae9b5235b51baf1dde47d98..1b4c50f34de5f7c2d6dc38226bab5ab8f6751bf8 100644 (file)
@@ -17,9 +17,6 @@ PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 You should have received a copy of the GNU General Public License along with
 this program.  If not, see https://www.gnu.org/licenses/.  */
 
-#include <config.h>
-
-#include <attribute.h>
 #include <inttypes.h>
 
 #include <limits.h>
@@ -29,11 +26,20 @@ this program.  If not, see https://www.gnu.org/licenses/.  */
 #include <stdlib.h>
 #include <errno.h>
 
-/* Deactivate "rpl_"-prefixed definitions of these symbols.  */
-#undef fclose
-#undef free
-#undef malloc
-#undef strerror
+/* This program is compiled in a separate directory to avoid linking to Gnulib
+   which may be cross-compiled.  Therefore, we also do not have config.h and
+   attribute.h.  Just define what we need.  */
+#if 2 < __GNUC__ + (95 <= __GNUC_MINOR__)
+# define ATTRIBUTE_CONST __attribute__ ((__const__))
+#else
+# define ATTRIBUTE_CONST
+#endif
+#if 3 < __GNUC__
+# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
+#else
+# define ATTRIBUTE_MALLOC
+#endif
+
 
 /* An unsigned type that is no narrower than 32 bits and no narrower
    than unsigned int.  It's best to make it as wide as possible.