xref: /unit/pkg/rpm/Makefile (revision 911:7012b4fd5113)
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 libopenssl-devel
41else
42BUILD_DEPENDS_unit += libxml2 libxslt openssl-devel
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
92ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 29'`; echo $$?),0)
93include Makefile.python37
94else
95include Makefile.python36
96endif
97include Makefile.go
98include Makefile.perl
99include Makefile.ruby
100endif
101
102CONFIGURE_ARGS=\
103	--prefix=/usr \
104	--state=%{_sharedstatedir}/unit \
105	--control="unix:/var/run/unit/control.sock" \
106	--pid=/var/run/unit.pid \
107	--log=/var/log/unit.log \
108	--tests \
109	--openssl
110
111export CR=\\n
112
113default:
114	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs test test-debug clean"
115
116all: check-build-depends-all unit modules
117
118modules: $(addprefix unit-, $(MODULES))
119
120specs: rpmbuild/SPECS/unit.spec $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES)))
121
122check-build-depends-%:
123	@{ \
124	case "$*" in \
125		all) pkgs="$(BUILD_DEPENDS)" ;; \
126		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
127		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
128	esac ; \
129	not_installed= ; \
130	for pkg in $${pkgs}; do \
131		rpm -qi $${pkg} >/dev/null 2>&1 ; \
132		if [ $$? -ne 0 ]; then \
133			not_installed="$${not_installed} $${pkg}" ; \
134		fi ; \
135	done ; \
136	if test -n "$${not_installed}" ; then \
137		echo "" >&2 ; \
138		echo "The following packages are required in order to proceed:" >&2 ; \
139		echo "" >&2 ; \
140		echo $${not_installed} >&2 ; \
141		echo "" >&2 ; \
142		exit 1 ; \
143	fi \
144	}
145	touch $@
146
147rpmbuild/SPECS:
148	mkdir -p rpmbuild/SPECS
149
150rpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS
151	cat unit.spec.in | \
152		sed -e "s#%%VERSION%%#$(VERSION)#g" \
153		    -e "s#%%RELEASE%%#$(RELEASE)#g" \
154		    -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
155		> rpmbuild/SPECS/unit.spec
156	cd ../../docs && make ../build/unit.rpm-changelog
157ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
158	cat ../../build/unit.rpm-changelog | sed -e \
159		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
160		>> rpmbuild/SPECS/unit.spec
161else
162	cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
163endif
164
165rpmbuild/SOURCES/unit-$(VERSION).tar.gz:
166	cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
167		--transform "s#^#unit-$(VERSION)/#" \
168		LICENSE NOTICE CHANGES README configure auto src test
169
170unit: check-build-depends-unit rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
171	@echo "===> Building $@ package" ; \
172	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \
173	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
174
175rpmlint:
176	find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
177
178rpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
179	@echo "===> Creating $@"
180	@{ \
181	set -e ; \
182	i=100 ; \
183	sources= ; \
184	for src in $(MODULE_SOURCES_$*); do \
185		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
186		sources="$${sources}\n$${s}" ; \
187		i=$$(($${i}+1)) ; \
188	done ; \
189	pkgname=$(shell echo $@ | cut -d '/' -f 3 | cut -d '.' -f 1) ; \
190	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
191	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
192	files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
193	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
194	cat unit.module.spec.in | sed \
195		-e "s#%%NAME%%#$${pkgname}#g" \
196		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
197		-e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
198		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
199		-e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
200		-e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
201		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
202		-e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
203		-e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
204		-e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
205		-e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
206		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
207		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
208		-e "s#%%MODULE_FILES%%#$${files}#g" \
209		-e "s#%%MODULE_POST%%#$${post}#g" \
210		> $@.tmp ; \
211	}
212	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog
213	cat ../../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog | sed -e \
214		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
215		>> $@.tmp
216	mv $@.tmp $@
217
218unit-%: check-build-depends-% rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
219	@echo "===> Building $@ package" ; \
220	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \
221	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
222
223test: unit modules
224	@{ \
225	for so in `find rpmbuild/BUILD/*/build-nodebug/ -type f -name "*.so"`; do \
226		soname=`basename $${so}` ; \
227		test -h rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} || \
228		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} ; \
229	done ; \
230	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-nodebug build && ./test/run.py ) ; \
231	}
232
233test-debug: unit modules
234	@{ \
235	for so in `find rpmbuild/BUILD/*/build-debug/ -type f -name "*.so"`; do \
236		soname=`basename $${so}` ; \
237		test -h rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} || \
238		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} ; \
239	done ; \
240	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-debug build && ./test/run.py ) ; \
241	}
242
243clean:
244	rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
245	rm -f rpmbuild/SOURCES/unit-*.tar.gz check-build-depends-*
246	find . -maxdepth 1 -type l -delete
247
248.PHONY: default all modules specs rpmlint test test-debug clean
249
250.SECONDARY: $(addprefix check-build-depends-, $(MODULES))
251