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