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