xref: /unit/pkg/rpm/Makefile (revision 1501:b83465063582)
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	--tests \
153	--openssl
154
155export CR=\\n
156
157default:
158	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs test test-debug clean"
159
160all: check-build-depends-all unit modules
161
162modules: $(addprefix unit-, $(MODULES))
163
164specs: rpmbuild/SPECS/unit.spec $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES)))
165
166check-build-depends-%:
167	@{ \
168	case "$*" in \
169		all) pkgs="$(BUILD_DEPENDS)" ;; \
170		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
171		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
172	esac ; \
173	not_installed= ; \
174	for pkg in $${pkgs}; do \
175		rpm -qi $${pkg} >/dev/null 2>&1 ; \
176		if [ $$? -ne 0 ]; then \
177			not_installed="$${not_installed} $${pkg}" ; \
178		fi ; \
179	done ; \
180	if test -n "$${not_installed}" ; then \
181		echo "" >&2 ; \
182		echo "The following packages are required in order to proceed:" >&2 ; \
183		echo "" >&2 ; \
184		echo $${not_installed} >&2 ; \
185		echo "" >&2 ; \
186		exit 1 ; \
187	fi \
188	}
189	touch $@
190
191rpmbuild/SPECS:
192	mkdir -p rpmbuild/SPECS
193
194rpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS
195	cat unit.spec.in | \
196		sed -e "s#%%VERSION%%#$(VERSION)#g" \
197		    -e "s#%%RELEASE%%#$(RELEASE)#g" \
198		    -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
199		> rpmbuild/SPECS/unit.spec
200	cd ../../docs && make ../build/unit.rpm-changelog
201ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
202	cat ../../build/unit.rpm-changelog | sed -e \
203		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
204		>> rpmbuild/SPECS/unit.spec
205else
206	cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
207endif
208
209rpmbuild/SOURCES/unit-$(VERSION).tar.gz:
210	cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
211		--transform "s#^#unit-$(VERSION)/#" \
212		LICENSE NOTICE CHANGES README configure auto src test version go
213
214unit: check-build-depends-unit rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
215	@echo "===> Building $@ package" ; \
216	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \
217	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
218
219rpmlint:
220	find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
221
222rpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
223	@echo "===> Creating $@"
224	@{ \
225	set -e ; \
226	i=100 ; \
227	sources= ; \
228	for src in $(MODULE_SOURCES_$*); do \
229		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
230		sources="$${sources}\n$${s}" ; \
231		i=$$(($${i}+1)) ; \
232	done ; \
233	pkgname=$(shell echo $@ | cut -d '/' -f 3 | tr '_' '-' | cut -d '.' -f 1) ; \
234	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
235	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
236	postinstall=`echo "$$MODULE_POSTINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
237	files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
238	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
239	cat unit.module.spec.in | sed \
240		-e "s#%%NAME%%#$${pkgname}#g" \
241		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
242		-e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
243		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
244		-e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
245		-e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
246		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
247		-e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
248		-e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
249		-e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
250		-e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
251		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
252		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
253		-e "s#%%MODULE_POSTINSTALL%%#$${postinstall}#g" \
254		-e "s#%%MODULE_FILES%%#$${files}#g" \
255		-e "s#%%MODULE_POST%%#$${post}#g" \
256		> $@.tmp ; \
257	}
258	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog
259	cat ../../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog | sed -e \
260		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
261		>> $@.tmp
262	mv $@.tmp $@
263
264unit-%: check-build-depends-% rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
265	@echo "===> Building $(subst _,-,$@) package" ; \
266	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \
267	ln -s rpmbuild/BUILD/$(subst _,-,$@)-$(VERSION)/build $@
268
269test: unit modules
270	@{ \
271	for so in `find rpmbuild/BUILD/*/build-nodebug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
272		soname=`basename $${so}` ; \
273		test "$${soname}" = "java.unit.so" && continue ; \
274		test -h rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} || \
275		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} ; \
276	done ; \
277	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-nodebug build && ./test/run.py ) ; \
278	}
279
280test-debug: unit modules
281	@{ \
282	for so in `find rpmbuild/BUILD/*/build-debug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
283		soname=`basename $${so}` ; \
284		test "$${soname}" = "java.unit.so" && continue ; \
285		test -h rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} || \
286		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} ; \
287	done ; \
288	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-debug build && ./test/run.py ) ; \
289	}
290
291clean:
292	rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
293	rm -f rpmbuild/SOURCES/unit-*.tar.gz check-build-depends-*
294	find . -maxdepth 1 -type l -delete
295
296.PHONY: default all modules specs rpmlint test test-debug clean
297
298.SECONDARY: $(addprefix check-build-depends-, $(MODULES))
299