|
| 1 | +# For each external target, the following must be defined in advance: |
| 2 | +# _SRC_URL : the hyperlink which points to archive. |
| 3 | +# _SRC : the file to be read by specific executable. |
| 4 | +# _SRC_SHA1 : the checksum of the content in _SRC |
| 5 | + |
| 6 | +TOP=$(shell pwd) |
| 7 | +CONF=$(TOP)/configs |
| 8 | +FILE=$(TOP)/target |
| 9 | + |
| 10 | +# Linux kernel |
| 11 | +LINUX_VER = 5.18.8 |
| 12 | +LINUX_SRC_URL = https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-${LINUX_VER}.tar.xz |
| 13 | +LINUX_SRC = $(OUT)/linux-${LINUX_VER} |
| 14 | +LINUX_SRC_SHA1 = 8db5e3c3bc63a66fba5cdac53c125252dfbf3b82 |
| 15 | + |
| 16 | +# BusyBox |
| 17 | +BUSYBOX_VER=1.35.0 |
| 18 | +BUSYBOX_SRC_URL = https://busybox.net/downloads/busybox-${BUSYBOX_VER}.tar.bz2 |
| 19 | +BUSYBOX_SRC = $(OUT)/busybox-${BUSYBOX_VER} |
| 20 | +BUSYBOX_SRC_SHA1 = 36a1766206c8148bc06aca4e1f134016d40912d0 |
| 21 | + |
| 22 | +define download-n-extract |
| 23 | +$(eval $(T)_SRC_ARCHIVE = $(OUT)/$(shell basename $($(T)_SRC_URL))) |
| 24 | +$($(T)_SRC_ARCHIVE): |
| 25 | + $(VECHO) " GET\t$$@\n" |
| 26 | + $(Q)curl --progress-bar -o $$@ -L -C - "$(strip $($(T)_SRC_URL))" |
| 27 | + $(Q)echo "$(strip $$($(T)_SRC_SHA1)) $$@" | shasum -c |
| 28 | +$($(T)_SRC): $($(T)_SRC_ARCHIVE) |
| 29 | + $(VECHO) "Unpacking $$@ ... " |
| 30 | + $(Q)tar -xf $$< -C ${OUT} && $(call notice, [OK]) |
| 31 | +endef |
| 32 | + |
| 33 | +EXTERNAL_SRC = LINUX BUSYBOX |
| 34 | +$(foreach T,$(EXTERNAL_SRC),$(eval $(download-n-extract))) |
| 35 | + |
| 36 | +# Build Linux kernel image |
| 37 | +LINUX_IMG = $(OUT)/bzImage |
| 38 | +$(LINUX_IMG): $(LINUX_SRC) |
| 39 | + $(VECHO) "Configuring Linux kernel... " |
| 40 | + $(Q)cp -f ${CONF}/linux.config $</.config |
| 41 | + $(Q)(cd $< ; make ARCH=x86 oldconfig $(REDIR)) && $(call notice, [OK]) |
| 42 | + $(VECHO) "Building Linux kernel image... " |
| 43 | + $(Q)(cd $< ; make ARCH=x86 bzImage $(PARALLEL) $(REDIR)) |
| 44 | + $(Q)(cd $< ; cp -f arch/x86/boot/bzImage $(TOP)/$(OUT)) && $(call notice, [OK]) |
| 45 | + |
| 46 | +# Build busybox single binary |
| 47 | +BUSYBOX_BIN = $(OUT)/rootfs/bin/busybox |
| 48 | +$(BUSYBOX_BIN): $(BUSYBOX_SRC) |
| 49 | + $(VECHO) "Configuring BusyBox... " |
| 50 | + $(Q)mkdir $(OUT)/rootfs || (rm -rf $(OUT)/rootfs ; mkdir -p $(OUT)/rootfs) |
| 51 | + $(Q)cp -f $(CONF)/busybox.config $</.config |
| 52 | + $(Q)(cd $< ; $(MAKE) oldconfig $(REDIR)) && $(call notice, [OK]) |
| 53 | + $(VECHO) "Building BusyBox single binary... " |
| 54 | + $(Q)(cd $< ; $(MAKE) $(PARALLEL) 2>/dev/null $(REDIR)) |
| 55 | + $(Q)(cd $< ; $(MAKE) CONFIG_PREFIX='../rootfs' install $(REDIR)) && $(call notice, [OK]) |
| 56 | + |
| 57 | +# Generate root file system |
| 58 | +ROOTFS_IMG = $(OUT)/rootfs.cpio |
| 59 | +$(ROOTFS_IMG): $(BUSYBOX_BIN) |
| 60 | + $(VECHO) "Generating root file system... " |
| 61 | + $(Q)(cd $(OUT)/rootfs ; \ |
| 62 | + mv linuxrc init ; \ |
| 63 | + mkdir -p etc/init.d ; \ |
| 64 | + cp -f $(FILE)/rc-startup etc/init.d/rcS ; \ |
| 65 | + chmod 755 etc/init.d/rcS ; \ |
| 66 | + find . | cpio -o --format=newc > $(TOP)/$(OUT)/rootfs.cpio 2>/dev/null) && $(call notice, [OK]) |
0 commit comments