From 24e54a65f60461e83a5ecbff70691780dd286fb4 Mon Sep 17 00:00:00 2001 From: Trammell Hudson Date: Fri, 27 Jan 2017 16:17:03 -0500 Subject: [PATCH] Build GNU make-4.2 if the system make is the wrong version (issue #88). Change all of the builds to use $(MAKE) instead of the /usr/bin/make. Download and build GNU make-4.2 if the wrong version is installed on the system. Re-invoke build/make-4.2/make with the target that was passed in once the correct make has been built. --- Makefile | 44 ++++++++++++++++++++++++++++++++++++++++---- modules/busybox | 2 +- modules/coreboot | 6 +++--- modules/kexec | 2 +- modules/linux | 2 +- modules/make | 13 +++++++++++++ 6 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 modules/make diff --git a/Makefile b/Makefile index 69c48bd..a37180b 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,14 @@ build := $(pwd)/build config := $(pwd)/build INSTALL := $(pwd)/install +# Check that we have a correct version of make +LOCAL_MAKE_VERSION := $(shell $(MAKE) --version | head -1 | cut -d' ' -f3) +include modules/make + +ifeq "$(LOCAL_MAKE_VERSION)" "$(make_version)" +# We are running our own version of make, +# proceed with the build. + # Currently supported targets are x230, chell and qemu BOARD ?= qemu @@ -12,6 +20,7 @@ BOARD ?= qemu # variable to point to it. musl_dep := musl heads_cc := $(INSTALL)/bin/musl-gcc +#heads_cc := $(HOME)/install/x86_64-linux-musl/x86_64-linux-musl/bin/gcc all: $(BOARD).rom @@ -108,7 +117,7 @@ define define_module = $(foreach d,$($1_depends),$(call outputs,$d)) \ $(foreach d,$($1_depends),$d.intermediate) \ $(build)/$($1_dir)/.configured - make -C "$(build)/$($1_dir)" $($1_target) + $(MAKE) -C "$(build)/$($1_dir)" $($1_target) .INTERMEDIATE: $1.intermediate endef @@ -168,7 +177,7 @@ initrd_bins += initrd/bin/busybox initrd/bin/busybox: $(build)/$(busybox_dir)/busybox cmp --quiet "$@" "$^" || \ - make \ + $(MAKE) \ -C $(build)/$(busybox_dir) \ CC="$(heads_cc)" \ CONFIG_PREFIX="$(pwd)/initrd" \ @@ -184,7 +193,7 @@ initrd/bin/cbmem: $(build)/$(coreboot_dir)/util/cbmem/cbmem $(build)/$(coreboot_dir)/util/cbmem/cbmem: \ $(build)/$(coreboot_dir)/.canary \ musl.intermediate - make -C "$(dir $@)" CC="$(heads_cc)" + $(MAKE) -C "$(dir $@)" CC="$(heads_cc)" # Update all of the libraries in the initrd based on the executables @@ -262,6 +271,33 @@ qemu.rom: $(build)/$(coreboot_dir)/qemu/coreboot.rom clean-modules: for dir in busybox-1.25.0 cryptsetup-1.7.3 gnupg-1.4.21 kexec-tools-2.0.12 libuuid-1.0.3 LVM2.2.02.168 mbedtls-2.3.0 popt-1.16 qrencode-3.4.4 tpmtotp-git ; do \ - make -C build/$$dir clean; \ + $(MAKE) -C build/$$dir clean; \ rm build/$$dir/.configured; \ done + + +else +# Wrong make version detected -- build our local version +# and re-invoke the Makefile with it instead. +$(info Wrong make detected: $(LOCAL_MAKE_VERSION)) +HEADS_MAKE := $(build)/$(make_dir)/make + +# Once we have a proper Make, we can just pass arguments into it +%: $(HEADS_MAKE) + LANG=C MAKE=$(HEADS_MAKE) $(HEADS_MAKE) $@ +all: + +# How to download and build the correct version of make +$(HEADS_MAKE): $(build)/$(make_dir)/Makefile + make -C "`dirname $@`" -j8 +$(build)/$(make_dir)/Makefile: $(packages)/$(make_tar) + tar xf "$<" -C build/ + cd "`dirname $@`" ; ./configure +$(packages)/$(make_tar): + wget -O "$@" "$(make_url)" + if ! echo "$(make_hash) $@" | sha256sum --check -; then \ + $(MV) "$@" "$@.failed"; \ + false; \ + fi + +endif diff --git a/modules/busybox b/modules/busybox index c6ca330..69b0534 100644 --- a/modules/busybox +++ b/modules/busybox @@ -6,7 +6,7 @@ busybox_tar := busybox-$(busybox_version).tar.bz2 busybox_url := https://busybox.net/downloads/$(busybox_tar) busybox_hash := 5a0fe06885ee1b805fb459ab6aaa023fe4f2eccee4fb8c0fd9a6c17c0daca2fc -busybox_configure := make CC=$(heads_cc) oldconfig +busybox_configure := $(MAKE) CC=$(heads_cc) oldconfig busybox_config := busybox.config busybox_output := busybox busybox_target := \ diff --git a/modules/coreboot b/modules/coreboot index 86b6556..94174d7 100644 --- a/modules/coreboot +++ b/modules/coreboot @@ -14,7 +14,7 @@ coreboot_repo := https://github.com/osresearch/coreboot #coreboot_config := coreboot-$(TARGET).config coreboot_configure := \ - make oldconfig obj=./$(BOARD) DOTCONFIG=../../config/coreboot-$(BOARD).config + $(MAKE) oldconfig obj=./$(BOARD) DOTCONFIG=../../config/coreboot-$(BOARD).config coreboot_target := \ obj=./$(BOARD) DOTCONFIG=../../config/coreboot-$(BOARD).config -j 8 @@ -26,9 +26,9 @@ coreboot_output := $(BOARD)/coreboot.rom $(build)/$(coreboot_dir)/.configured: $(build)/$(coreboot_dir)/util/crossgcc/xgcc/bin/i386-elf-gcc $(build)/$(coreboot_dir)/util/crossgcc/xgcc/bin/i386-elf-gcc: echo '******* Building crossgcc-i386 (this might take a while) ******' - make -C "$(build)/$(coreboot_dir)" crossgcc-i386 + $(MAKE) -C "$(build)/$(coreboot_dir)" crossgcc-i386 #echo '******* Building crossgcc-arm (this might take a while) ******' - #make -C "$(build)/$(coreboot_dir)" crossgcc-arm + #$(MAKE) -C "$(build)/$(coreboot_dir)" crossgcc-arm # The coreboot-blobs must be unpacked before we can build coreboot # if we are using a tar file; git checkout will clone the submodule. diff --git a/modules/kexec b/modules/kexec index a64e302..83cc1eb 100644 --- a/modules/kexec +++ b/modules/kexec @@ -13,7 +13,7 @@ kexec_configure := ./configure \ --prefix="$(INSTALL)" \ --without-zlib \ --without-lzma \ - && make clean + && $(MAKE) clean kexec_target := \ install \ diff --git a/modules/linux b/modules/linux index 35a5892..f62bbe0 100644 --- a/modules/linux +++ b/modules/linux @@ -11,7 +11,7 @@ linux-4.9_hash := 029098dcffab74875e086ae970e3828456838da6e0ba22ce3f64ef764f3d7f linux_hash := $(linux-$(linux_version)_hash) -linux_configure := make oldconfig +linux_configure := $(MAKE) oldconfig linux_output := arch/x86/boot/bzImage linux_config := linux.config linux_target := -j 8 bzImage diff --git a/modules/make b/modules/make new file mode 100644 index 0000000..460c0b3 --- /dev/null +++ b/modules/make @@ -0,0 +1,13 @@ +# This is not added to the module list since it is a special case +# of things that need to be built for the host system, instead of the +# target platform. +#modules += make + +make_version := 4.2 +make_dir := make-$(make_version) +make_tar := make-$(make_version).tar.bz2 +make_url := http://gnu.mirror.constant.com/make/$(make_tar) +make_hash := 4e5ce3b62fe5d75ff8db92b7f6df91e476d10c3aceebf1639796dc5bfece655f + +# This is built for the local machine, not the target, so it doesn't have any +# of the build instructions.