-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathMakefile.generic
238 lines (200 loc) · 7.74 KB
/
Makefile.generic
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# Generic makefile to build Qubes component package
#
# Variables used as "parameters":
# DIST
# SRC_DIR
# COMPONENT
# PACKAGE_SET (currently "dom0" or "vm")
ifeq (${VERBOSE},2)
Q =
else
Q = @
endif
### Global variables
.EXPORT_ALL_VARIABLES:
SHELL = /bin/bash
# should be defined by main Makefile, but set manually if called from outside
# of it
SRC_DIR ?= qubes-src
# this needs to be the first prerequisite, before any plugin-defined
update-repo-from-snapshot: update-repo-date-check
# Load "builder.config" from every plugin
# force dom0's builder plugin for handling template packages
ifeq ($(COMPONENT),linux-template-builder)
TEMPLATE_NAME := $(shell MAKEFLAGS= $(MAKE) -s -C $(SRC_DIR)/linux-template-builder DIST=$(DIST) template-name)
DIST_ORIG := $(DIST)
# reverse alias lookup
DIST_ORIG_ALIAS := $(firstword $(subst :, ,\
$(filter %:$(DIST_ORIG),\
$(TEMPLATE_ALIAS) $(DIST_ORIG):$(DIST_ORIG))))
override DIST := $(DIST_DOM0)
endif
LOADING_PLUGINS = 1
BUILDER_MAKEFILE :=
BUILDER_PLUGINS_COMBINED = $(BUILDER_PLUGINS) $(BUILDER_PLUGINS_$(DIST))
-include $(BUILDER_PLUGINS_COMBINED:%=$(SRC_DIR)/%/Makefile.builder)
ifeq ($(BUILDER_MAKEFILE),)
$(error Building packages for $(DIST) not supported by any of configured plugins)
endif
LOADING_PLUGINS :=
THIS_MAKEFILE = Makefile.generic
ORIG_SRC = $(SRC_DIR)/$(COMPONENT)
# repository for ready packages; directory content is distro-specific
BUILDER_REPO_DIR = $(PWD)/qubes-packages-mirror-repo/$(PACKAGE_SET)-$(DIST)
OUTPUT_DIR = pkgs/$(PACKAGE_SET)-$(DIST)
# build environment
CHROOT_DIR = $(PWD)/chroot-$(PACKAGE_SET)-$(DIST)
CACHEDIR = $(PWD)/cache/$(DIST)
# Logfile
BUILD_LOG="build-logs/$(COMPONENT)-$(PACKAGE_SET)-$(DIST).log"
# environment variables for build process (inside of chroot)
CHROOT_ENV = BACKEND_VMM=$(BACKEND_VMM) $(ENV_COMPONENT)
# default value
ifndef MIN_AGE
MIN_AGE = 5
endif
### Load component-specific settings
# Component specific settins. Generic variables:
# SOURCE_PREP - make target to run at "prep" stage
# SOURCE_COPY_IN - make target to run after "copy-in" stage
# SOURCE_COPY_OUT - make target to run after "copy-out" stage
# Above are mainly to extend Makefile with some component-specific actions
# (like handling additional sources)
#
#
# Check Makefile.DISTRIBUTION for distribution-specific supported variables
-include $(ORIG_SRC)/Makefile.builder
### Load distro-specific settings
# This file should define:
# 1. variables:
# 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)
# targets:
# dist-prepare-chroot - initial preparation of chroot environment
# dist-prep - some preparation of sources (if needed)
# dist-build-dep - install build dependencies (should operate on chroot directory)
# dist-package - compile package (should operate on chroot directory)
# 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-build-dep, dist-package and dist-copy-out targets are run in separate
# process with stdout+stderr redirected to log file. If you want to print
# some message, use 3-rd file descriptor
#
# This file can specify additional targets (like update-repo-*, sign)
include $(BUILDER_MAKEFILE)
DIST_SRC_ROOT=$(DIST_BUILD_DIR)/qubes-src
DIST_SRC=$(DIST_SRC_ROOT)/$(COMPONENT)
ifneq (,$(GIT_TARBALL_NAME))
ifneq (1,$(NO_ARCHIVE))
TARBALL_COPY_IN = make-git-tarball
endif
endif
.PHONY: copy-in
copy-in: generic-copy-in $(TARBALL_COPY_IN) $(SOURCE_COPY_IN)
.PHONY: make-git-tarball
make-git-tarball:
git -C $(CHROOT_DIR)$(DIST_SRC) clean -f -d -X
$(BUILDER_DIR)/scripts/create-archive $(CHROOT_DIR)$(DIST_SRC) $(GIT_TARBALL_NAME)
.PHONY: generic-copy-in
generic-copy-in:
${Q}mkdir -p $(CHROOT_DIR)/$(DIST_SRC_ROOT)
${Q}cp $(THIS_MAKEFILE) $(CHROOT_DIR)/$(DIST_BUILD_DIR)/
${Q}cp $(BUILDER_MAKEFILE) $(CHROOT_DIR)/$(DIST_BUILD_DIR)/
${Q}rm -rf $(CHROOT_DIR)/$(DIST_SRC)
${Q}cp -alt $(CHROOT_DIR)/$(DIST_SRC_ROOT)/ $(ORIG_SRC)
${Q}rm -rf $(CHROOT_DIR)/$(DIST_SRC)/pkgs
.PHONY: windows-image-extract
windows-image-extract:
ifneq (,$(WINDOWS_IMAGE_EXTRACT_EXTRA))
${Q}rm -rf $(WINDOWS_IMAGE_EXTRACT_EXTRA:%=$(ORIG_SRC)/%)
${Q}cp -r $(WINDOWS_IMAGE_EXTRACT_EXTRA:%=$(WINDOWS_IMAGE_DIR)/$(ORIG_SRC)/%) $(ORIG_SRC)/
endif
.PHONY: prep
prep: generic-prep dist-prep $(SOURCE_PREP)
.PHONY: generic-prep
generic-prep:
${Q}if [ -e "$(BUILD_LOG)" ]; then\
mv -f "$(BUILD_LOG)" "$(BUILD_LOG).old";\
fi
.PHONY: generic-prepare-chroot
generic-prepare-chroot:
${Q}if [ "`id -u`" = 0 ]; then \
echo "*******************************************************************************"; \
echo "*** ERROR ***"; \
echo "*** Start the build as normal user, it will use sudo (only) where necessary! ***"; \
echo "*** ***"; \
echo "*******************************************************************************"; \
exit 1; \
fi
${Q}mkdir -p "$(CACHEDIR)"
${Q}if ! scripts/test-sane-mount .; then \
mountpoint=$$(scripts/find-mount-point .); \
echo "*******************************************************************************"; \
echo "*** ERROR ***"; \
echo "*** Cannot create chroot because the current filesystem is mounted as nodev. ***"; \
echo "*** Build Qubes on a different filesystem, or run 'make remount' to remount ***"; \
echo "*** $$mountpoint with dev option."; \
echo "*** ***"; \
echo "*******************************************************************************"; \
exit 1; \
fi
.PHONY: prepare-chroot
prepare-chroot: generic-prepare-chroot dist-prepare-chroot
.PHONY: all
ifneq (,$(PACKAGE_LIST))
all: prepare-chroot prep copy-in packages
else ifeq (2,$(VERBOSE))
# Do nothing if no packages to compile
all:
$(info -> Nothing to be done in $(COMPONENT) for $(DIST) $(PACKAGE_SET))
${Q}true
else
# Do nothing if no packages to compile
all:
${Q}true
endif
.PHONY: packages
packages:
${Q}for package in $(PACKAGE_LIST); do\
set -o pipefail;\
echo "-> Building $(COMPONENT) ($$package) for $(DIST) $(PACKAGE_SET) (logfile: $(BUILD_LOG))";\
if [ $(VERBOSE) -eq 0 ]; then\
$(MAKE) -f $(THIS_MAKEFILE) PACKAGE=$$package package 3>&1 >>"$(BUILD_LOG)" 2>&1;\
BUILD_RETCODE=$$?;\
elif [ $(VERBOSE) -eq 1 ]; then\
$(MAKE) -s -f $(THIS_MAKEFILE) PACKAGE=$$package package 3>&2 2>&1 | tee -a $(BUILD_LOG);\
BUILD_RETCODE=$$?;\
else\
$(MAKE) -f $(THIS_MAKEFILE) PACKAGE=$$package package 3>&2 2>&1 | tee -a $(BUILD_LOG);\
BUILD_RETCODE=$$?;\
fi;\
if [ $$BUILD_RETCODE -gt 0 ]; then\
echo "--> build failed!";\
[ $(VERBOSE) -eq 0 ] && tail -n 100 "$(BUILD_LOG)";\
exit 1;\
fi;\
done
.PHONY: package
package: dist-build-dep dist-package dist-copy-out $(SOURCE_COPY_OUT)
# Returns variable value
# Example usage: GET_VAR=DISTS_VM make get-var
.PHONY: get-var
get-var::
${Q}GET_VAR=$${!GET_VAR}; \
echo "$${GET_VAR}"
.PHONY: update-repo-date-check
update-repo-date-check:
if ! [ -r $(SNAPSHOT_FILE) ]; then \
echo "`tput bold`*** Packages weren't uploaded to $(SNAPSHOT_REPO)! ***`tput sgr0`"; \
exit 1; \
fi
touch -t `date -d "$(MIN_AGE) days ago" +%Y%m%d%H%M` /tmp/age-compare-file
if ! [ $(SNAPSHOT_FILE) -ot /tmp/age-compare-file ]; then \
echo "`tput bold`*** Packages weren't in $(SNAPSHOT_REPO) for at least $(MIN_AGE) days! ***`tput sgr0`"; \
exit 1; \
fi
rm -f /tmp/age-compare-file