-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
262 lines (227 loc) · 6.74 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
SHELL = /bin/bash
PWD = $(shell pwd)
PCD_VERSION ?= $(shell git describe --tags --always --dirty)
export PCD_VERSION
KBUILD_BUILD_USER ?= brimstone
export KBUILD_BUILD_USER
KBUILD_BUILD_HOST ?= the.narro.ws
export KBUILD_BUILD_HOST
LOG ?= >/dev/null 2>/dev/null
ifdef VERBOSE
export VERBOSE
LOG = >&2
endif
ifneq ($(CACHE),)
PATH := /usr/lib/ccache:${PATH}
export PATH
cachedir := -v /tmp/pcd/download:/buildroot/download
CCACHE_DIR := /buildroot/download/ccache
export CCACHE_DIR
endif
ifneq ($(shell which docker),)
DOCKER ?= docker
endif
PACKERDEBUG=
ifdef DEBUG
PACKERDEBUG=-var 'boot_debug=docker exec -it ssh /bin/sh<enter><wait10><wait10><wait10><wait10>touch /tmp/ssh.log; tail -f /tmp/ssh.log&'
endif
KVMSERIAL=-nographic
ifdef GUI
KVMSERIAL=-serial stdio
endif
KVMSOURCE=-cdrom output/pcd-${PCD_VERSION}.iso -boot d
ifdef KERNEL
KVMSOURCE=-kernel output/pcd-${PCD_VERSION}.vmlinuz -append "console=ttyS0 initcall_debug url=http://10.0.2.2:8000/config.yaml"
endif
.DEFAULT_GOAL := help
.PHONY: help
help:
@awk 'BEGIN { \
FS = ":.*##"; \
printf "\nUsage:\n make \033[36m<target>\033[0m\n"\
} \
/^[a-zA-Z_-]+:.*?##/ { \
printf " \033[36m%-17s\033[0m %s\n", $$1, $$2 \
} \
/^##@/ { \
printf "\n\033[1m%s\033[0m\n", substr($$0, 5) \
} ' $(MAKEFILE_LIST)
##@ Build targets
.PHONY: all
all: box gce ## Produce the iso, raw kernel file, vagrant box, and GCE disk image
iso: output/pcd-${PCD_VERSION}.iso ## Produce an iso
ifneq (${DOCKER},)
output/pcd-${PCD_VERSION}.iso:
$(MAKE) docker
.PHONY: docker_image docker
docker_image:
@${DOCKER} build -t pcd:${PCD_VERSION} . ${LOG}
docker: docker_image
@echo "Building with docker"
@${DOCKER} run --rm -i \
-e PCD_VERSION \
-e KBUILD_BUILD_USER \
-e KBUILD_BUILD_HOST \
-e VERBOSE \
-e CACHE \
-e ARCH \
$(cachedir) \
pcd:${PCD_VERSION} make tar | tee /tmp/pcd.tar | tar -xC output
@iso-read -i output/pcd-${PCD_VERSION}.iso -e primary -o output/pcd-${PCD_VERSION}.vmlinuz
shell: docker_image
${DOCKER} run --rm -it \
-e PCD_VERSION \
$(cachedir) \
pcd:${PCD_VERSION}
else
output/pcd-${PCD_VERSION}.iso: kernel.lz
@rm -rf iso >&2
@mkdir iso >&2
@cp syslinux/syslinux/bios/core/isolinux.bin iso/ >&2
@cp syslinux/syslinux/bios/com32/elflink/ldlinux/ldlinux.c32 iso/ >&2
@cp kernel.lz iso/primary >&2
@cp installer iso >&2
@cd iso; sha256sum primary installer >sha256sum
@if [ -e signingkey.priv ]; then \
cd iso \
&& notminisign sign -i sha256sum -s ../signingkey.priv -o sha256sum.sig >&2 \
; fi
@echo "default pcd" > iso/isolinux.cfg
@echo "label pcd" >> iso/isolinux.cfg
@echo " kernel primary" >> iso/isolinux.cfg
@mkdir output
@genisoimage -o output/pcd-${PCD_VERSION}.iso \
-b isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table \
-J -V pcd iso/ >&2
endif
.PHONY: box
box: output/pcd-${PCD_VERSION}.box ## Produce a vagrant box
output/pcd-${PCD_VERSION}.box: output/pcd-${PCD_VERSION}.iso
cd packer \
; packer build \
${PACKERDEBUG} \
-var 'iso=${PWD}/output/pcd-${PCD_VERSION}.iso' \
-var 'version=${PCD_VERSION}' \
packer.json
.PHONY: img
img: output/pcd-${PCD_VERSION}.img ## Produce a raw disk image
output/pcd-${PCD_VERSION}.img: output/pcd-${PCD_VERSION}.iso output/pcd-${PCD_VERSION}.vmlinuz
dd if=/dev/zero of=$@ bs=4M count=256 conv=sparse
python -m SimpleHTTPServer & \
spid=$$! \
&& kvm -m 1024 -nographic -cdrom output/pcd-${PCD_VERSION}.iso \
-kernel output/pcd-${PCD_VERSION}.vmlinuz \
-append 'console=ttyS0 url=http://10.0.2.2:8000/install.yaml' \
$@ \
&& kill $$spid
.PHONY: gce
gce: output/pcd-${PCD_VERSION}.gce.tar.gz ## Produce the GCE image
output/pcd-${PCD_VERSION}.gce.tar.gz: output/pcd-${PCD_VERSION}.img
cp $< output/disk.raw
tar -Sczvf $@ -C output disk.raw
rm output/disk.raw
##@ Helper targets
.PHONY: kernel
kernel:
@echo "$$(date) Building kernel" >&2
@cd kernel && make </dev/null ${LOG}
ifeq (${ARCH},um)
kernel.lz: kernel out
@cd kernel/linux \
&& make CONFIG_INITRAMFS_SOURCE=${PWD}/out LOCALVERSION=-${PCD_VERSION} ${LOG} \
&& ls -l kernel ${LOG}
else
kernel.lz: kernel out
@cd kernel/linux \
&& make CONFIG_INITRAMFS_SOURCE=${PWD}/out LOCALVERSION=-${PCD_VERSION} ${LOG} \
&& cp arch/x86/boot/bzImage ../../kernel.lz ${LOG}
endif
.PHONY: libc
libc:
@echo "$$(date) Building musl" >&2
@cd musl && make ${LOG}
.PHONY: components
components: libc kernel
@for dir in */Makefile; do \
[ "$$dir" = "kernel/Makefile" ] && continue; \
[ "$$dir" = "musl/Makefile" ] && continue; \
echo "$$(date) Building $$(dirname "$$dir")" >&2; \
make -C "$$(dirname "$$dir")" ${LOG} || exit $$?; \
done
out: components
@echo "Extracting compiled modules to output directory" >&2
@mkdir -p out/dev >&2
@mknod out/dev/console c 136 0 >&2
@mknod out/dev/null c 1 3 >&2
@tar -xf kernel/out.tar -C out >&2
@tar -xf busybox/out.tar -C out >&2
@for tar in */out.tar; do \
[ "$$tar" = "kernel/out.tar" ] && continue; \
[ "$$tar" = "busybox/out.tar" ] && continue; \
tar -xf "$$tar" -C out >&2; \
done
@cat out/etc/ssl/certs/* > out/etc/ssl/certs/ca-certificates.crt
@mksquashfs out out.squash -comp zstd -Xcompression-level 22 >&2
@cd out; find . \
! -path ./bin/busybox \
-a ! -path ./init \
-a ! -path ./dev/console \
-a ! -path ./dev/null \
-delete || true
@mv out.squash out/squash
@find out ! -type d -ls >&2
.PHONY: tar
tar: output/pcd-${PCD_VERSION}.iso
@echo "Extracting output files" >&2
@tar -cf - -C output pcd-${PCD_VERSION}.iso
@echo "Export complete" >&2
.PHONY: clean
clean: ## Clean output directory
-rm output/pcd-*
.PHONY: dist-clean
dist-clean: clean
ifneq ($(CACHE),)
-docker run $(cachedir) --rm -i busybox rm -rf /buildroot/download/\*
endif
kvm: pcd.qcow2 ## Start a debug session in a kvm environment
kvm -m 1024 \
${KVMSERIAL} \
${KVMSOURCE} \
-usb \
-device usb-ehci \
-device usb-kbd \
-netdev user,id=net,hostfwd=tcp::2375-:2375 \
-device e1000,netdev=net \
pcd.qcow2 || true
pcd.qcow2:
qemu-img create -f qcow2 pcd.qcow2 20G
reload-box:
-vagrant box remove -f pcd
vagrant box add pcd.box --name pcd
.PHONY: vagrant-service
vagrant-service:
docker build -t vagrant vagrant-service
docker save vagrant > packer/http/vagrant.tar
ifneq ($(shell which docker),)
debug: docker_image
docker run --rm -it \
-e PCD_VERSION \
-e KBUILD_BUILD_USER \
-e KBUILD_BUILD_HOST \
-e VERBOSE \
-e ARCH \
$(cachedir) \
pcd:${PCD_VERSION} \
/bin/bash -c 'make debug; /bin/bash'
else
debug: ## Start a debug session in the build environment
# uncomment these to debug components
make kernel libc
make -C e2fsprogs
endif
.PHONY: versions
versions: ## Show versions of components used
@grep -E '^[A-Z]*_VERSION :' */Makefile -h | sort | uniq | sed 's/_VERSION//;s/ :=/:/;s/[A-Z]/\L&/g'
.PHONY: update
update:
@for f in */update; do pushd $$(dirname "$$f") >/dev/null; ./update; popd >/dev/null; done