-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
228 lines (184 loc) · 8.09 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
#
# Build a debian and armbian based initramfs system
#
# TODO:
# - Convert the minimalisation step into an excludes file generator
# and use that file in the cpio step
# - Add config file list / save to sdcard / load from sdcard package
# Default to just looking in the local directory for config files
CONFIGDIRS ?= .
CONFIG_DEBIAN = buster
CONFIG_DEBIAN_ARCH ?= armhf
CONFIG_ROOT_PASS = root
# Directories
BUILD = build
TAG = $(BUILD)/tags
DEBOOT = $(BUILD)/debian.$(CONFIG_DEBIAN).$(CONFIG_DEBIAN_ARCH)
BUILD_DEPENDS = \
multistrap \
binfmt-support \
qemu-user-static \
qemu-system-x86 \
expect \
shellcheck \
python3-jinja2 \
python3-libarchive-c \
flake8
# A default target to tell you what other targets might work
all:
$(info Build a platform neutral debian install)
$(info Try: $(MAKE) build/debian.$(CONFIG_DEBIAN).armhf.cpio CONFIG_DEBIAN_ARCH=$(CONFIG_DEBIAN_ARCH))
$(info or other variations for i386)
# Build and boot a test environment
.PHONY: test_run
test_run:
$(MAKE) -C test
# Run a test script against the booted test environment
.PHONY: test
test: shellcheck flake8
$(MAKE) -C test prepare
./scripts/test_harness "make test_run" config_pass=$(CONFIG_ROOT_PASS) tests/*.expect
# A list of all the shell scripts that need linting
# the scripts we run during the build
SHELLSCRIPTS := scripts/packages.addextra scripts/packages.runscripts
SHELLSCRIPTS += scripts/configdir_deps
SHELLSCRIPTS += scripts/authorized_keys_local scripts/authorized_keys_path
# then the scripts that are copied into the build
SHELLSCRIPTS += multistrap.configscript policy-rc.d
# Add the custom phase scripts
SHELLSCRIPTS += packages.d/*.minimise packages.d/*.fixup #packages.d/*.customise
# Add the pre-systemd init system (runs inside the image)
SHELLSCRIPTS += packages.d/_ALWAYS.fixup.add/init \
packages.d/_ALWAYS.fixup.add/init.d/*
# Add scripts that run inside the image
SHELLSCRIPTS += packages.d/_ALWAYS.fixup.add/usr/local/sbin/config_save \
packages.d/hostapd.customise.add/usr/local/sbin/hostapd.template \
packages.d/systemd.customise.add/usr/local/sbin/mesh.setup \
packages.d/systemd.customise.add/usr/local/sbin/udc.setup
# Run a shell script linter
shellcheck:
shellcheck $(SHELLSCRIPTS)
# A list of python scripts that need linting
PYTHONSCRIPTS := scripts/cpio-ls
PYTHONSCRIPTS += scripts/multistrapconf-create
# Run a python linter
flake8:
flake8 $(PYTHONSCRIPTS)
# install any packages needed for this builder
build-depends: $(TAG)/build-depends
$(TAG)/build-depends: Makefile
sudo apt-get -qq install $(BUILD_DEPENDS)
$(call tag,build-depends)
# some of the debian packages need a urandom to install properly
$(DEBOOT)/dev/urandom:
mkdir -p $(DEBOOT)/dev
sudo mknod $(DEBOOT)/dev/urandom c 1 9
$(TAG)/policy-rc.d.add: policy-rc.d
sudo mkdir -p $(DEBOOT)/usr/sbin
sudo cp $< $(DEBOOT)/usr/sbin/policy-rc.d
$(call tag,policy-rc.d.add)
# a list of files, which contain additional packages to install
packages_lists := $(wildcard $(addsuffix /packages.txt,$(CONFIGDIRS)))
multistrap_jinja := debian.multistrap.jinja
multistrap_jinja_src := $(lastword $(wildcard $(addsuffix /$(multistrap_jinja),$(CONFIGDIRS))))
multistrap_apt_source := $(lastword $(wildcard $(addsuffix /apt.sources/$(CONFIG_DEBIAN).list,$(CONFIGDIRS))))
MULTISTRAP_CONF=$(BUILD)/debian.$(CONFIG_DEBIAN).multistrap
$(MULTISTRAP_CONF): scripts/multistrapconf-create
$(MULTISTRAP_CONF): $(multistrap_jinja_src) $(packages_lists)
scripts/multistrapconf-create \
--source $(multistrap_apt_source) \
--template $(multistrap_jinja_src) \
$(addprefix --packagefile=, $(packages_lists)) \
--output $@
.PHONY: builddir
builddir:
mkdir -p $(BUILD)
# multistrap-pre runs the basic multistrap program, installing the packages
# until they need to run native code
$(TAG)/multistrap-pre.$(CONFIG_DEBIAN_ARCH): builddir
$(TAG)/multistrap-pre.$(CONFIG_DEBIAN_ARCH): $(TAG)/policy-rc.d.add
$(TAG)/multistrap-pre.$(CONFIG_DEBIAN_ARCH): $(MULTISTRAP_CONF)
$(TAG)/multistrap-pre.$(CONFIG_DEBIAN_ARCH): multistrap.configscript
$(TAG)/multistrap-pre.$(CONFIG_DEBIAN_ARCH): $(DEBOOT)/dev/urandom
sudo /usr/sbin/multistrap -d $(DEBOOT) --arch $(CONFIG_DEBIAN_ARCH) \
-f $(MULTISTRAP_CONF) >$(BUILD)/multistrap-pre.log
$(call tag,multistrap-pre.$(CONFIG_DEBIAN_ARCH))
# multistrap-post runs the package configure scripts under emulation
$(TAG)/multistrap-post.$(CONFIG_DEBIAN_ARCH): $(TAG)/multistrap-pre.$(CONFIG_DEBIAN_ARCH)
sudo chroot $(DEBOOT) ./multistrap.configscript >>$(BUILD)/multistrap.log
$(call tag,multistrap-post.$(CONFIG_DEBIAN_ARCH))
# perform the debian install
$(TAG)/multistrap.$(CONFIG_DEBIAN_ARCH): $(TAG)/multistrap-pre.$(CONFIG_DEBIAN_ARCH) $(TAG)/multistrap-post.$(CONFIG_DEBIAN_ARCH)
$(call tag,multistrap.$(CONFIG_DEBIAN_ARCH))
# TODO
# - the make targets using the ./scripts/packages.runscripts system should
# be depending on all the packages.d/ scripts. Need to add a auto
# dep system to do this.
# TODO - use dpkg config to avoid installing the locale files:
# eg:
# --path-exclude=/usr/share/doc/*
# --path-include=/usr/share/doc/*/copyright
# script deps
$(TAG)/minimise.$(CONFIG_DEBIAN_ARCH): ./scripts/packages.addextra
$(TAG)/minimise.$(CONFIG_DEBIAN_ARCH): ./scripts/packages.runscripts
$(TAG)/fixup.$(CONFIG_DEBIAN_ARCH): ./scripts/packages.addextra
$(TAG)/fixup.$(CONFIG_DEBIAN_ARCH): ./scripts/packages.runscripts
$(TAG)/customise.$(CONFIG_DEBIAN_ARCH): ./scripts/packages.addextra
$(TAG)/customise.$(CONFIG_DEBIAN_ARCH): ./scripts/packages.runscripts
$(TAG)/customise.$(CONFIG_DEBIAN_ARCH): scripts/authorized_keys_local
$(TAG)/customise.$(CONFIG_DEBIAN_ARCH): scripts/authorized_keys_path
# minimise the image size
$(TAG)/minimise.$(CONFIG_DEBIAN_ARCH): $(TAG)/multistrap.$(CONFIG_DEBIAN_ARCH)
sudo env "CONFIGDIRS=$(CONFIGDIRS)" ./scripts/packages.addextra \
$(DEBOOT) $(CONFIG_DEBIAN_ARCH) minimise
sudo env "CONFIGDIRS=$(CONFIGDIRS)" ./scripts/packages.runscripts \
$(DEBOOT) $(CONFIG_DEBIAN_ARCH) minimise
sudo rm -f $(DEBOOT)/multistrap.configscript $(DEBOOT)/dev/mmcblk0
$(call tag,minimise.$(CONFIG_DEBIAN_ARCH))
# fixup the image to actually boot
$(TAG)/fixup.$(CONFIG_DEBIAN_ARCH): $(TAG)/multistrap.$(CONFIG_DEBIAN_ARCH)
sudo env "CONFIGDIRS=$(CONFIGDIRS)" ./scripts/packages.addextra \
$(DEBOOT) $(CONFIG_DEBIAN_ARCH) fixup
sudo env "CONFIGDIRS=$(CONFIGDIRS)" ./scripts/packages.runscripts \
$(DEBOOT) $(CONFIG_DEBIAN_ARCH) fixup
sudo rm -f $(DEBOOT)/usr/sbin/policy-rc.d
$(call tag,fixup.$(CONFIG_DEBIAN_ARCH))
# image customisation - setting the default config.
$(TAG)/customise.$(CONFIG_DEBIAN_ARCH): $(TAG)/multistrap.$(CONFIG_DEBIAN_ARCH)
sudo env "CONFIGDIRS=$(CONFIGDIRS)" ./scripts/authorized_keys_local \
$(DEBOOT) $(CONFIG_DEBIAN_ARCH) customise
sudo env "CONFIGDIRS=$(CONFIGDIRS)" ./scripts/authorized_keys_path \
$(DEBOOT) $(CONFIG_DEBIAN_ARCH) customise
sudo env "CONFIGDIRS=$(CONFIGDIRS)" ./scripts/packages.addextra \
$(DEBOOT) $(CONFIG_DEBIAN_ARCH) customise
sudo env "CONFIGDIRS=$(CONFIGDIRS)" ./scripts/packages.runscripts \
$(DEBOOT) $(CONFIG_DEBIAN_ARCH) customise
echo root:$(CONFIG_ROOT_PASS) | sudo chpasswd -c SHA256 -R $(realpath $(DEBOOT))
$(call tag,customise.$(CONFIG_DEBIAN_ARCH))
# TODO: consider what password should be default
debian: $(TAG)/debian.$(CONFIG_DEBIAN_ARCH)
$(TAG)/debian.$(CONFIG_DEBIAN_ARCH): $(TAG)/minimise.$(CONFIG_DEBIAN_ARCH) $(TAG)/fixup.$(CONFIG_DEBIAN_ARCH) $(TAG)/customise.$(CONFIG_DEBIAN_ARCH)
$(call tag,debian.$(CONFIG_DEBIAN_ARCH))
$(BUILD)/debian.$(CONFIG_DEBIAN).$(CONFIG_DEBIAN_ARCH).cpio: $(TAG)/debian.$(CONFIG_DEBIAN_ARCH)
( \
cd $(DEBOOT); \
sudo find . -print0 | sudo cpio -0 -H newc -R 0:0 -o \
) > $@
# Create a dependancy file for a given configdir
%configdir.deps: Makefile
scripts/configdir_deps $@
CONFIGDIR_DEPS := $(addsuffix /.configdir.deps, $(CONFIGDIRS))
include $(CONFIGDIR_DEPS)
# Misc make infrastructure below here
%.lzma: %.cpio
lzma <$< >$@
clean:
rm -f $(MULTISTRAP_CONF) $(TAG)/* $(CONFIGDIR_DEPS)
sudo rm -rf $(BUILD)/debian.$(CONFIG_DEBIAN).*
reallyclean:
rm -rf $(BUILD)
define tag
@echo Touching tag $1
@mkdir -p $(TAG)
@touch $(TAG)/$1
endef