make cleanup/refactoring with more helper phony targets

This commit is contained in:
Lance Vick 2022-07-09 00:52:32 -07:00
parent 49bfc9dcd1
commit bda773f089
Signed by: lrvick
GPG Key ID: 8E47A1EC35A1551D
3 changed files with 70 additions and 48 deletions

View File

@ -12,11 +12,51 @@ ARCH := x86_64
include $(PWD)/config.env include $(PWD)/config.env
include $(PWD)/make/keys.mk include $(PWD)/make/keys.mk
include $(PWD)/make/fetch.mk include $(PWD)/make/fetch.mk
include $(PWD)/make/extract.mk
include $(PWD)/make/toolchain.mk include $(PWD)/make/toolchain.mk
.DEFAULT_GOAL := default .DEFAULT_GOAL := default
default: $(OUT_DIR)/bzImage .PHONY: default
default: fetch $(OUT_DIR)/bzImage
# Clean repo back to initial clone state
.PHONY: clean
clean:
rm -rf cache out
docker image rm -f local/$(NAME)-build
# Source anything required from the internet to build
.PHONY: fetch
fetch: \
toolchain \
keys \
$(OUT_DIR) \
$(CACHE_DIR) \
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar.xz \
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar.sign \
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION).tar.bz2 \
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION).tar.bz2.sig
# Build latest image and run in terminal via Qemu
.PHONY: run
run: default
qemu-system-x86_64 \
-m 512M \
-nographic \
-initrd $(OUT_DIR)/rootfs.cpio \
-kernel $(OUT_DIR)/bzImage
# Run ncurses busybox config menu and save output
.PHONY: busybox-config
busybox-config:
rm $(CONFIG_DIR)/busybox.config
make $(CONFIG_DIR)/busybox.config
# Run linux config menu and save output
.PHONY: linux-config
linux-config:
rm $(CONFIG_DIR)/linux.config
make $(CONFIG_DIR)/linux.config
$(CONFIG_DIR)/busybox.config: $(CONFIG_DIR)/busybox.config:
$(toolchain) " \ $(toolchain) " \
@ -58,8 +98,10 @@ endif
# | LANG=C bsdtar --null -cf - --format=newc @- \ # | LANG=C bsdtar --null -cf - --format=newc @- \
# " > $@ # " > $@
$(OUT_DIR)/busybox: \
$(OUT_DIR)/busybox: extract $(CACHE_DIR)/busybox-$(BUSYBOX_VERSION) \
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION).tar.bz2 \
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION).tar.bz2.sig
$(toolchain) " \ $(toolchain) " \
cd /cache/busybox-$(BUSYBOX_VERSION) && \ cd /cache/busybox-$(BUSYBOX_VERSION) && \
cp /config/busybox.config .config && \ cp /config/busybox.config .config && \
@ -67,7 +109,11 @@ $(OUT_DIR)/busybox: extract
cp busybox /out/; \ cp busybox /out/; \
" "
$(OUT_DIR)/bzImage: extract $(OUT_DIR)/rootfs.cpio $(OUT_DIR)/bzImage: \
$(OUT_DIR)/rootfs.cpio \
$(CACHE_DIR)/linux-$(LINUX_VERSION) \
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar.xz \
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar.sign
$(toolchain) " \ $(toolchain) " \
cd /cache/linux-$(LINUX_VERSION) && \ cd /cache/linux-$(LINUX_VERSION) && \
cp /config/linux.config .config && \ cp /config/linux.config .config && \
@ -76,10 +122,3 @@ $(OUT_DIR)/bzImage: extract $(OUT_DIR)/rootfs.cpio
cp arch/x86_64/boot/bzImage /out/; \ cp arch/x86_64/boot/bzImage /out/; \
" "
.PHONY: run
run:
qemu-system-x86_64 \
-m 512M \
-nographic \
-initrd $(OUT_DIR)/rootfs.cpio \
-kernel $(OUT_DIR)/bzImage

View File

@ -1,25 +0,0 @@
.PHONY: extract
extract: \
fetch \
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar \
$(CACHE_DIR)/linux-$(LINUX_VERSION)/README \
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION)/README
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar:
xz -d $(CACHE_DIR)/linux-$(LINUX_VERSION).tar.xz
$(CACHE_DIR)/linux-$(LINUX_VERSION)/README:
$(toolchain) " \
cd /cache && \
gpg --import /keys/$(LINUX_KEY).asc && \
gpg --verify linux-$(LINUX_VERSION).tar.sign && \
tar xf linux-$(LINUX_VERSION).tar; \
"
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION)/README:
$(toolchain) " \
cd /cache && \
gpg --import /keys/$(BUSYBOX_KEY).asc && \
gpg --verify busybox-$(BUSYBOX_VERSION).tar.bz2.sig && \
tar -xf busybox-$(BUSYBOX_VERSION).tar.bz2 \
"

View File

@ -1,14 +1,3 @@
.PHONY: fetch
fetch: \
toolchain \
keys \
$(OUT_DIR) \
$(CACHE_DIR) \
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar.xz \
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar.sign \
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION).tar.bz2 \
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION).tar.bz2.sig
$(OUT_DIR): $(OUT_DIR):
mkdir -p $(OUT_DIR) mkdir -p $(OUT_DIR)
@ -34,3 +23,22 @@ $(CACHE_DIR)/linux-$(LINUX_VERSION).tar.xz:
curl \ curl \
--url $(LINUX_SERVER)/linux-$(LINUX_VERSION).tar.xz \ --url $(LINUX_SERVER)/linux-$(LINUX_VERSION).tar.xz \
--output $(CACHE_DIR)/linux-$(LINUX_VERSION).tar.xz --output $(CACHE_DIR)/linux-$(LINUX_VERSION).tar.xz
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar:
xz -d $(CACHE_DIR)/linux-$(LINUX_VERSION).tar.xz
$(CACHE_DIR)/linux-$(LINUX_VERSION): $(CACHE_DIR)/linux-$(LINUX_VERSION).tar
$(toolchain) " \
cd /cache && \
gpg --import /keys/$(LINUX_KEY).asc && \
gpg --verify linux-$(LINUX_VERSION).tar.sign && \
tar xf linux-$(LINUX_VERSION).tar; \
"
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION):
$(toolchain) " \
cd /cache && \
gpg --import /keys/$(BUSYBOX_KEY).asc && \
gpg --verify busybox-$(BUSYBOX_VERSION).tar.bz2.sig && \
tar -xf busybox-$(BUSYBOX_VERSION).tar.bz2 \
"