porting Makefile to use a modular build system for each package

This commit is contained in:
Trammell Hudson 2016-08-02 19:25:47 -04:00
parent b3786d256a
commit 00559def5d
Failed to extract signature
10 changed files with 99 additions and 179 deletions

230
Makefile
View File

@ -1,192 +1,64 @@
all: coreboot modules :=
pwd := $(shell pwd)
packages := $(pwd)/packages
build := $(pwd)/build
config := $(pwd)/build
force: all:
-rm $(linux_dir)/arch/x86/boot/bzImage
# uclibc must be built after the kernel, include modules/qrencode
# since 'make headers_install' must be run to generate the include modules/kexec
# headers that uclibc needs. include modules/tpmtotp
uclibc_url := https://uclibc.org/downloads/uClibc-0.9.33.tar.xz include modules/mbedtls
all: $(modules)
kexec_version := 2.0.12 define prefix =
kexec_dir := kexec-tools-$(kexec_version) $(foreach _, $2, $1$_)
kexec_tar := kexec-tools-$(kexec_version).tar.gz endef
kexec_url := https://kernel.org/pub/linux/utils/kernel/kexec/$(kexec_tar)
kexec_hash := cc7b60dad0da202004048a6179d8a53606943062dd627a2edba45a8ea3a85135
$(kexec_tar): define outputs =
wget "$(kexec_url)" $(call prefix,$(build)/$($1_dir)/,$($1_output))
sha256sum "$(kexec_tar)" endef
echo "$(kexec_hash)"
$(kexec_dir): $(kexec_tar) #
tar xvf "$(kexec_tar)" # Generate the targets for a module.
cd "$(kexec_dir)" && ./configure #
# Special variables like $@ must be written as $$@ to avoid
# expansion during the first evaluation.
#
define define_module =
# Fetch and verify the source tar file
$(packages)/$($1_tar):
wget -O "$$@" $($1_url)
$(packages)/.$1_verify: $(packages)/$($1_tar)
echo "$($1_hash) $$^" | sha256sum --check -
touch "$$@"
kexec: $(kexec_dir) # Unpack the tar file and touch the canary so that we know
make -C "$(kexec_dir)" -j 8 # that the files are all present
$(build)/$($1_dir)/.canary: $(packages)/.$1_verify
tar -xvf "$(packages)/$($1_tar)" -C "$(build)"
touch "$$@"
# Copy our stored config file into the unpacked directory
$(build)/$($1_dir)/.config: config/$1.config $(build)/$($1_dir)/.canary
cp "$$<" "$$@"
qrencode_dir := qrencode-3.4.4 # Use the module's configure variable to build itself
qrencode_tar := qrencode-3.4.4.tar.gz $(build)/$($1_dir)/.configured: \
qrencode_url := https://fukuchi.org/works/qrencode/$(qrencode_tar) $(build)/$($1_dir)/.canary \
qrencode_canary := $(qrencode_dir)/.canary $(build)/$($1_dir)/.config
cd "$(build)/$($1_dir)" ; $($1_configure)
touch "$$@"
$(qrencode_tar): # Actually build the target
wget $(qrencode_url) $(call outputs,$1): $(build)/$($1_dir)/.configured $(call outputs,$($1_depends))
make -C "$(build)/$($1_dir)" $($1_target)
$1: $(call outputs,$1)
qrencode_lib := $(qrencode_dir)/.libs/libqrencode.so # Update any dependencies
$(qrencode_canary): $(qrencode_tar) endef
tar xvf "$<"
touch "$@"
$(qrencode_lib): $(qrencode_canary) $(foreach _, $(modules), $(eval $(call define_module,$_)))
cd $(qrencode_dir) ; ./configure --without-tools
make -C "$(qrencode_dir)"
initrd/bin/unsealtotp: $(qrencode_lib)
make -C tpmtotp unsealtotp
cp tpmtotp/unsealtotp "$@"
initrd/bin/sealtotp: $(qrencode_lib)
make -C tpmtotp sealtotp
cp tpmtotp/sealtotp "$@"
busybox_version := 1.25.0
busybox_dir := busybox-$(busybox_version)
busybox_tar := busybox-$(busybox_version).tar.bz2
busybox_url := https://busybox.net/downloads/$(busybox_tar)
busybox_hash := 5a0fe06885ee1b805fb459ab6aaa023fe4f2eccee4fb8c0fd9a6c17c0daca2fc
busybox_config := config/busybox.config
$(busybox_dir)/busybox: $(busybox_dir) $(busybox_dir)/.config
make -C "$(busybox_dir)" -j 8
$(busybox_dir): $(busybox_tar)
tar xvf "$(busybox_tar)"
$(busybox_dir)/.config: $(busybox_config)
cp "$<" "$@"
make -C "$(busybox_dir)" oldconfig
$(busybox_tar):
wget "$(busybox_url)"
sha256sum "$(busybox_tar)"
echo "$(busybox_hash)"
linux_version := 4.6.4
linux_dir := linux-$(linux_version)
linux_tar := linux-$(linux_version).tar.xz
linux_url := https://cdn.kernel.org/pub/linux/kernel/v4.x/$(linux_tar)
linux_hash := 8568d41c7104e941989b14a380d167129f83db42c04e950d8d9337fe6012ff7e
linux_config := config/linux.config
$(linux_dir): $(linux_tar)
tar xvf "$(linux_tar)"
$(linux_dir)/.config: $(linux_config)
cp "$<" "$@"
make -C "$(linux_dir)" oldconfig
bzImage: $(linux_dir)/arch/x86/boot/bzImage
$(linux_dir)/arch/x86/boot/bzImage: \
$(linux_dir) \
$(linux_dir)/.config \
initrd/bin/busybox \
initrd/libs \
make -C "$(linux_dir)" bzImage
ls -Fla "$@"
coreboot_version := 4.4
coreboot_dir := coreboot-$(coreboot_version)
coreboot_tar := coreboot-$(coreboot_version).tar.xz
coreboot_url := https://www.coreboot.org/releases/$(coreboot_tar)
coreboot_config := config/coreboot.config
coreboot-blobs_tar := coreboot-blobs-$(coreboot_version).tar.xz
coreboot-blobs_url := https://www.coreboot.org/releases/$(coreboot-blobs_tar)
coreboot-blobs_dir := coreboot-$(coreboot_version)/3rdparty/blobs
coreboot-blobs_hash := 43b993915c0f46a77ee7ddaa2dbe47581f399510632c62f2558dff931358d8ab
coreboot-blobs_canary := $(coreboot-blobs_dir)/documentation/binary_policy.md
$(coreboot_dir)/util/crossgcc/xgcc/bin/iasl:
echo '******* Building gcc (this might take a while) ******'
time make -C "$(coreboot_dir)" crossgcc
$(coreboot_dir)/bzImage: $(linux_dir)/arch/x86/boot/bzImage
cp "$<" "$@"
initrd.img:
( \
cd initrd && \
find . \
| cpio --quiet -H newc -o \
) | xz -9 > "$@"
# initrd image is now included by the Linux kernel build process
initrd: \
initrd/bin/busybox \
initrd/sbin/kexec \
initrd/libs
initrd/bin/busybox: $(busybox_dir)/busybox
make -C "$(busybox_dir)" CONFIG_PREFIX="`pwd`/initrd" install
initrd/sbin/kexec: $(kexec_dir)/build/sbin/kexec
-mkdir "`dirnname "$@"`"
cp "$<" "$@"
INITRD_LIBS += \
liblzma.so.5 \
libz.so.1 \
libc.so.6 \
libdl.so.2 \
initrd/libs:
./populate-lib ./initrd/lib/x86_64-linux-gnu/ initrd/bin/* initrd/sbin/*
$(coreboot_tar):
wget "$(coreboot_url)"
sha256sum "$(coreboot_tar)"
echo "$(coreboot_hash)"
$(coreboot-blobs_tar):
wget "$(coreboot-blobs_url)"
sha256sum "$(coreboot-blobs_tar)"
echo "$(coreboot-blobs_hash)"
$(coreboot_blobs_canary): $(coreboot-blobs_tar)
tar xvf "$(coreboot-blobs_tar)"
$(coreboot_dir): $(coreboot_tar)
tar xvf "$(coreboot_tar)"
$(coreboot_dir)/.config: $(coreboot_config)
cp "$<" "$@"
make -C "$(coreboot_dir)" oldconfig
$(coreboot_dir)/build/coreboot.rom: \
$(coreboot_dir) \
$(coreboot_dir)/.config \
$(coreboot_dir)/util/crossgcc/xgcc/bin/iasl \
$(coreboot_dir)/bzImage \
$(coreboot-blobs_canary) \
make -C "$(coreboot_dir)"
heads-x230.rom: $(coreboot_dir)/build/coreboot.rom
dd if="$<" of="$@" bs=1M skip=8
sha256sum "$@"
xxd -g 1 "$@" | head
xxd -g 1 "$@" | tail
coreboot: heads-x230.rom
FORCE:

1
build/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*

1
config/kexec.config Normal file
View File

@ -0,0 +1 @@
# nothing

1
config/mbedtls.config Normal file
View File

@ -0,0 +1 @@
# nothing

1
config/qrencode.config Normal file
View File

@ -0,0 +1 @@
# nothing

1
config/tpmtotp.config Normal file
View File

@ -0,0 +1 @@
# nothing

10
modules/kexec Normal file
View File

@ -0,0 +1,10 @@
modules += kexec
kexec_version := 2.0.12
kexec_dir := kexec-tools-$(kexec_version)
kexec_tar := kexec-tools-$(kexec_version).tar.gz
kexec_url := https://kernel.org/pub/linux/utils/kernel/kexec/$(kexec_tar)
kexec_hash := cc7b60dad0da202004048a6179d8a53606943062dd627a2edba45a8ea3a85135
kexec_configure := ./configure
kexec_output := build/sbin/kexec

10
modules/mbedtls Normal file
View File

@ -0,0 +1,10 @@
modules += mbedtls
mbedtls_version := 2.3.0
mbedtls_dir := mbedtls-$(mbedtls_version)
mbedtls_tar := mbedtls-$(mbedtls_version)-gpl.tgz
mbedtls_url := need-to-fix-url/$(mbedtls_tar)
mbedtls_hash := 21237014f779bde70b2d71399cc1ea53365eb7f10cdd74a13ee6329a1910cb49
mbedtls_output := library/libmbedcrypto.a
mbedtls_configure :=

10
modules/qrencode Normal file
View File

@ -0,0 +1,10 @@
modules += qrencode
qrencode_version := 3.4.4
qrencode_dir := qrencode-$(qrencode_version)
qrencode_tar := qrencode-$(qrencode_version).tar.gz
qrencode_url := https://fukuchi.org/works/qrencode/$(qrencode_tar)
qrencode_hash := e794e26a96019013c0e3665cb06b18992668f352c5553d0a553f5d144f7f2a72
qrencode_output := .libs/libqrencode.so.$(qrencode_version)
qrencode_configure := ./configure --without-tools

13
modules/tpmtotp Normal file
View File

@ -0,0 +1,13 @@
modules += tpmtotp
# depends on the mbedtls module
tpmtotp_depends := mbedtls
tpmtotp_version := 0.0.1
tpmtotp_dir := tpmtotp-$(tpmtotp_version)
tpmtotp_tar := tpmtotp-$(tpmtotp_version).tar.gz
tpmtotp_url := git-from-somewhere-$(tpmtotp_tar)
tpmtotp_hash := 4f2d7bc9282ad6cad75f6bca6362a79e893d41b46524c7f67803889118d9707b
tpmtotp_output := sealtotp unsealtotp
tpmtotp_configure :=