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