Makefile, bin/chroot-maint: Allow source distribution selection for Qemu.
[distorted-chroot] / Makefile
CommitLineData
e36b4f25
MW
1### -*-makefile-*-
2###
3### Main maintenance script for chroots
4###
5### (c) 2018 Mark Wooding
6###
7
8###----- Licensing notice ---------------------------------------------------
9###
10### This file is part of the distorted.org.uk chroot maintenance tools.
11###
12### distorted-chroot is free software: you can redistribute it and/or
13### modify it under the terms of the GNU General Public License as
14### published by the Free Software Foundation; either version 2 of the
15### License, or (at your option) any later version.
16###
17### distorted-chroot is distributed in the hope that it will be useful,
18### but WITHOUT ANY WARRANTY; without even the implied warranty of
19### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20### General Public License for more details.
21###
22### You should have received a copy of the GNU General Public License
23### along with distorted-chroot. If not, write to the Free Software
24### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25### USA.
26
27all::
28clean::
3e5b03e2
MW
29check::
30.PHONY: all clean check
e36b4f25
MW
31.SECONDEXPANSION: #sorry
32
33###--------------------------------------------------------------------------
34### Configuration.
35
36CONFIG_VARS =
37
3e5b03e2
MW
38## Level of pickiness to aspire to.
39NOTIFY_FATAL = 1
40
e36b4f25
MW
41## Volume group from which to allocate chroot volumes and snapshots.
42CONFIG_VARS += VG LVPREFIX
afb5d051 43VG := vg-$(shell hostname)
e36b4f25
MW
44LVPREFIX =
45
46## Logical volume size, as an LVM option.
3e5b03e2 47CONFIG_VARS += LVSZ SNAPOPT
e36b4f25 48LVSZ = -L8G
3e5b03e2 49SNAPOPT = -L8G
e36b4f25
MW
50
51## Debian mirror.
52CONFIG_VARS += DEBMIRROR
53DEBMIRROR = http://deb.debian.org/debian/
54
55## APT sources configurations. (Also, $($d_APTSRC) for each $d in $(DISTS).)
56CONFIG_VARS += APTSRC
57APTSRC = etc/aptsrc.conf $(wildcard etc/aptsrc.local.conf)
58
59## APT configuration fragment names. These will be linked into
60## `/etc/apt/apt.conf.d' in each chroot. To put a fragment f in a surprising
a98c9dba
MW
61## place, set $(_$f_APTCONFSRC).
62CONFIG_VARS += APTCONF $(foreach f,$(APTCONF),_$f_APTCONFSRC)
63APTCONF = $(notdir $(wildcard etc/apt-conf.d/[0-9]*[!~]))
e36b4f25
MW
64
65## Proxy setting.
66CONFIG_VARS += PROXY
4d529157 67PROXY = $(shell \
a98c9dba 68 eval $$(apt-config $(foreach a,$(APTCONF),-cetc/apt-conf.d/$a) \
e36b4f25
MW
69 shell proxy Acquire::http::proxy); \
70 case $${proxy+t} in (t) echo "$$proxy" ;; (*) echo nil ;; esac)
71
72## Debian distributions to support.
73CONFIG_VARS += PRIMARY_DIST DISTS
74PRIMARY_DIST = stretch
75DISTS = $(PRIMARY_DIST) buster bullseye sid
76
77## Host's native architecture(s).
78CONFIG_VARS += MYARCH NATIVE_ARCHS
afb5d051
MW
79MYARCH := $(shell dpkg --print-architecture)
80OTHERARCHS := $(shell dpkg --print-foreign-architectures)
e36b4f25
MW
81NATIVE_ARCHS = $(MYARCH) $(OTHERARCHS)
82
83## Foreign (emulated) architectures to support.
84CONFIG_VARS += FOREIGN_ARCHS
85FOREIGN_ARCHS =
86
87## Master lists of chroots to build and maintain.
a98c9dba 88CONFIG_VARS += NATIVE_CHROOTS FOREIGN_CHROOTS
e36b4f25
MW
89NATIVE_CHROOTS = $(foreach a,$(NATIVE_ARCHS), \
90 $(foreach d,$(or $($a_DISTS) $(DISTS)), \
91 $d-$a))
92FOREIGN_CHROOTS = $(foreach a,$(FOREIGN_ARCHS), \
93 $(foreach d,$(or $($a_DISTS) $(DISTS)), \
94 $d-$a))
95
a98c9dba
MW
96## Extra packages to be installed in chroots. `BASE_PACKAGES' are installed
97## through `debootstrap'; `EXTRA_PACKAGES' are installed later, using Apt,
98## which is faster in foreign chroots.
99CONFIG_VARS += BASE_PACKAGES EXTRA_PACKAGES
100BASE_PACKAGES = eatmydata
101EXTRA_PACKAGES = build-essential
102EXTRA_PACKAGES += ccache
103EXTRA_PACKAGES += fakeroot
104EXTRA_PACKAGES += libfile-fcntllock-perl
105EXTRA_PACKAGES += locales
106
107## Extra packages from which to install the cross tools.
108CONFIG_VARS += CROSS_PACKAGES
109CROSS_PACKAGES = bash coreutils dash findutils
110CROSS_PACKAGES += gzip m4 mawk sed tar xz-utils
111CROSS_PACKAGES += apt ccache eatmydata fakeroot make
112CROSS_PACKAGES += qemu-user-static
113CROSS_PACKAGES += $(foreach a,$(FOREIGN_GNUARCHS),\
114 gcc-$a g++-$a binutils-$a)
115
116## Native files to install in place of the foreign versions. `MULTI' here
117## stands for the donor's GNU multiarch name.
118CONFIG_VARS += CROSS_PATHS
119CROSS_PATHS += \
120 $(addprefix /usr/bin/, \
121 apt apt-cache apt-config apt-get apt-key apt-mark) \
122 $(addprefix /usr/lib/apt/, \
123 methods/ solvers/) \
124 $(addprefix /bin/, \
125 cat chgrp chown cp date dd df dir echo false ln ls mkdir \
126 mknod mktemp mv pwd readlink rm rmdir sleep stty sync touch \
127 true uname vdir) \
128 $(addprefix /usr/bin/, \
129 [ arch b2sum base32 base64 basename chcon cksum comm \
130 csplit cut dircolors dirname du env expand expr factor fmt \
131 fold groups head hostid id install join link logname md5sum \
132 mkfifo nice nl nohup nproc numfmt od paste pathchk pinky pr \
133 printenv printf ptx realpath runcon seq sha1sum sha224sum \
134 sha256sum sha384sum sha512sum shred shuf sort split stat \
135 stdbuf sum tac tail tee test timeout tr truncate tsort tty \
136 unexpand uniq unlink users wc who whoami yes) \
137 /usr/lib/MULTI/coreutils/ \
138 $(addprefix /lib/MULTI/, \
139 libnsl.so.* libnss_*.so.*) \
140 /usr/bin/gpgv \
141 /usr/bin/qemu-*-static \
142 $(addprefix /bin/, \
143 bash dash gzip sed tar) \
144 $(addprefix /usr/bin/, \
145 ccache find m4 make mawk xargs xz) \
146 $(addprefix /usr/lib/MULTI/, \
147 libeatmydata.so* libfakeroot/) \
148 $(addprefix /etc/ld.so.conf.d/, \
149 MULTI.conf fakeroot*.conf) \
150 $(foreach a,$(FOREIGN_GNUARCHS), \
151 $(addprefix /usr/bin/$a-, \
152 addr2line ar as c++filt dwp elfedit gprof ld ld.* \
153 nm objcopy objdump ranlib readelf size strings \
154 strip) \
155 $(addprefix /usr/bin/$a-, \
156 cpp gcc g++ gcov gcov-dump gcov-tool gprof \
157 gcc-ar gcc-nm gcc-ranlib) \
158 /usr/lib/gcc-cross/$a/)
3e5b03e2
MW
159
160## Local packages to be compiled and installed in chroots. Archives can be
161## found in `pkg/'.
a98c9dba 162CONFIG_VARS += LOCALPKGS $(foreach p,$(LOCALPKGS),$p_DEPS)
3e5b03e2 163LOCALPKGS = mLib checkpath
a98c9dba
MW
164mLib_DEPS =
165checkpath_DEPS = mLib
3e5b03e2 166
e36b4f25
MW
167## Which host architecture to use for foreign architectures. It turns out
168## that it's best to use a Qemu with the same host bitness as the target
169## architecture; otherwise it has to do a difficult job of converting
170## arguments and results between kernel ABI flavours.
17132BIT_QEMUHOST = $(or $(filter i386,$(NATIVE_ARCHS)),$(TOOLSARCH))
17264BIT_QEMUHOST = $(or $(filter amd64,$(NATIVE_ARCHS)),$(TOOLSARCH))
173
a98c9dba 174CONFIG_VARS += $(foreach a,$(FOREIGN_ARCHS),$a_QEMUHOST)
e36b4f25
MW
175armel_QEMUHOST = $(32BIT_QEMUHOST)
176armhf_QEMUHOST = $(32BIT_QEMUHOST)
177arm64_QEMUHOST = $(64BIT_QEMUHOST)
178i386_QEMUHOST = $(32BIT_QEMUHOST)
179amd64_QEMUHOST = $(64BIT_QEMUHOST)
180
d9f036c4
MW
181## Which distribution of Qemu to use.
182CONFIG_VARS += $(foreach d,$(DISTS),$d_QEMUDIST)
183
e36b4f25
MW
184## Qemu architecture names. These tell us which Qemu binary to use for a
185## particular Debian architecture.
a98c9dba 186CONFIG_VARS += $(foreach a,$(FOREIGN_ARCHS),$a_QEMUARCH)
e36b4f25
MW
187armel_QEMUARCH = arm
188armhf_QEMUARCH = arm
189arm64_QEMUARCH = aarch64
190i386_QEMUARCH = i386
191amd64_QEMUARCH = x86_64
192
193## Alias mapping for chroots.
a98c9dba 194CONFIG_VARS += $(foreach d,$(DISTS),$d_ALIASES)
e36b4f25
MW
195stretch_ALIASES = oldstable
196buster_ALIASES = stable
a98c9dba 197bullseye_ALIASES = testing
e36b4f25
MW
198sid_ALIASES = unstable
199
200## Which host architecture to use for commonly used tools in foreign chroots.
201CONFIG_VARS += TOOLSARCH
202TOOLSARCH = $(MYARCH)
203
204## A directory in which we can maintain private files and state.
205CONFIG_VARS += STATE
206STATE = state
207
208## A directory which will be spliced into chroots as `/usr/local.schroot/'.
209## This will be our primary point of contact with the chroot.
8918e451 210CONFIG_VARS += LOCAL ABSLOCAL
e36b4f25 211LOCAL = local.schroot
8918e451 212ABSLOCAL = $(abspath $(LOCAL))
e36b4f25
MW
213
214## How to run a command as a privileged user.
a98c9dba 215CONFIG_VARS += ROOTLY
e36b4f25
MW
216ROOTLY = sudo
217
218## Files to be copied into a chroot from the host.
219SCHROOT_COPYFILES = /etc/resolv.conf
220SCHROOT_NSSDATABASES = passwd shadow group gshadow
221
222## Local configuration hook.
223-include local.mk
224
225## All chroot names.
3e5b03e2
MW
226CONFIG_VARS += ALL_ARCHS ALL_CHROOTS
227ALL_ARCHS = $(NATIVE_ARCHS) $(FOREIGN_ARCHS)
e36b4f25
MW
228ALL_CHROOTS = $(NATIVE_CHROOTS) $(FOREIGN_CHROOTS)
229
a98c9dba
MW
230## GNU names for foreign architectures.
231CONFIG_VARS += FOREIGN_GNUARCHS
232FOREIGN_GNUARCHS := $(foreach a,$(FOREIGN_ARCHS),\
233 $(shell dpkg-architecture -A$a \
234 -qDEB_TARGET_GNU_TYPE))
235
e36b4f25
MW
236###--------------------------------------------------------------------------
237### Utilities.
238
3e5b03e2
MW
239## Hack to force rebuilding.
240_force:
241.PHONY: _force
242
243## Hack to not delimit function arguments. (Ugh!)
244comma = ,
245
246## Silent-rules machinery.
247V = 0
248V_AT = $(V_AT_$V)
249V_AT_0 = @
250v_print = $(call v_print_$V,$1,$2)
251v_print_0 = printf " %-8s %s\n" "$1" $(call squote,$2);
252v_tag = $(V_AT)$(call v_print,$1,$@)
253v_log = $(call v_log_$V,$1,$2)
254v_log_ = $(call v_log_1,$1,$2)
255v_log_0 = $2 >log/$1.log 2>&1
256v_log_1 = $(call catchrc,$(call throwrc,$2) 2>&1 | tee log/$1.log)
257v_echo = $(call v_echo_$V,$1)
258v_echo_0 = :
259v_echo_1 = printf "%s\n" $1
260CLEANFILES += log/*.log
261
262## Oh, shut up.
263SILENCE_LVM = \
264 LVM_SUPPRESS_FD_WARNINGS=1; export LVM_SUPPRESS_FD_WARNINGS
265
a98c9dba
MW
266## $(call definedp,VAR)
267##
268## Expand non-empty if and only if VAR is defined (but possibly empty).
269definedp = $(filter-out undefined,$(origin $1))
270
3e5b03e2
MW
271## $(call catchrc,...$(call throwrc,CMD)...)
272##
273## Catch the exit status of some subpart of a complicated shell rune.
274catchrc = (exec 3>&1; exit $$({ $1; } 4>&1 >&3 3>&-))
275throwrc = { $1; echo $$? >&4; }
276
277## $(call squote,TXT)
278##
279## Single-quote TXT.
1727e3c6
MW
280squote = '$(subst ','\'',$1)'
281#'
3e5b03e2 282
e36b4f25
MW
283## $(call chroot-dist,D-A) -> D
284## $(call chroot-arch,D-A) -> A
285##
286## Parse chroot descriptions.
287chroot-dist = $(patsubst %/,%,$(dir $(subst -,/,$1)))
288chroot-arch = $(notdir $(subst -,/,$1))
289
3e5b03e2
MW
290## $(call package-dir-name,P-V) -> P
291## $(call package-dir-version,P-V) -> V
292##
293## Parse (source) package directory names.
294package-dir-name = $(sort $(foreach p,$(LOCALPKGS),$(if $(filter $p-$($p_VERSION),$1),$p)))
295package-dir-version = $($(call package-dir-name,$1)_VERSION)
296
297## $(call package-dir,P-V.A) -> P-V
298## $(call package-name,P-V.A) -> P
299## $(call package-version,P-V.A) -> V
300## $(call package-arch,P-V.A) -> A
301##
302## Parse package stamp names.
303package-dir = $(basename $1)
304package-name = $(call package-dir-name,$(call package-dir,$1))
305package-version = $(call package-dir-version,$(call package-dir,$1))
306package-arch = $(patsubst .%,%,$(suffix $1))
307
e36b4f25
MW
308## $(call native-chroot-p,D-A) -> D | <empty>
309##
310## Answer whether D-A is a native chroot.
3e5b03e2 311native-chroot-p = $(filter $(call chroot-arch,$1),$(NATIVE_ARCHS))
e36b4f25
MW
312
313## $(call chroot-qemuhost,D-A) -> AA
314##
315## Answer the apporopriate Qemu host architecture for foreign chroot D-A.
316chroot-qemuhost = $($(call chroot-arch,$1)_QEMUHOST)
317
3e5b03e2 318## $(call chroot-deps,PRE,D-A) -> PREDD-AA ... | <empty>
e36b4f25
MW
319##
320## Answer a list of additional dependencies for the chroot D-A: specifically,
321## if D-A is foreign then include PRE/DD-AA entries for the tools
322## architecture, and Qemu host architecture (if that's different).
323chroot-deps = $(if $(call native-chroot-p,$2),, \
3e5b03e2
MW
324 $(addprefix $1$(call chroot-dist,$2)-,\
325 $(sort $(TOOLSARCH) \
e36b4f25
MW
326 $(call chroot-qemuhost,$2))))
327
328## Substituting placeholders in files.
329SUBSTITUTIONS := local=$(shell realpath $(LOCAL))
330SUBSTITUTIONS += primary-dist=$(PRIMARY_DIST)
331subst-file = { \
332 echo "$1 GENERATED by distorted-chroot: do not edit"; \
333 substs=""; \
334 for v in $(SUBSTITUTIONS); do \
335 var=$${v%%=*} value=$${v\#*=}; \
336 substs="$$substs s\a@$$var@\a$$value\ag;"; \
337 done; \
338 sed "$$substs"; \
339}
340
3e5b03e2
MW
341### $(call symlink-ok-p,LINK,DEST)
342###
343### Expand to `t' if LINK is a symbolic link to DEST, and empty otherwise.
344symlink-ok-p = $(shell \
345 case $$(readlink 2>/dev/null $(patsubst %/,%,$1)) in ($2) echo t ;; esac)
346
347### $(call general-notify,SEV,COLOUR,PREFIX,MSG)
348###
349### Report a message, highlighted in the right way, and maybe fail
350general-notify = { \
351 echo "$$(tput bold; tput setaf $2)$3 "$4"$$(tput sgr0; tput op)"; \
352 if [ "$1" -le "$(NOTIFY_FATAL)" ]; then exit 2; fi; \
353}
354
355### $(call report/SEV,MSG)
356###
357### Report a notification of a particular severity.
358notify/INFO = $(call general-notify,3,6,---,$1)
359notify/WARN = $(call general-notify,2,5,???,$1)
360notify/ERR = $(call general-notify,1,1,!!!,$1)
361
362## $(call check,SEV,MSG,UNLESS)
363##
364## If UNLESS completes successfully, all is OK; otherwise print MSG to stderr
365## and fail.
366check = @{ \
367 $(call v_echo,'check: '$(call squote,$3)''); \
368 if ! { $3; }; then $(call notify/$1,$2); fi; \
369}
370
371## $(call check-executable,SEV,PATH)
372##
373## Verify that PATH is an executable program.
374check-executable = $(call check,$1,"\`$2' is not an executable", \
375 [ -x "$2" ])
376
377## $(call check-mountpoint,SEV,DIR)
378##
379## Verify that DIR is a mountpoint.
380check-mountpoint = $(call check,$1,"\`$2' is not a mount point", \
381 mountpoint -q "$2")
382
383## $(call check-symlink,SEV,LINK,DEST)
384##
385## Verify that LINK is a symbolic link pointing to DEST.
386check-symlink = $(call check,$1,"\`$2' is not a link to \`$3'", \
387 [ -L "$2" ] && [ "$$(readlink "$2")" = "$3" ])
388
389###--------------------------------------------------------------------------
a4c5d71a
MW
390### Python extensions.
391
392CC = gcc
393CFLAGS = -O2 -g -Wall
394
395LD = $(CC)
396LDFLAGS =
397
398c-source = $(foreach c,$1,src/$c)
399c-object = $(foreach c,$1,$(STATE)/obj/$(basename $c).o)
400
401PYEXT_PKGFLAGS := $(shell pkg-config --cflags python2)
402PYEXT_CFLAGS = -fPIC -fno-strict-aliasing $(PYEXT_PKGFLAGS)
403PYEXT_LDFLAGS = -shared
404
405PYEXTS += jobclient
406jobclient_SOURCES = jobclient.c
407
408PYEXT_ALLSRC = $(foreach x,$(PYEXTS),\
409 $(call c-source,$($x_SOURCES)))
410PYEXT_ALLOBJ = $(foreach x,$(PYEXTS),\
411 $(call c-object,$($x_SOURCES)))
412$(PYEXT_ALLOBJ): $(STATE)/obj/%.o: src/%.c
413 $(V_AT)mkdir -p $(dir $@)
414 $(call v_tag,CC)$(CC) -c $(CFLAGS) $(PYEXT_CFLAGS) -o$@ $<
415
416PYMODULES = $(foreach x,$(PYEXTS),$(STATE)/lib/python/$x.so)
417all:: $(PYMODULES)
418$(PYMODULES): $(STATE)/lib/python/%.so: $$(call c-object,$$($$*_SOURCES))
419 $(V_AT)mkdir -p $(dir $@)
420 $(call v_tag,LD)$(LD) $(LDFLAGS) $(PYEXT_LDFLAGS) -o$@ $^
421
422###--------------------------------------------------------------------------
3e5b03e2
MW
423### Scripts.
424
a98c9dba 425SCRIPTS += chroot-maint
3e5b03e2 426SCRIPTS += mkchrootconf
3e5b03e2
MW
427
428SUBST_SCRIPTS = $(addprefix $(STATE)/bin/,$(SCRIPTS))
429all:: $(SUBST_SCRIPTS)
430$(SUBST_SCRIPTS): $(STATE)/bin/%: bin/% $(STATE)/config.sh
431 $(V_AT)mkdir -p $(dir $@)
432 $(call v_tag,SUBST){ \
433 sed \
434 -e '2i### GENERATED by distorted-chroot: do not edit' \
435 -e '/@@@config@@@/ {' \
436 -e 'r $(STATE)/config.sh' \
437 -e 'd'\
438 -e '}' $<; \
439 } >$@.new && chmod +x $@.new && mv $@.new $@
e36b4f25
MW
440
441###--------------------------------------------------------------------------
442### APT configuration.
443
444## In a chroot, `/etc/apt/sources.list' links to
445## `/usr/local.schroot/etc/apt/sources.$d' for the appropriate distribution.
4004ed52 446APT_SOURCES = $(foreach d,$(DISTS),$(LOCAL)/etc/apt/sources.$d)
e36b4f25
MW
447all:: $(APT_SOURCES)
448
4004ed52 449$(foreach d,$(DISTS),$(STATE)/etc/apt/aptsrc.$d): $(STATE)/etc/apt/aptsrc.%:
e36b4f25
MW
450 $(V_AT)mkdir -p $(dir $@)
451 $(call v_tag,GEN){ \
452 echo "### -*-conf-*- GENERATED by distorted-chroot: do not edit"; \
453 echo "subscribe"; \
454 echo " debian : $*"; \
455 } >$@.new && mv $@.new $@
456
457$(APT_SOURCES): $(LOCAL)/etc/apt/sources.%: \
458 $$(APTSRC) $$($$*_APTSRC) $$(STATE)/etc/apt/aptsrc.$$*
459 $(V_AT)mkdir -p $(dir $@)
460 $(call v_tag,GEN)bin/mkaptsrc \
461 $(APTSRC) $($*_APTSRC) $(STATE)/etc/apt/aptsrc.$* \
462 >$@.new && mv $@.new $@
0539140c 463CLEANFILES += $(APT_SOURCES)
e36b4f25
MW
464
465## In a chroot, a link `/etc/apt/apt.conf.d/FOO' is created for each file in
466## `/usr/local.schroot/etc/apt/apt.conf.d/FOO'.
467APT_CONFIGS = $(addprefix $(LOCAL)/etc/apt/apt.conf.d/,$(APTCONF))
468all:: $(APT_CONFIGS)
469$(APT_CONFIGS): $(LOCAL)/etc/apt/apt.conf.d/%: \
a98c9dba 470 $$(or $$(_$$*_APTCONFSRC) etc/apt-conf.d/$$*)
e36b4f25
MW
471 $(V_AT)mkdir -p $(dir $@)
472 $(call v_tag,COPY)cp $< $@.new && mv $@.new $@
3e5b03e2
MW
473clean::; rm -f $(APT_CONFIGS)
474
475###--------------------------------------------------------------------------
476### Build hacks.
477
478check::; $(call check-executable,ERR,/usr/bin/eatmydata)
479
480EATMYDATA_HACKS += apt-get aptitude dpkg
481SYMLINK_EATMYDATA_HACKS = $(addprefix $(LOCAL)/hacks/,$(EATMYDATA_HACKS))
482all:: $(SYMLINK_EATMYDATA_HACKS)
483$(SYMLINK_EATMYDATA_HACKS): $(LOCAL)/hacks/%: \
484 $$(if $$(call symlink-ok-p,$$@,/usr/bin/eatmydata),,_force)
485 $(V_AT)mkdir -p $(dir $@)
486 $(call v_tag,SYMLINK)ln -sf /usr/bin/eatmydata $@.new && mv $@.new $@
487clean::; rm -f $(SYMLINK_EATMYDATA_HACKS)
488
489SCRIPT_HACKS += buildwrap
490COPY_SCRIPT_HACKS = $(addprefix $(LOCAL)/hacks/,$(SCRIPT_HACKS))
491all:: $(COPY_SCRIPT_HACKS)
492$(COPY_SCRIPT_HACKS): $(LOCAL)/hacks/%: bin/%
493 $(V_AT)mkdir -p $(dir $@)
494 $(call v_tag,COPY)cp $< $@.new && mv $@.new $@
495clean::; rm -f $(COPY_SCRIPT_HACKS)
e36b4f25
MW
496
497###--------------------------------------------------------------------------
498### `schroot' and `sbuild' configuration.
499
500all:: schroot-config
501schroot-config::
502.PHONY: schroot-config
503
3e5b03e2
MW
504check::; $(call check-mountpoint,WARN,/var/lib/sbuild/build)
505check::; $(call check-symlink,WARN,/build,/var/lib/sbuild/build)
506check::; $(call check-symlink,ERR,/schroot,/run/schroot/mount)
507
e36b4f25
MW
508%print-varlist = { \
509 echo "\#\#\# -*-sh-*- GENERATED by distorted-chroot: do not edit"; \
a98c9dba
MW
510 $(foreach v,$1,$(if $(call definedp,$v),\
511 echo $v=\'$(call squote,$($v))\';)) \
fb28f2a8 512}
e36b4f25
MW
513schroot-config_HASH := \
514 $(shell $(call %print-varlist,$(CONFIG_VARS)) | \
515 sha256sum | cut -c1-32)
516schroot-config_FILE = $(STATE)/config.sh-$(schroot-config_HASH)
517$(schroot-config_FILE):
518 $(V_AT)mkdir -p $(STATE)
519 $(V_AT)rm -f $(STATE)/config.sh-*
6ccac28c 520 $(call v_tag,GEN)$(call %print-varlist,$(CONFIG_VARS)) \
e36b4f25
MW
521 >$@.new && mv $@.new $@
522
523schroot-config:: $(STATE)/config.sh
524$(STATE)/config.sh: $(schroot-config_FILE)
525 $(call v_tag,SYMLINK)ln -sf $(notdir $<) $@
526
67a8479c
MW
527schroot-config:: $(LOCAL)/etc/schroot/sbuild.schroot
528$(LOCAL)/etc/schroot/sbuild.schroot: $(STATE)/bin/mkchrootconf
e36b4f25 529 $(V_AT)mkdir -p $(dir $@)
3e5b03e2
MW
530 $(call v_tag,GEN)$(STATE)/bin/mkchrootconf >$@.new && \
531 $(ROOTLY) chown root:root $@.new && mv $@.new $@
67a8479c 532CLEANFILES += $(LOCAL)/etc/schroot/sbuild.schroot
8918e451 533check::; $(call check-symlink,WARN,/etc/schroot/chroot.d/sbuild,$(ABSLOCAL)/etc/schroot/sbuild.schroot)
e36b4f25 534
67a8479c
MW
535schroot-config:: $(LOCAL)/etc/schroot/sbuild.profile/copyfiles
536$(LOCAL)/etc/schroot/sbuild.profile/copyfiles: $(schroot-config_STAMP)
e36b4f25
MW
537 $(V_AT)mkdir -p $(dir $@)
538 $(call v_tag,GEN){ \
539 echo "### -*-conf-*- GENERATED by distorted-chroot: do not edit"; \
540 for i in $(SCHROOT_COPYFILES); do echo "$$i"; done; \
541 } >$@.new && mv $@.new $@
67a8479c 542CLEANFILES += $(LOCAL)/etc/schroot/sbuild.profile/copyfiles
e36b4f25 543
67a8479c
MW
544schroot-config:: $(LOCAL)/etc/schroot/sbuild.profile/nssdatabases
545$(LOCAL)/etc/schroot/sbuild.profile/nssdatabases: $(schroot-config_STAMP)
e36b4f25
MW
546 $(V_AT)mkdir -p $(dir $@)
547 $(call v_tag,GEN){ \
548 echo "### -*-conf-*- GENERATED by distorted-chroot: do not edit"; \
549 for i in $(SCHROOT_NSSDATABASES); do echo "$$i"; done; \
550 } >$@.new && mv $@.new $@
67a8479c 551CLEANFILES += $(LOCAL)/etc/schroot/sbuild.profile/nssdatabases
e36b4f25 552
67a8479c
MW
553schroot-config:: $(LOCAL)/etc/schroot/sbuild.profile/fstab
554$(LOCAL)/etc/schroot/sbuild.profile/fstab: \
e36b4f25
MW
555 etc/sbuild.fstab.in $(schroot-config_STAMP)
556 $(V_AT)mkdir -p $(dir $@)
557 $(call v_tag,SUBST)$(call subst-file,### -*-conf-*-) \
558 <$< >$@.new && mv $@.new $@
67a8479c 559CLEANFILES += $(LOCAL)/etc/schroot/sbuild.profile/fstab
e36b4f25 560
8918e451 561check::; $(call check-symlink,WARN,/etc/schroot/sbuild,$(ABSLOCAL)/etc/schroot/sbuild.profile)
3e5b03e2 562
67a8479c
MW
563schroot-config:: $(LOCAL)/etc/sbuild.conf
564$(LOCAL)/etc/sbuild.conf: etc/sbuild.conf.in $(schroot-config_STAMP)
e36b4f25
MW
565 $(V_AT)mkdir -p $(dir $@)
566 $(call v_tag,SUBST)$(call subst-file,### -*-perl-*-) \
567 <$< >$@.new && mv $@.new $@
67a8479c 568CLEANFILES += $(LOCAL)/etc/sbuild.conf
8918e451 569check::; $(call check-symlink,WARN,/etc/sbuild/sbuild.conf,$(ABSLOCAL)/etc/sbuild.conf)
d56d9258 570check::; $(call check-executable,WARN,/usr/local.schroot/hacks/apt-get)
e36b4f25 571
3e5b03e2
MW
572SCHROOT_SCRIPTS += 11private
573SCHROOT_SCRIPTS += 15binfmt
574SCHROOT_SCRIPTS += 51chrootenv
67a8479c 575COPY_SCHROOT_SCRIPTS = $(addprefix $(LOCAL)/etc/schroot/setup.d/,$(SCHROOT_SCRIPTS))
3e5b03e2
MW
576schroot-config:: $(COPY_SCHROOT_SCRIPTS)
577$(COPY_SCHROOT_SCRIPTS): \
67a8479c 578 $(LOCAL)/etc/schroot/setup.d/%: etc/schroot-scripts/%
3e5b03e2
MW
579 $(V_AT)mkdir -p $(dir $@)
580 $(call v_tag,COPY)cp $< $@.new && mv $@.new $@
67a8479c 581CLEANFILES += $(COPY_SCHROOT_SCRIPTS)
3e5b03e2
MW
582
583CHECK_SCHROOT_SCRIPTS = $(addprefix check-script/,$(SCHROOT_SCRIPTS))
584check:: $(CHECK_SCHROOT_SCRIPTS)
585$(CHECK_SCHROOT_SCRIPTS): check-script/%:
8918e451 586 $(call check-symlink,WARN,/etc/schroot/setup.d/$*,$(ABSLOCAL)/etc/schroot/setup.d/$*)
3e5b03e2
MW
587.PHONY: $(addprefix check-script/,$(SCHROOT_SCRIPTS))
588
589###--------------------------------------------------------------------------
0a9fcbbc
MW
590### Ccache setup.
591
592CCACHE_CONFIGS = $(foreach r,$(ALL_CHROOTS), \
593 /var/lib/sbuild/build/.ccache/$(LVPREFIX)$r/ccache.conf)
594all:: $(CCACHE_CONFIGS)
595$(CCACHE_CONFIGS): /var/lib/sbuild/build/.ccache/$(LVPREFIX)%/ccache.conf: \
596 etc/ccache.conf
597 $(V_AT)mkdir -p $(dir $@)
598 $(call v_tag,COPY)cp $< $@.new && mv $@.new $@
599
600###--------------------------------------------------------------------------
3e5b03e2
MW
601### `/usr/local/' structure.
602
603LOCAL_COMMON_DIRS = share/ src/
27922408
MW
604LOCAL_EXTRA_DIRS = share/man/
605all:: $(foreach d,$(LOCAL_COMMON_DIRS) $(LOCAL_EXTRA_DIRS),$(LOCAL)/$d)
606$(foreach d,$(LOCAL_COMMON_DIRS) $(LOCAL_EXTRA_DIRS),$(LOCAL)/$d):
3e5b03e2
MW
607 $(V_AT)mkdir -p $(dir $(patsubst %/,%,$@))
608 $(call v_tag,MKDIR)mkdir $@
609
942fed18
MW
610LOCAL_ARCH_DIRS = bin/ etc/ games/ include/ include.aside/
611LOCAL_ARCH_DIRS += lib/ libexec/ sbin/
3e5b03e2
MW
612LOCAL_ARCH_LINKS = man
613man_LINKDEST = share/man
614all:: $(foreach a,$(ALL_ARCHS),\
615 $(LOCAL)/$a/ \
616 $(foreach d,$(LOCAL_ARCH_DIRS),$(LOCAL)/$a/$d) \
617 $(foreach d,$(LOCAL_ARCH_LINKS),$(LOCAL)/$a/$d) \
618 $(foreach d,$(LOCAL_COMMON_DIRS),$(LOCAL)/$a/$d))
619
620$(foreach a,$(ALL_ARCHS),$(LOCAL)/$a/):
621 $(call v_tag,MKDIR)mkdir $@
622$(foreach a,$(ALL_ARCHS),\
623 $(foreach d,$(LOCAL_ARCH_DIRS),$(LOCAL)/$a/$d)):
624 $(V_AT)mkdir -p $(dir $(patsubst %/,%,$@))
625 $(call v_tag,MKDIR)mkdir $@
626$(foreach a,$(ALL_ARCHS),\
627 $(foreach d,$(LOCAL_ARCH_LINKS),$(LOCAL)/$a/$d)): \
628 $$(if $$(call symlink-ok-p,$$@,$$($$(notdir $$@)_LINKDEST)),,_force)
629 $(V_AT)mkdir -p $(notdir $@)
630 $(call v_tag,SYMLINK)ln -sf $($(notdir $@)_LINKDEST) $@
631$(foreach a,$(ALL_ARCHS),\
632 $(foreach d,$(LOCAL_COMMON_DIRS),$(LOCAL)/$a/$d)): \
633 $$(if $$(call symlink-ok-p,$$@,../$$(notdir $$(patsubst %/,%,$$@))),,_force)
634 $(V_AT)mkdir -p $(dir $(patsubst %/,%,$@))
635 $(call v_tag,SYMLINK)ln -sf ../$(notdir $(patsubst %/,%,$@)) $(patsubst %/,%,$@)
636
e36b4f25 637###--------------------------------------------------------------------------
a98c9dba 638### Main chroot maintenance.
e36b4f25 639
a98c9dba 640OPTS =
642f47f9 641FRESH = 1w
a98c9dba
MW
642JOBS = chroot cross-tools pkg-build
643
644MAINTQ_ = -q
645MAINTQ_0 = -q
fe87403b 646MAINT = +$(call v_tag,MAINT)\
a98c9dba
MW
647 PYTHONPATH=$(STATE)/lib/python $(STATE)/bin/chroot-maint \
648 $(MAINTQ_$V) $(OPTS)
649
650maint: all check
651 $(MAINT) -f$(FRESH) $(JOBS)
652.PHONY: maint
e36b4f25
MW
653
654###--------------------------------------------------------------------------
7443a1fb
MW
655### Running random commands.
656
657CMD = echo %d %a
658subst-command = $(subst %d,$(call chroot-dist,$1), \
659 $(subst %a,$(call chroot-arch,$1), \
660 $(subst %r,$1, $(CMD))))
661
662run: $(foreach c,$(ALL_CHROOTS),run/$c)
663$(foreach c,$(ALL_CHROOTS),run/$c): run/%:
664 $(V_AT)$(call v_print,RUN,$(call subst-command,$*))\
665 $(call subst-command,$*)
666
667###--------------------------------------------------------------------------
e36b4f25
MW
668### Other maintenance targets.
669
670show:; : $x
671
672clean::
673 rm -f $(CLEANFILES)
674 rm -rf $(STATE)
675
676realclean:: clean
677 rm -rf $(LOCAL)
678
679###----- That's all, folks --------------------------------------------------