forked from on-prem/tinycore-kernel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
117 lines (99 loc) · 3.77 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Makefile
#
# Build a TinyCore Linux kernel, modules, and firmware extensions
#
# Usage:
# make kernel extensions os
# make all
MODULES ?= all base filesystems ipv6-netfilter mtd raid-dm scsi
KERNEL ?= 5.10.108
KERNEL_ARCH ?= x86_64
KERNEL_SOURCE ?= https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.108.tar.xz
KERNEL_SHA256 ?= bf6cc2d6e0918b8f34d1cde2fa39a6ad69c45025425048be1a1dac4a5b3641d8
OSDIR ?= /opt/tinycore/11.x/x86_64/release/distribution_files
WORKDIR ?= /tmp/tinycore-kernel-build
curdir := $(realpath .)
filename := $(notdir $(KERNEL_SOURCE))
kerneldir := $(WORKDIR)/linux-$(KERNEL)
ifeq ($(KERNEL_ARCH),x86_64)
ostype := 64
osfile := corepure64
kernelname := $(KERNEL)-tinycore$(ostype)
arch := x86_64
else
ostype :=
osfile := core
kernelname := $(KERNEL)-tinycore
arch := i386
endif
.PHONY: all clean kernel extensions verify-kernel build-kernel compress-modules pkg-modules os
all:
$(MAKE) kernel
$(MAKE) extensions
kernel:
$(MAKE) $(WORKDIR)/$(filename)
$(MAKE) verify-kernel
$(MAKE) build-kernel
extensions:
$(MAKE) compress-modules
$(MAKE) pkg-modules
$(WORKDIR)/$(filename):
mkdir -p $(WORKDIR) && \
cd $(WORKDIR) && \
wget $(KERNEL_SOURCE)
verify-kernel:
cd $(WORKDIR) && \
echo -n "$(KERNEL_SHA256) $(filename)" | sha256sum -c -
build-kernel:
rm -rf $(kerneldir)
cd $(WORKDIR) && \
tar -Jxf $(filename) -C $(WORKDIR)
cp -v $(curdir)/kernels/config-$(kernelname) $(kerneldir)/.config
$(MAKE) -C $(kerneldir) ARCH=$(arch) oldconfig
$(MAKE) -C $(kerneldir) ARCH=$(arch) bzImage
$(MAKE) -C $(kerneldir) ARCH=$(arch) modules
$(MAKE) -C $(kerneldir) ARCH=$(arch) INSTALL_MOD_PATH=$(WORKDIR)/modules-$(KERNEL) modules_install
cp -v $(kerneldir)/arch/x86/boot/bzImage $(WORKDIR)/vmlinuz$(ostype)
compress-modules:
mkdir -p $(WORKDIR) && \
cd $(WORKDIR)/modules-$(KERNEL) && \
find . -type f -name "*.ko" -exec strip --strip-unneeded {} \; && \
find . -type f -name "*.ko" -exec gzip {} \;
$(WORKDIR)/%-$(kernelname).tcz:
cd $(WORKDIR) && \
rm -rf modules-$* && \
mkdir -p modules-$*/usr/local/lib/modules/$(kernelname)
cd $(WORKDIR)/modules-$(KERNEL)/lib/modules/$(kernelname) && \
for i in `cat $(curdir)/modules/$(kernelname)/$*.txt`; do \
cp -v --parents $$i $(WORKDIR)/modules-$*/usr/local/lib/modules/$(kernelname)/; \
done
cd $(WORKDIR) && \
mksquashfs modules-$* $@ -b 4096
pkg-modules:
for module in $(MODULES); do \
[ -f "$(curdir)/modules/$(kernelname)/$$module.txt" ] && $(MAKE) $(WORKDIR)/$$module-$(kernelname).tcz || { >&2 echo "Missing module file: $(curdir)/modules/$(kernelname)/$$module.txt"; exit 127; }; \
done
os:
rm -rf $(WORKDIR)/os-$(osfile)
mkdir -p $(WORKDIR)/os-$(osfile)
cd $(WORKDIR)/os-$(osfile) && \
gunzip -c $(OSDIR)/$(osfile).gz | cpio -id && \
rm -rf lib/modules/* && \
mkdir -p lib/modules/$(kernelname) && \
cp -rp $(WORKDIR)/modules-base/usr/local/lib/modules/$(kernelname)/kernel lib/modules/$(kernelname)/
cd $(WORKDIR)/modules-$(KERNEL)/lib/modules/$(kernelname) && \
cp modules.alias modules.dep $(WORKDIR)/os-$(osfile)/lib/modules/$(kernelname)/
mv $(WORKDIR)/os-$(osfile)/usr/local/lib/modules/5.4.3-tinycore64 $(WORKDIR)/os-$(osfile)/usr/local/lib/modules/$(kernelname)
ln -sf /usr/local/lib/modules/$(kernelname)/kernel $(WORKDIR)/os-$(osfile)/lib/modules/$(kernelname)/kernel.tclocal
cd $(WORKDIR)/os-$(osfile)/lib/modules/$(kernelname) && \
sed -i 's/.ko/.ko.gz/g' modules.dep
$(MAKE) $(WORKDIR)/$(osfile)
$(WORKDIR)/$(osfile):
cd $(WORKDIR)/os-$(osfile) && \
find | sort | cpio -o -H newc > $(WORKDIR)/$(osfile)
$(MAKE) $(WORKDIR)/$(osfile).gz
$(WORKDIR)/$(osfile).gz:
cd $(WORKDIR) && \
gzip -c $(osfile) > $(osfile).gz
clean:
rm -rf $(kerneldir) $(WORKDIR)/$(filename) $(WORKDIR)/modules-* $(WORKDIR)/vmlinuz$(ostype) $(WORKDIR)/*$(kernelname).tcz $(WORKDIR)/$(osfile)* $(WORKDIR)/os-$(osfile)