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