xref: /unit/pkg/rpm/Makefile (revision 372:616449084bee)
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 = libxml2 libxslt rpm-build rpmlint
12
13MODULES=
14-include Makefile.*
15
16CONFIGURE_ARGS=\
17	--prefix=/usr \
18	--state=%{_sharedstatedir}/unit \
19	--control="unix:/var/run/control.unit.sock" \
20	--pid=/var/run/unit.pid \
21	--log=/var/log/unit.log \
22	--tests
23
24export CR=\\n
25
26default:
27	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs clean"
28
29all: check-build-depends unit modules
30
31modules: $(addprefix unit-, $(MODULES))
32
33specs: $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES)))
34
35check-build-depends:
36	@{ \
37	not_installed= ; \
38	for pkg in $(BUILD_DEPENDS); do \
39		rpm -qi $${pkg} >/dev/null 2>&1 ; \
40		if [ $$? -ne 0 ]; then \
41			not_installed="$${not_installed} $${pkg}" ; \
42		fi ; \
43	done ; \
44	if test -n "$${not_installed}" ; then \
45		echo "" >&2 ; \
46		echo "The following packages are required in order to proceed:" >&2 ; \
47		echo "" >&2 ; \
48		echo $${not_installed} >&2 ; \
49		echo "" >&2 ; \
50		exit 1 ; \
51	fi \
52	}
53
54rpmbuild/SPECS:
55	mkdir -p rpmbuild/SPECS
56
57rpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS
58	cat unit.spec.in | \
59		sed -e "s#%%VERSION%%#$(VERSION)#g" \
60		    -e "s#%%RELEASE%%#$(RELEASE)#g" \
61		    -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
62		> rpmbuild/SPECS/unit.spec
63	cd ../../docs && make ../build/unit.rpm-changelog
64ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
65	cat ../../build/unit.rpm-changelog | sed -e \
66		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \
67		>> rpmbuild/SPECS/unit.spec
68else
69	cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec
70endif
71
72rpmbuild/SOURCES/unit-$(VERSION).tar.gz:
73	cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \
74		--transform "s#^#unit-$(VERSION)/#" \
75		LICENSE NOTICE CHANGES README configure auto src test
76
77unit: rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
78	@echo "===> Building $@ package" ; \
79	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \
80	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
81
82rpmlint:
83	find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \;
84
85rpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS
86	@echo "===> Creating $@"
87	@{ \
88	set -e ; \
89	i=100 ; \
90	sources= ; \
91	for src in $(MODULE_SOURCES_$*); do \
92		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
93		sources="$${sources}\n$${s}" ; \
94		i=$$(($${i}+1)) ; \
95	done ; \
96	pkgname=$(shell echo $@ | cut -d '/' -f 3 | cut -d '.' -f 1) ; \
97	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
98	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
99	files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
100	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
101	cat unit.module.spec.in | sed \
102		-e "s#%%NAME%%#$${pkgname}#g" \
103		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
104		-e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
105		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
106		-e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
107		-e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
108		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
109		-e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
110		-e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
111		-e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
112		-e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
113		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
114		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
115		-e "s#%%MODULE_FILES%%#$${files}#g" \
116		-e "s#%%MODULE_POST%%#$${post}#g" \
117		> $@.tmp ; \
118	}
119	cd ../../docs && make ../build/unit-$*.rpm-changelog
120	cat ../../build/unit-$*.rpm-changelog | sed -e \
121		"s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \
122		>> $@.tmp
123	mv $@.tmp $@
124
125unit-%: rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz
126	@echo "===> Building $@ package" ; \
127	rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \
128	ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@
129
130clean:
131	rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build
132	rm -f rpmbuild/SOURCES/unit-*.tar.gz unit
133	find . -maxdepth 1 -type l -delete
134
135.PHONY: default all modules specs check-build-depends rpmlint clean
136
137.SECONDARY:
138