-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
95 lines (71 loc) · 2.79 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
CONFIG ?= menuconfig
kernel-ver := 5.5.8
kernel-maj := $(word 1,$(subst ., ,$(kernel-ver)))
kernel-dir := linux-$(kernel-ver)
kernel-tar := $(kernel-dir).tar.xz
kernel-url := https://cdn.kernel.org/pub/linux/kernel/v$(kernel-maj).x/$(kernel-tar)
busybox-ver := 1.31.1
busybox-dir := busybox-$(busybox-ver)
busybox-tar := $(busybox-dir).tar.bz2
busybox-url := https://www.busybox.net/downloads/$(busybox-tar)
sysroot := sysroot-$(kernel-ver)
tc = $(1)-unknown-linux-gnu$(if $(filter $(1),arm),eabi,)
karch = $(if $(filter $(1),aarch64),arm64,$(1))
kbuild = $(MAKE) CROSS_COMPILE=$(call tc,$(2))- ARCH=$(call karch,$(2)) O=../$(3) \
-C $(1) $(4)
kinstall = $(if $(filter $(1),arm),zinstall,install)
all: \
aarch64-$(sysroot).tar.xz \
arm-$(sysroot).tar.xz \
powerpc-$(sysroot).tar.xz \
x86_64-$(sysroot).tar.xz
%-$(sysroot).tar.xz: %-$(sysroot)/init
tar cJf $@ $(dir $<)
%-$(sysroot)/init: \
skel/init \
%-$(sysroot)/usr/include/linux/version.h \
%-$(sysroot)/boot/vmlinuz-$(kernel-ver) \
%-$(sysroot)/bin/busybox
$(call tc,$*)-populate -m -s skel/ -d $*-$(sysroot)/ -l c:m
%-$(sysroot)/usr/include/linux/version.h: %-kernel-obj/vmlinux | %-$(sysroot)/usr
+$(call kbuild,$(kernel-dir),$*,$(dir $<),INSTALL_HDR_PATH=$(CURDIR)/$*-$(sysroot)/usr headers_install)
%-$(sysroot)/boot/vmlinuz-$(kernel-ver): %-kernel-obj/vmlinux | %-$(sysroot)/boot
+$(call kbuild,$(kernel-dir),$*,$(dir $<),INSTALL_PATH=$(CURDIR)/$(dir $@) $(call kinstall,$*))
powerpc-$(sysroot)/boot/vmlinuz-$(kernel-ver): powerpc-kernel-obj/arch/powerpc/boot/zImage | powerpc-$(sysroot)/boot
cp $< $@
powerpc-kernel-obj/arch/powerpc/boot/zImage: powerpc-kernel-obj/vmlinux | powerpc-kernel-obj
+$(call kbuild,$(kernel-dir),powerpc,$|,zImage)
%-kernel-config: $(kernel-dir)/Makefile | %-kernel-obj
$(call kbuild,$(kernel-dir),$*,$|,$(CONFIG))
%-kernel-obj/vmlinux: %-kernel-obj/.config $(kernel-dir)/Makefile | %-kernel-obj
+$(call kbuild,$(kernel-dir),$*,$|)
%-kernel-obj/.config: %-kernel.config $(kernel-dir)/Makefile | %-kernel-obj
cp $< $@
$(kernel-dir)/Makefile: $(kernel-tar)
tar maxf $<
$(kernel-tar):
wget -q $(kernel-url)
%-$(sysroot)/bin/busybox: %-busybox-obj/busybox | %-$(sysroot)
+$(call kbuild,$(busybox-dir),$*,$(dir $<),install) && \
cp -a $(dir $<)/_install/* $*-$(sysroot)/
%-busybox-config: $(busybox-dir)/Makefile | %-busybox-obj
$(call kbuild,$(busybox-dir),$*,$|,$(CONFIG))
%-busybox-obj/busybox: %-busybox-obj/.config | %-busybox-obj
+$(call kbuild,$(busybox-dir),$*,$|)
%-busybox-obj/.config: busybox.config $(busybox-dir)/Makefile | %-busybox-obj
cp $< $@
$(busybox-dir)/Makefile: $(busybox-tar)
tar maxf $<
$(busybox-tar):
wget -q $(busybox-url)
%-$(sysroot):
mkdir -p $@
%-$(sysroot)/boot:
mkdir -p $@
%-$(sysroot)/usr:
mkdir -p $@
%-kernel-obj:
mkdir -p $@
%-busybox-obj:
mkdir -p $@
.SECONDARY: