-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Makefile.rpmbuilder
241 lines (201 loc) · 8.45 KB
/
Makefile.rpmbuilder
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
239
240
241
# Generic makefile for Fedora packages build
#
# For "API" documentation check Makefile.generic
#
# Variables supposed to be in component's Makefile.builder:
# RPM_SPEC_FILES - list of spec files to build
# RPM_SRC_PACKAGES - list of src.rpm packages to rebuild (if any)
# USE_DIST_BUILD_TOOLS - if set to 1, use new "mock" build
#
# Extra variables that may influence the build:
# RPM_BUILD_EXTRA_DEFINES - extra --define=... options to rpm-build (or mock)
### Variables required Makefile.generic
# Use spec files list as PACKAGE_LIST
PACKAGE_LIST = $(strip $(RPM_SPEC_FILES) $(RPM_SRC_PACKAGES))
DIST_BUILD_DIR = /home/user
export REPO_PROXY
ifneq (1,$(NO_ARCHIVE))
# allow Makefile.builder in component to override this value
GIT_TARBALL_NAME ?= $(notdir \
$(shell [ -r "$(ORIG_SRC)/$(firstword $(RPM_SPEC_FILES))".in ] && \
$(RPM_PLUGIN_DIR)scripts/query-spec \
"$(ORIG_SRC)" "$(ORIG_SRC)/$(firstword $(RPM_SPEC_FILES))" "%{SOURCE0}" "$(DIST)"\
| cut -d ' ' -f 2))
unexport GIT_TARBALL_NAME
endif
### Local variables
RUN_AS_USER = user
ifndef OUTPUT_DIR
OUTPUT_DIR= rpm
endif
RPM_ARCH := $(shell uname -m)
# In RPM_BUILD_DEFINES and RPM_QUERY_DEFINES, use += to allow
# Makefile.builder to define some initial values
ifeq (fedora,$(DISTRIBUTION))
DIST_VER = $(subst fc,,$(DIST))
DIST_TAG = $(DIST)
RPM_BUILD_DEFINES += --define "fedora $(DIST_VER)"
RPM_QUERY_DEFINES += --define "fedora $(DIST_VER)"
BUILD_PKG_LIST = build-pkgs-base-fedora.list
ifdef FEDORA_MIRROR
YUM_OPTS += --setopt=fedora.baseurl=$(patsubst %/,%,$(FEDORA_MIRROR))/releases/$(DIST_VER)/Everything/x86_64/os/ --setopt=fedora.metalink=
YUM_OPTS += --setopt=updates.baseurl=$(patsubst %/,%,$(FEDORA_MIRROR))/updates/$(DIST_VER)/Everything/x86_64/ --setopt=updates.metalink=
endif
endif
ifeq (centos-stream,$(DISTRIBUTION))
DIST_VER = $(subst centos-stream,,$(DIST))
DIST_TAG = el$(DIST_VER)
RPM_BUILD_DEFINES += --define "centos $(DIST_VER)"
RPM_BUILD_DEFINES += --define "rhel $(DIST_VER)"
RPM_QUERY_DEFINES += --define "centos $(DIST_VER)"
RPM_QUERY_DEFINES += --define "rhel $(DIST_VER)"
BUILD_PKG_LIST = build-pkgs-base-centos-stream.list
endif
ifeq (centos,$(DISTRIBUTION))
DIST_VER = $(subst centos,,$(DIST))
DIST_TAG = el$(DIST_VER)
RPM_BUILD_DEFINES += --define "centos $(DIST_VER)"
RPM_BUILD_DEFINES += --define "rhel $(DIST_VER)"
RPM_QUERY_DEFINES += --define "centos $(DIST_VER)"
RPM_QUERY_DEFINES += --define "rhel $(DIST_VER)"
BUILD_PKG_LIST = build-pkgs-base-centos.list
ifdef CENTOS_MIRROR
YUM_OPTS += --setopt=base.baseurl=$(patsubst %/,%,$(CENTOS_MIRROR))/$(DIST_VER)/os/x86_64 --setopt=base.mirrorlist=
YUM_OPTS += --setopt=updates.baseurl=$(patsubst %/,%,$(CENTOS_MIRROR))/$(DIST_VER)/updates/x86_64 --setopt=updates.mirrorlist=
YUM_OPTS += --setopt=extras.baseurl=$(patsubst %/,%,$(CENTOS_MIRROR))/$(DIST_VER)/extras/x86_64 --setopt=extras.mirrorlist=
endif
ifdef EPEL_MIRROR
YUM_OPTS += --setopt=epel.baseurl=$(patsubst %/,%,$(EPEL_MIRROR))/$(DIST_VER)/x86_64 --setopt=epel.metalink=
endif
endif
RPM_BUILD_DEFINES += --define "dist .$(DIST_TAG)"
RPM_QUERY_DEFINES += --define "dist .$(DIST_TAG)"
BUILDINFO_SIGN_CMD ?= $(shell rpm --eval %{__gpg})
BUILDINFO_SIGN_CMD += --clearsign
unexport BUILDINFO_SIGN_CMD
RPMSIGN_OPTS ?=
RPMSIGN_OPTS += --digest-algo=sha256
ifneq (,$(SIGN_KEY))
BUILDINFO_SIGN_CMD += --local-user $(SIGN_KEY)
RPMSIGN_OPTS += --key-id=$(SIGN_KEY)
endif
ifdef REPO_PROXY
YUM_OPTS += --setopt=proxy=$(REPO_PROXY)
endif
### Private "functions"
# List packages produced by given spec file(s)
# this '[ -n "$(1)" ] && ' is to suppress "call" at function definition
spec_packages = $(shell cd $(ORIG_SRC) && [ -n "$(1)" ] && \
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 \
$(RPM_PLUGIN_DIR)scripts/query-spec . "$(1)" "$(RPM_QUERY_FORMAT)" "$(DIST)" 2>/dev/null; \
fi)
unexport spec_packages
srpm_packages = $(shell cd $(ORIG_SRC) && [ -n "$(1)" ] && \
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 \
rpm2cpio $(1) |cpio -i --to-stdout '*.spec' 2>/dev/null | \
$(RPM_PLUGIN_DIR)scripts/query-spec . /dev/stdin "$(RPM_QUERY_FORMAT)" "$(DIST)" 1>&2; \
fi)
unexport srpm_packages
%.spec: %.spec.in $(wildcard $(DIST_SRC)/version) $(wildcard $(DIST_SRC)/rel)
$(RPM_PLUGIN_DIR)scripts/generate-spec $(ORIG_SRC) $< $@
dist-prep:
${Q}true
# Common target with Makefile-mock.rpmbuilder and Makefile-legacy.rpmbuilder for
# generating the spec file
dist-build-dep: $(CHROOT_DIR)$(DIST_SRC)/$(PACKAGE)
ifdef INCREMENT_DEVEL_VERSIONS
dist-package: devel_ver_path = $(ORIG_SRC)/$(OUTPUT_DIR)/$(notdir $(PACKAGE)).devel
dist-package: devel_ver_prev = $(shell cat $(devel_ver_path) 2>/dev/null)
dist-package: devel_ver := $(shell expr $(devel_ver_prev) + 1)
dist-package: RPM_BUILD_DEFINES += --define "dist .$(devel_ver).$(DIST_TAG)"
dist-package: RPM_QUERY_DEFINES += --define "dist .$(devel_ver).$(DIST_TAG)"
endif
dist-package: RPM_BUILD_DEFINES += $(RPM_BUILD_EXTRA_DEFINES)
dist-package: dist-package-build
ifeq (1,$(USE_DIST_BUILD_TOOLS))
include $(RPM_PLUGIN_DIR)Makefile-mock.rpmbuilder
else ifeq (0,$(or $(USE_DIST_BUILD_TOOLS),0))
include $(RPM_PLUGIN_DIR)Makefile-legacy.rpmbuilder
else
$(error bad value for $$(USE_DIST_BUILD_TOOLS) (must be 1, 0, or empty string))
endif
# dist-package-build and dist-copy-out defined in Makefile-*.rpmbuilder included above
### Additional targets
# Copies requested packages (based on PACKAGE_SET, COMPONENT, DIST) to
# requested repository (UPDATE_REPO)
# Optionally saves list of copied packages in $(SNAPSHOT_FILE)
unexport packages
update-repo: packages = $(foreach SPEC,$(RPM_SPEC_FILES),$(call spec_packages,$(SPEC)))
update-repo: packages += $(foreach SPEC,$(RPM_SRC_PACKAGES),$(call srpm_packages,$(SPEC)))
update-repo: update-repo-do
update-repo-do:
ifndef UPDATE_REPO
$(error "You need to specify destination repo in UPDATE_REPO variable")
endif
ifeq (,$(PACKAGE_LIST))
${Q}true
else
${Q}mkdir -p $(UPDATE_REPO)/rpm
${Q}if [ -n "$(strip $(packages))" ]; then \
cd $(ORIG_SRC) && ln -f $(packages) $(UPDATE_REPO)/rpm/; \
else \
echo "`tput bold`No packages defined by $(PACKAGE_LIST), syntax error?`tput sgr0`"; \
exit 1; \
fi
endif
ifdef SNAPSHOT_FILE
${Q}cd $(ORIG_SRC) && echo $(packages) > $(SNAPSHOT_FILE)
endif
update-repo-from-snapshot: packages = $(shell cat $(SNAPSHOT_FILE) 2>/dev/null)
update-repo-from-snapshot: update-repo-from-snapshot-do
update-repo-from-snapshot-do:
ifndef UPDATE_REPO
$(error "You need to specify destination repo in UPDATE_REPO variable")
endif
for f in $(packages); do \
ln -f $(subst /$(TARGET_REPO)/,/$(SNAPSHOT_REPO)/,$(UPDATE_REPO)/)rpm/`basename $$f` $(UPDATE_REPO)/rpm/ || exit 1; \
done
sign-prep: rpmsign_client := $(if $(GNUPG),$(GNUPG),$(shell rpm --eval %{__gpg}))
sign-prep:
${Q}if [ -n "$(rpmsign_client)" ]; then \
mkdir -p $(BUILDER_DIR)/keyrings/rpmdb; \
tmpname=$$(mktemp); \
$(rpmsign_client) --armor --export "$(SIGN_KEY)" > "$$tmpname"; \
rpmkeys --dbpath=$(BUILDER_DIR)/keyrings/rpmdb --import "$$tmpname"; \
rm -f "$$tmpname"; \
fi
sign: packages = $(foreach SPEC,$(RPM_SPEC_FILES),$(call spec_packages,$(SPEC)))
sign: packages += $(foreach SPEC,$(RPM_SRC_PACKAGES),$(call srpm_packages,$(SPEC)))
sign: sign-prep
ifeq (,$(PACKAGE_LIST))
${Q}true
else
# buildinfo should be the last on the list, so update-rpmbuildinfo will
# collect hashes of already signed packages
${Q}cd $(ORIG_SRC) && for pkg in $(packages); do \
if [ "$${pkg##*.}" = "buildinfo" ]; then \
$(RPM_PLUGIN_DIR)scripts/update-rpmbuildinfo "$$pkg" | $(BUILDINFO_SIGN_CMD) > "$$pkg".tmp && \
mv -f "$$pkg".tmp "$$pkg"; \
elif [ "$$(rpmkeys --checksig -- "$$pkg")" != "$$pkg: digests signatures OK" ]; then \
setsid -w rpmsign $(RPMSIGN_OPTS) --addsign $(and $(filter fc25,$(DIST)),--rpmv3) -- "$$pkg" </dev/null || exit 1; \
fi; \
done
endif
check-repo: packages = $(foreach SPEC,$(RPM_SPEC_FILES),$(call spec_packages,$(SPEC)))
check-repo: packages += $(foreach SPEC,$(RPM_SRC_PACKAGES),$(call srpm_packages,$(SPEC)))
check-repo:
ifndef UPDATE_REPO
$(error "You need to specify destination repo in UPDATE_REPO variable")
endif
${Q}if [ -n "$(strip $(packages))" ]; then \
cd $(ORIG_SRC) && ls $(addprefix $(UPDATE_REPO)/rpm/, $(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