forked from spacewalkproject/spacewalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.srpm
200 lines (166 loc) · 6.46 KB
/
Makefile.srpm
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
RPMBUILD ?= rpmbuild
RPMBUILD_BASEDIR ?= $(CURDIR)
# After content is exported via git archive and untarred, make is
# called in that directory, with X_RPMBUILD_DIR parameter, which
# determines output directory.
ifdef X_RPMBUILD_DIR
X_RPMBUILD_DIR_OPTS = --define "_sourcedir $(CURDIR)" \
--define "_builddir $(X_RPMBUILD_DIR)/BUILD" \
--define "_srcrpmdir $(X_RPMBUILD_DIR)" \
--define "_rpmdir $(X_RPMBUILD_DIR)"
# The COMMIT parameter is used when we want to make tar.gz / .src.rpm
# from any commit we like (including HEAD). In that case thou, the
# name and content of the tar.gz / .src.rpm is modified to contain
# the SHA1 of the commit, to distinguish them from sources that
# come from tagged commits.
else ifdef COMMIT
COMMIT_SHA1 := $(shell git rev-parse --verify $(COMMIT))
ifdef COMMIT_SHA1
NAME_TAR_GZ_DIR := $(NAME)-git-$(COMMIT_SHA1)
COMMIT_TIMESTAMP = $(shell git rev-list --timestamp --max-count=1 $(COMMIT_SHA1) | awk '{print $$1}')
ifndef DIR
DIR := $(shell git show $(COMMIT_SHA1):rel-eng/packages/$(NAME) 2> /dev/null | awk '{print $$2; exit }')
endif
RPMBUILD_DIR := $(RPMBUILD_BASEDIR)/rpmbuild-$(NAME)-git-$(COMMIT_SHA1)
endif
# The TAG parameter determines git tag, and by stripping
# version-release from its name also package NAME, and via
# rel-eng/package/NAME also DIR.
else
# If TAG is not defined, we use the latest known version.
ifndef TAG
ifdef NAME
TAG := $(shell awk '{ print "$(NAME)" "-" $$1 ; exit }' $(PACKAGES_DIR)$(NAME) 2> /dev/null )
endif
endif
ifdef TAG
TAG_SHA1 := $(shell git ls-remote ./. --tag $(TAG) | awk '{ print $$1 ; exit }' )
ifndef TAG_SHA1
ifndef DIST
TEST_TAG := $(shell perl -lne 'BEGIN { $$TAG = shift } if ($$_ eq substr($$TAG, -length)) { print substr $$TAG, 0, -length ; exit }' $(TAG) $(THIS_DIR)known-dists)
ifdef TEST_TAG
TAG_SHA1 := $(shell git ls-remote ./. --tag $(TEST_TAG) | awk '{ print $$1 ; exit }' )
ifdef TAG_SHA1
DIST := $(shell perl -le 'print substr shift, length shift' $(TAG) $(TEST_TAG))
override TAG := $(TEST_TAG)
endif
endif
endif
endif
endif
ifdef TAG_SHA1
COMMIT_SHA1 := $(shell git rev-list --max-count=1 $(TAG_SHA1) )
endif
ifdef COMMIT_SHA1
NAME := $(shell echo $(TAG)| sed 's!-[^-]*-[^-]*$$!!')
NAME_VERSION := $(shell echo $(TAG)| sed 's!-[^-]*$$!!')
NAME_TAR_GZ_DIR := $(shell echo $(TAG)| sed 's!-[^-]*$$!!')
COMMIT_TIMESTAMP = $(shell git rev-list --timestamp --max-count=1 $(COMMIT_SHA1) | awk '{print $$1}')
DIR := $(shell git show $(COMMIT_SHA1):rel-eng/packages/$(NAME) | awk '{print $$2; exit }')
RPMBUILD_DIR := $(RPMBUILD_BASEDIR)/rpmbuild-$(TAG)
endif
endif
RPMBUILD_SOURCEDIR := $(RPMBUILD_DIR)/SOURCES/$(DIR)
NAME_TAR_GZ := $(NAME_TAR_GZ_DIR).tar.gz
ifdef DIST
DIST_OPTS = --define 'dist $(DIST)'
DIST_PARAMS = DIST=$(DIST)
endif
ifdef COMMIT
COMMIT_PARAMS = COMMIT=$(COMMIT)
endif
ifdef DIR
DIR_OR_PREFIX := $(DIR)
else
DIR_OR_PREFIX := $(GIT_PREFIX)
endif
tgz : git-archive-to-tar-gz
@echo "Wrote: $(RPMBUILD_DIR)/$(NAME_TAR_GZ)"
git-archive-unpack : git-archive-to-tar-gz unpack-tar-gz
rpm srpm : check-tag git-archive-unpack
$(MAKE) --no-print-directory -C $(RPMBUILD_SOURCEDIR) x-build-$@ X_RPMBUILD_DIR=$(RPMBUILD_DIR) $(DIST_PARAMS) $(COMMIT_PARAMS)
test-srpm :
$(MAKE) --no-print-directory srpm COMMIT=$(HEAD_COMMIT_SHA1) NAME=$(NAME) DIR=$(DIR_OR_PREFIX)
test-rpm :
$(MAKE) --no-print-directory rpm COMMIT=$(HEAD_COMMIT_SHA1) NAME=$(NAME) DIR=$(DIR_OR_PREFIX)
check-tag :
@if test -n "$(TAG)" ; then \
if test -z "$(TAG_SHA1)" ; then \
echo "The tag [$(TAG)] does not seem to be available." ; \
exit 1 ; \
fi ; \
export UPSTREAM_REPO=`cat $(THIS_DIR)upstream-repo` ; \
export UPSTREAM_TAG=`git ls-remote $$UPSTREAM_REPO --tag $(TAG) | awk '{ print $$1 ; exit }'` ; \
if test -z "$$UPSTREAM_TAG" ; then \
echo "The tag [$(TAG)] does not seem to be available in upstream repo [$$UPSTREAM_REPO]." ; exit 1 ; \
fi ; \
if test "x$$UPSTREAM_TAG" != "x$(TAG_SHA1)" ; then \
echo "The tag [$(TAG)] points to [$(TAG_SHA1)] locally while to [$$UPSTREAM_TAG] in upstream repo [$$UPSTREAM_REPO]." ; \
exit 1 ; \
fi ; \
echo "package [$(NAME)] tag [$(TAG)]" ; \
echo " tag SHA1 [$(TAG_SHA1)] commit SHA1 [$(COMMIT_SHA1)]" ; \
fi
git-archive-to-tar-gz : setup-source-dir
@cd $(GIT_CDUP) && \
git archive --format=tar --prefix=$(NAME_TAR_GZ_DIR)/ $(COMMIT_SHA1):$(DIR) \
| perl $(THIS_DIR)tar-fixup-stamp-comment.pl $(COMMIT_TIMESTAMP) $(COMMIT_SHA1) \
| gzip -n -c - > $(RPMBUILD_DIR)/$(NAME_TAR_GZ)
unpack-tar-gz : setup-source-dir-2
@cd $(RPMBUILD_SOURCEDIR) && tar xz --strip-components 1 -f $(RPMBUILD_DIR)/$(NAME_TAR_GZ)
setup-source-dir :
@if test -d $(RPMBUILD_DIR) ; then \
echo "Removing previous [$(RPMBUILD_DIR)]" ; \
rm -rf $(RPMBUILD_DIR) ; \
fi
@echo "Creating [$(RPMBUILD_DIR)]"
@mkdir -p $(RPMBUILD_DIR)
setup-source-dir-2 :
@mkdir -p $(RPMBUILD_SOURCEDIR)
@ln -s $(THIS_DIR) $(RPMBUILD_DIR)/SOURCES/rel-eng
rpmbuild_x-build-srpm_params = --nodeps -bs
rpmbuild_x-build-rpm_params = --nodeps --clean -ba
x-build-srpm x-build-rpm : x-setup-specfile x-pull-in-tar-gz x-download-source0
@mkdir -p $(X_RPMBUILD_DIR)/BUILD
$(RPMBUILD) $(X_RPMBUILD_DIR_OPTS) $(DIST_OPTS) $(rpmbuild_$@_params) $(SPECFILE)
@rm -rf $(X_RPMBUILD_DIR)/BUILD
@find $(X_RPMBUILD_DIR) -name '*.rpm' | while read i ; do \
echo rpmlint $$i ; \
rpmlint $$i | perl $(THIS_DIR)rpmlint-silence-warnings.pl $(if $(COMMIT),--ignore,) ; \
done
x-setup-specfile :
@if test -n "$(COMMIT)" ; then \
if test -n "$(NO_TAR_GZ)" ; then \
perl $(THIS_DIR)test-setup-specfile.pl $(SPECFILE) $(COMMIT) ; \
else \
perl $(THIS_DIR)test-setup-specfile.pl $(SPECFILE) $(COMMIT) $(NAME)-git-$(COMMIT) $(NAME)-git-$(COMMIT).tar.gz ; \
fi ; \
fi
x-pull-in-tar-gz :
@if test -z "$(NO_TAR_GZ)" ; then \
for i in $(X_RPMBUILD_DIR)/*.tar.gz ; do \
NAME_TAR_GZ=`basename $$i` ; \
if test -e $$NAME_TAR_GZ ; then \
echo "The tarball seems to contain $$NAME_TAR_GZ already." ; \
exit 1 ; \
fi ; \
mv $(X_RPMBUILD_DIR)/*.tar.gz . ; \
done ; \
fi
x-download-source0 :
@if test -n "$(DOWNLOAD_SOURCES)" ; then \
for i in $(DOWNLOAD_SOURCES) ; do \
wget $$i ; \
done ; \
fi
upload-tgz : tgz
@scp $(RPMBUILD_DIR)/$(NAME_TAR_GZ) fedorahosted.org:spacewalk
%.src.rpm %.srpm :
$(MAKE) --no-print-directory srpm TAG=$*
%.tar.gz %.tgz :
$(MAKE) --no-print-directory tgz TAG=$*
.PHONY : tgz git-archive-unpack git-archive-to-tar-gz unpack-tar-gz \
rpm srpm test-srpm test-rpm \
setup-source-dir setup-source-dir-2 \
x-build-srpm x-build-rpm x-setup-specfile x-setup-specfile \
upload-tgz check-tag