xref: /unit/pkg/rpm/Makefile (revision 980:e1c4434c1060)
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 "%{?amzn}"), 1)
15OSVER = amazonlinux1
16else ifeq ($(shell rpm --eval "%{?amzn}"), 2)
17OSVER = amazonlinux2
18else ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1315 -a 0%{?suse_version} -lt 1330 -a 0%{?is_opensuse} -eq 1'`; echo $$?), 0)
19OSVER = opensuse-leap
20else ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1330 -a 0%{?is_opensuse} -eq 1'`; echo $$?), 0)
21OSVER = opensuse-tumbleweed
22else ifeq ($(shell test `rpm --eval '0%{?suse_version} -ge 1315 -a 0%{?is_opensuse} -eq 0'`; echo $$?), 0)
23OSVER = sles
24else ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 26'`; echo $$?),0)
25OSVER = fedora
26endif
27
28BUILD_DEPENDS_unit = gcc rpm-build rpmlint
29
30ifeq ($(OSVER), centos7)
31BUILD_DEPENDS_unit += which
32endif
33
34ifeq ($(OSVER), amazonlinux1)
35BUILD_DEPENDS_unit += system-rpm-config
36endif
37
38ifneq (,$(findstring $(OSVER),opensuse-leap opensuse-tumbleweed sles))
39BUILD_DEPENDS_unit += libxml2-tools libxslt1 libopenssl-devel
40else
41BUILD_DEPENDS_unit += libxml2 libxslt openssl-devel
42endif
43
44BUILD_DEPENDS = $(BUILD_DEPENDS_unit)
45
46MODULES=
47
48ifeq ($(OSVER), centos6)
49include Makefile.php
50include Makefile.python
51include Makefile.go
52include Makefile.jsc-common
53include Makefile.jsc8
54endif
55
56ifeq ($(OSVER), centos7)
57include Makefile.php
58include Makefile.python
59include Makefile.go
60include Makefile.perl
61include Makefile.jsc-common
62include Makefile.jsc8
63include Makefile.jsc11
64endif
65
66ifeq ($(OSVER), amazonlinux1)
67include Makefile.php
68include Makefile.python27
69include Makefile.python34
70include Makefile.python35
71include Makefile.python36
72include Makefile.go
73include Makefile.perl
74include Makefile.jsc-common
75include Makefile.jsc8
76endif
77
78ifeq ($(OSVER), amazonlinux2)
79include Makefile.php
80include Makefile.python
81include Makefile.go
82include Makefile.perl
83include Makefile.jsc-common
84include Makefile.jsc8
85endif
86
87ifeq ($(OSVER), opensuse-leap)
88include Makefile.python27
89include Makefile.python34
90include Makefile.go
91include Makefile.perl
92include Makefile.ruby
93endif
94
95ifeq ($(OSVER), opensuse-tumbleweed)
96include Makefile.php
97include Makefile.python27
98include Makefile.python36
99include Makefile.go
100include Makefile.perl
101include Makefile.ruby
102endif
103
104ifeq ($(OSVER), sles)
105include Makefile.python27
106include Makefile.python34
107include Makefile.perl
108endif
109
110ifeq ($(OSVER), fedora)
111include Makefile.php
112include Makefile.python27
113ifeq ($(shell test `rpm --eval '0%{?fedora} -ge 29'`; echo $$?),0)
114include Makefile.python37
115else
116include Makefile.python36
117endif
118include Makefile.go
119include Makefile.perl
120include Makefile.ruby
121include Makefile.jsc-common
122include Makefile.jsc8
123include Makefile.jsc11
124endif
125
126CONFIGURE_ARGS=\
127	--prefix=/usr \
128	--state=%{_sharedstatedir}/unit \
129	--control="unix:/var/run/unit/control.sock" \
130	--pid=/var/run/unit.pid \
131	--log=/var/log/unit.log \
132	--tests \
133	--openssl
134
135export CR=\\n
136
137default:
138	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs test test-debug clean"
139
140all: check-build-depends-all unit modules
141
142modules: $(addprefix unit-, $(MODULES))
143
144specs: rpmbuild/SPECS/unit.spec $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES)))
145
146check-build-depends-%:
147	@{ \
148	case "$*" in \
149		all) pkgs="$(BUILD_DEPENDS)" ;; \
150		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
151		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
152	esac ; \
153	not_installed= ; \
154	for pkg in $${pkgs}; do \
155		rpm -qi $${pkg} >/dev/null 2>&1 ; \
156		if [ $$? -ne 0 ]; then \
157			not_installed="$${not_installed} $${pkg}" ; \
158		fi ; \
159	done ; \
160	if test -n "$${not_installed}" ; then \
161		echo "" >&2 ; \
162		echo "The following packages are required in order to proceed:" >&2 ; \
163		echo "" >&2 ; \
164		echo $${not_installed} >&2 ; \
165		echo "" >&2 ; \
166		exit 1 ; \
167	fi \
168	}
169	touch $@
170
171rpmbuild/SPECS:
172	mkdir -p rpmbuild/SPECS
173
174rpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS
175	cat unit.spec.in | \
176		sed -e "s#%%VERSION%%#$(VERSION)#g" \
177		    -e "s#%%RELEASE%%#$(RELEASE)#g" \
178		    -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
179		> rpmbuild/SPECS/unit.spec
180	cd ../../docs && make ../build/unit.rpm-changelog
181ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
182	cat ../../build/unit.rpm-changelog | sed -e \
183		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
184		>> rpmbuild/SPECS/unit.spec
185else
186	cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
187endif
188
189rpmbuild/SOURCES/unit-$(VERSION).tar.gz:
190	cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
191		--transform "s#^#unit-$(VERSION)/#" \
192		LICENSE NOTICE CHANGES README configure auto src test version
193
194unit: check-build-depends-unit rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
195	@echo "===> Building $@ package" ; \
196	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \
197	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
198
199rpmlint:
200	find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
201
202rpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
203	@echo "===> Creating $@"
204	@{ \
205	set -e ; \
206	i=100 ; \
207	sources= ; \
208	for src in $(MODULE_SOURCES_$*); do \
209		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
210		sources="$${sources}\n$${s}" ; \
211		i=$$(($${i}+1)) ; \
212	done ; \
213	pkgname=$(shell echo $@ | cut -d '/' -f 3 | tr '_' '-' | cut -d '.' -f 1) ; \
214	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
215	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
216	postinstall=`echo "$$MODULE_POSTINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
217	files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
218	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
219	cat unit.module.spec.in | sed \
220		-e "s#%%NAME%%#$${pkgname}#g" \
221		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
222		-e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
223		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
224		-e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
225		-e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
226		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
227		-e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
228		-e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
229		-e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
230		-e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
231		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
232		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
233		-e "s#%%MODULE_POSTINSTALL%%#$${postinstall}#g" \
234		-e "s#%%MODULE_FILES%%#$${files}#g" \
235		-e "s#%%MODULE_POST%%#$${post}#g" \
236		> $@.tmp ; \
237	}
238	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog
239	cat ../../build/unit-$(MODULE_SUFFIX_$*).rpm-changelog | sed -e \
240		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
241		>> $@.tmp
242	mv $@.tmp $@
243
244unit-%: check-build-depends-% rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
245	@echo "===> Building $(subst _,-,$@) package" ; \
246	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \
247	ln -s rpmbuild/BUILD/$(subst _,-,$@)-$(VERSION)/build $@
248
249test: unit modules
250	@{ \
251	for so in `find rpmbuild/BUILD/*/build-nodebug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
252		soname=`basename $${so}` ; \
253		test "$${soname}" = "java.unit.so" && continue ; \
254		test -h rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} || \
255		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-nodebug/$${soname} ; \
256	done ; \
257	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-nodebug build && ./test/run.py ) ; \
258	}
259
260test-debug: unit modules
261	@{ \
262	for so in `find rpmbuild/BUILD/*/build-debug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
263		soname=`basename $${so}` ; \
264		test "$${soname}" = "java.unit.so" && continue ; \
265		test -h rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} || \
266		ln -fs `pwd`/$${so} rpmbuild/BUILD/unit-$(VERSION)/build-debug/$${soname} ; \
267	done ; \
268	( cd rpmbuild/BUILD/unit-$(VERSION) && rm -f build && ln -s build-debug build && ./test/run.py ) ; \
269	}
270
271clean:
272	rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
273	rm -f rpmbuild/SOURCES/unit-*.tar.gz check-build-depends-*
274	find . -maxdepth 1 -type l -delete
275
276.PHONY: default all modules specs rpmlint test test-debug clean
277
278.SECONDARY: $(addprefix check-build-depends-, $(MODULES))
279