From 7390f29cfc9a3cc0636e20f84f24fbd05f821720 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 30 Oct 2022 08:25:45 +0000 Subject: build system: allow building with w64devkit Make some adjustments to the build system to allow busybox-w32 to be built with w64devkit: - Strip drive prefix from CURDIR in Makefile to avoid confusing make with colons. - Limit file redirection to a subshell in the usage_compressed and embedded_scripts scripts. Otherwise it isn't possible to move the open generated file on Windows. - Change the option tests in Kbuild.include to allow for /dev/null not existing on Windows. - Create host binaries without a '.exe' extension. Otherwise they're rebuilt more often than necessary. - Modify split-include.c to allow for Windows' popen() not expanding wildcards. (GitHub issue #239) --- Makefile | 4 ++++ applets/usage_compressed | 2 ++ scripts/Kbuild.include | 10 +++++----- scripts/Makefile.host | 21 +++++++++++++++++++-- scripts/basic/split-include.c | 11 +++++++++++ scripts/embedded_scripts | 2 ++ 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index a65cd61a4..333795e0d 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,10 @@ SUBLEVEL = 0 EXTRAVERSION = .git NAME = Unnamed +# Colon is used as a separator in makefiles. Strip any drive prefix +# from the current directory to avoid confusion. +CURDIR := $(lastword $(subst :, ,$(CURDIR))) + # *DOCUMENTATION* # To see a list of typical targets execute "make help" # More info can be located in ./README diff --git a/applets/usage_compressed b/applets/usage_compressed index 36fc2a007..94d70f33b 100755 --- a/applets/usage_compressed +++ b/applets/usage_compressed @@ -16,6 +16,7 @@ if test $? != 0; then exit 1 fi +( exec >"$target.$$" echo '#define UNPACKED_USAGE "" \' @@ -58,5 +59,6 @@ echo '#define PACKED_USAGE \' -e 's/\(...\)/0\1,/g' \ -e 's/$/ \\/' echo '' +) mv -- "$target.$$" "$target" diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 5b4db5c2c..b61ff8b42 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -52,25 +52,25 @@ endef # as-option # Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,) -as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o /dev/null \ - -xassembler /dev/null > /dev/null 2>&1; then echo "$(1)"; \ +as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o - \ + -xassembler - /dev/null 2>&1; then echo "$(1)"; \ else echo "$(2)"; fi ;) # cc-option # Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586) -cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ +cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o - -xc - /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) # hostcc-option # Usage: hostcflags-y += $(call hostcc-option, -march=winchip-c6, -march=i586) -hostcc-option = $(shell if $(HOSTCC) $(HOSTCFLAGS) $(1) -S -o /dev/null -xc /dev/null \ +hostcc-option = $(shell if $(HOSTCC) $(HOSTCFLAGS) $(1) -S -o - -xc - /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) # cc-option-yn # Usage: flag := $(call cc-option-yn, -march=winchip-c6) -cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ +cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o - -xc - /dev/null 2>&1; then echo "y"; else echo "n"; fi;) # cc-option-align diff --git a/scripts/Makefile.host b/scripts/Makefile.host index 2e628508d..0deec32e6 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -92,13 +92,30 @@ endif hostc_flags = -Wp,-MD,$(depfile) $(__hostc_flags) hostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags) +# Programs built for use on the host are defined without a suffix +# (usually '.exe' on Windows). Rather than adjust all the makefiles +# force a suffix of '.' if the host platform is mingw32. This will +# result in binaries with no suffix. +# +# It's not a big deal if this doesn't work. MSYS2 doesn't need it +# and the downside is just that the programs will be rebuilt more +# often than really needed. +# +host_target := $(shell $(HOSTCC) -v 2>&1 | grep ^Target:) +host_platform := $(lastword $(subst -, ,$(host_target))) +ifeq ($(host_platform),mingw32) +dot := . +else +dot := +endif + ##### # Compile programs on the host # Create executable from a single .c file # host-csingle -> Executable quiet_cmd_host-csingle = HOSTCC $@ - cmd_host-csingle = $(HOSTCC) $(hostc_flags) -o $@ $< \ + cmd_host-csingle = $(HOSTCC) $(hostc_flags) -o $@$(dot) $< \ $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) $(host-csingle): %: %.c FORCE $(call if_changed_dep,host-csingle) @@ -106,7 +123,7 @@ $(host-csingle): %: %.c FORCE # Link an executable based on list of .o files, all plain c # host-cmulti -> executable quiet_cmd_host-cmulti = HOSTLD $@ - cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \ + cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@$(dot) \ $(addprefix $(obj)/,$($(@F)-objs)) \ $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) $(host-cmulti): %: $(host-cobjs) $(host-cshlib) FORCE diff --git a/scripts/basic/split-include.c b/scripts/basic/split-include.c index 290bea2fb..a85ede8ef 100644 --- a/scripts/basic/split-include.c +++ b/scripts/basic/split-include.c @@ -197,13 +197,21 @@ int main(int argc, const char * argv []) * So by having an initial \n, strstr will find exact matches. */ +#ifdef __MINGW32__ + fp_find = popen("find . -type f -name \"*.h\" -print", "r"); +#else fp_find = popen("find * -type f -name \"*.h\" -print", "r"); +#endif if (fp_find == 0) ERROR_EXIT( "find" ); line[0] = '\n'; while (fgets(line+1, buffer_size, fp_find)) { +#ifdef __MINGW32__ + line[2] = '\n'; +# define line (line + 2) +#endif if (strstr(list_target, line) == NULL) { /* @@ -226,6 +234,9 @@ int main(int argc, const char * argv []) ERROR_EXIT(line); } } +#ifdef __MINGW32__ +# undef line +#endif } if (pclose(fp_find) != 0) diff --git a/scripts/embedded_scripts b/scripts/embedded_scripts index 205ac591a..8407c1f78 100755 --- a/scripts/embedded_scripts +++ b/scripts/embedded_scripts @@ -90,6 +90,7 @@ concatenate_scripts() { done } +( exec >"$target.$$" if [ $n -ne 0 ] @@ -127,5 +128,6 @@ then -e 's/$/ \\/' printf '\n' fi +) mv -- "$target.$$" "$target" -- cgit v1.2.3-55-g6feb