From 7f30b22b82791dca2c2dce5462f6f53a923585bb Mon Sep 17 00:00:00 2001 From: Trammell hudson Date: Fri, 16 Mar 2018 12:59:24 -0400 Subject: [PATCH] allow CROSS or MUSL_DIR to be set on the command line so that an external cross compiler can be used (issue #162) --- Makefile | 7 ++++--- modules/musl-cross | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 6 deletions(-) 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