2022-07-28 00:27:16 +00:00
|
|
|
DEBUG := false
|
2022-06-24 09:02:51 +00:00
|
|
|
OUT_DIR := out
|
|
|
|
KEY_DIR := keys
|
2022-07-28 00:27:16 +00:00
|
|
|
SRC_DIR := src
|
2022-06-24 09:02:51 +00:00
|
|
|
TARGET := local
|
|
|
|
CACHE_DIR := cache
|
2022-07-29 19:32:45 +00:00
|
|
|
CONFIG_DIR := config
|
2022-07-24 12:30:55 +00:00
|
|
|
TOOLCHAIN_DIR := toolchain
|
2022-07-29 19:32:45 +00:00
|
|
|
SRC_DIR := src
|
2022-07-24 12:30:55 +00:00
|
|
|
USER := $(shell id -g):$(shell id -g)
|
2022-06-24 09:02:51 +00:00
|
|
|
CPUS := $(shell nproc)
|
2022-07-09 00:37:00 +00:00
|
|
|
ARCH := x86_64
|
2022-06-24 09:02:51 +00:00
|
|
|
|
2022-07-29 19:32:45 +00:00
|
|
|
include $(PWD)/config/global.env
|
2022-06-24 09:02:51 +00:00
|
|
|
include $(PWD)/make/keys.mk
|
|
|
|
include $(PWD)/make/fetch.mk
|
2022-07-24 12:30:55 +00:00
|
|
|
include $(PWD)/toolchain/Makefile
|
2022-06-24 09:02:51 +00:00
|
|
|
|
|
|
|
.DEFAULT_GOAL := default
|
2022-07-09 07:52:32 +00:00
|
|
|
.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
|
|
|
|
|
2022-07-24 12:30:55 +00:00
|
|
|
# Launch a shell inside the toolchain container
|
|
|
|
.PHONY: toolchain-shell
|
|
|
|
toolchain-shell: $(OUT_DIR)/toolchain.tar
|
|
|
|
$(call toolchain,root,bash)
|
|
|
|
|
|
|
|
# Pin all packages in toolchain container to latest versions
|
|
|
|
.PHONY: toolchain-update
|
|
|
|
toolchain-update:
|
|
|
|
$(call toolchain,root,toolchain-update )
|
|
|
|
|
2022-07-09 07:52:32 +00:00
|
|
|
# Source anything required from the internet to build
|
|
|
|
.PHONY: fetch
|
|
|
|
fetch: \
|
|
|
|
keys \
|
|
|
|
$(OUT_DIR) \
|
2022-07-24 12:30:55 +00:00
|
|
|
$(OUT_DIR)/toolchain.tar \
|
2022-07-09 07:52:32 +00:00
|
|
|
$(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 \
|
|
|
|
-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:
|
2022-07-29 19:32:45 +00:00
|
|
|
rm $(CONFIG_DIR)/$(TARGET)/linux.config
|
|
|
|
make $(CONFIG_DIR)/$(TARGET)/linux.config
|
2022-07-09 07:52:32 +00:00
|
|
|
|
2022-07-24 12:30:55 +00:00
|
|
|
# This can likely be eliminated with path fixes in toolchain/Makefile
|
|
|
|
$(OUT_DIR)/toolchain.tar:
|
|
|
|
ARCH=$(ARCH) \
|
|
|
|
OUT_DIR=../$(OUT_DIR) \
|
|
|
|
DEBIAN_HASH=$(DEBIAN_HASH) \
|
|
|
|
$(MAKE) -C $(TOOLCHAIN_DIR) \
|
|
|
|
../$(OUT_DIR)/toolchain.tar
|
|
|
|
|
2022-06-24 09:02:51 +00:00
|
|
|
$(CONFIG_DIR)/busybox.config:
|
2022-07-24 12:30:55 +00:00
|
|
|
$(call toolchain,$(USER), " \
|
2022-06-24 09:02:51 +00:00
|
|
|
cd /cache/busybox-$(BUSYBOX_VERSION) && \
|
2022-07-09 00:37:00 +00:00
|
|
|
KCONFIG_NOTIMESTAMP=1 make menuconfig && \
|
2022-06-24 09:02:51 +00:00
|
|
|
cp .config /config/busybox.config; \
|
2022-07-24 12:30:55 +00:00
|
|
|
")
|
2022-06-24 09:02:51 +00:00
|
|
|
|
2022-07-29 19:32:45 +00:00
|
|
|
$(CONFIG_DIR)/$(TARGET)/linux.config:
|
2022-07-24 12:30:55 +00:00
|
|
|
$(call toolchain,$(USER)," \
|
2022-06-24 09:02:51 +00:00
|
|
|
cd /cache/linux-$(LINUX_VERSION) && \
|
|
|
|
make menuconfig && \
|
2022-07-29 19:32:45 +00:00
|
|
|
cp .config /config/$(TARGET)/linux.config; \
|
2022-07-24 12:30:55 +00:00
|
|
|
")
|
2022-07-09 00:37:00 +00:00
|
|
|
|
2022-07-09 07:52:32 +00:00
|
|
|
$(OUT_DIR)/busybox: \
|
|
|
|
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION) \
|
|
|
|
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION).tar.bz2 \
|
|
|
|
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION).tar.bz2.sig
|
2022-07-24 12:30:55 +00:00
|
|
|
$(call toolchain,$(USER)," \
|
2022-06-24 09:02:51 +00:00
|
|
|
cd /cache/busybox-$(BUSYBOX_VERSION) && \
|
|
|
|
cp /config/busybox.config .config && \
|
|
|
|
make -j$(CPUS) busybox && \
|
|
|
|
cp busybox /out/; \
|
2022-07-24 12:30:55 +00:00
|
|
|
")
|
2022-06-24 09:02:51 +00:00
|
|
|
|
2022-07-28 00:27:16 +00:00
|
|
|
$(OUT_DIR)/sample_init:
|
|
|
|
$(call toolchain,$(USER)," \
|
|
|
|
gcc \
|
|
|
|
-static \
|
|
|
|
-static-libgcc /src/sample/init.c \
|
|
|
|
-o /out/sample_init; \
|
|
|
|
")
|
|
|
|
|
2022-07-12 11:42:03 +00:00
|
|
|
$(CACHE_DIR)/linux-$(LINUX_VERSION)/usr/gen_init_cpio: \
|
2022-07-12 12:15:15 +00:00
|
|
|
$(CACHE_DIR)/linux-$(LINUX_VERSION) \
|
|
|
|
$(CACHE_DIR)/linux-$(LINUX_VERSION) \
|
|
|
|
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar.xz \
|
|
|
|
$(CACHE_DIR)/linux-$(LINUX_VERSION).tar.sign
|
2022-07-24 12:30:55 +00:00
|
|
|
$(call toolchain,$(USER)," \
|
2022-07-12 11:42:03 +00:00
|
|
|
cd /cache/linux-$(LINUX_VERSION) && \
|
|
|
|
gcc usr/gen_init_cpio.c -o usr/gen_init_cpio \
|
2022-07-24 12:30:55 +00:00
|
|
|
")
|
2022-07-12 11:42:03 +00:00
|
|
|
|
|
|
|
$(OUT_DIR)/rootfs.cpio: \
|
|
|
|
$(OUT_DIR)/busybox \
|
2022-07-28 00:27:16 +00:00
|
|
|
$(OUT_DIR)/sample_init \
|
2022-07-12 11:42:03 +00:00
|
|
|
$(CACHE_DIR)/linux-$(LINUX_VERSION)/usr/gen_init_cpio
|
|
|
|
mkdir -p $(CACHE_DIR)/rootfs/bin
|
2022-07-28 00:27:16 +00:00
|
|
|
ifeq ($(DEBUG), true)
|
|
|
|
cp $(OUT_DIR)/sample_init $(CACHE_DIR)/rootfs/sample_init
|
2022-07-29 19:32:45 +00:00
|
|
|
cp $(SRC_DIR)/scripts/busybox_init $(CACHE_DIR)/rootfs/init
|
2022-07-12 11:42:03 +00:00
|
|
|
cp $(OUT_DIR)/busybox $(CACHE_DIR)/rootfs/bin/
|
2022-07-28 00:27:16 +00:00
|
|
|
else
|
|
|
|
cp $(OUT_DIR)/sample_init $(CACHE_DIR)/rootfs/init
|
|
|
|
endif
|
2022-07-24 12:30:55 +00:00
|
|
|
$(call toolchain,$(USER)," \
|
2022-07-12 12:15:15 +00:00
|
|
|
cd /cache/rootfs && \
|
|
|
|
find . -mindepth 1 -execdir touch -hcd "@0" "{}" + && \
|
|
|
|
find . -mindepth 1 -printf '%P\0' && \
|
|
|
|
cd /cache/linux-$(LINUX_VERSION) && \
|
2022-07-29 19:32:45 +00:00
|
|
|
usr/gen_initramfs.sh \
|
|
|
|
-o /out/rootfs.cpio \
|
|
|
|
/config/$(TARGET)/rootfs.list && \
|
2022-07-12 12:15:15 +00:00
|
|
|
cpio -itv < /out/rootfs.cpio && \
|
|
|
|
sha256sum /out/rootfs.cpio; \
|
2022-07-24 12:30:55 +00:00
|
|
|
")
|
2022-07-12 11:42:03 +00:00
|
|
|
|
2022-07-09 07:52:32 +00:00
|
|
|
$(OUT_DIR)/bzImage: \
|
2022-07-12 12:15:15 +00:00
|
|
|
$(OUT_DIR)/rootfs.cpio
|
2022-07-24 12:30:55 +00:00
|
|
|
$(call toolchain,$(USER)," \
|
2022-06-24 09:02:51 +00:00
|
|
|
cd /cache/linux-$(LINUX_VERSION) && \
|
2022-07-29 19:32:45 +00:00
|
|
|
cp /config/$(TARGET)/linux.config .config && \
|
2022-07-09 00:37:00 +00:00
|
|
|
make olddefconfig && \
|
|
|
|
make -j$(CPUS) ARCH=$(ARCH) bzImage && \
|
2022-07-12 12:15:15 +00:00
|
|
|
cp arch/x86_64/boot/bzImage /out/ && \
|
|
|
|
sha256sum /out/bzImage; \
|
2022-07-24 12:30:55 +00:00
|
|
|
")
|