xref: /unit/pkg/rpm/Makefile (revision 2765:5e31d3ff500a)
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
132138Sthresh@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
212399Sthresh@nginx.comelse ifeq ($(shell rpm --eval "%{?amzn}"), 2023)
222399Sthresh@nginx.comOSVER = amazonlinux2023
232254Sthresh@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 35 -a 0%{?fedora} -le 36'`; echo $$?),0)
24563Sdefan@nginx.comOSVER = fedora
25*2639Sthresh@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 37 -a 0%{?fedora} -le 38'`; echo $$?),0)
262254Sthresh@nginx.comOSVER = fedora37
27*2639Sthresh@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 39'`; echo $$?),0)
28*2639Sthresh@nginx.comOSVER = fedora39
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
371849Sthresh@nginx.comifneq (,$(findstring $(OSVER),amazonlinux2))
381849Sthresh@nginx.comBUILD_DEPENDS_unit += libxml2 libxslt openssl11-devel
391849Sthresh@nginx.comelse
40778Sdefan@nginx.comBUILD_DEPENDS_unit += libxml2 libxslt openssl-devel
41562Sdefan@nginx.comendif
42562Sdefan@nginx.com
43562Sdefan@nginx.comBUILD_DEPENDS = $(BUILD_DEPENDS_unit)
44562Sdefan@nginx.com
45372Sdefan@nginx.comMODULES=
46490Sdefan@nginx.com
47980Sdefan@nginx.comifeq ($(OSVER), centos7)
48490Sdefan@nginx.cominclude Makefile.php
491301Sdefan@nginx.cominclude Makefile.python27
501301Sdefan@nginx.cominclude Makefile.python36
51490Sdefan@nginx.cominclude Makefile.go
52524Sdefan@nginx.cominclude Makefile.perl
53980Sdefan@nginx.cominclude Makefile.jsc-common
54980Sdefan@nginx.cominclude Makefile.jsc8
55980Sdefan@nginx.cominclude Makefile.jsc11
56490Sdefan@nginx.comendif
57490Sdefan@nginx.com
581016Sdefan@nginx.comifeq ($(OSVER), centos8)
591016Sdefan@nginx.cominclude Makefile.php
601016Sdefan@nginx.cominclude Makefile.python27
611016Sdefan@nginx.cominclude Makefile.python36
622233Sthresh@nginx.cominclude Makefile.python38
632233Sthresh@nginx.cominclude Makefile.python39
641016Sdefan@nginx.cominclude Makefile.go
651016Sdefan@nginx.cominclude Makefile.perl
661016Sdefan@nginx.cominclude Makefile.jsc-common
671016Sdefan@nginx.cominclude Makefile.jsc8
681016Sdefan@nginx.cominclude Makefile.jsc11
692524Sthresh@nginx.cominclude Makefile.wasm
701016Sdefan@nginx.comendif
711016Sdefan@nginx.com
722116Sthresh@nginx.comifeq ($(OSVER), centos9)
732116Sthresh@nginx.cominclude Makefile.php
742116Sthresh@nginx.cominclude Makefile.python39
752116Sthresh@nginx.cominclude Makefile.go
762116Sthresh@nginx.cominclude Makefile.perl
772116Sthresh@nginx.cominclude Makefile.jsc-common
782116Sthresh@nginx.cominclude Makefile.jsc8
792116Sthresh@nginx.cominclude Makefile.jsc11
802524Sthresh@nginx.cominclude Makefile.wasm
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
912524Sthresh@nginx.cominclude Makefile.wasm
92490Sdefan@nginx.comendif
93372Sdefan@nginx.com
942399Sthresh@nginx.comifeq ($(OSVER), amazonlinux2023)
952399Sthresh@nginx.cominclude Makefile.php
962399Sthresh@nginx.cominclude Makefile.python39
972399Sthresh@nginx.cominclude Makefile.python311
982399Sthresh@nginx.cominclude Makefile.go
992399Sthresh@nginx.cominclude Makefile.perl
1002399Sthresh@nginx.cominclude Makefile.jsc-common
1012399Sthresh@nginx.cominclude Makefile.jsc17
1022524Sthresh@nginx.cominclude Makefile.wasm
1032399Sthresh@nginx.comendif
1042399Sthresh@nginx.com
105563Sdefan@nginx.comifeq ($(OSVER), fedora)
106563Sdefan@nginx.cominclude Makefile.php
1072003Sdefan@nginx.cominclude Makefile.python310
108563Sdefan@nginx.cominclude Makefile.go
109563Sdefan@nginx.cominclude Makefile.perl
110600Sdefan@nginx.cominclude Makefile.ruby
111980Sdefan@nginx.cominclude Makefile.jsc-common
112980Sdefan@nginx.cominclude Makefile.jsc8
113980Sdefan@nginx.cominclude Makefile.jsc11
1142524Sthresh@nginx.cominclude Makefile.wasm
115563Sdefan@nginx.comendif
116563Sdefan@nginx.com
1172254Sthresh@nginx.comifeq ($(OSVER), fedora37)
1182254Sthresh@nginx.cominclude Makefile.php
1192254Sthresh@nginx.cominclude Makefile.python311
1202254Sthresh@nginx.cominclude Makefile.go
1212254Sthresh@nginx.cominclude Makefile.perl
1222254Sthresh@nginx.cominclude Makefile.ruby
1232254Sthresh@nginx.cominclude Makefile.jsc-common
1242254Sthresh@nginx.cominclude Makefile.jsc8
1252254Sthresh@nginx.cominclude Makefile.jsc11
1262524Sthresh@nginx.cominclude Makefile.wasm
1272254Sthresh@nginx.comendif
1282254Sthresh@nginx.com
129*2639Sthresh@nginx.comifeq ($(OSVER), fedora39)
130*2639Sthresh@nginx.cominclude Makefile.php
131*2639Sthresh@nginx.cominclude Makefile.python312
132*2639Sthresh@nginx.cominclude Makefile.go
133*2639Sthresh@nginx.cominclude Makefile.perl
134*2639Sthresh@nginx.cominclude Makefile.ruby
135*2639Sthresh@nginx.cominclude Makefile.jsc-common
136*2639Sthresh@nginx.cominclude Makefile.jsc17
137*2639Sthresh@nginx.cominclude Makefile.wasm
138*2639Sthresh@nginx.comendif
139*2639Sthresh@nginx.com
140*2639Sthresh@nginx.com
1412277Sthresh@nginx.comCONFIGURE_ARGS_COMMON=\
142372Sdefan@nginx.com	--prefix=/usr \
1432396Salx@nginx.com	--statedir=%{_sharedstatedir}/unit \
144911Sremi@remirepo.net	--control="unix:/var/run/unit/control.sock" \
1452529Sthresh@nginx.com	--runstatedir=/var/run \
1461089Sdefan@nginx.com	--pid=/var/run/unit/unit.pid \
1472529Sthresh@nginx.com	--logdir=/var/log \
1481089Sdefan@nginx.com	--log=/var/log/unit/unit.log \
1492319Sthresh@nginx.com	--tmpdir=/var/tmp \
1501753Sdefan@nginx.com	--user=unit \
1511753Sdefan@nginx.com	--group=unit \
152778Sdefan@nginx.com	--tests \
153778Sdefan@nginx.com	--openssl
154372Sdefan@nginx.com
1552277Sthresh@nginx.comCONFIGURE_ARGS=\
1562277Sthresh@nginx.com	$(CONFIGURE_ARGS_COMMON) \
1572277Sthresh@nginx.com	--njs
1582277Sthresh@nginx.com
159372Sdefan@nginx.comexport CR=\\n
160372Sdefan@nginx.com
161372Sdefan@nginx.comdefault:
162500Sdefan@nginx.com	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs test test-debug clean"
163372Sdefan@nginx.com
164559Sdefan@nginx.comall: check-build-depends-all unit modules
165372Sdefan@nginx.com
166372Sdefan@nginx.commodules: $(addprefix unit-, $(MODULES))
167372Sdefan@nginx.com
168560Sdefan@nginx.comspecs: rpmbuild/SPECS/unit.spec $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES)))
169372Sdefan@nginx.com
170559Sdefan@nginx.comcheck-build-depends-%:
171372Sdefan@nginx.com	@{ \
172559Sdefan@nginx.com	case "$*" in \
173559Sdefan@nginx.com		all) pkgs="$(BUILD_DEPENDS)" ;; \
174559Sdefan@nginx.com		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
175559Sdefan@nginx.com		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
176559Sdefan@nginx.com	esac ; \
177372Sdefan@nginx.com	not_installed= ; \
178559Sdefan@nginx.com	for pkg in $${pkgs}; do \
1792398Sthresh@nginx.com		rpm -qi --whatprovides $${pkg} >/dev/null 2>&1 ; \
180372Sdefan@nginx.com		if [ $$? -ne 0 ]; then \
181372Sdefan@nginx.com			not_installed="$${not_installed} $${pkg}" ; \
182372Sdefan@nginx.com		fi ; \
183372Sdefan@nginx.com	done ; \
184372Sdefan@nginx.com	if test -n "$${not_installed}" ; then \
185372Sdefan@nginx.com		echo "" >&2 ; \
186372Sdefan@nginx.com		echo "The following packages are required in order to proceed:" >&2 ; \
187372Sdefan@nginx.com		echo "" >&2 ; \
188372Sdefan@nginx.com		echo $${not_installed} >&2 ; \
189372Sdefan@nginx.com		echo "" >&2 ; \
190372Sdefan@nginx.com		exit 1 ; \
191372Sdefan@nginx.com	fi \
192372Sdefan@nginx.com	}
193559Sdefan@nginx.com	touch $@
194489Sdefan@nginx.com
195372Sdefan@nginx.comrpmbuild/SPECS:
196372Sdefan@nginx.com	mkdir -p rpmbuild/SPECS
197372Sdefan@nginx.com
198372Sdefan@nginx.comrpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS
199372Sdefan@nginx.com	cat unit.spec.in | \
200372Sdefan@nginx.com		sed -e "s#%%VERSION%%#$(VERSION)#g" \
201372Sdefan@nginx.com		    -e "s#%%RELEASE%%#$(RELEASE)#g" \
202372Sdefan@nginx.com		    -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
2031853Sdefan@nginx.com		    -e "s#%%PACKAGE_VENDOR%%#$(PACKAGE_VENDOR)#g" \
204372Sdefan@nginx.com		> rpmbuild/SPECS/unit.spec
205372Sdefan@nginx.com	cd ../../docs && make ../build/unit.rpm-changelog
206372Sdefan@nginx.comifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
207372Sdefan@nginx.com	cat ../../build/unit.rpm-changelog | sed -e \
208372Sdefan@nginx.com		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
209372Sdefan@nginx.com		>> rpmbuild/SPECS/unit.spec
210372Sdefan@nginx.comelse
211372Sdefan@nginx.com	cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
212372Sdefan@nginx.comendif
213372Sdefan@nginx.com
214372Sdefan@nginx.comrpmbuild/SOURCES/unit-$(VERSION).tar.gz:
215372Sdefan@nginx.com	cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
216372Sdefan@nginx.com		--transform "s#^#unit-$(VERSION)/#" \
2172406Sthresh@nginx.com		LICENSE NOTICE CHANGES README.md CONTRIBUTING.md configure auto src \
2182439Salx@nginx.com		test tools version go pkg/contrib docs/man/man8/unitd.8.in
219372Sdefan@nginx.com
220489Sdefan@nginx.comunit: check-build-depends-unit rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
221372Sdefan@nginx.com	@echo "===> Building $@ package" ; \
2222294Sthresh@nginx.com	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba --noclean rpmbuild/SPECS/unit.spec && \
223372Sdefan@nginx.com	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
224372Sdefan@nginx.com
225372Sdefan@nginx.comrpmlint:
226372Sdefan@nginx.com	find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
227372Sdefan@nginx.com
228372Sdefan@nginx.comrpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
229372Sdefan@nginx.com	@echo "===> Creating $@"
230372Sdefan@nginx.com	@{ \
231372Sdefan@nginx.com	set -e ; \
232372Sdefan@nginx.com	i=100 ; \
233372Sdefan@nginx.com	sources= ; \
234372Sdefan@nginx.com	for src in $(MODULE_SOURCES_$*); do \
235372Sdefan@nginx.com		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
236372Sdefan@nginx.com		sources="$${sources}\n$${s}" ; \
237372Sdefan@nginx.com		i=$$(($${i}+1)) ; \
238372Sdefan@nginx.com	done ; \
239980Sdefan@nginx.com	pkgname=$(shell echo $@ | cut -d '/' -f 3 | tr '_' '-' | cut -d '.' -f 1) ; \
240372Sdefan@nginx.com	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
2412524Sthresh@nginx.com	prebuild=`echo "$$MODULE_PREBUILD_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
242372Sdefan@nginx.com	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
243980Sdefan@nginx.com	postinstall=`echo "$$MODULE_POSTINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
244372Sdefan@nginx.com	files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
245372Sdefan@nginx.com	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
246372Sdefan@nginx.com	cat unit.module.spec.in | sed \
247372Sdefan@nginx.com		-e "s#%%NAME%%#$${pkgname}#g" \
248372Sdefan@nginx.com		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
249372Sdefan@nginx.com		-e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
250372Sdefan@nginx.com		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
251372Sdefan@nginx.com		-e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
252372Sdefan@nginx.com		-e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
2531853Sdefan@nginx.com		-e "s#%%PACKAGE_VENDOR%%#$(PACKAGE_VENDOR)#g" \
254372Sdefan@nginx.com		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
2552277Sthresh@nginx.com		-e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS_COMMON)#g" \
256372Sdefan@nginx.com		-e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
257372Sdefan@nginx.com		-e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
258372Sdefan@nginx.com		-e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
259372Sdefan@nginx.com		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
2602524Sthresh@nginx.com		-e "s#%%MODULE_PREBUILD%%#$${prebuild}#g" \
261372Sdefan@nginx.com		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
262980Sdefan@nginx.com		-e "s#%%MODULE_POSTINSTALL%%#$${postinstall}#g" \
263372Sdefan@nginx.com		-e "s#%%MODULE_FILES%%#$${files}#g" \
264372Sdefan@nginx.com		-e "s#%%MODULE_POST%%#$${post}#g" \
265372Sdefan@nginx.com		> $@.tmp ; \
266372Sdefan@nginx.com	}
267561Sdefan@nginx.com	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog
268561Sdefan@nginx.com	cat ../../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog | sed -e \
269372Sdefan@nginx.com		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
270372Sdefan@nginx.com		>> $@.tmp
2712617Szelenkov@nginx.com	mv $@.tmp $@
272372Sdefan@nginx.com
273489Sdefan@nginx.comunit-%: check-build-depends-% rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
274980Sdefan@nginx.com	@echo "===> Building $(subst _,-,$@) package" ; \
2752294Sthresh@nginx.com	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba --noclean rpmbuild/SPECS/$@.spec && \
276980Sdefan@nginx.com	ln -s rpmbuild/BUILD/$(subst _,-,$@)-$(VERSION)/build $@
277372Sdefan@nginx.com
278500Sdefan@nginx.comtest: unit modules
279500Sdefan@nginx.com	@{ \
280980Sdefan@nginx.com	for so in `find rpmbuild/BUILD/*/build-nodebug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
281500Sdefan@nginx.com		soname=`basename $${so}` ; \
282980Sdefan@nginx.com		test "$${soname}" = "java.unit.so" && continue ; \
283500Sdefan@nginx.com		test -h rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} || \
284500Sdefan@nginx.com		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} ; \
285500Sdefan@nginx.com	done ; \
2861762Sdefan@nginx.com	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-nodebug build && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
287500Sdefan@nginx.com	}
288500Sdefan@nginx.com
289500Sdefan@nginx.comtest-debug: unit modules
290500Sdefan@nginx.com	@{ \
291980Sdefan@nginx.com	for so in `find rpmbuild/BUILD/*/build-debug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
292500Sdefan@nginx.com		soname=`basename $${so}` ; \
293980Sdefan@nginx.com		test "$${soname}" = "java.unit.so" && continue ; \
294500Sdefan@nginx.com		test -h rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} || \
295500Sdefan@nginx.com		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} ; \
296500Sdefan@nginx.com	done ; \
2971762Sdefan@nginx.com	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-debug build && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
298500Sdefan@nginx.com	}
299500Sdefan@nginx.com
300372Sdefan@nginx.comclean:
301372Sdefan@nginx.com	rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
302559Sdefan@nginx.com	rm -f rpmbuild/SOURCES/unit-*.tar.gz check-build-depends-*
303372Sdefan@nginx.com	find . -maxdepth 1 -type l -delete
304372Sdefan@nginx.com
305559Sdefan@nginx.com.PHONY: default all modules specs rpmlint test test-debug clean
306372Sdefan@nginx.com
307559Sdefan@nginx.com.SECONDARY: $(addprefix check-build-depends-, $(MODULES))
308