xref: /unit/pkg/rpm/Makefile (revision 2138:8223904cc4bb)
1372Sdefan@nginx.com#!/usr/bin/make
2372Sdefan@nginx.com
3953Salexander.borisov@nginx.cominclude ../../version
4372Sdefan@nginx.com
51764Sdefan@nginx.comDEFAULT_VERSION := $(NXT_VERSION)
6821Svbart@nginx.comDEFAULT_RELEASE := 1
7372Sdefan@nginx.com
81764Sdefan@nginx.comVERSION ?= $(DEFAULT_VERSION)
9372Sdefan@nginx.comRELEASE ?= $(DEFAULT_RELEASE)
10372Sdefan@nginx.com
111853Sdefan@nginx.comPACKAGE_VENDOR = NGINX Packaging <nginx-packaging@f5.com>
121853Sdefan@nginx.com
13*2138Sthresh@nginx.comifeq ($(shell test `rpm --eval '0%{?rhel} -eq 7 -a 0%{?amzn} -eq 0'`; echo $$?), 0)
14490Sdefan@nginx.comOSVER = centos7
151016Sdefan@nginx.comelse ifeq ($(shell rpm --eval "%{?rhel}"), 8)
161016Sdefan@nginx.comOSVER = centos8
172116Sthresh@nginx.comelse ifeq ($(shell rpm --eval "%{?rhel}"), 9)
182116Sthresh@nginx.comOSVER = centos9
19490Sdefan@nginx.comelse ifeq ($(shell rpm --eval "%{?amzn}"), 2)
20490Sdefan@nginx.comOSVER = amazonlinux2
21562Sdefan@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1315 -a 0%{?suse_version} -lt 1330 -a 0%{?is_opensuse} -eq 1'`; echo $$?), 0)
22562Sdefan@nginx.comOSVER = opensuse-leap
23562Sdefan@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1330 -a 0%{?is_opensuse} -eq 1'`; echo $$?), 0)
24562Sdefan@nginx.comOSVER = opensuse-tumbleweed
25562Sdefan@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1315 -a 0%{?is_opensuse} -eq 0'`; echo $$?), 0)
26562Sdefan@nginx.comOSVER = sles
27*2138Sthresh@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 35'`; echo $$?),0)
28563Sdefan@nginx.comOSVER = fedora
29490Sdefan@nginx.comendif
30490Sdefan@nginx.com
31562Sdefan@nginx.comBUILD_DEPENDS_unit = gcc rpm-build rpmlint
32562Sdefan@nginx.com
33562Sdefan@nginx.comifeq ($(OSVER), centos7)
34562Sdefan@nginx.comBUILD_DEPENDS_unit += which
35562Sdefan@nginx.comendif
36562Sdefan@nginx.com
37562Sdefan@nginx.comifneq (,$(findstring $(OSVER),opensuse-leap opensuse-tumbleweed sles))
38778Sdefan@nginx.comBUILD_DEPENDS_unit += libxml2-tools libxslt1 libopenssl-devel
39562Sdefan@nginx.comelse
401849Sthresh@nginx.comifneq (,$(findstring $(OSVER),amazonlinux2))
411849Sthresh@nginx.comBUILD_DEPENDS_unit += libxml2 libxslt openssl11-devel
421849Sthresh@nginx.comelse
43778Sdefan@nginx.comBUILD_DEPENDS_unit += libxml2 libxslt openssl-devel
44562Sdefan@nginx.comendif
451849Sthresh@nginx.comendif
46562Sdefan@nginx.com
47562Sdefan@nginx.comBUILD_DEPENDS = $(BUILD_DEPENDS_unit)
48562Sdefan@nginx.com
49372Sdefan@nginx.comMODULES=
50490Sdefan@nginx.com
51980Sdefan@nginx.comifeq ($(OSVER), centos7)
52490Sdefan@nginx.cominclude Makefile.php
531301Sdefan@nginx.cominclude Makefile.python27
541301Sdefan@nginx.cominclude Makefile.python36
55490Sdefan@nginx.cominclude Makefile.go
56524Sdefan@nginx.cominclude Makefile.perl
57980Sdefan@nginx.cominclude Makefile.jsc-common
58980Sdefan@nginx.cominclude Makefile.jsc8
59980Sdefan@nginx.cominclude Makefile.jsc11
60490Sdefan@nginx.comendif
61490Sdefan@nginx.com
621016Sdefan@nginx.comifeq ($(OSVER), centos8)
631016Sdefan@nginx.cominclude Makefile.php
641016Sdefan@nginx.cominclude Makefile.python27
651016Sdefan@nginx.cominclude Makefile.python36
661016Sdefan@nginx.cominclude Makefile.go
671016Sdefan@nginx.cominclude Makefile.perl
681016Sdefan@nginx.cominclude Makefile.jsc-common
691016Sdefan@nginx.cominclude Makefile.jsc8
701016Sdefan@nginx.cominclude Makefile.jsc11
711016Sdefan@nginx.comendif
721016Sdefan@nginx.com
732116Sthresh@nginx.comifeq ($(OSVER), centos9)
742116Sthresh@nginx.cominclude Makefile.php
752116Sthresh@nginx.cominclude Makefile.python39
762116Sthresh@nginx.cominclude Makefile.go
772116Sthresh@nginx.cominclude Makefile.perl
782116Sthresh@nginx.cominclude Makefile.jsc-common
792116Sthresh@nginx.cominclude Makefile.jsc8
802116Sthresh@nginx.cominclude Makefile.jsc11
812116Sthresh@nginx.comendif
822116Sthresh@nginx.com
83980Sdefan@nginx.comifeq ($(OSVER), amazonlinux2)
84980Sdefan@nginx.cominclude Makefile.php
851310Sdefan@nginx.cominclude Makefile.python27
861310Sdefan@nginx.cominclude Makefile.python37
87980Sdefan@nginx.cominclude Makefile.go
88980Sdefan@nginx.cominclude Makefile.perl
89980Sdefan@nginx.cominclude Makefile.jsc-common
90980Sdefan@nginx.cominclude Makefile.jsc8
91490Sdefan@nginx.comendif
92372Sdefan@nginx.com
93562Sdefan@nginx.comifeq ($(OSVER), opensuse-leap)
94562Sdefan@nginx.cominclude Makefile.python27
95562Sdefan@nginx.cominclude Makefile.python34
96562Sdefan@nginx.cominclude Makefile.go
97562Sdefan@nginx.cominclude Makefile.perl
98600Sdefan@nginx.cominclude Makefile.ruby
99562Sdefan@nginx.comendif
100562Sdefan@nginx.com
101562Sdefan@nginx.comifeq ($(OSVER), opensuse-tumbleweed)
102562Sdefan@nginx.cominclude Makefile.php
103562Sdefan@nginx.cominclude Makefile.python27
104562Sdefan@nginx.cominclude Makefile.python36
105562Sdefan@nginx.cominclude Makefile.go
106562Sdefan@nginx.cominclude Makefile.perl
107600Sdefan@nginx.cominclude Makefile.ruby
108562Sdefan@nginx.comendif
109562Sdefan@nginx.com
110562Sdefan@nginx.comifeq ($(OSVER), sles)
111562Sdefan@nginx.cominclude Makefile.python27
112562Sdefan@nginx.cominclude Makefile.python34
113562Sdefan@nginx.cominclude Makefile.perl
114562Sdefan@nginx.comendif
115562Sdefan@nginx.com
116563Sdefan@nginx.comifeq ($(OSVER), fedora)
117563Sdefan@nginx.cominclude Makefile.php
1182003Sdefan@nginx.cominclude Makefile.python310
119563Sdefan@nginx.cominclude Makefile.go
120563Sdefan@nginx.cominclude Makefile.perl
121600Sdefan@nginx.cominclude Makefile.ruby
122980Sdefan@nginx.cominclude Makefile.jsc-common
123980Sdefan@nginx.cominclude Makefile.jsc8
124980Sdefan@nginx.cominclude Makefile.jsc11
125563Sdefan@nginx.comendif
126563Sdefan@nginx.com
127372Sdefan@nginx.comCONFIGURE_ARGS=\
128372Sdefan@nginx.com	--prefix=/usr \
129372Sdefan@nginx.com	--state=%{_sharedstatedir}/unit \
130911Sremi@remirepo.net	--control="unix:/var/run/unit/control.sock" \
1311089Sdefan@nginx.com	--pid=/var/run/unit/unit.pid \
1321089Sdefan@nginx.com	--log=/var/log/unit/unit.log \
1331403Smax.romanov@nginx.com	--tmp=/var/tmp \
1341753Sdefan@nginx.com	--user=unit \
1351753Sdefan@nginx.com	--group=unit \
136778Sdefan@nginx.com	--tests \
137778Sdefan@nginx.com	--openssl
138372Sdefan@nginx.com
139372Sdefan@nginx.comexport CR=\\n
140372Sdefan@nginx.com
141372Sdefan@nginx.comdefault:
142500Sdefan@nginx.com	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs test test-debug clean"
143372Sdefan@nginx.com
144559Sdefan@nginx.comall: check-build-depends-all unit modules
145372Sdefan@nginx.com
146372Sdefan@nginx.commodules: $(addprefix unit-, $(MODULES))
147372Sdefan@nginx.com
148560Sdefan@nginx.comspecs: rpmbuild/SPECS/unit.spec $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES)))
149372Sdefan@nginx.com
150559Sdefan@nginx.comcheck-build-depends-%:
151372Sdefan@nginx.com	@{ \
152559Sdefan@nginx.com	case "$*" in \
153559Sdefan@nginx.com		all) pkgs="$(BUILD_DEPENDS)" ;; \
154559Sdefan@nginx.com		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
155559Sdefan@nginx.com		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
156559Sdefan@nginx.com	esac ; \
157372Sdefan@nginx.com	not_installed= ; \
158559Sdefan@nginx.com	for pkg in $${pkgs}; do \
159372Sdefan@nginx.com		rpm -qi $${pkg} >/dev/null 2>&1 ; \
160372Sdefan@nginx.com		if [ $$? -ne 0 ]; then \
161372Sdefan@nginx.com			not_installed="$${not_installed} $${pkg}" ; \
162372Sdefan@nginx.com		fi ; \
163372Sdefan@nginx.com	done ; \
164372Sdefan@nginx.com	if test -n "$${not_installed}" ; then \
165372Sdefan@nginx.com		echo "" >&2 ; \
166372Sdefan@nginx.com		echo "The following packages are required in order to proceed:" >&2 ; \
167372Sdefan@nginx.com		echo "" >&2 ; \
168372Sdefan@nginx.com		echo $${not_installed} >&2 ; \
169372Sdefan@nginx.com		echo "" >&2 ; \
170372Sdefan@nginx.com		exit 1 ; \
171372Sdefan@nginx.com	fi \
172372Sdefan@nginx.com	}
173559Sdefan@nginx.com	touch $@
174489Sdefan@nginx.com
175372Sdefan@nginx.comrpmbuild/SPECS:
176372Sdefan@nginx.com	mkdir -p rpmbuild/SPECS
177372Sdefan@nginx.com
178372Sdefan@nginx.comrpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS
179372Sdefan@nginx.com	cat unit.spec.in | \
180372Sdefan@nginx.com		sed -e "s#%%VERSION%%#$(VERSION)#g" \
181372Sdefan@nginx.com		    -e "s#%%RELEASE%%#$(RELEASE)#g" \
182372Sdefan@nginx.com		    -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
1831853Sdefan@nginx.com		    -e "s#%%PACKAGE_VENDOR%%#$(PACKAGE_VENDOR)#g" \
184372Sdefan@nginx.com		> rpmbuild/SPECS/unit.spec
185372Sdefan@nginx.com	cd ../../docs && make ../build/unit.rpm-changelog
186372Sdefan@nginx.comifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
187372Sdefan@nginx.com	cat ../../build/unit.rpm-changelog | sed -e \
188372Sdefan@nginx.com		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
189372Sdefan@nginx.com		>> rpmbuild/SPECS/unit.spec
190372Sdefan@nginx.comelse
191372Sdefan@nginx.com	cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
192372Sdefan@nginx.comendif
193372Sdefan@nginx.com
194372Sdefan@nginx.comrpmbuild/SOURCES/unit-$(VERSION).tar.gz:
195372Sdefan@nginx.com	cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
196372Sdefan@nginx.com		--transform "s#^#unit-$(VERSION)/#" \
1972103Sthresh@nginx.com		LICENSE NOTICE CHANGES README.md CONTRIBUTING.md configure auto src test version go docs/man/unitd.8.in
198372Sdefan@nginx.com
199489Sdefan@nginx.comunit: check-build-depends-unit rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
200372Sdefan@nginx.com	@echo "===> Building $@ package" ; \
201372Sdefan@nginx.com	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \
202372Sdefan@nginx.com	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
203372Sdefan@nginx.com
204372Sdefan@nginx.comrpmlint:
205372Sdefan@nginx.com	find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
206372Sdefan@nginx.com
207372Sdefan@nginx.comrpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
208372Sdefan@nginx.com	@echo "===> Creating $@"
209372Sdefan@nginx.com	@{ \
210372Sdefan@nginx.com	set -e ; \
211372Sdefan@nginx.com	i=100 ; \
212372Sdefan@nginx.com	sources= ; \
213372Sdefan@nginx.com	for src in $(MODULE_SOURCES_$*); do \
214372Sdefan@nginx.com		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
215372Sdefan@nginx.com		sources="$${sources}\n$${s}" ; \
216372Sdefan@nginx.com		i=$$(($${i}+1)) ; \
217372Sdefan@nginx.com	done ; \
218980Sdefan@nginx.com	pkgname=$(shell echo $@ | cut -d '/' -f 3 | tr '_' '-' | cut -d '.' -f 1) ; \
219372Sdefan@nginx.com	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
220372Sdefan@nginx.com	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
221980Sdefan@nginx.com	postinstall=`echo "$$MODULE_POSTINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
222372Sdefan@nginx.com	files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
223372Sdefan@nginx.com	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
224372Sdefan@nginx.com	cat unit.module.spec.in | sed \
225372Sdefan@nginx.com		-e "s#%%NAME%%#$${pkgname}#g" \
226372Sdefan@nginx.com		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
227372Sdefan@nginx.com		-e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
228372Sdefan@nginx.com		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
229372Sdefan@nginx.com		-e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
230372Sdefan@nginx.com		-e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
2311853Sdefan@nginx.com		-e "s#%%PACKAGE_VENDOR%%#$(PACKAGE_VENDOR)#g" \
232372Sdefan@nginx.com		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
233372Sdefan@nginx.com		-e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
234372Sdefan@nginx.com		-e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
235372Sdefan@nginx.com		-e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
236372Sdefan@nginx.com		-e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
237372Sdefan@nginx.com		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
238372Sdefan@nginx.com		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
239980Sdefan@nginx.com		-e "s#%%MODULE_POSTINSTALL%%#$${postinstall}#g" \
240372Sdefan@nginx.com		-e "s#%%MODULE_FILES%%#$${files}#g" \
241372Sdefan@nginx.com		-e "s#%%MODULE_POST%%#$${post}#g" \
242372Sdefan@nginx.com		> $@.tmp ; \
243372Sdefan@nginx.com	}
244561Sdefan@nginx.com	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog
245561Sdefan@nginx.com	cat ../../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog | sed -e \
246372Sdefan@nginx.com		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
247372Sdefan@nginx.com		>> $@.tmp
248372Sdefan@nginx.com	mv $@.tmp $@
249372Sdefan@nginx.com
250489Sdefan@nginx.comunit-%: check-build-depends-% rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
251980Sdefan@nginx.com	@echo "===> Building $(subst _,-,$@) package" ; \
252372Sdefan@nginx.com	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \
253980Sdefan@nginx.com	ln -s rpmbuild/BUILD/$(subst _,-,$@)-$(VERSION)/build $@
254372Sdefan@nginx.com
255500Sdefan@nginx.comtest: unit modules
256500Sdefan@nginx.com	@{ \
257980Sdefan@nginx.com	for so in `find rpmbuild/BUILD/*/build-nodebug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
258500Sdefan@nginx.com		soname=`basename $${so}` ; \
259980Sdefan@nginx.com		test "$${soname}" = "java.unit.so" && continue ; \
260500Sdefan@nginx.com		test -h rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} || \
261500Sdefan@nginx.com		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} ; \
262500Sdefan@nginx.com	done ; \
2631762Sdefan@nginx.com	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-nodebug build && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
264500Sdefan@nginx.com	}
265500Sdefan@nginx.com
266500Sdefan@nginx.comtest-debug: unit modules
267500Sdefan@nginx.com	@{ \
268980Sdefan@nginx.com	for so in `find rpmbuild/BUILD/*/build-debug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
269500Sdefan@nginx.com		soname=`basename $${so}` ; \
270980Sdefan@nginx.com		test "$${soname}" = "java.unit.so" && continue ; \
271500Sdefan@nginx.com		test -h rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} || \
272500Sdefan@nginx.com		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} ; \
273500Sdefan@nginx.com	done ; \
2741762Sdefan@nginx.com	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-debug build && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
275500Sdefan@nginx.com	}
276500Sdefan@nginx.com
277372Sdefan@nginx.comclean:
278372Sdefan@nginx.com	rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
279559Sdefan@nginx.com	rm -f rpmbuild/SOURCES/unit-*.tar.gz check-build-depends-*
280372Sdefan@nginx.com	find . -maxdepth 1 -type l -delete
281372Sdefan@nginx.com
282559Sdefan@nginx.com.PHONY: default all modules specs rpmlint test test-debug clean
283372Sdefan@nginx.com
284559Sdefan@nginx.com.SECONDARY: $(addprefix check-build-depends-, $(MODULES))
285