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