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