xref: /unit/pkg/deb/Makefile (revision 1826:d0d76464f1a5)
1#!/usr/bin/make
2
3include ../../version
4
5DEFAULT_VERSION := $(NXT_VERSION)
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 libssl-dev
16BUILD_DEPENDS = $(BUILD_DEPENDS_unit)
17
18MODULES=
19
20# Ubuntu 20.10
21ifeq ($(CODENAME),groovy)
22include Makefile.php
23include Makefile.python27
24include Makefile.python38
25include Makefile.go
26include Makefile.perl
27include Makefile.ruby
28include Makefile.jsc-common
29include Makefile.jsc11
30include Makefile.jsc13
31include Makefile.jsc14
32include Makefile.jsc15
33endif
34
35# Ubuntu 20.04
36ifeq ($(CODENAME),focal)
37include Makefile.php
38include Makefile.python27
39include Makefile.python38
40include Makefile.go
41include Makefile.perl
42include Makefile.ruby
43include Makefile.jsc-common
44include Makefile.jsc11
45endif
46
47# Ubuntu 19.10
48ifeq ($(CODENAME),eoan)
49include Makefile.php
50include Makefile.python27
51include Makefile.python37
52include Makefile.python38
53include Makefile.go
54include Makefile.perl
55include Makefile.ruby
56include Makefile.jsc-common
57include Makefile.jsc11
58endif
59
60# Ubuntu 19.04
61ifeq ($(CODENAME),disco)
62include Makefile.php
63include Makefile.python27
64include Makefile.python37
65include Makefile.python38
66include Makefile.go
67include Makefile.perl
68include Makefile.ruby
69include Makefile.jsc-common
70include Makefile.jsc11
71endif
72
73# Ubuntu 18.10
74ifeq ($(CODENAME),cosmic)
75include Makefile.php
76include Makefile.python27
77include Makefile.python36
78include Makefile.python37
79include Makefile.go
80include Makefile.perl
81include Makefile.ruby
82include Makefile.jsc-common
83include Makefile.jsc8
84include Makefile.jsc11
85endif
86
87# Ubuntu 18.04
88ifeq ($(CODENAME),bionic)
89include Makefile.php
90include Makefile.python27
91include Makefile.python36
92include Makefile.python37
93include Makefile.python38
94include Makefile.go
95include Makefile.perl
96include Makefile.ruby
97include Makefile.jsc-common
98include Makefile.jsc8
99include Makefile.jsc11
100endif
101
102# Ubuntu 16.04
103ifeq ($(CODENAME),xenial)
104include Makefile.php
105include Makefile.python27
106include Makefile.python35
107include Makefile.go
108include Makefile.perl
109include Makefile.ruby
110include Makefile.jsc-common
111include Makefile.jsc8
112endif
113
114# Ubuntu 14.04
115ifeq ($(CODENAME),trusty)
116include Makefile.php
117include Makefile.python
118include Makefile.perl
119endif
120
121# Debian 10
122ifeq ($(CODENAME),buster)
123include Makefile.php
124include Makefile.python27
125include Makefile.python37
126include Makefile.go
127include Makefile.perl
128include Makefile.ruby
129include Makefile.jsc-common
130include Makefile.jsc11
131endif
132
133# Debian 9
134ifeq ($(CODENAME),stretch)
135include Makefile.php
136include Makefile.python27
137include Makefile.python35
138include Makefile.go
139include Makefile.perl
140include Makefile.ruby
141include Makefile.jsc-common
142include Makefile.jsc8
143endif
144
145# Debian 8
146ifeq ($(CODENAME),jessie)
147include Makefile.php
148include Makefile.python27
149include Makefile.python34
150include Makefile.perl
151include Makefile.ruby
152endif
153
154CONFIGURE_ARGS=\
155	--prefix=/usr \
156	--state=/var/lib/unit \
157	--control="unix:/var/run/control.unit.sock" \
158	--pid=/var/run/unit.pid \
159	--log=/var/log/unit.log \
160	--tmp=/var/tmp \
161	--user=unit \
162	--group=unit \
163	--tests \
164	--openssl
165
166export CR=\\n
167
168default:
169	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) test test-debug clean"
170
171all: check-build-depends-all unit modules
172
173modules: $(addprefix unit-, $(MODULES))
174
175check-build-depends-%:
176	@{ \
177	case "$*" in \
178		all) pkgs="$(BUILD_DEPENDS)" ;; \
179		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
180		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
181	esac ; \
182	not_installed= ; \
183	for pkg in $${pkgs}; do \
184		dpkg -s $${pkg} >/dev/null 2>&1 ; \
185		if [ $$? -ne 0 ]; then \
186			not_installed="$${not_installed} $${pkg}" ; \
187		fi ; \
188	done ; \
189	if test -n "$${not_installed}" ; then \
190		echo "" >&2 ; \
191		echo "The following packages are required in order to proceed:" >&2 ; \
192		echo "" >&2 ; \
193		echo $${not_installed} >&2 ; \
194		echo "" >&2 ; \
195		exit 1 ; \
196	fi \
197	}
198	touch $@
199
200debuild/$(SRCDIR)/debian:
201	@{ \
202	set -e ; \
203	mkdir -p debuild/$(SRCDIR) ; \
204	cp -pr debian debuild/$(SRCDIR) ; \
205	echo '9' > debuild/$(SRCDIR)/debian/compat ; \
206	mkdir -p debuild/$(SRCDIR)/debian/source ; \
207	echo '3.0 (quilt)' > debuild/$(SRCDIR)/debian/source/format ; \
208        cat debian/rules.in | sed \
209                -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
210        > debuild/$(SRCDIR)/debian/rules ; \
211	chmod +x debuild/$(SRCDIR)/debian/rules ; \
212	}
213
214debuild/$(SRCDIR)/debian/changelog: ../../docs/changes.xml | debuild/$(SRCDIR)/debian
215	cd ../../docs && make ../build/unit.deb-changelog
216ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
217	cat ../../build/unit.deb-changelog | sed \
218		-e "s/unit ($(DEFAULT_VERSION)-$(DEFAULT_RELEASE)~/unit ($(VERSION)-$(RELEASE)~/" \
219		-e "s#%%CODENAME%%#$(CODENAME)#g" \
220		> debuild/$(SRCDIR)/debian/changelog
221else
222	cat ../../build/unit.deb-changelog | sed \
223		-e "s#%%CODENAME%%#$(CODENAME)#g" \
224		> debuild/$(SRCDIR)/debian/changelog
225endif
226
227debuild/unit_$(VERSION).orig.tar.gz: | debuild/$(SRCDIR)/debian
228	cd ../.. && tar -czf pkg/deb/debuild/$(SRCDIR).tar.gz \
229		--transform "s#^#$(SRCDIR)/#" \
230		LICENSE NOTICE CHANGES README configure auto src test version go docs/man/unitd.8.in
231	mv debuild/$(SRCDIR).tar.gz debuild/unit_$(VERSION).orig.tar.gz
232	cd debuild && tar zxf unit_$(VERSION).orig.tar.gz
233
234unit: check-build-depends-unit debuild/unit_$(VERSION).orig.tar.gz debuild/$(SRCDIR)/debian/changelog
235	@echo "===> Building $@ package"
236	cd debuild/$(SRCDIR) && debuild -us -uc
237	mkdir -p debs
238	find debuild/ -maxdepth 1 -type f -exec cp {} debs/ \;
239	ln -s debuild/$(SRCDIR)/build $@
240
241debuild-%: debuild/unit_$(VERSION).orig.tar.gz ../../docs/changes.xml
242	mkdir $@
243	cp debuild/unit_$(VERSION).orig.tar.gz debuild-$*/unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz
244	cd $@ && tar zxf unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz
245	mkdir $@/$(SRCDIR)/debian
246	echo '9' > $@/$(SRCDIR)/debian/compat
247	mkdir $@/$(SRCDIR)/debian/source
248	echo '3.0 (quilt)' > $@/$(SRCDIR)/debian/source/format
249	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).deb-changelog
250ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
251	cat ../../build/unit-$(MODULE_SUFFIX_$*).deb-changelog | sed \
252		-e "s/unit-$* ($(DEFAULT_VERSION)-$(DEFAULT_RELEASE)~/unit-$* ($(VERSION)-$(RELEASE)~/" \
253		-e "s#%%CODENAME%%#$(CODENAME)#g" \
254		> $@/$(SRCDIR)/debian/changelog
255else
256	cat ../../build/unit-$(MODULE_SUFFIX_$*).deb-changelog | sed \
257		-e "s#%%CODENAME%%#$(CODENAME)#g" \
258		> $@/$(SRCDIR)/debian/changelog
259endif
260	if [ -f debian.module/copyright.unit-$(MODULE_SUFFIX_$*) ]; then \
261		cp debian.module/copyright.unit-$(MODULE_SUFFIX_$*) debuild-$*/$(SRCDIR)/debian/copyright ; \
262	else \
263		cp debian/copyright debuild-$*/$(SRCDIR)/debian/ ; \
264	fi
265	@{ \
266	set -e ; \
267	for src in $(MODULE_SOURCES_$*); do \
268		cp debian.module/$${src} $@/$(SRCDIR)/debian/ ; \
269	done ; \
270	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
271	prebuild=`echo "$$MODULE_PREBUILD_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
272	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
273	postinstall=`echo "$$MODULE_POSTINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
274	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
275	cat debian.module/$(if $(MODULE_NOARCH_$*),control-noarch.in,control.in) | sed \
276                -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \
277                -e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
278                -e "s#%%CODENAME%%#$(CODENAME)#g" \
279                -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
280                -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
281                -e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
282                -e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
283                -e "s#%%MODULE_BUILD_DEPENDS%%#$(MODULE_BUILD_DEPENDS_$*)#g" \
284                -e "s#%%MODULE_DEPENDS%%#$(MODULE_DEPENDS_$*)#g" \
285        > $@/$(SRCDIR)/debian/control ; \
286        cat debian.module/$(if $(MODULE_NOARCH_$*),rules-noarch.in,rules.in) | sed \
287                -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \
288                -e "s#%%CODENAME%%#$(CODENAME)#g" \
289                -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
290                -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
291                -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
292                -e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
293                -e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
294                -e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
295                -e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
296                -e "s#%%MODULE_PREBUILD%%#$${prebuild}#g" \
297                -e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
298                -e "s#%%MODULE_POSTINSTALL%%#$${postinstall}#g" \
299        > $@/$(SRCDIR)/debian/rules ; \
300        cat debian.module/preinst.in | sed \
301                -e "s#%%MODULE_POST%%#$$post#g" \
302        > $@/$(SRCDIR)/debian/preinst ; \
303        chmod +x $@/$(SRCDIR)/debian/rules ; \
304	}
305
306unit-%: check-build-depends-% | debuild-%
307	@echo "===> Building $@ package"
308	cd debuild-$*/$(SRCDIR) && debuild -us -uc
309	mkdir -p debs
310	find debuild-$*/ -maxdepth 1 -type f -exec cp {} debs/ \;
311	ln -s debuild-$*/$(SRCDIR)/build $@
312
313test: unit modules
314	@{ \
315	for so in `find debuild-*/unit-$(VERSION)/debian/build-unit/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
316		soname=`basename $${so}` ; \
317		test "$${soname}" = "java.unit.so" && continue ; \
318		test -h debuild/unit-$(VERSION)/debian/build-unit/build/$${soname} || \
319		ln -fs `pwd`/$${so} debuild/unit-$(VERSION)/debian/build-unit/build/$${soname} ; \
320	done ; \
321	( cd debuild/unit-$(VERSION)/debian/build-unit && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
322	}
323
324test-debug: unit modules
325	@{ \
326	for so in `find debuild-*/unit-$(VERSION)/debian/build-unit-debug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
327		soname=`basename $${so}` ; \
328		test "$${soname}" = "java.unit.so" && continue ; \
329		test -h debuild/unit-$(VERSION)/debian/build-unit-debug/build/$${soname} || \
330		ln -fs `pwd`/$${so} debuild/unit-$(VERSION)/debian/build-unit-debug/build/$${soname} ; \
331	done ; \
332	( cd debuild/unit-$(VERSION)/debian/build-unit-debug && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
333	}
334
335clean:
336	rm -rf debuild debuild-* debs ../../build
337	rm -f check-build-depends-*
338	find . -maxdepth 1 -type l -delete
339
340.PHONY: default all modules test test-debug clean
341
342.SECONDARY: $(addprefix check-build-depends-, $(MODULES)) $(addprefix debuild-, $(MODULES))
343