From: Collin Funk Date: Fri, 16 May 2025 05:02:26 +0000 (-0700) Subject: build: support cross-compiling directly from git checkout X-Git-Tag: v9.8~323 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3844c15934ed232241558f4181163d11739edc4c;p=thirdparty%2Fcoreutils.git build: support cross-compiling directly from git checkout * 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 --- diff --git a/.gitignore b/.gitignore index bafeb2bc51..ba7344994a 100644 --- a/.gitignore +++ b/.gitignore @@ -201,7 +201,6 @@ /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 e147d4ae7d..fa032f52e5 100644 --- 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$$ diff --git a/src/local.mk b/src/local.mk index fd9dc81c27..68c7db63a8 100644 --- a/src/local.mk +++ b/src/local.mk @@ -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. diff --git a/src/make-prime-list.c b/src/make-prime-list.c index 35cf3627c4..1b4c50f34d 100644 --- a/src/make-prime-list.c +++ b/src/make-prime-list.c @@ -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 - -#include #include #include @@ -29,11 +26,20 @@ this program. If not, see https://www.gnu.org/licenses/. */ #include #include -/* 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.