2023-08-25 21:44:09 +00:00
|
|
|
# Makefile for Alpine Linux packages build
|
2022-03-04 19:33:13 +00:00
|
|
|
#
|
|
|
|
# For "API" documentation check Makefile.generic
|
|
|
|
#
|
|
|
|
# Variables supposed to be in component's Makefile.builder:
|
|
|
|
# ALPINE_BUILD_DIRS - list of alpinelinux directories containing build sripts (PKGFILES...)
|
|
|
|
|
|
|
|
### Variables required as per Makefile.generic:
|
|
|
|
#
|
|
|
|
# PACKAGE_LIST - list of packages to build. Targets 'build-dep', 'package' and 'copy-out'
|
|
|
|
# will be run for each word on the list, with PACKAGE set to current word
|
|
|
|
# DIST_BUILD_DIR - basedir for sources inside of chroot - relative to
|
|
|
|
# CHROOT_DIR (qubes-src will be created in this directory)
|
|
|
|
#
|
|
|
|
PACKAGE_LIST = $(ALPINE_BUILD_DIRS)
|
|
|
|
DIST_BUILD_DIR = /home/user
|
|
|
|
|
|
|
|
### Local variables
|
|
|
|
RUN_AS_USER = user
|
|
|
|
|
|
|
|
ALPINELINUX_MIRROR ?= https://dl-cdn.alpinelinux.org/alpine
|
|
|
|
|
|
|
|
DEBUG ?= 0
|
|
|
|
ifneq ($(DEBUG),0)
|
|
|
|
$(info ╔══ DEBUG ══════════════════════════════════════════════════════════════════════)
|
|
|
|
$(info ║ Repo Variables)
|
|
|
|
$(info ╠───────────────────────────────────────────────────────────────────────────────)
|
|
|
|
$(info ║ SRC_DIR: $(SRC_DIR)) # qubes-src
|
|
|
|
$(info ║ CHROOT_DIR: $(CHROOT_DIR)) # /home/user/qubes-builder/chroot-alpinelinux
|
|
|
|
$(info ║ BUILDER_REPO_DIR: $(BUILDER_REPO_DIR)) # /home/user/qubes-builder/qubes-packages-mirror-repo/alpinelinux
|
|
|
|
$(info ╠───────────────────────────────────────────────────────────────────────────────)
|
|
|
|
$(info ║ Chroot Variables)
|
|
|
|
$(info ╠───────────────────────────────────────────────────────────────────────────────)
|
|
|
|
$(info ║ CHROOT_DIR: $(CHROOT_DIR)) #
|
|
|
|
$(info ║ DIST_BUILD_DIR: $(DIST_BUILD_DIR)) # /home/user
|
|
|
|
$(info ║ DIST_SRC: $(DIST_SRC)) # /home/user/qubes-src/repo
|
|
|
|
$(info ╠───────────────────────────────────────────────────────────────────────────────)
|
|
|
|
$(info ║ Build Variables)
|
|
|
|
$(info ╠───────────────────────────────────────────────────────────────────────────────)
|
|
|
|
$(info ║ ALPINELINUX_PLUGIN_DIR: $(ALPINELINUX_PLUGIN_DIR)) # /home/user/qubes-builder/qubes-src/builder-alpinelinux
|
|
|
|
$(info ║ CACHEDIR: $(CACHEDIR)) # cache/alpinelinux
|
|
|
|
$(info ║ PACKAGE_LIST: $(PACKAGE_LIST)) # alpinelinux
|
|
|
|
$(info ║ DISTRIBUTION: $(DISTRIBUTION)) # alpinelinux
|
|
|
|
$(info ║ DIST: $(DIST)) #
|
|
|
|
$(info ║ COMPONENT: $(COMPONENT)) #
|
|
|
|
$(info ║ PACKAGE_SET: $(PACKAGE_SET)) # vm
|
|
|
|
$(info ║ CHROOT_ENV: $(CHROOT_ENV)) # BACKEND_VMM=xen
|
|
|
|
$(info ╠───────────────────────────────────────────────────────────────────────────────)
|
|
|
|
$(info ║ Repository Variables)
|
|
|
|
$(info ╠───────────────────────────────────────────────────────────────────────────────)
|
|
|
|
$(info ║ UPDATE_REPO: $(UPDATE_REPO)) #
|
|
|
|
$(info ║ TARGET_REPO: $(TARGET_REPO)) #
|
|
|
|
$(info ║ SNAPSHOT_REPO: $(SNAPSHOT_REPO)) #
|
|
|
|
$(info ║ SNAPSHOT_FILE: $(SNAPSHOT_FILE)) #
|
|
|
|
$(info ║ REPO_PROXY: $(REPO_PROXY)) #
|
|
|
|
$(info ║ ALPINELINUX_SRC_PREFIX: $(ALPINELINUX_SRC_PREFIX)) # http://mirrors.kernel.org/alpinelinux
|
|
|
|
$(info ║ ALPINELINUX_REL_VERSION: $(ALPINELINUX_REL_VERSION)) #
|
|
|
|
$(info ║ ALPINELINUX_MIRROR: $(ALPINELINUX_MIRROR)) # mirror.rackspace.com
|
|
|
|
$(info ╚═══════════════════════════════════════════════════════════════════════════════)
|
|
|
|
endif
|
|
|
|
|
|
|
|
define bin_packages
|
|
|
|
$(shell cd $(ORIG_SRC) && \
|
|
|
|
if [ 0`stat -c %Y $(OUTPUT_DIR)/$(notdir $(1)).list 2>/dev/null` -ge \
|
|
|
|
0`git log -1 --pretty=format:%ct` ]; then \
|
|
|
|
cat $(OUTPUT_DIR)/$(notdir $(1)).list; \
|
|
|
|
else \
|
|
|
|
echo unknown.package; \
|
|
|
|
fi)
|
|
|
|
endef
|
|
|
|
|
|
|
|
### Targets required by Makefile.generic to build packages:
|
|
|
|
|
|
|
|
# dist-prepare-chroot - initial preparation of chroot environment
|
|
|
|
# Specifically, load mounts for the build chroot
|
|
|
|
dist-prepare-chroot: $(CHROOT_DIR)/home/user/.prepared_base
|
|
|
|
@echo "--> Alpine linux dist-prepare-chroot (makefile):"
|
|
|
|
@mkdir -p "$(BUILDER_REPO_DIR)/pkgs"
|
|
|
|
@mkdir -p "$(CHROOT_DIR)/var/cache/apk"
|
|
|
|
@mkdir -p "$(CHROOT_DIR)/tmp/qubes-packages-mirror-repo"
|
|
|
|
|
|
|
|
# Create the build chroot, if it does not already exist
|
|
|
|
$(CHROOT_DIR)/home/user/.prepared_base: $(ALPINELINUX_PLUGIN_DIR)/prepare-chroot-builder
|
|
|
|
@echo "--> Alpine linux preparing build chroot environment"
|
|
|
|
@sudo -E "$(ALPINELINUX_PLUGIN_DIR)/prepare-chroot-builder" "$(CHROOT_DIR)" $(DIST) || exit 1
|
|
|
|
@touch "$(CHROOT_DIR)/home/user/.prepared_base"
|
|
|
|
|
|
|
|
# dist-prep - some preparation of sources (if needed)
|
|
|
|
dist-prep:
|
|
|
|
@true
|
|
|
|
|
|
|
|
# dist-build-dep - install build dependencies (should operate on chroot directory)
|
|
|
|
dist-build-dep:
|
|
|
|
@echo "--> Alpine linux dist-build-dep (makefile)"
|
|
|
|
@echo " --> Generate locales..."
|
|
|
|
@echo "en_US.UTF-8 UTF-8" | sudo tee -a $(CHROOT_DIR)/etc/locale.gen
|
|
|
|
@sudo $(CHROOT_ENV) chroot "$(CHROOT_DIR)" locale-gen
|
|
|
|
@echo "LANG=en_US.UTF-8" | sudo tee -a $(CHROOT_DIR)/etc/locale.conf
|
|
|
|
@sudo -E "$(ALPINELINUX_PLUGIN_DIR)/update-local-repo.sh" $(DIST)
|
|
|
|
|
|
|
|
# dist-package - compile package (should operate on chroot directory)
|
|
|
|
# TODO: makepkg doesn't seem to honor $http_proxy
|
|
|
|
dist-package:
|
|
|
|
@echo "--> Alpine linux dist-package (makefile)"
|
|
|
|
ifndef PACKAGE
|
|
|
|
$(error "PACKAGE need to be set!")
|
|
|
|
endif
|
|
|
|
@echo " --> Building package in $(DIST_SRC)"
|
|
|
|
sudo $(CHROOT_ENV) /usr/sbin/chroot "$(CHROOT_DIR)" sh -c -l "abuild -r $(ABUILD_ARGS)"
|
|
|
|
|
|
|
|
# dist-copy-out - copy compiled package out of chroot env; this target should
|
|
|
|
# move packages to ORIG_SRC (distro-specific subdir) and hardlink them to
|
|
|
|
# BUILDER_REPO_DIR
|
|
|
|
dist-copy-out: pkg_list_path = $(ORIG_SRC)/$(OUTPUT_DIR)/$(notdir $(PACKAGE)).list
|
|
|
|
dist-copy-out:
|
2023-08-25 21:44:09 +00:00
|
|
|
@echo "--> Alpine Linux dist-copy-out (makefile)"
|
2022-03-04 19:33:13 +00:00
|
|
|
@echo "--> Done:" >&3
|
|
|
|
@set -e;\
|
|
|
|
shopt -s nullglob;\
|
|
|
|
mkdir -p $(ORIG_SRC)/$(OUTPUT_DIR);\
|
|
|
|
echo -n > $(pkg_list_path);\
|
2023-08-25 21:44:09 +00:00
|
|
|
for alpine_chroot_dir in $(CHROOT_DIR)/$(DIST_SRC)/; do\
|
|
|
|
alpine_pkg_dir=$(ORIG_SRC)/$(OUTPUT_DIR);\
|
|
|
|
mkdir -p $$alpine_pkg_dir;\
|
|
|
|
for pkg in $$alpine_chroot_dir/*.pkg.tar.*; do\
|
|
|
|
echo " $$alpine_pkg_dir/`basename $$pkg`" >&3 ;\
|
2022-03-04 19:33:13 +00:00
|
|
|
echo "$(OUTPUT_DIR)/`basename $$pkg`" >> $(pkg_list_path);\
|
|
|
|
done;\
|
|
|
|
mkdir -p $(BUILDER_REPO_DIR)/pkgs;\
|
2023-08-25 21:44:09 +00:00
|
|
|
ln -f -t $(BUILDER_REPO_DIR)/pkgs $$alpine_chroot_dir/*.pkg.tar.*;\
|
2022-03-04 19:33:13 +00:00
|
|
|
done;\
|
2023-08-25 21:44:09 +00:00
|
|
|
mv -t $$alpine_pkg_dir $$alpine_chroot_dir/*.pkg.tar.*
|
2022-03-04 19:33:13 +00:00
|
|
|
|
|
|
|
### Additional targets
|
|
|
|
|
|
|
|
# Sign packages
|
|
|
|
sign: sign_client = $(if $(GNUPG),$(GNUPG),gpg)
|
|
|
|
sign:
|
|
|
|
@if [ -d $(ORIG_SRC)/$(OUTPUT_DIR) ]; then \
|
|
|
|
cd $(ORIG_SRC)/$(OUTPUT_DIR); \
|
|
|
|
for filename in *.pkg.tar.zst; do\
|
|
|
|
echo $$filename; \
|
|
|
|
$(sign_client) --yes --local-user "$(ALPINELINUX_SIGN_KEY)" --detach-sign -o "$$filename.sig" "$$filename";\
|
|
|
|
ln -f -t $(BUILDER_REPO_DIR)/pkgs "$$filename.sig";\
|
|
|
|
done; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Copies requested packages (based on PACKAGE_SET, COMPONENT, DIST) to
|
|
|
|
# requested repository (UPDATE_REPO)
|
|
|
|
update-repo:
|
|
|
|
ifndef UPDATE_REPO
|
|
|
|
$(error "You need to specify destination repo in UPDATE_REPO variable")
|
|
|
|
endif
|
|
|
|
ifeq (,$(PACKAGE_LIST))
|
|
|
|
@true
|
|
|
|
else
|
|
|
|
ifdef SNAPSHOT_FILE
|
|
|
|
@echo -n > $(SNAPSHOT_FILE)
|
|
|
|
endif
|
|
|
|
mkdir -p $(UPDATE_REPO)/pkgs; \
|
|
|
|
for package in $(PACKAGE_LIST); do\
|
|
|
|
pkgnames=`cat $(ORIG_SRC)/$(OUTPUT_DIR)/$$package.list`;\
|
|
|
|
for pkgname in $$pkgnames; do\
|
|
|
|
ln -f $(ORIG_SRC)/$$pkgname $(UPDATE_REPO)/pkgs/ || exit 1;\
|
|
|
|
ln -f $(ORIG_SRC)/$$pkgname.sig $(UPDATE_REPO)/pkgs/ 2>/dev/null;\
|
|
|
|
if [ -n "$(SNAPSHOT_FILE)" ]; then \
|
|
|
|
echo $$pkgname >> "$(SNAPSHOT_FILE)"; \
|
|
|
|
fi; \
|
|
|
|
done; \
|
|
|
|
done
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
update-repo-from-snapshot: packages = $(shell cat $(SNAPSHOT_FILE) 2>/dev/null)
|
|
|
|
update-repo-from-snapshot:
|
|
|
|
ifndef UPDATE_REPO
|
|
|
|
$(error "You need to specify destination repo in UPDATE_REPO variable")
|
|
|
|
endif
|
|
|
|
mkdir -p $(UPDATE_REPO)/pkgs; \
|
|
|
|
for f in $(packages); do \
|
|
|
|
ln -f $(subst /$(TARGET_REPO)/,/$(SNAPSHOT_REPO)/,$(UPDATE_REPO)/)pkgs/`basename $$f` $(UPDATE_REPO)/pkgs/ || exit 1; \
|
|
|
|
ln -f $(subst /$(TARGET_REPO)/,/$(SNAPSHOT_REPO)/,$(UPDATE_REPO)/)pkgs/`basename $$f`.sig $(UPDATE_REPO)/pkgs/ 2>/dev/null; \
|
|
|
|
done
|
|
|
|
|
|
|
|
check-repo: packages = $(foreach pkg,$(PACKAGE_LIST),$(call bin_packages,$(pkg)))
|
|
|
|
check-repo:
|
|
|
|
ifndef UPDATE_REPO
|
|
|
|
$(error "You need to specify destination repo in UPDATE_REPO variable")
|
|
|
|
endif
|
|
|
|
@if [ -n "$(strip $(packages))" ]; then \
|
|
|
|
cd $(ORIG_SRC) && ls $(addprefix $(UPDATE_REPO)/pkgs/, $(notdir $(packages))) >/dev/null 2>&1 || exit 1; \
|
|
|
|
else \
|
|
|
|
echo "`tput bold`No packages defined by $(PACKAGE_LIST), syntax error?`tput sgr0`"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|