forked from QubesOS/qubes-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.generic
181 lines (151 loc) · 5.46 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
# Generic makefile to build Qubes component package
#
# Variables used as "parameters":
# DIST
# SRC_DIR
# COMPONENT
# PACKAGE_SET (currently "dom0" or "vm")
### Global variables
.EXPORT_ALL_VARIABLES:
SHELL = /bin/bash
# Load "builder.config" from every plugin
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/$(DIST)
OUTPUT_DIR = pkgs/$(DIST)
# build environment
CHROOT_DIR = $(PWD)/chroot-$(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)
# default value
ifndef MIN_AGE
MIN_AGE = 7
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)
.PHONY: copy-in
copy-in: generic-copy-in $(SOURCE_COPY_IN)
.PHONY: generic-copy-in
generic-copy-in:
@mkdir -p $(CHROOT_DIR)/$(DIST_SRC_ROOT)
@cp $(THIS_MAKEFILE) $(CHROOT_DIR)/$(DIST_BUILD_DIR)/
@cp $(BUILDER_MAKEFILE) $(CHROOT_DIR)/$(DIST_BUILD_DIR)/
@rm -rf $(CHROOT_DIR)/$(DIST_SRC)
@cp -alt $(CHROOT_DIR)/$(DIST_SRC_ROOT)/ $(ORIG_SRC)
.PHONY: windows-image-extract
windows-image-extract:
ifneq (,$(WINDOWS_IMAGE_EXTRACT_EXTRA))
@rm -rf $(WINDOWS_IMAGE_EXTRACT_EXTRA:%=$(ORIG_SRC)/%)
@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:
@if [ -e "$(BUILD_LOG)" ]; then\
mv -f "$(BUILD_LOG)" "$(BUILD_LOG).old";\
fi
.PHONY: generic-prepare-chroot
generic-prepare-chroot:
@mkdir -p "$(CACHEDIR)"
.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))
@true
else
# Do nothing if no packages to compile
all:
@true
endif
.PHONY: packages
packages:
@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 30 "$(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::
@GET_VAR=$${!GET_VAR}; \
echo "$${GET_VAR}"
update-repo-from-snapshot: 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