xref: /unit/pkg/rpm/Makefile (revision 2003:28f0ed517b6e)
1#!/usr/bin/make
2
3include ../../version
4
5DEFAULT_VERSION := $(NXT_VERSION)
6DEFAULT_RELEASE := 1
7
8VERSION ?= $(DEFAULT_VERSION)
9RELEASE ?= $(DEFAULT_RELEASE)
10
11PACKAGE_VENDOR = NGINX Packaging <nginx-packaging@f5.com>
12
13ifeq ($(shell test `rpm --eval '0%{?rhel} -eq 6 -a 0%{?amzn} -eq 0'`; echo $$?), 0)
14OSVER = centos6
15else ifeq ($(shell test `rpm --eval '0%{?rhel} -eq 7 -a 0%{?amzn} -eq 0'`; echo $$?), 0)
16OSVER = centos7
17else ifeq ($(shell rpm --eval "%{?rhel}"), 8)
18OSVER = centos8
19else ifeq ($(shell rpm --eval "%{?amzn}"), 1)
20OSVER = amazonlinux1
21else ifeq ($(shell rpm --eval "%{?amzn}"), 2)
22OSVER = amazonlinux2
23else ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1315 -a 0%{?suse_version} -lt 1330 -a 0%{?is_opensuse} -eq 1'`; echo $$?), 0)
24OSVER = opensuse-leap
25else ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1330 -a 0%{?is_opensuse} -eq 1'`; echo $$?), 0)
26OSVER = opensuse-tumbleweed
27else ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1315 -a 0%{?is_opensuse} -eq 0'`; echo $$?), 0)
28OSVER = sles
29else ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 26'`; echo $$?),0)
30OSVER = fedora
31endif
32
33BUILD_DEPENDS_unit = gcc rpm-build rpmlint
34
35ifeq ($(OSVER), centos7)
36BUILD_DEPENDS_unit += which
37endif
38
39ifeq ($(OSVER), amazonlinux1)
40BUILD_DEPENDS_unit += system-rpm-config
41endif
42
43ifneq (,$(findstring $(OSVER),opensuse-leap opensuse-tumbleweed sles))
44BUILD_DEPENDS_unit += libxml2-tools libxslt1 libopenssl-devel
45else
46ifneq (,$(findstring $(OSVER),amazonlinux2))
47BUILD_DEPENDS_unit += libxml2 libxslt openssl11-devel
48else
49BUILD_DEPENDS_unit += libxml2 libxslt openssl-devel
50endif
51endif
52
53BUILD_DEPENDS = $(BUILD_DEPENDS_unit)
54
55MODULES=
56
57ifeq ($(OSVER), centos6)
58include Makefile.php
59include Makefile.python
60include Makefile.go
61include Makefile.jsc-common
62include Makefile.jsc8
63endif
64
65ifeq ($(OSVER), centos7)
66include Makefile.php
67include Makefile.python27
68include Makefile.python36
69include Makefile.go
70include Makefile.perl
71include Makefile.jsc-common
72include Makefile.jsc8
73include Makefile.jsc11
74endif
75
76ifeq ($(OSVER), centos8)
77include Makefile.php
78include Makefile.python27
79include Makefile.python36
80include Makefile.go
81include Makefile.perl
82include Makefile.jsc-common
83include Makefile.jsc8
84include Makefile.jsc11
85endif
86
87ifeq ($(OSVER), amazonlinux1)
88include Makefile.php
89include Makefile.python27
90include Makefile.python34
91include Makefile.python35
92include Makefile.python36
93include Makefile.go
94include Makefile.perl
95include Makefile.jsc-common
96include Makefile.jsc8
97endif
98
99ifeq ($(OSVER), amazonlinux2)
100include Makefile.php
101include Makefile.python27
102include Makefile.python37
103include Makefile.go
104include Makefile.perl
105include Makefile.jsc-common
106include Makefile.jsc8
107endif
108
109ifeq ($(OSVER), opensuse-leap)
110include Makefile.python27
111include Makefile.python34
112include Makefile.go
113include Makefile.perl
114include Makefile.ruby
115endif
116
117ifeq ($(OSVER), opensuse-tumbleweed)
118include Makefile.php
119include Makefile.python27
120include Makefile.python36
121include Makefile.go
122include Makefile.perl
123include Makefile.ruby
124endif
125
126ifeq ($(OSVER), sles)
127include Makefile.python27
128include Makefile.python34
129include Makefile.perl
130endif
131
132ifeq ($(OSVER), fedora)
133include Makefile.php
134ifeq ($(shell test `rpm --eval '0%{?fedora} -lt 32'`; echo $$?),0)
135include Makefile.python27
136endif
137ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 35'`; echo $$?),0)
138include Makefile.python310
139else ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 33'`; echo $$?),0)
140include Makefile.python39
141else ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 32'`; echo $$?),0)
142include Makefile.python38
143else ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 29'`; echo $$?),0)
144include Makefile.python37
145else
146include Makefile.python36
147endif
148include Makefile.go
149include Makefile.perl
150include Makefile.ruby
151include Makefile.jsc-common
152include Makefile.jsc8
153include Makefile.jsc11
154endif
155
156CONFIGURE_ARGS=\
157	--prefix=/usr \
158	--state=%{_sharedstatedir}/unit \
159	--control="unix:/var/run/unit/control.sock" \
160	--pid=/var/run/unit/unit.pid \
161	--log=/var/log/unit/unit.log \
162	--tmp=/var/tmp \
163	--user=unit \
164	--group=unit \
165	--tests \
166	--openssl
167
168export CR=\\n
169
170default:
171	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs test test-debug clean"
172
173all: check-build-depends-all unit modules
174
175modules: $(addprefix unit-, $(MODULES))
176
177specs: rpmbuild/SPECS/unit.spec $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES)))
178
179check-build-depends-%:
180	@{ \
181	case "$*" in \
182		all) pkgs="$(BUILD_DEPENDS)" ;; \
183		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
184		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
185	esac ; \
186	not_installed= ; \
187	for pkg in $${pkgs}; do \
188		rpm -qi $${pkg} >/dev/null 2>&1 ; \
189		if [ $$? -ne 0 ]; then \
190			not_installed="$${not_installed} $${pkg}" ; \
191		fi ; \
192	done ; \
193	if test -n "$${not_installed}" ; then \
194		echo "" >&2 ; \
195		echo "The following packages are required in order to proceed:" >&2 ; \
196		echo "" >&2 ; \
197		echo $${not_installed} >&2 ; \
198		echo "" >&2 ; \
199		exit 1 ; \
200	fi \
201	}
202	touch $@
203
204rpmbuild/SPECS:
205	mkdir -p rpmbuild/SPECS
206
207rpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS
208	cat unit.spec.in | \
209		sed -e "s#%%VERSION%%#$(VERSION)#g" \
210		    -e "s#%%RELEASE%%#$(RELEASE)#g" \
211		    -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
212		    -e "s#%%PACKAGE_VENDOR%%#$(PACKAGE_VENDOR)#g" \
213		> rpmbuild/SPECS/unit.spec
214	cd ../../docs && make ../build/unit.rpm-changelog
215ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
216	cat ../../build/unit.rpm-changelog | sed -e \
217		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
218		>> rpmbuild/SPECS/unit.spec
219else
220	cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
221endif
222
223rpmbuild/SOURCES/unit-$(VERSION).tar.gz:
224	cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
225		--transform "s#^#unit-$(VERSION)/#" \
226		LICENSE NOTICE CHANGES README configure auto src test version go docs/man/unitd.8.in
227
228unit: check-build-depends-unit rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
229	@echo "===> Building $@ package" ; \
230	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \
231	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
232
233rpmlint:
234	find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
235
236rpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
237	@echo "===> Creating $@"
238	@{ \
239	set -e ; \
240	i=100 ; \
241	sources= ; \
242	for src in $(MODULE_SOURCES_$*); do \
243		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
244		sources="$${sources}\n$${s}" ; \
245		i=$$(($${i}+1)) ; \
246	done ; \
247	pkgname=$(shell echo $@ | cut -d '/' -f 3 | tr '_' '-' | cut -d '.' -f 1) ; \
248	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
249	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
250	postinstall=`echo "$$MODULE_POSTINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
251	files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
252	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
253	cat unit.module.spec.in | sed \
254		-e "s#%%NAME%%#$${pkgname}#g" \
255		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
256		-e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
257		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
258		-e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
259		-e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
260		-e "s#%%PACKAGE_VENDOR%%#$(PACKAGE_VENDOR)#g" \
261		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
262		-e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
263		-e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
264		-e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
265		-e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
266		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
267		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
268		-e "s#%%MODULE_POSTINSTALL%%#$${postinstall}#g" \
269		-e "s#%%MODULE_FILES%%#$${files}#g" \
270		-e "s#%%MODULE_POST%%#$${post}#g" \
271		> $@.tmp ; \
272	}
273	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog
274	cat ../../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog | sed -e \
275		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
276		>> $@.tmp
277	mv $@.tmp $@
278
279unit-%: check-build-depends-% rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
280	@echo "===> Building $(subst _,-,$@) package" ; \
281	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \
282	ln -s rpmbuild/BUILD/$(subst _,-,$@)-$(VERSION)/build $@
283
284test: unit modules
285	@{ \
286	for so in `find rpmbuild/BUILD/*/build-nodebug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
287		soname=`basename $${so}` ; \
288		test "$${soname}" = "java.unit.so" && continue ; \
289		test -h rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} || \
290		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} ; \
291	done ; \
292	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-nodebug build && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
293	}
294
295test-debug: unit modules
296	@{ \
297	for so in `find rpmbuild/BUILD/*/build-debug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
298		soname=`basename $${so}` ; \
299		test "$${soname}" = "java.unit.so" && continue ; \
300		test -h rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} || \
301		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} ; \
302	done ; \
303	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-debug build && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
304	}
305
306clean:
307	rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
308	rm -f rpmbuild/SOURCES/unit-*.tar.gz check-build-depends-*
309	find . -maxdepth 1 -type l -delete
310
311.PHONY: default all modules specs rpmlint test test-debug clean
312
313.SECONDARY: $(addprefix check-build-depends-, $(MODULES))
314