xref: /unit/pkg/deb/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
11SRCDIR=	unit-$(VERSION)
12
13CODENAME = $(shell lsb_release -cs)
14
15BUILD_DEPENDS_unit = debhelper devscripts libxml2-utils lintian lsb-release xsltproc
16BUILD_DEPENDS = $(BUILD_DEPENDS_unit)
17
18MODULES=
19
20# Ubuntu 17.10
21ifeq ($(CODENAME),artful)
22include Makefile.php
23include Makefile.python27
24include Makefile.python36
25include Makefile.go18
26include Makefile.go19
27include Makefile.perl
28endif
29
30# Ubuntu 17.04
31ifeq ($(CODENAME),zesty)
32include Makefile.php
33include Makefile.python27
34include Makefile.python35
35include Makefile.go17
36include Makefile.go18
37include Makefile.perl
38endif
39
40# Ubuntu 16.04
41ifeq ($(CODENAME),xenial)
42include Makefile.php
43include Makefile.python27
44include Makefile.python35
45include Makefile.go
46include Makefile.perl
47endif
48
49# Ubuntu 14.04
50ifeq ($(CODENAME),trusty)
51include Makefile.php
52include Makefile.python
53include Makefile.perl
54endif
55
56# Debian 9
57ifeq ($(CODENAME),stretch)
58include Makefile.php
59include Makefile.python27
60include Makefile.python35
61include Makefile.go17
62include Makefile.go18
63include Makefile.perl
64endif
65
66# Debian 8
67ifeq ($(CODENAME),jessie)
68include Makefile.php
69include Makefile.python27
70include Makefile.python34
71include Makefile.perl
72endif
73
74CONFIGURE_ARGS=\
75	--prefix=/usr \
76	--state=/var/lib/unit \
77	--control="unix:/var/run/control.unit.sock" \
78	--pid=/var/run/unit.pid \
79	--log=/var/log/unit.log \
80	--tests
81
82export CR=\\n
83
84default:
85	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) test test-debug clean"
86
87all: check-build-depends unit modules
88
89modules: $(addprefix unit-, $(MODULES))
90
91check-build-depends:
92	@{ \
93	not_installed= ; \
94	for pkg in $(BUILD_DEPENDS); do \
95		dpkg -s $${pkg} >/dev/null 2>&1 ; \
96		if [ $$? -ne 0 ]; then \
97			not_installed="$${not_installed} $${pkg}" ; \
98		fi ; \
99	done ; \
100	if test -n "$${not_installed}" ; then \
101		echo "" >&2 ; \
102		echo "The following packages are required in order to proceed:" >&2 ; \
103		echo "" >&2 ; \
104		echo $${not_installed} >&2 ; \
105		echo "" >&2 ; \
106		exit 1 ; \
107	fi \
108	}
109
110check-build-depends-%:
111	@{ \
112	not_installed= ; \
113	for pkg in $(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*); do \
114		dpkg -s $${pkg} >/dev/null 2>&1 ; \
115		if [ $$? -ne 0 ]; then \
116			not_installed="$${not_installed} $${pkg}" ; \
117		fi ; \
118	done ; \
119	if test -n "$${not_installed}" ; then \
120		echo "" >&2 ; \
121		echo "The following packages are required in order to proceed:" >&2 ; \
122		echo "" >&2 ; \
123		echo $${not_installed} >&2 ; \
124		echo "" >&2 ; \
125		exit 1 ; \
126	fi \
127	}
128
129debuild/$(SRCDIR)/debian:
130	@{ \
131	set -e ; \
132	mkdir -p debuild/$(SRCDIR) ; \
133	cp -pr debian debuild/$(SRCDIR) ; \
134	echo '9' > debuild/$(SRCDIR)/debian/compat ; \
135	mkdir -p debuild/$(SRCDIR)/debian/source ; \
136	echo '3.0 (quilt)' > debuild/$(SRCDIR)/debian/source/format ; \
137        cat debian/rules.in | sed \
138                -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
139        > debuild/$(SRCDIR)/debian/rules ; \
140	}
141
142debuild/$(SRCDIR)/debian/changelog: ../../docs/changes.xml | debuild/$(SRCDIR)/debian
143	cd ../../docs && make ../build/unit.deb-changelog
144ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
145	cat ../../build/unit.deb-changelog | sed \
146		-e "s/unit ($(DEFAULT_VERSION)-$(DEFAULT_RELEASE)~/unit ($(VERSION)-$(RELEASE)~/" \
147		-e "s#%%CODENAME%%#$(CODENAME)#g" \
148		> debuild/$(SRCDIR)/debian/changelog
149else
150	cat ../../build/unit.deb-changelog | sed \
151		-e "s#%%CODENAME%%#$(CODENAME)#g" \
152		> debuild/$(SRCDIR)/debian/changelog
153endif
154
155debuild/unit_$(VERSION).orig.tar.gz: | debuild/$(SRCDIR)/debian
156	cd ../.. && tar -czf pkg/deb/debuild/$(SRCDIR).tar.gz \
157		--transform "s#^#$(SRCDIR)/#" \
158		LICENSE NOTICE CHANGES README configure auto src test
159	mv debuild/$(SRCDIR).tar.gz debuild/unit_$(VERSION).orig.tar.gz
160	cd debuild && tar zxf unit_$(VERSION).orig.tar.gz
161
162unit: check-build-depends-unit debuild/unit_$(VERSION).orig.tar.gz debuild/$(SRCDIR)/debian/changelog
163	@echo "===> Building $@ package"
164	cd debuild/$(SRCDIR) && debuild -us -uc
165	mkdir -p debs
166	find debuild/ -maxdepth 1 -type f -exec cp {} debs/ \;
167	ln -s debuild/$(SRCDIR)/build $@
168
169debuild-%: debuild/unit_$(VERSION).orig.tar.gz ../../docs/changes.xml
170	mkdir $@
171	cp debuild/unit_$(VERSION).orig.tar.gz debuild-$*/unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz
172	cd $@ && tar zxf unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz
173	mkdir $@/$(SRCDIR)/debian
174	echo '9' > $@/$(SRCDIR)/debian/compat
175	mkdir $@/$(SRCDIR)/debian/source
176	echo '3.0 (quilt)' > $@/$(SRCDIR)/debian/source/format
177	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).deb-changelog
178	cat ../../build/unit-$(MODULE_SUFFIX_$*).deb-changelog | sed \
179		-e "s#%%CODENAME%%#$(CODENAME)#g" \
180		> $@/$(SRCDIR)/debian/changelog
181	cp debian/copyright debuild-$*/$(SRCDIR)/debian/
182	@{ \
183	set -e ; \
184	for src in $(MODULE_SOURCES_$*); do \
185		cp debian.module/$${src} $@/$(SRCDIR)/debian/ ; \
186	done ; \
187	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
188	prebuild=`echo "$$MODULE_PREBUILD_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
189	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
190	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
191	cat debian.module/$(if $(MODULE_NOARCH_$*),control-noarch.in,control.in) | sed \
192                -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \
193                -e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
194                -e "s#%%CODENAME%%#$(CODENAME)#g" \
195                -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
196                -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
197                -e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
198                -e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
199                -e "s#%%MODULE_BUILD_DEPENDS%%#$(MODULE_BUILD_DEPENDS_$*)#g" \
200                -e "s#%%MODULE_DEPENDS%%#$(MODULE_DEPENDS_$*)#g" \
201        > $@/$(SRCDIR)/debian/control ; \
202        cat debian.module/$(if $(MODULE_NOARCH_$*),rules-noarch.in,rules.in) | sed \
203                -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \
204                -e "s#%%CODENAME%%#$(CODENAME)#g" \
205                -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
206                -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
207                -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
208                -e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
209                -e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
210                -e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
211                -e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
212                -e "s#%%MODULE_PREBUILD%%#$${prebuild}#g" \
213                -e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
214        > $@/$(SRCDIR)/debian/rules ; \
215        cat debian.module/preinst.in | sed \
216                -e "s#%%MODULE_POST%%#$$post#g" \
217        > $@/$(SRCDIR)/debian/preinst ; \
218        chmod +x $@/$(SRCDIR)/debian/rules ; \
219	}
220
221unit-%: check-build-depends-% | debuild-%
222	@echo "===> Building $@ package"
223	cd debuild-$*/$(SRCDIR) && debuild -us -uc
224	mkdir -p debs
225	find debuild-$*/ -maxdepth 1 -type f -exec cp {} debs/ \;
226	ln -s debuild-$*/$(SRCDIR)/build $@
227
228test: unit modules
229	@{ \
230	for so in `find debuild-*/unit-$(VERSION)/debian/build-unit/ -type f -name "*.so"` ; do \
231		soname=`basename $${so}` ; \
232		test -h debuild/unit-$(VERSION)/debian/build-unit/build/$${soname} || \
233		ln -fs `pwd`/$${so} debuild/unit-$(VERSION)/debian/build-unit/build/$${soname} ; \
234	done ; \
235	( cd debuild/unit-$(VERSION)/debian/build-unit && ./test/run.py ) ; \
236	}
237
238test-debug: unit modules
239	@{ \
240	for so in `find debuild-*/unit-$(VERSION)/debian/build-unit-debug/ -type f -name "*.so"` ; do \
241		soname=`basename $${so}` ; \
242		test -h debuild/unit-$(VERSION)/debian/build-unit-debug/build/$${soname} || \
243		ln -fs `pwd`/$${so} debuild/unit-$(VERSION)/debian/build-unit-debug/build/$${soname} ; \
244	done ; \
245	( cd debuild/unit-$(VERSION)/debian/build-unit-debug && ./test/run.py ) ; \
246	}
247
248clean:
249	rm -rf debuild debuild-* debs ../../build
250	find . -maxdepth 1 -type l -delete
251
252.PHONY: default all modules check-build-depends test test-debug clean
253
254.SECONDARY:
255