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