forked from fepitre/qubes-builder-gentoo
/
Makefile.gentoo
164 lines (142 loc) · 9.16 KB
/
Makefile.gentoo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Makefile for Gentoo packages build
#
# Variables supposed to be in component's Makefile.builder:
# GENTOO_BUILD_DIRS - list of gentoo directories containing build sripts
### 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)
#
ifneq ($(GENTOO_OVERLAY),)
# Get available package in the Qubes Gentoo Overlay
AVAILABLE_PACKAGES = $(shell find $(GENTOO_OVERLAY) -type f -name "*.ebuild.0" -exec basename {} \; | sed 's|.\(.*\).ebuild.0|\1|g')
REQUESTED_PACKAGES := $(foreach _pkg, $(GENTOO_PACKAGES), $(subst $(_pkg),$(NAME_$(subst -,_,$(_pkg))),$(_pkg)))
PACKAGE_LIST=$(filter $(REQUESTED_PACKAGES),$(AVAILABLE_PACKAGES))
endif
DIST_BUILD_DIR = /home/user
### Local variables
RUN_AS_USER = user
GENTOO_DISTFILES ?= http://distfiles.gentoo.org
DEBUG ?= 0
ifneq ($(DEBUG),0)
$(info ╔══ DEBUG ══════════════════════════════════════════════════════════════════════)
$(info ║ Repo Variables)
$(info ╠───────────────────────────────────────────────────────────────────────────────)
$(info ║ SRC_DIR: $(SRC_DIR)) # qubes-src
$(info ║ VERSION: $(PV)) #
$(info ║ RELEASE: $(PR)) #
$(info ║ CHROOT_DIR: $(CHROOT_DIR)) # /home/user/qubes-builder/chroot-gentoo
$(info ║ BUILDER_REPO_DIR: $(BUILDER_REPO_DIR)) # /home/user/qubes-builder/qubes-packages-mirror-repo/vm-gentoo
$(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 ║ GENTOO_PLUGIN_DIR: $(GENTOO_PLUGIN_DIR)) # /home/user/qubes-builder/qubes-src/builder-gentoo
$(info ║ CACHE_DIR: $(CACHE_DIR)) # cache/gentoo
$(info ║ PACKAGE_LIST: $(PACKAGE_LIST)) # gentoo
$(info ║ DISTRIBUTION: $(DISTRIBUTION)) # gentoo
$(info ║ DIST: $(DIST)) #
$(info ║ GENTOO_PACKAGES: $(GENTOO_PACKAGES)) # qubes-db
$(info ║ TEMPLATE_FLAVOR: $(TEMPLATE_FLAVOR)) # gnome, xfce or minimal
$(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 ║ REPO_PROXY: $(REPO_PROXY)) #
$(info ║ GENTOO_DISTFILES: $(GENTOO_DISTFILES)) # http://distfiles.gentoo.org
$(info ╚═══════════════════════════════════════════════════════════════════════════════)
endif
### 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 "--> Gentoo dist-prepare-chroot (makefile):"
@echo " --> Checking mounting of dev/proc/sys on build chroot..."
@if [ ! -r "$(CHROOT_DIR)/dev/zero" ]; then\
echo " --> sudo mount --bind /dev $(CHROOT_DIR)/dev";\
sudo mount --rbind /dev "$(CHROOT_DIR)/dev";\
fi
@if [ "$(shell stat -f -c '%T' ${CHROOT_DIR}/dev/shm 2>/dev/null)" != tmpfs ]; then\
echo " --> sudo mount -t tmpfs shm $(CHROOT_DIR)/dev/shm";\
sudo mkdir -p "$(CHROOT_DIR)/dev/shm";\
sudo mount -t tmpfs shm "$(CHROOT_DIR)/dev/shm";\
sudo chmod 1777 "$(CHROOT_DIR)/dev/shm";\
fi
@if [ ! -r "$(CHROOT_DIR)/proc/cpuinfo" ]; then\
echo " --> sudo mount -t proc proc $(CHROOT_DIR)/proc";\
mkdir -p $(CHROOT_DIR)/proc; \
sudo mount -t proc proc "$(CHROOT_DIR)/proc";\
fi
@if [ ! -d "$(CHROOT_DIR)/sys" ]; then\
echo " --> sudo mount --bind /sys $(CHROOT_DIR)/sys";\
mkdir -p $(CHROOT_DIR)/sys;\
sudo mount --bind /sys "$(CHROOT_DIR)/sys";\
fi
@sudo mkdir -p "$(CACHE_DIR)/distfiles"
@sudo touch "$(CACHE_DIR)/distfiles/.mnt"
@if ! [ -r "$(CHROOT_DIR)/var/cache/distfiles/.mnt" ]; then\
echo " --> mount --bind ${CACHE_DIR}/distfiles ${CHROOT_DIR}/var/cache/distfiles"; \
sudo mkdir -p "$(CHROOT_DIR)/var/cache/distfiles";\
sudo mount --bind "${CACHE_DIR}/distfiles" "${CHROOT_DIR}/var/cache/distfiles";\
fi
@sudo mkdir -p "$(CACHE_DIR)/binpkgs"
@sudo touch "$(CACHE_DIR)/binpkgs/.mnt"
@if ! [ -r "$(CHROOT_DIR)/var/cache/binpkgs/.mnt" ]; then\
echo " --> mount --bind ${CACHE_DIR}/binpkgs ${CHROOT_DIR}/var/cache/binpkgs"; \
sudo mkdir -p "$(CHROOT_DIR)/var/cache/binpkgs";\
sudo mount --bind "${CACHE_DIR}/binpkgs" "${CHROOT_DIR}/var/cache/binpkgs";\
fi
@sudo mkdir -p "$(BUILDER_REPO_DIR)"
@sudo touch "$(BUILDER_REPO_DIR)/.mnt"
@if ! [ -r "$(CHROOT_DIR)/tmp/qubes-packages-mirror-repo/.mnt" ]; then\
echo " --> mount --bind $(BUILDER_REPO_DIR) $(CHROOT_DIR)/tmp/qubes-packages-mirror-repo"; \
sudo mkdir -p "$(CHROOT_DIR)/tmp/qubes-packages-mirror-repo";\
sudo mount --bind "$(BUILDER_REPO_DIR)" "$(CHROOT_DIR)/tmp/qubes-packages-mirror-repo";\
fi
@echo " --> Synchronize resolv.conf"
@sudo cp /etc/resolv.conf "$(CHROOT_DIR)/etc/resolv.conf"
# Create the build chroot, if it does not already exist
$(CHROOT_DIR)/home/user/.prepared_base: $(GENTOO_PLUGIN_DIR)/prepare-chroot-builder
@echo "--> Gentoo preparing build chroot environment"
# The template flavor influence how packages are built. It has to be specified in env of the 'make' call:
# make gentoo GENTOO_PACKAGES=core-agent-linux TEMPLATE_FLAVOR=gnome
@sudo -E "$(GENTOO_PLUGIN_DIR)/prepare-chroot-builder" "$(CHROOT_DIR)" "$(DIST)" "$(TEMPLATE_FLAVOR)" || exit 1
@touch $(CHROOT_DIR)/home/user/.prepared_base
# dist-prep - some preparation of sources (if needed)
dist-prep:
@echo "--> Gentoo dist-prep (makefile)"
# dist-build-dep - install build dependencies (should operate on chroot directory)
dist-build-dep:
@echo "--> Gentoo dist-build-dep (makefile)"
@sudo -E "$(GENTOO_PLUGIN_DIR)/update-local-repo.sh" "$(CHROOT_DIR)" "$(DIST)"
# dist-package - compile package (should operate on chroot directory)
dist-package:
ifndef PACKAGE
$(error "PACKAGE need to be set!")
endif
@echo "--> Gentoo dist-package (makefile)"
@echo " --> Preparing package in $(DIST_SRC)"
sudo $(CHROOT_ENV) /usr/sbin/chroot "$(CHROOT_DIR)" bash -c -l "emerge $(EMERGE_OPTS) --onlydeps --onlydeps-with-rdeps=n $(PACKAGE)"
sudo $(CHROOT_ENV) /usr/sbin/chroot "$(CHROOT_DIR)" bash -c -l "emerge $(EMERGE_OPTS) --buildpkgonly $(PACKAGE)"
# 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:
@echo "--> Gentoo dist-copy-out (makefile)"
@echo "--> Done:" >&3
# Copies requested packages (based on PACKAGE_SET, COMPONENT, DIST) to
# requested repository (UPDATE_REPO)
update-repo:
@echo "--> Gentoo update-repo (makefile)"
ifndef UPDATE_REPO
$(error "You need to specify destination repo in UPDATE_REPO variable")
endif