xref: /unit/pkg/rpm/Makefile (revision 953)
1372Sdefan@nginx.com#!/usr/bin/make
2372Sdefan@nginx.com
3*953Salexander.borisov@nginx.cominclude ../../version
4372Sdefan@nginx.com
5821Svbart@nginx.comDEFAULT_RELEASE := 1
6372Sdefan@nginx.com
7*953Salexander.borisov@nginx.comVERSION ?= $(NXT_VERSION)
8372Sdefan@nginx.comRELEASE ?= $(DEFAULT_RELEASE)
9372Sdefan@nginx.com
10490Sdefan@nginx.comifeq ($(shell rpm --eval "%{?rhel}"), 6)
11490Sdefan@nginx.comOSVER = centos6
12490Sdefan@nginx.comelse ifeq ($(shell rpm --eval "%{?rhel}"), 7)
13490Sdefan@nginx.comOSVER = centos7
14490Sdefan@nginx.comelse ifeq ($(shell rpm --eval "%{?amzn}"), 1)
15490Sdefan@nginx.comOSVER = amazonlinux1
16490Sdefan@nginx.comelse ifeq ($(shell rpm --eval "%{?amzn}"), 2)
17490Sdefan@nginx.comOSVER = amazonlinux2
18562Sdefan@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1315 -a 0%{?suse_version} -lt 1330 -a 0%{?is_opensuse} -eq 1'`; echo $$?), 0)
19562Sdefan@nginx.comOSVER = opensuse-leap
20562Sdefan@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1330 -a 0%{?is_opensuse} -eq 1'`; echo $$?), 0)
21562Sdefan@nginx.comOSVER = opensuse-tumbleweed
22562Sdefan@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1315 -a 0%{?is_opensuse} -eq 0'`; echo $$?), 0)
23562Sdefan@nginx.comOSVER = sles
24563Sdefan@nginx.comelse ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 26'`; echo $$?),0)
25563Sdefan@nginx.comOSVER = fedora
26490Sdefan@nginx.comendif
27490Sdefan@nginx.com
28562Sdefan@nginx.comBUILD_DEPENDS_unit = gcc rpm-build rpmlint
29562Sdefan@nginx.com
30562Sdefan@nginx.comifeq ($(OSVER), centos7)
31562Sdefan@nginx.comBUILD_DEPENDS_unit += which
32562Sdefan@nginx.comendif
33562Sdefan@nginx.com
34562Sdefan@nginx.comifeq ($(OSVER), amazonlinux1)
35562Sdefan@nginx.comBUILD_DEPENDS_unit += system-rpm-config
36562Sdefan@nginx.comendif
37562Sdefan@nginx.com
38562Sdefan@nginx.comifneq (,$(findstring $(OSVER),opensuse-leap opensuse-tumbleweed sles))
39778Sdefan@nginx.comBUILD_DEPENDS_unit += libxml2-tools libxslt1 libopenssl-devel
40562Sdefan@nginx.comelse
41778Sdefan@nginx.comBUILD_DEPENDS_unit += libxml2 libxslt openssl-devel
42562Sdefan@nginx.comendif
43562Sdefan@nginx.com
44562Sdefan@nginx.comBUILD_DEPENDS = $(BUILD_DEPENDS_unit)
45562Sdefan@nginx.com
46372Sdefan@nginx.comMODULES=
47490Sdefan@nginx.com
48937Sdefan@nginx.comifeq ($(OSVER), centos6)
49937Sdefan@nginx.cominclude Makefile.php
50937Sdefan@nginx.cominclude Makefile.python
51937Sdefan@nginx.cominclude Makefile.go
52937Sdefan@nginx.comendif
53937Sdefan@nginx.com
54937Sdefan@nginx.comifneq (,$(findstring $(OSVER),centos7 amazonlinux2))
55490Sdefan@nginx.cominclude Makefile.php
56490Sdefan@nginx.cominclude Makefile.python
57490Sdefan@nginx.cominclude Makefile.go
58524Sdefan@nginx.cominclude Makefile.perl
59490Sdefan@nginx.comendif
60490Sdefan@nginx.com
61490Sdefan@nginx.comifeq ($(OSVER), amazonlinux1)
62490Sdefan@nginx.cominclude Makefile.php
63490Sdefan@nginx.cominclude Makefile.python27
64490Sdefan@nginx.cominclude Makefile.python34
65490Sdefan@nginx.cominclude Makefile.python35
66490Sdefan@nginx.cominclude Makefile.python36
67490Sdefan@nginx.cominclude Makefile.go
68524Sdefan@nginx.cominclude Makefile.perl
69490Sdefan@nginx.comendif
70372Sdefan@nginx.com
71562Sdefan@nginx.comifeq ($(OSVER), opensuse-leap)
72562Sdefan@nginx.cominclude Makefile.python27
73562Sdefan@nginx.cominclude Makefile.python34
74562Sdefan@nginx.cominclude Makefile.go
75562Sdefan@nginx.cominclude Makefile.perl
76600Sdefan@nginx.cominclude Makefile.ruby
77562Sdefan@nginx.comendif
78562Sdefan@nginx.com
79562Sdefan@nginx.comifeq ($(OSVER), opensuse-tumbleweed)
80562Sdefan@nginx.cominclude Makefile.php
81562Sdefan@nginx.cominclude Makefile.python27
82562Sdefan@nginx.cominclude Makefile.python36
83562Sdefan@nginx.cominclude Makefile.go
84562Sdefan@nginx.cominclude Makefile.perl
85600Sdefan@nginx.cominclude Makefile.ruby
86562Sdefan@nginx.comendif
87562Sdefan@nginx.com
88562Sdefan@nginx.comifeq ($(OSVER), sles)
89562Sdefan@nginx.cominclude Makefile.python27
90562Sdefan@nginx.cominclude Makefile.python34
91562Sdefan@nginx.cominclude Makefile.perl
92562Sdefan@nginx.comendif
93562Sdefan@nginx.com
94563Sdefan@nginx.comifeq ($(OSVER), fedora)
95563Sdefan@nginx.cominclude Makefile.php
96563Sdefan@nginx.cominclude Makefile.python27
97910Sremi@remirepo.netifeq ($(shell test `rpm --eval '0%{?fedora} -ge 29'`; echo $$?),0)
98910Sremi@remirepo.netinclude Makefile.python37
99910Sremi@remirepo.netelse
100563Sdefan@nginx.cominclude Makefile.python36
101910Sremi@remirepo.netendif
102563Sdefan@nginx.cominclude Makefile.go
103563Sdefan@nginx.cominclude Makefile.perl
104600Sdefan@nginx.cominclude Makefile.ruby
105563Sdefan@nginx.comendif
106563Sdefan@nginx.com
107372Sdefan@nginx.comCONFIGURE_ARGS=\
108372Sdefan@nginx.com	--prefix=/usr \
109372Sdefan@nginx.com	--state=%{_sharedstatedir}/unit \
110911Sremi@remirepo.net	--control="unix:/var/run/unit/control.sock" \
111372Sdefan@nginx.com	--pid=/var/run/unit.pid \
112372Sdefan@nginx.com	--log=/var/log/unit.log \
113778Sdefan@nginx.com	--tests \
114778Sdefan@nginx.com	--openssl
115372Sdefan@nginx.com
116372Sdefan@nginx.comexport CR=\\n
117372Sdefan@nginx.com
118372Sdefan@nginx.comdefault:
119500Sdefan@nginx.com	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs test test-debug clean"
120372Sdefan@nginx.com
121559Sdefan@nginx.comall: check-build-depends-all unit modules
122372Sdefan@nginx.com
123372Sdefan@nginx.commodules: $(addprefix unit-, $(MODULES))
124372Sdefan@nginx.com
125560Sdefan@nginx.comspecs: rpmbuild/SPECS/unit.spec $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES)))
126372Sdefan@nginx.com
127559Sdefan@nginx.comcheck-build-depends-%:
128372Sdefan@nginx.com	@{ \
129559Sdefan@nginx.com	case "$*" in \
130559Sdefan@nginx.com		all) pkgs="$(BUILD_DEPENDS)" ;; \
131559Sdefan@nginx.com		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
132559Sdefan@nginx.com		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
133559Sdefan@nginx.com	esac ; \
134372Sdefan@nginx.com	not_installed= ; \
135559Sdefan@nginx.com	for pkg in $${pkgs}; do \
136372Sdefan@nginx.com		rpm -qi $${pkg} >/dev/null 2>&1 ; \
137372Sdefan@nginx.com		if [ $$? -ne 0 ]; then \
138372Sdefan@nginx.com			not_installed="$${not_installed} $${pkg}" ; \
139372Sdefan@nginx.com		fi ; \
140372Sdefan@nginx.com	done ; \
141372Sdefan@nginx.com	if test -n "$${not_installed}" ; then \
142372Sdefan@nginx.com		echo "" >&2 ; \
143372Sdefan@nginx.com		echo "The following packages are required in order to proceed:" >&2 ; \
144372Sdefan@nginx.com		echo "" >&2 ; \
145372Sdefan@nginx.com		echo $${not_installed} >&2 ; \
146372Sdefan@nginx.com		echo "" >&2 ; \
147372Sdefan@nginx.com		exit 1 ; \
148372Sdefan@nginx.com	fi \
149372Sdefan@nginx.com	}
150559Sdefan@nginx.com	touch $@
151489Sdefan@nginx.com
152372Sdefan@nginx.comrpmbuild/SPECS:
153372Sdefan@nginx.com	mkdir -p rpmbuild/SPECS
154372Sdefan@nginx.com
155372Sdefan@nginx.comrpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS
156372Sdefan@nginx.com	cat unit.spec.in | \
157372Sdefan@nginx.com		sed -e "s#%%VERSION%%#$(VERSION)#g" \
158372Sdefan@nginx.com		    -e "s#%%RELEASE%%#$(RELEASE)#g" \
159372Sdefan@nginx.com		    -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
160372Sdefan@nginx.com		> rpmbuild/SPECS/unit.spec
161372Sdefan@nginx.com	cd ../../docs && make ../build/unit.rpm-changelog
162372Sdefan@nginx.comifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
163372Sdefan@nginx.com	cat ../../build/unit.rpm-changelog | sed -e \
164372Sdefan@nginx.com		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
165372Sdefan@nginx.com		>> rpmbuild/SPECS/unit.spec
166372Sdefan@nginx.comelse
167372Sdefan@nginx.com	cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
168372Sdefan@nginx.comendif
169372Sdefan@nginx.com
170372Sdefan@nginx.comrpmbuild/SOURCES/unit-$(VERSION).tar.gz:
171372Sdefan@nginx.com	cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
172372Sdefan@nginx.com		--transform "s#^#unit-$(VERSION)/#" \
173372Sdefan@nginx.com		LICENSE NOTICE CHANGES README configure auto src test
174372Sdefan@nginx.com
175489Sdefan@nginx.comunit: check-build-depends-unit rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
176372Sdefan@nginx.com	@echo "===> Building $@ package" ; \
177372Sdefan@nginx.com	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \
178372Sdefan@nginx.com	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
179372Sdefan@nginx.com
180372Sdefan@nginx.comrpmlint:
181372Sdefan@nginx.com	find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
182372Sdefan@nginx.com
183372Sdefan@nginx.comrpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
184372Sdefan@nginx.com	@echo "===> Creating $@"
185372Sdefan@nginx.com	@{ \
186372Sdefan@nginx.com	set -e ; \
187372Sdefan@nginx.com	i=100 ; \
188372Sdefan@nginx.com	sources= ; \
189372Sdefan@nginx.com	for src in $(MODULE_SOURCES_$*); do \
190372Sdefan@nginx.com		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
191372Sdefan@nginx.com		sources="$${sources}\n$${s}" ; \
192372Sdefan@nginx.com		i=$$(($${i}+1)) ; \
193372Sdefan@nginx.com	done ; \
194372Sdefan@nginx.com	pkgname=$(shell echo $@ | cut -d '/' -f 3 | cut -d '.' -f 1) ; \
195372Sdefan@nginx.com	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
196372Sdefan@nginx.com	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
197372Sdefan@nginx.com	files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
198372Sdefan@nginx.com	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
199372Sdefan@nginx.com	cat unit.module.spec.in | sed \
200372Sdefan@nginx.com		-e "s#%%NAME%%#$${pkgname}#g" \
201372Sdefan@nginx.com		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
202372Sdefan@nginx.com		-e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
203372Sdefan@nginx.com		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
204372Sdefan@nginx.com		-e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
205372Sdefan@nginx.com		-e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
206372Sdefan@nginx.com		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
207372Sdefan@nginx.com		-e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
208372Sdefan@nginx.com		-e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
209372Sdefan@nginx.com		-e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
210372Sdefan@nginx.com		-e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
211372Sdefan@nginx.com		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
212372Sdefan@nginx.com		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
213372Sdefan@nginx.com		-e "s#%%MODULE_FILES%%#$${files}#g" \
214372Sdefan@nginx.com		-e "s#%%MODULE_POST%%#$${post}#g" \
215372Sdefan@nginx.com		> $@.tmp ; \
216372Sdefan@nginx.com	}
217561Sdefan@nginx.com	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog
218561Sdefan@nginx.com	cat ../../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog | sed -e \
219372Sdefan@nginx.com		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
220372Sdefan@nginx.com		>> $@.tmp
221372Sdefan@nginx.com	mv $@.tmp $@
222372Sdefan@nginx.com
223489Sdefan@nginx.comunit-%: check-build-depends-% rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
224372Sdefan@nginx.com	@echo "===> Building $@ package" ; \
225372Sdefan@nginx.com	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \
226372Sdefan@nginx.com	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
227372Sdefan@nginx.com
228500Sdefan@nginx.comtest: unit modules
229500Sdefan@nginx.com	@{ \
230500Sdefan@nginx.com	for so in `find rpmbuild/BUILD/*/build-nodebug/ -type f -name "*.so"`; do \
231500Sdefan@nginx.com		soname=`basename $${so}` ; \
232500Sdefan@nginx.com		test -h rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} || \
233500Sdefan@nginx.com		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} ; \
234500Sdefan@nginx.com	done ; \
235500Sdefan@nginx.com	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-nodebug build && ./test/run.py ) ; \
236500Sdefan@nginx.com	}
237500Sdefan@nginx.com
238500Sdefan@nginx.comtest-debug: unit modules
239500Sdefan@nginx.com	@{ \
240500Sdefan@nginx.com	for so in `find rpmbuild/BUILD/*/build-debug/ -type f -name "*.so"`; do \
241500Sdefan@nginx.com		soname=`basename $${so}` ; \
242500Sdefan@nginx.com		test -h rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} || \
243500Sdefan@nginx.com		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} ; \
244500Sdefan@nginx.com	done ; \
245500Sdefan@nginx.com	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-debug build && ./test/run.py ) ; \
246500Sdefan@nginx.com	}
247500Sdefan@nginx.com
248372Sdefan@nginx.comclean:
249372Sdefan@nginx.com	rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
250559Sdefan@nginx.com	rm -f rpmbuild/SOURCES/unit-*.tar.gz check-build-depends-*
251372Sdefan@nginx.com	find . -maxdepth 1 -type l -delete
252372Sdefan@nginx.com
253559Sdefan@nginx.com.PHONY: default all modules specs rpmlint test test-debug clean
254372Sdefan@nginx.com
255559Sdefan@nginx.com.SECONDARY: $(addprefix check-build-depends-, $(MODULES))
256