3 ### Main maintenance script for chroots
5 ### (c) 2018 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the distorted.org.uk chroot maintenance tools.
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.
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.
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,
30 .PHONY
: all clean check
31 .SECONDEXPANSION
: #sorry
33 ###--------------------------------------------------------------------------
38 ## Level of pickiness to aspire to.
41 ## Path to this working tree.
45 ## Volume group from which to allocate chroot volumes and snapshots.
46 CONFIG_VARS
+= VG LVPREFIX
47 VG
= vg-
$(shell hostname
)
50 ## Logical volume size, as an LVM option.
51 CONFIG_VARS
+= LVSZ SNAPOPT
56 CONFIG_VARS
+= DEBMIRROR
57 DEBMIRROR
= http
://deb.debian.org
/debian
/
59 ## APT sources configurations. (Also, $($d_APTSRC) for each $d in $(DISTS).)
61 APTSRC
= etc
/aptsrc.conf
$(wildcard etc
/aptsrc.local.conf
)
63 ## APT configuration fragment names. These will be linked into
64 ## `/etc/apt/apt.conf.d' in each chroot. To put a fragment f in a surprising
65 ## place, set $($f_APTCONFSRC).
66 CONFIG_VARS
+= APTCONF
67 APTCONF_DIR
= etc
/apt-conf.d
68 APTCONF
= $(notdir $(wildcard $(APTCONF_DIR
)/[0-9]*[!~
]))
73 eval
$$(apt-config
$(foreach a
,$(APTCONF
), -c
$(APTCONF_DIR
)/$a) \
74 shell proxy Acquire
::http
::proxy
); \
75 case
$${proxy
+t
} in
(t
) echo
"$$proxy" ;; (*) echo nil
;; esac
)
77 ## Debian distributions to support.
78 CONFIG_VARS
+= PRIMARY_DIST DISTS
79 PRIMARY_DIST
= stretch
80 DISTS
= $(PRIMARY_DIST
) buster bullseye sid
82 ## Host's native architecture(s).
83 CONFIG_VARS
+= MYARCH NATIVE_ARCHS
84 MYARCH
= $(shell dpkg
--print-architecture
)
85 OTHERARCHS
= $(shell dpkg
--print-foreign-architectures
)
86 NATIVE_ARCHS
= $(MYARCH
) $(OTHERARCHS
)
88 ## Foreign (emulated) architectures to support.
89 CONFIG_VARS
+= FOREIGN_ARCHS
92 ## Master lists of chroots to build and maintain.
93 NATIVE_CHROOTS
= $(foreach a
,$(NATIVE_ARCHS
), \
94 $(foreach d
,$(or
$($a_DISTS) $(DISTS
)), \
96 FOREIGN_CHROOTS
= $(foreach a
,$(FOREIGN_ARCHS
), \
97 $(foreach d
,$(or
$($a_DISTS) $(DISTS
)), \
100 ## Extra packages to be installed in chroots.
101 CONFIG_VARS
+= BASE_PACKAGES NATIVE_BASE_PACKAGES FOREIGN_BASE_PACKAGES
102 BASE_PACKAGES
= ccache
103 BASE_PACKAGES
+= eatmydata fakeroot
104 BASE_PACKAGES
+= locales tzdata
105 BASE_PACKAGES
+= libfile-fcntllock-perl
106 NATIVE_BASE_PACKAGES
= build-essential
107 FOREIGN_BASE_PACKAGES
=
109 ## Local packages to be compiled and installed in chroots. Archives can be
111 LOCALPKGS
= mLib checkpath
113 ## Which host architecture to use for foreign architectures. It turns out
114 ## that it's best to use a Qemu with the same host bitness as the target
115 ## architecture; otherwise it has to do a difficult job of converting
116 ## arguments and results between kernel ABI flavours.
117 32BIT_QEMUHOST
= $(or
$(filter i386
,$(NATIVE_ARCHS
)),$(TOOLSARCH
))
118 64BIT_QEMUHOST
= $(or
$(filter amd64
,$(NATIVE_ARCHS
)),$(TOOLSARCH
))
120 CONFIG_VARS
+= $(foreach a
,$(FOREIGN_ARCHS
), $a_QEMUHOST)
121 armel_QEMUHOST
= $(32BIT_QEMUHOST
)
122 armhf_QEMUHOST
= $(32BIT_QEMUHOST
)
123 arm64_QEMUHOST
= $(64BIT_QEMUHOST
)
124 i386_QEMUHOST
= $(32BIT_QEMUHOST
)
125 amd64_QEMUHOST
= $(64BIT_QEMUHOST
)
127 ## Qemu architecture names. These tell us which Qemu binary to use for a
128 ## particular Debian architecture.
129 CONFIG_VARS
+= $(foreach a
,$(FOREIGN_ARCHS
), $a_QEMUARCH)
132 arm64_QEMUARCH
= aarch64
134 amd64_QEMUARCH
= x86_64
136 ## Alias mapping for chroots.
137 CONFIG_VARS
+= $(foreach d
,$(DISTS
), $d_ALIASES)
138 stretch_ALIASES
= oldstable
139 buster_ALIASES
= stable
140 bullseye_ALIASE
= testing
141 sid_ALIASES
= unstable
143 ## Which host architecture to use for commonly used tools in foreign chroots.
144 CONFIG_VARS
+= TOOLSARCH
145 TOOLSARCH
= $(MYARCH
)
147 ## A directory in which we can maintain private files and state.
151 ## A directory which will be spliced into chroots as `/usr/local.schroot/'.
152 ## This will be our primary point of contact with the chroot.
154 LOCAL
= local.schroot
156 ## How to run a command as a privileged user.
159 ## Files to be copied into a chroot from the host.
160 SCHROOT_COPYFILES
= /etc
/resolv.conf
161 SCHROOT_NSSDATABASES
= passwd shadow group gshadow
163 ## Local configuration hook.
167 CONFIG_VARS
+= ALL_ARCHS ALL_CHROOTS
168 ALL_ARCHS
= $(NATIVE_ARCHS
) $(FOREIGN_ARCHS
)
169 ALL_CHROOTS
= $(NATIVE_CHROOTS
) $(FOREIGN_CHROOTS
)
171 ###--------------------------------------------------------------------------
174 ## Hack to force rebuilding.
178 ## Hack to not delimit function arguments. (Ugh!)
181 ## Silent-rules machinery.
185 v_print
= $(call v_print_
$V,$1,$2)
186 v_print_0
= printf
" %-8s %s\n" "$1" $(call squote
,$2);
187 v_tag
= $(V_AT
)$(call v_print
,$1,$@
)
188 v_log
= $(call v_log_
$V,$1,$2)
189 v_log_
= $(call v_log_1
,$1,$2)
190 v_log_0
= $2 >log
/$1.log
2>&1
191 v_log_1
= $(call catchrc
,$(call throwrc
,$2) 2>&1 | tee log
/$1.log
)
192 v_echo
= $(call v_echo_
$V,$1)
194 v_echo_1
= printf
"%s\n" $1
195 CLEANFILES
+= log
/*.log
199 LVM_SUPPRESS_FD_WARNINGS
=1; export LVM_SUPPRESS_FD_WARNINGS
201 ## $(call catchrc,...$(call throwrc,CMD)...)
203 ## Catch the exit status of some subpart of a complicated shell rune.
204 catchrc
= (exec
3>&1; exit
$$({ $1; } 4>&1 >&3 3>&-))
205 throwrc
= { $1; echo
$$?
>&4; }
207 ## $(call squote,TXT)
210 squote
= '$(subst ','\\'',$1)'
212 ## $(call chroot-dist,D-A) -> D
213 ## $(call chroot-arch,D-A) -> A
215 ## Parse chroot descriptions.
216 chroot-dist
= $(patsubst %/,%,$(dir $(subst -,/,$1)))
217 chroot-arch
= $(notdir $(subst -,/,$1))
219 ## $(call package-dir-name,P-V) -> P
220 ## $(call package-dir-version,P-V) -> V
222 ## Parse (source) package directory names.
223 package-dir-name
= $(sort $(foreach p
,$(LOCALPKGS
),$(if
$(filter $p-$($p_VERSION),$1),$p)))
224 package-dir-version
= $($(call package-dir-name
,$1)_VERSION
)
226 ## $(call package-dir,P-V.A) -> P-V
227 ## $(call package-name,P-V.A) -> P
228 ## $(call package-version,P-V.A) -> V
229 ## $(call package-arch,P-V.A) -> A
231 ## Parse package stamp names.
232 package-dir
= $(basename $1)
233 package-name
= $(call package-dir-name
,$(call package-dir
,$1))
234 package-version
= $(call package-dir-version
,$(call package-dir
,$1))
235 package-arch
= $(patsubst .
%,%,$(suffix $1))
237 ## $(call native-chroot-p,D-A) -> D | <empty>
239 ## Answer whether D-A is a native chroot.
240 native-chroot-p
= $(filter $(call chroot-arch
,$1),$(NATIVE_ARCHS
))
242 ## $(call chroot-qemuhost,D-A) -> AA
244 ## Answer the apporopriate Qemu host architecture for foreign chroot D-A.
245 chroot-qemuhost
= $($(call chroot-arch
,$1)_QEMUHOST
)
247 ## $(call chroot-deps,PRE,D-A) -> PREDD-AA ... | <empty>
249 ## Answer a list of additional dependencies for the chroot D-A: specifically,
250 ## if D-A is foreign then include PRE/DD-AA entries for the tools
251 ## architecture, and Qemu host architecture (if that's different).
252 chroot-deps
= $(if
$(call native-chroot-p
,$2),, \
253 $(addprefix $1$(call chroot-dist
,$2)-,\
254 $(sort $(TOOLSARCH
) \
255 $(call chroot-qemuhost
,$2))))
257 ## Substituting placeholders in files.
258 SUBSTITUTIONS
:= local
=$(shell realpath
$(LOCAL
))
259 SUBSTITUTIONS
+= primary-dist
=$(PRIMARY_DIST
)
261 echo
"$1 GENERATED by distorted-chroot: do not edit"; \
263 for v in
$(SUBSTITUTIONS
); do \
264 var
=$${v
%%=*} value
=$${v\
#*=}; \
265 substs
="$$substs s\a@$$var@\a$$value\ag;"; \
270 ### $(call symlink-ok-p,LINK,DEST)
272 ### Expand to `t' if LINK is a symbolic link to DEST, and empty otherwise.
273 symlink-ok-p
= $(shell \
274 case
$$(readlink
2>/dev
/null
$(patsubst %/,%,$1)) in
($2) echo t
;; esac
)
276 ### $(call general-notify,SEV,COLOUR,PREFIX,MSG)
278 ### Report a message, highlighted in the right way, and maybe fail
280 echo
"$$(tput bold; tput setaf $2)$3 "$4"$$(tput sgr0; tput op)"; \
281 if
[ "$1" -le
"$(NOTIFY_FATAL)" ]; then exit
2; fi
; \
284 ### $(call report/SEV,MSG)
286 ### Report a notification of a particular severity.
287 notify
/INFO
= $(call general-notify
,3,6,---,$1)
288 notify
/WARN
= $(call general-notify
,2,5,???
,$1)
289 notify
/ERR
= $(call general-notify
,1,1,!!!,$1)
291 ## $(call check,SEV,MSG,UNLESS)
293 ## If UNLESS completes successfully, all is OK; otherwise print MSG to stderr
296 $(call v_echo
,'check: '$(call squote
,$3)''); \
297 if
! { $3; }; then
$(call notify
/$1,$2); fi
; \
300 ## $(call check-executable,SEV,PATH)
302 ## Verify that PATH is an executable program.
303 check-executable
= $(call
check,$1,"\`$2' is not an executable", \
306 ## $(call check-mountpoint,SEV,DIR)
308 ## Verify that DIR is a mountpoint.
309 check-mountpoint
= $(call
check,$1,"\`$2' is not a mount point", \
312 ## $(call check-symlink,SEV,LINK,DEST)
314 ## Verify that LINK is a symbolic link pointing to DEST.
315 check-symlink
= $(call
check,$1,"\`$2' is not a link to \`$3'", \
316 [ -L
"$2" ] && [ "$$(readlink "$2")" = "$3" ])
318 ###--------------------------------------------------------------------------
321 SCRIPTS
+= mkbuildchroot
322 SCRIPTS
+= mkchrootconf
323 SCRIPTS
+= install-cross-tools update-cross-tools
325 SUBST_SCRIPTS
= $(addprefix $(STATE
)/bin
/,$(SCRIPTS
))
326 all:: $(SUBST_SCRIPTS
)
327 $(SUBST_SCRIPTS
): $(STATE
)/bin
/%: bin
/% $(STATE
)/config.sh
328 $(V_AT
)mkdir
-p
$(dir $@
)
329 $(call v_tag
,SUBST
){ \
331 -e
'2i### GENERATED by distorted-chroot: do not edit' \
332 -e
'/@@@config@@@/ {' \
333 -e
'r $(STATE)/config.sh' \
336 } >$@.new
&& chmod
+x
$@.new
&& mv
$@.new
$@
338 ###--------------------------------------------------------------------------
339 ### APT configuration.
341 ## In a chroot, `/etc/apt/sources.list' links to
342 ## `/usr/local.schroot/etc/apt/sources.$d' for the appropriate distribution.
343 APT_SOURCES
= $(foreach d
,$(DISTS
), $(LOCAL
)/etc
/apt
/sources.
$d)
344 CLEANFILES
+= $(APT_SOURCES
)
347 $(foreach d
,$(DISTS
), $(STATE
)/etc
/apt
/aptsrc.
$d): $(STATE
)/etc
/apt
/aptsrc.
%:
348 $(V_AT
)mkdir
-p
$(dir $@
)
350 echo
"### -*-conf-*- GENERATED by distorted-chroot: do not edit"; \
352 echo
" debian : $*"; \
353 } >$@.new
&& mv
$@.new
$@
355 $(APT_SOURCES
): $(LOCAL
)/etc
/apt
/sources.
%: \
356 $$(APTSRC
) $$($$*_APTSRC
) $$(STATE
)/etc
/apt
/aptsrc.
$$*
357 $(V_AT
)mkdir
-p
$(dir $@
)
358 $(call v_tag
,GEN
)bin
/mkaptsrc \
359 $(APTSRC
) $($*_APTSRC
) $(STATE
)/etc
/apt
/aptsrc.
$* \
360 >$@.new
&& mv
$@.new
$@
362 ## In a chroot, a link `/etc/apt/apt.conf.d/FOO' is created for each file in
363 ## `/usr/local.schroot/etc/apt/apt.conf.d/FOO'.
364 APT_CONFIGS
= $(addprefix $(LOCAL
)/etc
/apt
/apt.conf.d
/,$(APTCONF
))
366 $(APT_CONFIGS
): $(LOCAL
)/etc
/apt
/apt.conf.d
/%: \
367 $$(or
$$($$*_APTCONFSRC
) $$(APTCONF_DIR
)/$$*)
368 $(V_AT
)mkdir
-p
$(dir $@
)
369 $(call v_tag
,COPY
)cp
$< $@.new
&& mv
$@.new
$@
370 clean::; rm -f
$(APT_CONFIGS
)
372 ###--------------------------------------------------------------------------
375 check::; $(call check-executable
,ERR
,/usr
/bin
/eatmydata
)
377 EATMYDATA_HACKS
+= apt-get aptitude dpkg
378 SYMLINK_EATMYDATA_HACKS
= $(addprefix $(LOCAL
)/hacks
/,$(EATMYDATA_HACKS
))
379 all:: $(SYMLINK_EATMYDATA_HACKS
)
380 $(SYMLINK_EATMYDATA_HACKS
): $(LOCAL
)/hacks
/%: \
381 $$(if
$$(call symlink-ok-p
,$$@
,/usr
/bin
/eatmydata
),,_force
)
382 $(V_AT
)mkdir
-p
$(dir $@
)
383 $(call v_tag
,SYMLINK
)ln
-sf
/usr
/bin
/eatmydata
$@.new
&& mv
$@.new
$@
384 clean::; rm -f
$(SYMLINK_EATMYDATA_HACKS
)
386 SCRIPT_HACKS
+= buildwrap
387 COPY_SCRIPT_HACKS
= $(addprefix $(LOCAL
)/hacks
/,$(SCRIPT_HACKS
))
388 all:: $(COPY_SCRIPT_HACKS
)
389 $(COPY_SCRIPT_HACKS
): $(LOCAL
)/hacks
/%: bin
/%
390 $(V_AT
)mkdir
-p
$(dir $@
)
391 $(call v_tag
,COPY
)cp
$< $@.new
&& mv
$@.new
$@
392 clean::; rm -f
$(COPY_SCRIPT_HACKS
)
394 ###--------------------------------------------------------------------------
395 ### `schroot' and `sbuild' configuration.
399 .PHONY
: schroot-config
401 check::; $(call check-mountpoint
,WARN
,/var
/lib
/sbuild
/build
)
402 check::; $(call check-symlink
,WARN
,/build
,/var
/lib
/sbuild
/build
)
403 check::; $(call check-symlink
,ERR
,/schroot
,/run
/schroot
/mount
)
406 echo
"\#\#\# -*-sh-*- GENERATED by distorted-chroot: do not edit"; \
407 $(foreach v
,$1, echo
$v=\''$(subst ','\'\\\'\'',$($v))'\';) \
409 schroot-config_HASH
:= \
410 $(shell $(call
%print-varlist
,$(CONFIG_VARS
)) | \
411 sha256sum | cut
-c1-32
)
412 schroot-config_FILE
= $(STATE
)/config.sh-
$(schroot-config_HASH
)
413 $(schroot-config_FILE
):
414 $(V_AT
)mkdir
-p
$(STATE
)
415 $(V_AT
)rm -f
$(STATE
)/config.sh-
*
416 $(call v_tag
,STAMP
)$(call
%print-varlist
,$(CONFIG_VARS
)) \
417 >$@.new
&& mv
$@.new
$@
419 schroot-config
:: $(STATE
)/config.sh
420 $(STATE
)/config.sh
: $(schroot-config_FILE
)
421 $(call v_tag
,SYMLINK
)ln
-sf
$(notdir $<) $@
423 schroot-config
:: $(STATE
)/etc
/schroot
/sbuild.schroot
424 $(STATE
)/etc
/schroot
/sbuild.schroot
: $(STATE
)/bin
/mkchrootconf
425 $(V_AT
)mkdir
-p
$(dir $@
)
426 $(call v_tag
,GEN
)$(STATE
)/bin
/mkchrootconf
>$@.new
&& \
427 $(ROOTLY
) chown root
:root
$@.new
&& mv
$@.new
$@
428 check::; $(call check-symlink
,WARN
,/etc
/schroot
/chroot.d
/sbuild
,$(HERE
)/$(STATE
)/etc
/schroot
/sbuild.schroot
)
430 schroot-config
:: $(STATE
)/etc
/schroot
/sbuild.profile
/copyfiles
431 $(STATE
)/etc
/schroot
/sbuild.profile
/copyfiles
: $(schroot-config_STAMP
)
432 $(V_AT
)mkdir
-p
$(dir $@
)
434 echo
"### -*-conf-*- GENERATED by distorted-chroot: do not edit"; \
435 for i in
$(SCHROOT_COPYFILES
); do echo
"$$i"; done
; \
436 } >$@.new
&& mv
$@.new
$@
438 schroot-config
:: $(STATE
)/etc
/schroot
/sbuild.profile
/nssdatabases
439 $(STATE
)/etc
/schroot
/sbuild.profile
/nssdatabases
: $(schroot-config_STAMP
)
440 $(V_AT
)mkdir
-p
$(dir $@
)
442 echo
"### -*-conf-*- GENERATED by distorted-chroot: do not edit"; \
443 for i in
$(SCHROOT_NSSDATABASES
); do echo
"$$i"; done
; \
444 } >$@.new
&& mv
$@.new
$@
446 schroot-config
:: $(STATE
)/etc
/schroot
/sbuild.profile
/fstab
447 $(STATE
)/etc
/schroot
/sbuild.profile
/fstab
: \
448 etc
/sbuild.fstab.in
$(schroot-config_STAMP
)
449 $(V_AT
)mkdir
-p
$(dir $@
)
450 $(call v_tag
,SUBST
)$(call subst-file
,### -*-conf-*-) \
451 <$< >$@.new
&& mv
$@.new
$@
453 check::; $(call check-symlink
,WARN
,/etc
/schroot
/sbuild
,$(HERE
)/$(STATE
)/etc
/schroot
/sbuild.profile
)
455 schroot-config
:: $(STATE
)/etc
/sbuild.conf
456 $(STATE
)/etc
/sbuild.conf
: etc
/sbuild.conf.in
$(schroot-config_STAMP
)
457 $(V_AT
)mkdir
-p
$(dir $@
)
458 $(call v_tag
,SUBST
)$(call subst-file
,### -*-perl-*-) \
459 <$< >$@.new
&& mv
$@.new
$@
460 check::; $(call check-symlink
,WARN
,/etc
/sbuild
/sbuild.conf
,$(HERE
)/$(STATE
)/etc
/sbuild.conf
)
461 check::; $(call check-executable
,WARN
,/usr
/local.schroot
/hacks
/apt-get
)
463 SCHROOT_SCRIPTS
+= 11private
464 SCHROOT_SCRIPTS
+= 15binfmt
465 SCHROOT_SCRIPTS
+= 51chrootenv
466 COPY_SCHROOT_SCRIPTS
= $(addprefix $(STATE
)/etc
/schroot
/setup.d
/,$(SCHROOT_SCRIPTS
))
467 schroot-config
:: $(COPY_SCHROOT_SCRIPTS
)
468 $(COPY_SCHROOT_SCRIPTS
): \
469 $(STATE
)/etc
/schroot
/setup.d
/%: etc
/schroot-scripts
/%
470 $(V_AT
)mkdir
-p
$(dir $@
)
471 $(call v_tag
,COPY
)cp
$< $@.new
&& mv
$@.new
$@
473 CHECK_SCHROOT_SCRIPTS
= $(addprefix check-script
/,$(SCHROOT_SCRIPTS
))
474 check:: $(CHECK_SCHROOT_SCRIPTS
)
475 $(CHECK_SCHROOT_SCRIPTS
): check-script
/%:
476 $(call check-symlink
,WARN
,/etc
/schroot
/setup.d
/$*,$(HERE
)/$(STATE
)/etc
/schroot
/setup.d
/$*)
477 .PHONY
: $(addprefix check-script
/,$(SCHROOT_SCRIPTS
))
479 ###--------------------------------------------------------------------------
480 ### `/usr/local/' structure.
482 LOCAL_COMMON_DIRS
= share
/ src
/
483 all:: $(foreach d
,$(LOCAL_COMMON_DIRS
),$(LOCAL
)/$d)
484 $(foreach d
,$(LOCAL_COMMON_DIRS
),$(LOCAL
)/$d):
485 $(V_AT
)mkdir
-p
$(dir $(patsubst %/,%,$@
))
486 $(call v_tag
,MKDIR
)mkdir
$@
488 LOCAL_ARCH_DIRS
= bin
/ etc
/ games
/ include/ lib
/ libexec
/ sbin
/
489 LOCAL_ARCH_LINKS
= man
490 man_LINKDEST
= share
/man
491 all:: $(foreach a
,$(ALL_ARCHS
),\
493 $(foreach d
,$(LOCAL_ARCH_DIRS
),$(LOCAL
)/$a/$d) \
494 $(foreach d
,$(LOCAL_ARCH_LINKS
),$(LOCAL
)/$a/$d) \
495 $(foreach d
,$(LOCAL_COMMON_DIRS
),$(LOCAL
)/$a/$d))
497 $(foreach a
,$(ALL_ARCHS
),$(LOCAL
)/$a/):
498 $(call v_tag
,MKDIR
)mkdir
$@
499 $(foreach a
,$(ALL_ARCHS
),\
500 $(foreach d
,$(LOCAL_ARCH_DIRS
),$(LOCAL
)/$a/$d)):
501 $(V_AT
)mkdir
-p
$(dir $(patsubst %/,%,$@
))
502 $(call v_tag
,MKDIR
)mkdir
$@
503 $(foreach a
,$(ALL_ARCHS
),\
504 $(foreach d
,$(LOCAL_ARCH_LINKS
),$(LOCAL
)/$a/$d)): \
505 $$(if
$$(call symlink-ok-p
,$$@
,$$($$(notdir $$@
)_LINKDEST
)),,_force
)
506 $(V_AT
)mkdir
-p
$(notdir $@
)
507 $(call v_tag
,SYMLINK
)ln
-sf
$($(notdir $@
)_LINKDEST
) $@
508 $(foreach a
,$(ALL_ARCHS
),\
509 $(foreach d
,$(LOCAL_COMMON_DIRS
),$(LOCAL
)/$a/$d)): \
510 $$(if
$$(call symlink-ok-p
,$$@
,..
/$$(notdir $$(patsubst %/,%,$$@
))),,_force
)
511 $(V_AT
)mkdir
-p
$(dir $(patsubst %/,%,$@
))
512 $(call v_tag
,SYMLINK
)ln
-sf ..
/$(notdir $(patsubst %/,%,$@
)) $(patsubst %/,%,$@
)
514 ###--------------------------------------------------------------------------
515 ### Constructing chroots.
517 chroot-stamp
= $(addprefix $(STATE
)/stamp
/chroot.
,$1)
518 BUILD_CHROOTS
= $(addprefix chroot
/,$(ALL_CHROOTS
))
519 CHROOT_STAMPS
= $(call chroot-stamp
,$(ALL_CHROOTS
))
520 setup-chroots
: $(BUILD_CHROOTS
)
521 $(BUILD_CHROOTS
): chroot
/%: $(STATE
)/stamp
/chroot.
%
522 .PHONY
: setup-chroots
$(BUILD_CHROOTS
)
524 $(CHROOT_STAMPS
): $(STATE
)/stamp
/chroot.
%: \
525 $$(call chroot-deps
,$(STATE
)/stamp
/cross-tools.
,$$*)
526 $(V_AT
)mkdir
-p
$(dir $@
) log
/
528 $(STATE
)/bin
/mkbuildchroot
$(STATE
)/bin
/install-cross-tools \
529 $(STATE
)/etc
/schroot
/sbuild.schroot
530 $(call v_tag
,CHROOT
)$(call v_log
,setup-chroot.
$*, \
532 $(ROOTLY
) $(STATE
)/bin
/mkbuildchroot \
533 $(call chroot-dist
,$*) $(call chroot-arch
,$*))
536 UPDATE_CHROOTS
= $(addprefix update
/,$(ALL_CHROOTS
))
537 update-chroots
: $(UPDATE_CHROOTS
)
538 $(UPDATE_CHROOTS
): update
/%: $(STATE
)/stamp
/chroot.
%
540 $(MAKE
) $(STATE
)/bin
/install-cross-tools
541 $(call v_tag
,UPDATE
)$(call v_log
,update-chroot.
$*, { \
542 schroot
-uroot
-csource
:$(LVPREFIX
)$* -- \
544 schroot
-uroot
-csource
:$(LVPREFIX
)$* -- \
545 apt-get
-y dist-upgrade
&& \
546 schroot
-uroot
-csource
:$(LVPREFIX
)$* -- \
547 apt-get
-y autoremove
&& \
548 schroot
-uroot
-csource
:$(LVPREFIX
)$* -- \
549 apt-get
-y
clean && \
550 $(if
$(filter $*,$(FOREIGN_CHROOTS
)), \
551 $(ROOTLY
) $(STATE
)/bin
/install-cross-tools \
552 $(call chroot-dist
,$*) \
553 $(call chroot-arch
,$*), \
556 .PHONY
: update-chroots
$(UPDATE_CHROOTS
)
558 cross-tools-stamp
= $(addprefix $(STATE
)/stamp
/cross-tools.
,$1)
559 CROSS_TOOLS
= $(addprefix cross-tools
/,$(NATIVE_CHROOTS
))
560 UPDATE_CROSS_TOOLS
= $(addprefix update-cross-tools
/,$(NATIVE_CHROOTS
))
561 cross-tools
: $(CROSS_TOOLS
)
562 update-cross-tools
: $(UPDATE_CROSS_TOOLS
)
563 $(CROSS_TOOLS
): cross-tools
/%: $(STATE
)/stamp
/cross-tools.
%
566 $(MAKE
) $(STATE
)/bin
/update-cross-tools
567 $(call v_tag
,UPDCROSS
)$(call v_log
,update-cross-tools.
$*, \
568 $(STATE
)/bin
/update-cross-tools \
569 $(call chroot-dist
,$*) \
570 $(call chroot-arch
,$*))
571 $(V_AT
)touch
$(call cross-tools-stamp
,$*)
573 $(call cross-tools-stamp
,$(NATIVE_CHROOTS
)): $(STATE
)/stamp
/cross-tools.
%: \
574 $$(call chroot-stamp
,$$*)
575 $(V_AT
)mkdir
-p
$(dir $@
)
577 $(UPDATE_CROSS_TOOLS
): update-cross-tools
/%: \
578 $$(call chroot-stamp
,$$*) _force
580 .PHONY
: cross-tools update-cross-tools
$(CROSS_TOOLS
) $(UPDATE_CROSS_TOOLS
)
582 ###--------------------------------------------------------------------------
583 ### Installing basic custom software.
585 $(foreach p
,$(LOCALPKGS
), $(eval
$p_VERSION := $(shell \
586 set
-- pkg
/$p-[0-9]*.
tar.gz
; \
588 (1,*\
**) echo
"NOT-FOUND"; exit
2 ;; \
589 (1,*) v
=$${1#pkg/$p-}; v=$${v%.tar.gz}; echo "$$v" ;; \
590 (*) echo
"AMBIGUOUS"; exit
2 ;; \
594 $(foreach p
,$1,$(STATE
)/stamp
/package.
$p-$($p_VERSION).
$2)
596 $(foreach p
,$1,$(STATE
)/stamp
/unpack.
$p-$($p_VERSION))
598 $(foreach a
,$(ALL_ARCHS
),$(call pkg-stamp
,$(LOCALPKGS
),$a))
599 INSTALL_PACKAGES
= $(addprefix install/,$(LOCALPKGS
))
600 install-packages
: $(INSTALL_PACKAGES
)
601 $(INSTALL_PACKAGES
): install/%: \
602 $$(foreach a
,$$(ALL_ARCHS
),$$(call pkg-stamp
,$$*,$$a))
604 $(foreach p
,$(LOCALPKGS
),$(call unpack-pkg-stamp
,$p)): \
605 $(STATE
)/stamp
/unpack.
%: pkg
/%.
tar.gz
606 $(V_AT
)mkdir
-p
$(dir $@
) $(LOCAL
)/src
/
607 $(call v_tag
,UNPACK
){ \
609 p
=$(call package-dir-name
,$*); \
610 v
=$(call package-dir-version
,$*); \
612 $(ROOTLY
) rm -rf
$$p-*; \
613 mkdir
$$p-$$v.unpack
; \
614 (cd
$$p-$$v.unpack
&& tar xf
$(HERE
)/$<); \
615 mv
$$p-$$v.unpack
/$$p-$$v $$p-$$v; \
616 rmdir
$$p-$$v.unpack
/; \
621 $(PACKAGE_STAMPS
): $(STATE
)/stamp
/package.
%: \
622 $$(call unpack-pkg-stamp
,$$(call package-name
,$$*)) \
623 $$(call chroot-stamp
,$$(PRIMARY_DIST
)-$$(call package-arch
,$$*))
624 $(V_AT
)mkdir
-p
$(dir $@
) log
/
625 $(call v_tag
,BUILD
)$(call v_log
,install-package.
$*, { \
627 schroot
-uroot
-c
$(LVPREFIX
)$(PRIMARY_DIST
)-$(call package-arch
,$*) -- \
629 mount -oremount$(comma)rw /usr/local.schroot; \
630 eatmydata apt-get update; \
631 eatmydata apt-get -y install pkg-config; \
632 p=$(call package-name,$*); \
633 v=$(call package-version,$*); \
634 a=$(call package-arch,$*); \
635 cd /usr/local/src/$$p-$$v/; \
639 ../configure PKG_CONFIG_PATH=/usr/local/lib/pkgconfig.hidden; \
642 mkdir -p /usr/local/lib/pkgconfig.hidden; \
643 mv /usr/local/lib/pkgconfig/*.pc /usr/local/lib/pkgconfig.hidden || :' && \
644 schroot
-uroot
-csource
:$(LVPREFIX
)$(PRIMARY_DIST
)-$(call package-arch
,$*) -- \
649 ###--------------------------------------------------------------------------
650 ### Other maintenance targets.
661 ###----- That's all, folks --------------------------------------------------