### -*-makefile-*- ### ### Main maintenance script for chroots ### ### (c) 2018 Mark Wooding ### ###----- Licensing notice --------------------------------------------------- ### ### This file is part of the distorted.org.uk chroot maintenance tools. ### ### distorted-chroot is free software: you can redistribute it and/or ### modify it under the terms of the GNU General Public License as ### published by the Free Software Foundation; either version 2 of the ### License, or (at your option) any later version. ### ### distorted-chroot is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ### General Public License for more details. ### ### You should have received a copy of the GNU General Public License ### along with distorted-chroot. If not, write to the Free Software ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, ### USA. all:: clean:: check:: .PHONY: all clean check .SECONDEXPANSION: #sorry ###-------------------------------------------------------------------------- ### Configuration. CONFIG_VARS = ## Level of pickiness to aspire to. NOTIFY_FATAL = 1 ## Path to this working tree. CONFIG_VARS += HERE HERE = $(abspath .) ## Volume group from which to allocate chroot volumes and snapshots. CONFIG_VARS += VG LVPREFIX VG = vg-$(shell hostname) LVPREFIX = ## Logical volume size, as an LVM option. CONFIG_VARS += LVSZ SNAPOPT LVSZ = -L8G SNAPOPT = -L8G ## Debian mirror. CONFIG_VARS += DEBMIRROR DEBMIRROR = http://deb.debian.org/debian/ ## APT sources configurations. (Also, $($d_APTSRC) for each $d in $(DISTS).) CONFIG_VARS += APTSRC APTSRC = etc/aptsrc.conf $(wildcard etc/aptsrc.local.conf) ## APT configuration fragment names. These will be linked into ## `/etc/apt/apt.conf.d' in each chroot. To put a fragment f in a surprising ## place, set $($f_APTCONFSRC). CONFIG_VARS += APTCONF APTCONF_DIR = etc/apt-conf.d APTCONF = $(notdir $(wildcard $(APTCONF_DIR)/[0-9]*[!~])) ## Proxy setting. CONFIG_VARS += PROXY PROXY := $(shell \ eval $$(apt-config $(foreach a,$(APTCONF), -c$(APTCONF_DIR)/$a) \ shell proxy Acquire::http::proxy); \ case $${proxy+t} in (t) echo "$$proxy" ;; (*) echo nil ;; esac) ## Debian distributions to support. CONFIG_VARS += PRIMARY_DIST DISTS PRIMARY_DIST = stretch DISTS = $(PRIMARY_DIST) buster bullseye sid ## Host's native architecture(s). CONFIG_VARS += MYARCH NATIVE_ARCHS MYARCH = $(shell dpkg --print-architecture) OTHERARCHS = $(shell dpkg --print-foreign-architectures) NATIVE_ARCHS = $(MYARCH) $(OTHERARCHS) ## Foreign (emulated) architectures to support. CONFIG_VARS += FOREIGN_ARCHS FOREIGN_ARCHS = ## Master lists of chroots to build and maintain. NATIVE_CHROOTS = $(foreach a,$(NATIVE_ARCHS), \ $(foreach d,$(or $($a_DISTS) $(DISTS)), \ $d-$a)) FOREIGN_CHROOTS = $(foreach a,$(FOREIGN_ARCHS), \ $(foreach d,$(or $($a_DISTS) $(DISTS)), \ $d-$a)) ## Extra packages to be installed in chroots. CONFIG_VARS += BASE_PACKAGES NATIVE_BASE_PACKAGES FOREIGN_BASE_PACKAGES BASE_PACKAGES = ccache BASE_PACKAGES += eatmydata fakeroot BASE_PACKAGES += locales tzdata BASE_PACKAGES += libfile-fcntllock-perl NATIVE_BASE_PACKAGES = build-essential FOREIGN_BASE_PACKAGES = ## Local packages to be compiled and installed in chroots. Archives can be ## found in `pkg/'. LOCALPKGS = mLib checkpath ## Which host architecture to use for foreign architectures. It turns out ## that it's best to use a Qemu with the same host bitness as the target ## architecture; otherwise it has to do a difficult job of converting ## arguments and results between kernel ABI flavours. 32BIT_QEMUHOST = $(or $(filter i386,$(NATIVE_ARCHS)),$(TOOLSARCH)) 64BIT_QEMUHOST = $(or $(filter amd64,$(NATIVE_ARCHS)),$(TOOLSARCH)) CONFIG_VARS += $(foreach a,$(FOREIGN_ARCHS), $a_QEMUHOST) armel_QEMUHOST = $(32BIT_QEMUHOST) armhf_QEMUHOST = $(32BIT_QEMUHOST) arm64_QEMUHOST = $(64BIT_QEMUHOST) i386_QEMUHOST = $(32BIT_QEMUHOST) amd64_QEMUHOST = $(64BIT_QEMUHOST) ## Qemu architecture names. These tell us which Qemu binary to use for a ## particular Debian architecture. CONFIG_VARS += $(foreach a,$(FOREIGN_ARCHS), $a_QEMUARCH) armel_QEMUARCH = arm armhf_QEMUARCH = arm arm64_QEMUARCH = aarch64 i386_QEMUARCH = i386 amd64_QEMUARCH = x86_64 ## Alias mapping for chroots. CONFIG_VARS += $(foreach d,$(DISTS), $d_ALIASES) stretch_ALIASES = oldstable buster_ALIASES = stable bullseye_ALIASE = testing sid_ALIASES = unstable ## Which host architecture to use for commonly used tools in foreign chroots. CONFIG_VARS += TOOLSARCH TOOLSARCH = $(MYARCH) ## A directory in which we can maintain private files and state. CONFIG_VARS += STATE STATE = state ## A directory which will be spliced into chroots as `/usr/local.schroot/'. ## This will be our primary point of contact with the chroot. CONFIG_VARS += LOCAL LOCAL = local.schroot ## How to run a command as a privileged user. ROOTLY = sudo ## Files to be copied into a chroot from the host. SCHROOT_COPYFILES = /etc/resolv.conf SCHROOT_NSSDATABASES = passwd shadow group gshadow ## Local configuration hook. -include local.mk ## All chroot names. CONFIG_VARS += ALL_ARCHS ALL_CHROOTS ALL_ARCHS = $(NATIVE_ARCHS) $(FOREIGN_ARCHS) ALL_CHROOTS = $(NATIVE_CHROOTS) $(FOREIGN_CHROOTS) ###-------------------------------------------------------------------------- ### Utilities. ## Hack to force rebuilding. _force: .PHONY: _force ## Hack to not delimit function arguments. (Ugh!) comma = , ## Silent-rules machinery. V = 0 V_AT = $(V_AT_$V) V_AT_0 = @ v_print = $(call v_print_$V,$1,$2) v_print_0 = printf " %-8s %s\n" "$1" $(call squote,$2); v_tag = $(V_AT)$(call v_print,$1,$@) v_log = $(call v_log_$V,$1,$2) v_log_ = $(call v_log_1,$1,$2) v_log_0 = $2 >log/$1.log 2>&1 v_log_1 = $(call catchrc,$(call throwrc,$2) 2>&1 | tee log/$1.log) v_echo = $(call v_echo_$V,$1) v_echo_0 = : v_echo_1 = printf "%s\n" $1 CLEANFILES += log/*.log ## Oh, shut up. SILENCE_LVM = \ LVM_SUPPRESS_FD_WARNINGS=1; export LVM_SUPPRESS_FD_WARNINGS ## $(call catchrc,...$(call throwrc,CMD)...) ## ## Catch the exit status of some subpart of a complicated shell rune. catchrc = (exec 3>&1; exit $$({ $1; } 4>&1 >&3 3>&-)) throwrc = { $1; echo $$? >&4; } ## $(call squote,TXT) ## ## Single-quote TXT. squote = '$(subst ','\\'',$1)' ## $(call chroot-dist,D-A) -> D ## $(call chroot-arch,D-A) -> A ## ## Parse chroot descriptions. chroot-dist = $(patsubst %/,%,$(dir $(subst -,/,$1))) chroot-arch = $(notdir $(subst -,/,$1)) ## $(call package-dir-name,P-V) -> P ## $(call package-dir-version,P-V) -> V ## ## Parse (source) package directory names. package-dir-name = $(sort $(foreach p,$(LOCALPKGS),$(if $(filter $p-$($p_VERSION),$1),$p))) package-dir-version = $($(call package-dir-name,$1)_VERSION) ## $(call package-dir,P-V.A) -> P-V ## $(call package-name,P-V.A) -> P ## $(call package-version,P-V.A) -> V ## $(call package-arch,P-V.A) -> A ## ## Parse package stamp names. package-dir = $(basename $1) package-name = $(call package-dir-name,$(call package-dir,$1)) package-version = $(call package-dir-version,$(call package-dir,$1)) package-arch = $(patsubst .%,%,$(suffix $1)) ## $(call native-chroot-p,D-A) -> D | ## ## Answer whether D-A is a native chroot. native-chroot-p = $(filter $(call chroot-arch,$1),$(NATIVE_ARCHS)) ## $(call chroot-qemuhost,D-A) -> AA ## ## Answer the apporopriate Qemu host architecture for foreign chroot D-A. chroot-qemuhost = $($(call chroot-arch,$1)_QEMUHOST) ## $(call chroot-deps,PRE,D-A) -> PREDD-AA ... | ## ## Answer a list of additional dependencies for the chroot D-A: specifically, ## if D-A is foreign then include PRE/DD-AA entries for the tools ## architecture, and Qemu host architecture (if that's different). chroot-deps = $(if $(call native-chroot-p,$2),, \ $(addprefix $1$(call chroot-dist,$2)-,\ $(sort $(TOOLSARCH) \ $(call chroot-qemuhost,$2)))) ## Substituting placeholders in files. SUBSTITUTIONS := local=$(shell realpath $(LOCAL)) SUBSTITUTIONS += primary-dist=$(PRIMARY_DIST) subst-file = { \ echo "$1 GENERATED by distorted-chroot: do not edit"; \ substs=""; \ for v in $(SUBSTITUTIONS); do \ var=$${v%%=*} value=$${v\#*=}; \ substs="$$substs s@$$var@$$valueg;"; \ done; \ sed "$$substs"; \ } ### $(call symlink-ok-p,LINK,DEST) ### ### Expand to `t' if LINK is a symbolic link to DEST, and empty otherwise. symlink-ok-p = $(shell \ case $$(readlink 2>/dev/null $(patsubst %/,%,$1)) in ($2) echo t ;; esac) ### $(call general-notify,SEV,COLOUR,PREFIX,MSG) ### ### Report a message, highlighted in the right way, and maybe fail general-notify = { \ echo "$$(tput bold; tput setaf $2)$3 "$4"$$(tput sgr0; tput op)"; \ if [ "$1" -le "$(NOTIFY_FATAL)" ]; then exit 2; fi; \ } ### $(call report/SEV,MSG) ### ### Report a notification of a particular severity. notify/INFO = $(call general-notify,3,6,---,$1) notify/WARN = $(call general-notify,2,5,???,$1) notify/ERR = $(call general-notify,1,1,!!!,$1) ## $(call check,SEV,MSG,UNLESS) ## ## If UNLESS completes successfully, all is OK; otherwise print MSG to stderr ## and fail. check = @{ \ $(call v_echo,'check: '$(call squote,$3)''); \ if ! { $3; }; then $(call notify/$1,$2); fi; \ } ## $(call check-executable,SEV,PATH) ## ## Verify that PATH is an executable program. check-executable = $(call check,$1,"\`$2' is not an executable", \ [ -x "$2" ]) ## $(call check-mountpoint,SEV,DIR) ## ## Verify that DIR is a mountpoint. check-mountpoint = $(call check,$1,"\`$2' is not a mount point", \ mountpoint -q "$2") ## $(call check-symlink,SEV,LINK,DEST) ## ## Verify that LINK is a symbolic link pointing to DEST. check-symlink = $(call check,$1,"\`$2' is not a link to \`$3'", \ [ -L "$2" ] && [ "$$(readlink "$2")" = "$3" ]) ###-------------------------------------------------------------------------- ### Scripts. SCRIPTS += mkbuildchroot SCRIPTS += mkchrootconf SCRIPTS += install-cross-tools update-cross-tools SUBST_SCRIPTS = $(addprefix $(STATE)/bin/,$(SCRIPTS)) all:: $(SUBST_SCRIPTS) $(SUBST_SCRIPTS): $(STATE)/bin/%: bin/% $(STATE)/config.sh $(V_AT)mkdir -p $(dir $@) $(call v_tag,SUBST){ \ sed \ -e '2i### GENERATED by distorted-chroot: do not edit' \ -e '/@@@config@@@/ {' \ -e 'r $(STATE)/config.sh' \ -e 'd'\ -e '}' $<; \ } >$@.new && chmod +x $@.new && mv $@.new $@ ###-------------------------------------------------------------------------- ### APT configuration. ## In a chroot, `/etc/apt/sources.list' links to ## `/usr/local.schroot/etc/apt/sources.$d' for the appropriate distribution. APT_SOURCES = $(foreach d,$(DISTS), $(LOCAL)/etc/apt/sources.$d) CLEANFILES += $(APT_SOURCES) all:: $(APT_SOURCES) $(foreach d,$(DISTS), $(STATE)/etc/apt/aptsrc.$d): $(STATE)/etc/apt/aptsrc.%: $(V_AT)mkdir -p $(dir $@) $(call v_tag,GEN){ \ echo "### -*-conf-*- GENERATED by distorted-chroot: do not edit"; \ echo "subscribe"; \ echo " debian : $*"; \ } >$@.new && mv $@.new $@ $(APT_SOURCES): $(LOCAL)/etc/apt/sources.%: \ $$(APTSRC) $$($$*_APTSRC) $$(STATE)/etc/apt/aptsrc.$$* $(V_AT)mkdir -p $(dir $@) $(call v_tag,GEN)bin/mkaptsrc \ $(APTSRC) $($*_APTSRC) $(STATE)/etc/apt/aptsrc.$* \ >$@.new && mv $@.new $@ ## In a chroot, a link `/etc/apt/apt.conf.d/FOO' is created for each file in ## `/usr/local.schroot/etc/apt/apt.conf.d/FOO'. APT_CONFIGS = $(addprefix $(LOCAL)/etc/apt/apt.conf.d/,$(APTCONF)) all:: $(APT_CONFIGS) $(APT_CONFIGS): $(LOCAL)/etc/apt/apt.conf.d/%: \ $$(or $$($$*_APTCONFSRC) $$(APTCONF_DIR)/$$*) $(V_AT)mkdir -p $(dir $@) $(call v_tag,COPY)cp $< $@.new && mv $@.new $@ clean::; rm -f $(APT_CONFIGS) ###-------------------------------------------------------------------------- ### Build hacks. check::; $(call check-executable,ERR,/usr/bin/eatmydata) EATMYDATA_HACKS += apt-get aptitude dpkg SYMLINK_EATMYDATA_HACKS = $(addprefix $(LOCAL)/hacks/,$(EATMYDATA_HACKS)) all:: $(SYMLINK_EATMYDATA_HACKS) $(SYMLINK_EATMYDATA_HACKS): $(LOCAL)/hacks/%: \ $$(if $$(call symlink-ok-p,$$@,/usr/bin/eatmydata),,_force) $(V_AT)mkdir -p $(dir $@) $(call v_tag,SYMLINK)ln -sf /usr/bin/eatmydata $@.new && mv $@.new $@ clean::; rm -f $(SYMLINK_EATMYDATA_HACKS) SCRIPT_HACKS += buildwrap COPY_SCRIPT_HACKS = $(addprefix $(LOCAL)/hacks/,$(SCRIPT_HACKS)) all:: $(COPY_SCRIPT_HACKS) $(COPY_SCRIPT_HACKS): $(LOCAL)/hacks/%: bin/% $(V_AT)mkdir -p $(dir $@) $(call v_tag,COPY)cp $< $@.new && mv $@.new $@ clean::; rm -f $(COPY_SCRIPT_HACKS) ###-------------------------------------------------------------------------- ### `schroot' and `sbuild' configuration. all:: schroot-config schroot-config:: .PHONY: schroot-config check::; $(call check-mountpoint,WARN,/var/lib/sbuild/build) check::; $(call check-symlink,WARN,/build,/var/lib/sbuild/build) check::; $(call check-symlink,ERR,/schroot,/run/schroot/mount) %print-varlist = { \ echo "\#\#\# -*-sh-*- GENERATED by distorted-chroot: do not edit"; \ $(foreach v,$1, echo $v=\''$(subst ','\'\\\'\'',$($v))'\';) \ } #' schroot-config_HASH := \ $(shell $(call %print-varlist,$(CONFIG_VARS)) | \ sha256sum | cut -c1-32) schroot-config_FILE = $(STATE)/config.sh-$(schroot-config_HASH) $(schroot-config_FILE): $(V_AT)mkdir -p $(STATE) $(V_AT)rm -f $(STATE)/config.sh-* $(call v_tag,STAMP)$(call %print-varlist,$(CONFIG_VARS)) \ >$@.new && mv $@.new $@ schroot-config:: $(STATE)/config.sh $(STATE)/config.sh: $(schroot-config_FILE) $(call v_tag,SYMLINK)ln -sf $(notdir $<) $@ schroot-config:: $(STATE)/etc/schroot/sbuild.schroot $(STATE)/etc/schroot/sbuild.schroot: $(STATE)/bin/mkchrootconf $(V_AT)mkdir -p $(dir $@) $(call v_tag,GEN)$(STATE)/bin/mkchrootconf >$@.new && \ $(ROOTLY) chown root:root $@.new && mv $@.new $@ check::; $(call check-symlink,WARN,/etc/schroot/chroot.d/sbuild,$(HERE)/$(STATE)/etc/schroot/sbuild.schroot) schroot-config:: $(STATE)/etc/schroot/sbuild.profile/copyfiles $(STATE)/etc/schroot/sbuild.profile/copyfiles: $(schroot-config_STAMP) $(V_AT)mkdir -p $(dir $@) $(call v_tag,GEN){ \ echo "### -*-conf-*- GENERATED by distorted-chroot: do not edit"; \ for i in $(SCHROOT_COPYFILES); do echo "$$i"; done; \ } >$@.new && mv $@.new $@ schroot-config:: $(STATE)/etc/schroot/sbuild.profile/nssdatabases $(STATE)/etc/schroot/sbuild.profile/nssdatabases: $(schroot-config_STAMP) $(V_AT)mkdir -p $(dir $@) $(call v_tag,GEN){ \ echo "### -*-conf-*- GENERATED by distorted-chroot: do not edit"; \ for i in $(SCHROOT_NSSDATABASES); do echo "$$i"; done; \ } >$@.new && mv $@.new $@ schroot-config:: $(STATE)/etc/schroot/sbuild.profile/fstab $(STATE)/etc/schroot/sbuild.profile/fstab: \ etc/sbuild.fstab.in $(schroot-config_STAMP) $(V_AT)mkdir -p $(dir $@) $(call v_tag,SUBST)$(call subst-file,### -*-conf-*-) \ <$< >$@.new && mv $@.new $@ check::; $(call check-symlink,WARN,/etc/schroot/sbuild,$(HERE)/$(STATE)/etc/schroot/sbuild.profile) schroot-config:: $(STATE)/etc/sbuild.conf $(STATE)/etc/sbuild.conf: etc/sbuild.conf.in $(schroot-config_STAMP) $(V_AT)mkdir -p $(dir $@) $(call v_tag,SUBST)$(call subst-file,### -*-perl-*-) \ <$< >$@.new && mv $@.new $@ SCHROOT_SCRIPTS += 11private SCHROOT_SCRIPTS += 15binfmt SCHROOT_SCRIPTS += 51chrootenv COPY_SCHROOT_SCRIPTS = $(addprefix $(STATE)/etc/schroot/setup.d/,$(SCHROOT_SCRIPTS)) schroot-config:: $(COPY_SCHROOT_SCRIPTS) $(COPY_SCHROOT_SCRIPTS): \ $(STATE)/etc/schroot/setup.d/%: etc/schroot-scripts/% $(V_AT)mkdir -p $(dir $@) $(call v_tag,COPY)cp $< $@.new && mv $@.new $@ CHECK_SCHROOT_SCRIPTS = $(addprefix check-script/,$(SCHROOT_SCRIPTS)) check:: $(CHECK_SCHROOT_SCRIPTS) $(CHECK_SCHROOT_SCRIPTS): check-script/%: $(call check-symlink,WARN,/etc/schroot/setup.d/$*,$(HERE)/$(STATE)/etc/schroot/setup.d/$*) .PHONY: $(addprefix check-script/,$(SCHROOT_SCRIPTS)) ###-------------------------------------------------------------------------- ### `/usr/local/' structure. LOCAL_COMMON_DIRS = share/ src/ all:: $(foreach d,$(LOCAL_COMMON_DIRS),$(LOCAL)/$d) $(foreach d,$(LOCAL_COMMON_DIRS),$(LOCAL)/$d): $(V_AT)mkdir -p $(dir $(patsubst %/,%,$@)) $(call v_tag,MKDIR)mkdir $@ LOCAL_ARCH_DIRS = bin/ etc/ games/ include/ lib/ libexec/ sbin/ LOCAL_ARCH_LINKS = man man_LINKDEST = share/man all:: $(foreach a,$(ALL_ARCHS),\ $(LOCAL)/$a/ \ $(foreach d,$(LOCAL_ARCH_DIRS),$(LOCAL)/$a/$d) \ $(foreach d,$(LOCAL_ARCH_LINKS),$(LOCAL)/$a/$d) \ $(foreach d,$(LOCAL_COMMON_DIRS),$(LOCAL)/$a/$d)) $(foreach a,$(ALL_ARCHS),$(LOCAL)/$a/): $(call v_tag,MKDIR)mkdir $@ $(foreach a,$(ALL_ARCHS),\ $(foreach d,$(LOCAL_ARCH_DIRS),$(LOCAL)/$a/$d)): $(V_AT)mkdir -p $(dir $(patsubst %/,%,$@)) $(call v_tag,MKDIR)mkdir $@ $(foreach a,$(ALL_ARCHS),\ $(foreach d,$(LOCAL_ARCH_LINKS),$(LOCAL)/$a/$d)): \ $$(if $$(call symlink-ok-p,$$@,$$($$(notdir $$@)_LINKDEST)),,_force) $(V_AT)mkdir -p $(notdir $@) $(call v_tag,SYMLINK)ln -sf $($(notdir $@)_LINKDEST) $@ $(foreach a,$(ALL_ARCHS),\ $(foreach d,$(LOCAL_COMMON_DIRS),$(LOCAL)/$a/$d)): \ $$(if $$(call symlink-ok-p,$$@,../$$(notdir $$(patsubst %/,%,$$@))),,_force) $(V_AT)mkdir -p $(dir $(patsubst %/,%,$@)) $(call v_tag,SYMLINK)ln -sf ../$(notdir $(patsubst %/,%,$@)) $(patsubst %/,%,$@) ###-------------------------------------------------------------------------- ### Constructing chroots. chroot-stamp = $(addprefix $(STATE)/stamp/chroot.,$1) BUILD_CHROOTS = $(addprefix chroot/,$(ALL_CHROOTS)) CHROOT_STAMPS = $(call chroot-stamp,$(ALL_CHROOTS)) setup-chroots: $(BUILD_CHROOTS) $(BUILD_CHROOTS): chroot/%: $(STATE)/stamp/chroot.% .PHONY: setup-chroots $(BUILD_CHROOTS) $(CHROOT_STAMPS): $(STATE)/stamp/chroot.%: \ $$(call chroot-deps,$(STATE)/stamp/cross-tools.,$$*) $(V_AT)mkdir -p $(dir $@) log/ $(MAKE) \ $(STATE)/bin/mkbuildchroot $(STATE)/bin/install-cross-tools \ $(STATE)/etc/schroot/sbuild.schroot $(call v_tag,CHROOT)$(call v_log,setup-chroot.$*, \ $(SILENCE_LVM); \ $(ROOTLY) $(STATE)/bin/mkbuildchroot \ $(call chroot-dist,$*) $(call chroot-arch,$*)) $(V_AT)touch $@ UPDATE_CHROOTS = $(addprefix update/,$(ALL_CHROOTS)) update-chroots: $(UPDATE_CHROOTS) $(UPDATE_CHROOTS): update/%: $(STATE)/stamp/chroot.% $(V_AT)mkdir -p log/ $(MAKE) $(STATE)/bin/install-cross-tools $(call v_tag,UPDATE)$(call v_log,update-chroot.$*, { \ schroot -uroot -csource:$(LVPREFIX)$* -- \ apt-get update && \ schroot -uroot -csource:$(LVPREFIX)$* -- \ apt-get -y dist-upgrade && \ schroot -uroot -csource:$(LVPREFIX)$* -- \ apt-get -y autoremove && \ schroot -uroot -csource:$(LVPREFIX)$* -- \ apt-get -y clean && \ $(if $(filter $*,$(FOREIGN_CHROOTS)), \ $(ROOTLY) $(STATE)/bin/install-cross-tools \ $(call chroot-dist,$*) \ $(call chroot-arch,$*), \ :); \ }) .PHONY: update-chroots $(UPDATE_CHROOTS) cross-tools-stamp = $(addprefix $(STATE)/stamp/cross-tools.,$1) CROSS_TOOLS = $(addprefix cross-tools/,$(NATIVE_CHROOTS)) UPDATE_CROSS_TOOLS = $(addprefix update-cross-tools/,$(NATIVE_CHROOTS)) cross-tools: $(CROSS_TOOLS) update-cross-tools: $(UPDATE_CROSS_TOOLS) $(CROSS_TOOLS): cross-tools/%: $(STATE)/stamp/cross-tools.% define updcross $(V_AT)mkdir -p log/ $(MAKE) $(STATE)/bin/update-cross-tools $(call v_tag,UPDCROSS)$(call v_log,update-cross-tools.$*, \ $(STATE)/bin/update-cross-tools \ $(call chroot-dist,$*) \ $(call chroot-arch,$*)) $(V_AT)touch $(call cross-tools-stamp,$*) endef $(call cross-tools-stamp,$(NATIVE_CHROOTS)): $(STATE)/stamp/cross-tools.%: \ $$(call chroot-stamp,$$*) $(V_AT)mkdir -p $(dir $@) $(updcross) $(UPDATE_CROSS_TOOLS): update-cross-tools/%: \ $$(call chroot-stamp,$$*) _force $(updcross) .PHONY: cross-tools update-cross-tools $(CROSS_TOOLS) $(UPDATE_CROSS_TOOLS) ###-------------------------------------------------------------------------- ### Installing basic custom software. $(foreach p,$(LOCALPKGS), $(eval $p_VERSION := $(shell \ set -- pkg/$p-[0-9]*.tar.gz; \ case $$#,$$1 in \ (1,*\**) echo "NOT-FOUND"; exit 2 ;; \ (1,*) v=$${1#pkg/$p-}; v=$${v%.tar.gz}; echo "$$v" ;; \ (*) echo "AMBIGUOUS"; exit 2 ;; \ esac))) pkg-stamp = \ $(foreach p,$1,$(STATE)/stamp/package.$p-$($p_VERSION).$2) unpack-pkg-stamp = \ $(foreach p,$1,$(STATE)/stamp/unpack.$p-$($p_VERSION)) PACKAGE_STAMPS = \ $(foreach a,$(ALL_ARCHS),$(call pkg-stamp,$(LOCALPKGS),$a)) INSTALL_PACKAGES = $(addprefix install/,$(LOCALPKGS)) install-packages: $(INSTALL_PACKAGES) $(INSTALL_PACKAGES): install/%: \ $$(foreach a,$$(ALL_ARCHS),$$(call pkg-stamp,$$*,$$a)) $(foreach p,$(LOCALPKGS),$(call unpack-pkg-stamp,$p)): \ $(STATE)/stamp/unpack.%: pkg/%.tar.gz $(V_AT)mkdir -p $(dir $@) $(LOCAL)/src/ $(call v_tag,UNPACK){ \ set -e; \ p=$(call package-dir-name,$*); \ v=$(call package-dir-version,$*); \ cd $(LOCAL)/src/; \ $(ROOTLY) rm -rf $$p-*; \ mkdir $$p-$$v.unpack; \ (cd $$p-$$v.unpack && tar xf $(HERE)/$<); \ mv $$p-$$v.unpack/$$p-$$v $$p-$$v; \ rmdir $$p-$$v.unpack/; \ cd $(HERE); \ touch $@; \ } $(PACKAGE_STAMPS): $(STATE)/stamp/package.%: \ $$(call unpack-pkg-stamp,$$(call package-name,$$*)) \ $$(call chroot-stamp,$$(PRIMARY_DIST)-$$(call package-arch,$$*)) $(V_AT)mkdir -p $(dir $@) log/ $(call v_tag,BUILD)$(call v_log,install-package.$*, { \ $(SILENCE_LVM); \ schroot -uroot -c$(LVPREFIX)$(PRIMARY_DIST)-$(call package-arch,$*) -- \ sh -exc ' \ mount -oremount$(comma)rw /usr/local.schroot; \ eatmydata apt-get update; \ eatmydata apt-get -y install pkg-config; \ p=$(call package-name,$*); \ v=$(call package-version,$*); \ a=$(call package-arch,$*); \ cd /usr/local/src/$$p-$$v/; \ rm -rf build.$$a/; \ mkdir build.$$a/; \ cd build.$$a/; \ ../configure PKG_CONFIG_PATH=/usr/local/lib/pkgconfig.hidden; \ make -j4; \ make install; \ mkdir -p /usr/local/lib/pkgconfig.hidden; \ mv /usr/local/lib/pkgconfig/*.pc /usr/local/lib/pkgconfig.hidden || :' && \ schroot -uroot -csource:$(LVPREFIX)$(PRIMARY_DIST)-$(call package-arch,$*) -- \ ldconfig; \ }) $(V_AT)touch $@ ###-------------------------------------------------------------------------- ### Other maintenance targets. show:; : $x clean:: rm -f $(CLEANFILES) rm -rf $(STATE) realclean:: clean rm -rf $(LOCAL) ###----- That's all, folks --------------------------------------------------