Skip to content

Commit

Permalink
build system: allow building with w64devkit
Browse files Browse the repository at this point in the history
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 rmyorston#239)
  • Loading branch information
rmyorston committed Oct 30, 2022
1 parent d71cb67 commit 7390f29
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions applets/usage_compressed
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if test $? != 0; then
exit 1
fi

(
exec >"$target.$$"

echo '#define UNPACKED_USAGE "" \'
Expand Down Expand Up @@ -58,5 +59,6 @@ echo '#define PACKED_USAGE \'
-e 's/\(...\)/0\1,/g' \
-e 's/$/ \\/'
echo ''
)

mv -- "$target.$$" "$target"
10 changes: 5 additions & 5 deletions scripts/Kbuild.include
Original file line number Diff line number Diff line change
Expand Up @@ -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 > /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 \
> /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 \
> /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 \
> /dev/null 2>&1; then echo "y"; else echo "n"; fi;)

# cc-option-align
Expand Down
21 changes: 19 additions & 2 deletions scripts/Makefile.host
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,38 @@ 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)

# 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
Expand Down
11 changes: 11 additions & 0 deletions scripts/basic/split-include.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
/*
Expand All @@ -226,6 +234,9 @@ int main(int argc, const char * argv [])
ERROR_EXIT(line);
}
}
#ifdef __MINGW32__
# undef line
#endif
}

if (pclose(fp_find) != 0)
Expand Down
2 changes: 2 additions & 0 deletions scripts/embedded_scripts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ concatenate_scripts() {
done
}

(
exec >"$target.$$"

if [ $n -ne 0 ]
Expand Down Expand Up @@ -127,5 +128,6 @@ then
-e 's/$/ \\/'
printf '\n'
fi
)

mv -- "$target.$$" "$target"

0 comments on commit 7390f29

Please sign in to comment.