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