xref: /unit/pkg/rpm/Makefile (revision 524:7eef37b824b3)
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
11BUILD_DEPENDS_unit = libxml2 libxslt rpm-build rpmlint
12BUILD_DEPENDS = $(BUILD_DEPENDS_unit)
13
14ifeq ($(shell rpm --eval "%{?rhel}"), 6)
15OSVER = centos6
16else ifeq ($(shell rpm --eval "%{?rhel}"), 7)
17OSVER = centos7
18else ifeq ($(shell rpm --eval "%{?amzn}"), 1)
19OSVER = amazonlinux1
20BUILD_DEPENDS += system-rpm-config
21else ifeq ($(shell rpm --eval "%{?amzn}"), 2)
22OSVER = amazonlinux2
23endif
24
25MODULES=
26
27ifneq (,$(findstring $(OSVER),centos6 centos7 amazonlinux2))
28include Makefile.php
29include Makefile.python
30include Makefile.go
31include Makefile.perl
32endif
33
34ifeq ($(OSVER), amazonlinux1)
35include Makefile.php
36include Makefile.python27
37include Makefile.python34
38include Makefile.python35
39include Makefile.python36
40include Makefile.go
41include Makefile.perl
42endif
43
44CONFIGURE_ARGS=\
45	--prefix=/usr \
46	--state=%{_sharedstatedir}/unit \
47	--control="unix:/var/run/control.unit.sock" \
48	--pid=/var/run/unit.pid \
49	--log=/var/log/unit.log \
50	--tests
51
52export CR=\\n
53
54default:
55	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs test test-debug clean"
56
57all: check-build-depends unit modules
58
59modules: $(addprefix unit-, $(MODULES))
60
61specs: $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES)))
62
63check-build-depends:
64	@{ \
65	not_installed= ; \
66	for pkg in $(BUILD_DEPENDS); do \
67		rpm -qi $${pkg} >/dev/null 2>&1 ; \
68		if [ $$? -ne 0 ]; then \
69			not_installed="$${not_installed} $${pkg}" ; \
70		fi ; \
71	done ; \
72	if test -n "$${not_installed}" ; then \
73		echo "" >&2 ; \
74		echo "The following packages are required in order to proceed:" >&2 ; \
75		echo "" >&2 ; \
76		echo $${not_installed} >&2 ; \
77		echo "" >&2 ; \
78		exit 1 ; \
79	fi \
80	}
81
82check-build-depends-%:
83	@{ \
84	not_installed= ; \
85	for pkg in $(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*); do \
86		rpm -qi $${pkg} >/dev/null 2>&1 ; \
87		if [ $$? -ne 0 ]; then \
88			not_installed="$${not_installed} $${pkg}" ; \
89		fi ; \
90	done ; \
91	if test -n "$${not_installed}" ; then \
92		echo "" >&2 ; \
93		echo "The following packages are required in order to proceed:" >&2 ; \
94		echo "" >&2 ; \
95		echo $${not_installed} >&2 ; \
96		echo "" >&2 ; \
97		exit 1 ; \
98	fi \
99	}
100
101rpmbuild/SPECS:
102	mkdir -p rpmbuild/SPECS
103
104rpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS
105	cat unit.spec.in | \
106		sed -e "s#%%VERSION%%#$(VERSION)#g" \
107		    -e "s#%%RELEASE%%#$(RELEASE)#g" \
108		    -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
109		> rpmbuild/SPECS/unit.spec
110	cd ../../docs && make ../build/unit.rpm-changelog
111ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
112	cat ../../build/unit.rpm-changelog | sed -e \
113		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
114		>> rpmbuild/SPECS/unit.spec
115else
116	cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
117endif
118
119rpmbuild/SOURCES/unit-$(VERSION).tar.gz:
120	cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
121		--transform "s#^#unit-$(VERSION)/#" \
122		LICENSE NOTICE CHANGES README configure auto src test
123
124unit: check-build-depends-unit rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
125	@echo "===> Building $@ package" ; \
126	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \
127	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
128
129rpmlint:
130	find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
131
132rpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
133	@echo "===> Creating $@"
134	@{ \
135	set -e ; \
136	i=100 ; \
137	sources= ; \
138	for src in $(MODULE_SOURCES_$*); do \
139		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
140		sources="$${sources}\n$${s}" ; \
141		i=$$(($${i}+1)) ; \
142	done ; \
143	pkgname=$(shell echo $@ | cut -d '/' -f 3 | cut -d '.' -f 1) ; \
144	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
145	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
146	files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
147	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
148	cat unit.module.spec.in | sed \
149		-e "s#%%NAME%%#$${pkgname}#g" \
150		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
151		-e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
152		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
153		-e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
154		-e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
155		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
156		-e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
157		-e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
158		-e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
159		-e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
160		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
161		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
162		-e "s#%%MODULE_FILES%%#$${files}#g" \
163		-e "s#%%MODULE_POST%%#$${post}#g" \
164		> $@.tmp ; \
165	}
166	cd ../../docs && make ../build/unit-$*.rpm-changelog
167	cat ../../build/unit-$*.rpm-changelog | sed -e \
168		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
169		>> $@.tmp
170	mv $@.tmp $@
171
172unit-%: check-build-depends-% rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
173	@echo "===> Building $@ package" ; \
174	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \
175	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
176
177test: unit modules
178	@{ \
179	for so in `find rpmbuild/BUILD/*/build-nodebug/ -type f -name "*.so"`; do \
180		soname=`basename $${so}` ; \
181		test -h rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} || \
182		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} ; \
183	done ; \
184	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-nodebug build && ./test/run.py ) ; \
185	}
186
187test-debug: unit modules
188	@{ \
189	for so in `find rpmbuild/BUILD/*/build-debug/ -type f -name "*.so"`; do \
190		soname=`basename $${so}` ; \
191		test -h rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} || \
192		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} ; \
193	done ; \
194	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-debug build && ./test/run.py ) ; \
195	}
196
197clean:
198	rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
199	rm -f rpmbuild/SOURCES/unit-*.tar.gz unit
200	find . -maxdepth 1 -type l -delete
201
202.PHONY: default all modules specs check-build-depends rpmlint test test-debug clean
203
204.SECONDARY:
205