xref: /unit/pkg/rpm/Makefile (revision 600:694767e0b8c9)
1#!/usr/bin/make
2
3DEFAULT_VERSION := $(shell grep 'define NXT_VERSION' ../../src/nxt_main.h \
4			| sed -e 's/^.*"\(.*\)".*/\1/')
5
6DEFAULT_RELEASE := 1
7
8VERSION ?= $(DEFAULT_VERSION)
9RELEASE ?= $(DEFAULT_RELEASE)
10
11ifeq ($(shell rpm --eval "%{?rhel}"), 6)
12OSVER = centos6
13else ifeq ($(shell rpm --eval "%{?rhel}"), 7)
14OSVER = centos7
15else ifeq ($(shell rpm --eval "%{?amzn}"), 1)
16OSVER = amazonlinux1
17else ifeq ($(shell rpm --eval "%{?amzn}"), 2)
18OSVER = amazonlinux2
19else ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1315 -a 0%{?suse_version} -lt 1330 -a 0%{?is_opensuse} -eq 1'`; echo $$?), 0)
20OSVER = opensuse-leap
21else ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1330 -a 0%{?is_opensuse} -eq 1'`; echo $$?), 0)
22OSVER = opensuse-tumbleweed
23else ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1315 -a 0%{?is_opensuse} -eq 0'`; echo $$?), 0)
24OSVER = sles
25else ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 26'`; echo $$?),0)
26OSVER = fedora
27endif
28
29BUILD_DEPENDS_unit = gcc rpm-build rpmlint
30
31ifeq ($(OSVER), centos7)
32BUILD_DEPENDS_unit += which
33endif
34
35ifeq ($(OSVER), amazonlinux1)
36BUILD_DEPENDS_unit += system-rpm-config
37endif
38
39ifneq (,$(findstring $(OSVER),opensuse-leap opensuse-tumbleweed sles))
40BUILD_DEPENDS_unit += libxml2-tools libxslt1
41else
42BUILD_DEPENDS_unit += libxml2 libxslt
43endif
44
45BUILD_DEPENDS = $(BUILD_DEPENDS_unit)
46
47MODULES=
48
49ifneq (,$(findstring $(OSVER),centos6 centos7 amazonlinux2))
50include Makefile.php
51include Makefile.python
52include Makefile.go
53include Makefile.perl
54endif
55
56ifeq ($(OSVER), amazonlinux1)
57include Makefile.php
58include Makefile.python27
59include Makefile.python34
60include Makefile.python35
61include Makefile.python36
62include Makefile.go
63include Makefile.perl
64endif
65
66ifeq ($(OSVER), opensuse-leap)
67include Makefile.python27
68include Makefile.python34
69include Makefile.go
70include Makefile.perl
71include Makefile.ruby
72endif
73
74ifeq ($(OSVER), opensuse-tumbleweed)
75include Makefile.php
76include Makefile.python27
77include Makefile.python36
78include Makefile.go
79include Makefile.perl
80include Makefile.ruby
81endif
82
83ifeq ($(OSVER), sles)
84include Makefile.python27
85include Makefile.python34
86include Makefile.perl
87endif
88
89ifeq ($(OSVER), fedora)
90include Makefile.php
91include Makefile.python27
92include Makefile.python36
93include Makefile.go
94include Makefile.perl
95include Makefile.ruby
96endif
97
98CONFIGURE_ARGS=\
99	--prefix=/usr \
100	--state=%{_sharedstatedir}/unit \
101	--control="unix:/var/run/control.unit.sock" \
102	--pid=/var/run/unit.pid \
103	--log=/var/log/unit.log \
104	--tests
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		> rpmbuild/SPECS/unit.spec
151	cd ../../docs && make ../build/unit.rpm-changelog
152ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
153	cat ../../build/unit.rpm-changelog | sed -e \
154		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
155		>> rpmbuild/SPECS/unit.spec
156else
157	cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
158endif
159
160rpmbuild/SOURCES/unit-$(VERSION).tar.gz:
161	cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
162		--transform "s#^#unit-$(VERSION)/#" \
163		LICENSE NOTICE CHANGES README configure auto src test
164
165unit: check-build-depends-unit rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
166	@echo "===> Building $@ package" ; \
167	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \
168	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
169
170rpmlint:
171	find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
172
173rpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
174	@echo "===> Creating $@"
175	@{ \
176	set -e ; \
177	i=100 ; \
178	sources= ; \
179	for src in $(MODULE_SOURCES_$*); do \
180		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
181		sources="$${sources}\n$${s}" ; \
182		i=$$(($${i}+1)) ; \
183	done ; \
184	pkgname=$(shell echo $@ | cut -d '/' -f 3 | cut -d '.' -f 1) ; \
185	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
186	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
187	files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
188	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
189	cat unit.module.spec.in | sed \
190		-e "s#%%NAME%%#$${pkgname}#g" \
191		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
192		-e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
193		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
194		-e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
195		-e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
196		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
197		-e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
198		-e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
199		-e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
200		-e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
201		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
202		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
203		-e "s#%%MODULE_FILES%%#$${files}#g" \
204		-e "s#%%MODULE_POST%%#$${post}#g" \
205		> $@.tmp ; \
206	}
207	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog
208	cat ../../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog | sed -e \
209		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
210		>> $@.tmp
211	mv $@.tmp $@
212
213unit-%: check-build-depends-% rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
214	@echo "===> Building $@ package" ; \
215	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \
216	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
217
218test: unit modules
219	@{ \
220	for so in `find rpmbuild/BUILD/*/build-nodebug/ -type f -name "*.so"`; do \
221		soname=`basename $${so}` ; \
222		test -h rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} || \
223		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} ; \
224	done ; \
225	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-nodebug build && ./test/run.py ) ; \
226	}
227
228test-debug: unit modules
229	@{ \
230	for so in `find rpmbuild/BUILD/*/build-debug/ -type f -name "*.so"`; do \
231		soname=`basename $${so}` ; \
232		test -h rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} || \
233		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} ; \
234	done ; \
235	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-debug build && ./test/run.py ) ; \
236	}
237
238clean:
239	rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
240	rm -f rpmbuild/SOURCES/unit-*.tar.gz check-build-depends-*
241	find . -maxdepth 1 -type l -delete
242
243.PHONY: default all modules specs rpmlint test test-debug clean
244
245.SECONDARY: $(addprefix check-build-depends-, $(MODULES))
246