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