diff --git a/Makefile b/Makefile index 4bf31208..921bc3f4 100644 --- a/Makefile +++ b/Makefile @@ -73,15 +73,16 @@ $(shell mkdir -p "$(initrd_lib_dir)" "$(initrd_bin_dir)") SHELL := /bin/bash .SHELLFLAGS := -o pipefail -c -# If musl-libc is being used in the initrd, set the heads_cc -# variable to point to it. +# Include the musl-cross module early so that $(CROSS) will +# be defined prior to any other module. +include modules/musl-cross + musl_dep := musl heads_cc := $(INSTALL)/bin/musl-gcc \ -fdebug-prefix-map=$(pwd)=heads \ -gno-record-gcc-switches \ -D__MUSL__ \ -CROSS := $(build)/../crossgcc/x86_64-linux-musl/bin/x86_64-musl-linux- CROSS_TOOLS_NOCC := \ AR="$(CROSS)ar" \ LD="$(CROSS)ld" \ diff --git a/modules/musl-cross b/modules/musl-cross index 4107df88..ff331b24 100644 --- a/modules/musl-cross +++ b/modules/musl-cross @@ -1,14 +1,42 @@ -modules-y += musl-cross +ifeq "$(MUSL_CROSS_ONCE)" "" +MUSL_CROSS_ONCE := 1 + +# Allow the path to the musl-cross directory to be passed on +# the environment so that the full path doens't need to be spelled out +ifneq "$(MUSL_DIR)" "" +CROSS := $(MUSL_DIR)/crossgcc/x86_64-linux-musl/bin/x86_64-linux-musl- +endif + +ifneq "$(CROSS)" "" + +# check that $(CROSS)gcc exists or else things just won't work +ifneq "y" "$(shell [ -x '$(CROSS)gcc' ] && echo y)" +$(error $(CROSS)gcc does not exist - can not build +endif + +# The cross compiler has already been built, so the musl-cross target +# is a NOP. +musl-cross.intermediate: + +else + +# Force a full build of the cross compiler + +modules-y += musl-cross musl-cross_version := git musl-cross_dir := musl-cross-$(musl-cross_version) musl-cross_repo := https://github.com/GregorR/musl-cross -musl-cross_output := ../../crossgcc/x86_64-linux-musl/bin/x86_64-linux-musl-gcc - musl-cross_configure := \ /bin/echo -e > Makefile \ '$(musl-cross_output):\n\tCC_BASE_PREFIX="$(pwd)/crossgcc" ./build.sh' +CROSS := $(build)/../crossgcc/x86_64-linux-musl/bin/x86_64-musl-linux- +musl-cross_output := $(CROSS)gcc + +endif + musl-cross_target := +endif