xref: /unit/pkg/deb/Makefile (revision 1994)
1373Sdefan@nginx.com#!/usr/bin/make
2373Sdefan@nginx.com
3953Salexander.borisov@nginx.cominclude ../../version
4373Sdefan@nginx.com
51764Sdefan@nginx.comDEFAULT_VERSION := $(NXT_VERSION)
6821Svbart@nginx.comDEFAULT_RELEASE := 1
7373Sdefan@nginx.com
81764Sdefan@nginx.comVERSION ?= $(DEFAULT_VERSION)
9373Sdefan@nginx.comRELEASE ?= $(DEFAULT_RELEASE)
10373Sdefan@nginx.com
111853Sdefan@nginx.comPACKAGE_VENDOR = NGINX Packaging <nginx-packaging@f5.com>
121853Sdefan@nginx.com
13373Sdefan@nginx.comSRCDIR=	unit-$(VERSION)
14373Sdefan@nginx.com
15373Sdefan@nginx.comCODENAME = $(shell lsb_release -cs)
16373Sdefan@nginx.com
17778Sdefan@nginx.comBUILD_DEPENDS_unit = build-essential debhelper devscripts fakeroot libxml2-utils lintian lsb-release xsltproc libssl-dev
18489Sdefan@nginx.comBUILD_DEPENDS = $(BUILD_DEPENDS_unit)
19373Sdefan@nginx.com
20373Sdefan@nginx.comMODULES=
21373Sdefan@nginx.com
221973Sdefan@nginx.com# Ubuntu 21.10
231973Sdefan@nginx.comifeq ($(CODENAME),impish)
241973Sdefan@nginx.cominclude Makefile.php
251973Sdefan@nginx.cominclude Makefile.python27
261973Sdefan@nginx.cominclude Makefile.python39
271973Sdefan@nginx.cominclude Makefile.python310
281973Sdefan@nginx.cominclude Makefile.go
291973Sdefan@nginx.cominclude Makefile.perl
301973Sdefan@nginx.cominclude Makefile.ruby
311973Sdefan@nginx.cominclude Makefile.jsc-common
321973Sdefan@nginx.cominclude Makefile.jsc11
331973Sdefan@nginx.cominclude Makefile.jsc16
341973Sdefan@nginx.cominclude Makefile.jsc17
351973Sdefan@nginx.cominclude Makefile.jsc18
361973Sdefan@nginx.comendif
371973Sdefan@nginx.com
381887Sdefan@nginx.com# Ubuntu 21.04
391887Sdefan@nginx.comifeq ($(CODENAME),hirsute)
401887Sdefan@nginx.cominclude Makefile.php
411887Sdefan@nginx.cominclude Makefile.python27
421887Sdefan@nginx.cominclude Makefile.python39
431887Sdefan@nginx.cominclude Makefile.go
441887Sdefan@nginx.cominclude Makefile.perl
451887Sdefan@nginx.cominclude Makefile.ruby
461887Sdefan@nginx.cominclude Makefile.jsc-common
471887Sdefan@nginx.cominclude Makefile.jsc11
481887Sdefan@nginx.cominclude Makefile.jsc15
491887Sdefan@nginx.cominclude Makefile.jsc16
501887Sdefan@nginx.cominclude Makefile.jsc17
511887Sdefan@nginx.comendif
521887Sdefan@nginx.com
531466Sdefan@nginx.com# Ubuntu 20.04
541466Sdefan@nginx.comifeq ($(CODENAME),focal)
551466Sdefan@nginx.cominclude Makefile.php
561466Sdefan@nginx.cominclude Makefile.python27
571466Sdefan@nginx.cominclude Makefile.python38
581466Sdefan@nginx.cominclude Makefile.go
591466Sdefan@nginx.cominclude Makefile.perl
601466Sdefan@nginx.cominclude Makefile.ruby
611466Sdefan@nginx.cominclude Makefile.jsc-common
621466Sdefan@nginx.cominclude Makefile.jsc11
631466Sdefan@nginx.comendif
641466Sdefan@nginx.com
65672Sdefan@nginx.com# Ubuntu 18.04
66672Sdefan@nginx.comifeq ($(CODENAME),bionic)
67672Sdefan@nginx.cominclude Makefile.php
68672Sdefan@nginx.cominclude Makefile.python27
69672Sdefan@nginx.cominclude Makefile.python36
701074Sdefan@nginx.cominclude Makefile.python37
711289Sdefan@nginx.cominclude Makefile.python38
721314Smax.romanov@nginx.cominclude Makefile.go
73672Sdefan@nginx.cominclude Makefile.perl
74672Sdefan@nginx.cominclude Makefile.ruby
75980Sdefan@nginx.cominclude Makefile.jsc-common
76980Sdefan@nginx.cominclude Makefile.jsc8
771076Sdefan@nginx.cominclude Makefile.jsc11
78672Sdefan@nginx.comendif
79672Sdefan@nginx.com
801941Sdefan@nginx.com# Debian 11
811941Sdefan@nginx.comifeq ($(CODENAME),bullseye)
821941Sdefan@nginx.cominclude Makefile.php
831941Sdefan@nginx.cominclude Makefile.python27
841941Sdefan@nginx.cominclude Makefile.python39
851941Sdefan@nginx.cominclude Makefile.go
861941Sdefan@nginx.cominclude Makefile.perl
871941Sdefan@nginx.cominclude Makefile.ruby
881941Sdefan@nginx.cominclude Makefile.jsc-common
891941Sdefan@nginx.cominclude Makefile.jsc11
901941Sdefan@nginx.comendif
911941Sdefan@nginx.com
921094Sdefan@nginx.com# Debian 10
931094Sdefan@nginx.comifeq ($(CODENAME),buster)
941094Sdefan@nginx.cominclude Makefile.php
951094Sdefan@nginx.cominclude Makefile.python27
961094Sdefan@nginx.cominclude Makefile.python37
971314Smax.romanov@nginx.cominclude Makefile.go
981094Sdefan@nginx.cominclude Makefile.perl
991094Sdefan@nginx.cominclude Makefile.ruby
1001094Sdefan@nginx.cominclude Makefile.jsc-common
1011094Sdefan@nginx.cominclude Makefile.jsc11
1021094Sdefan@nginx.comendif
1031094Sdefan@nginx.com
104373Sdefan@nginx.comCONFIGURE_ARGS=\
105373Sdefan@nginx.com	--prefix=/usr \
106373Sdefan@nginx.com	--state=/var/lib/unit \
107373Sdefan@nginx.com	--control="unix:/var/run/control.unit.sock" \
108373Sdefan@nginx.com	--pid=/var/run/unit.pid \
109373Sdefan@nginx.com	--log=/var/log/unit.log \
1101403Smax.romanov@nginx.com	--tmp=/var/tmp \
1111753Sdefan@nginx.com	--user=unit \
1121753Sdefan@nginx.com	--group=unit \
113778Sdefan@nginx.com	--tests \
114778Sdefan@nginx.com	--openssl
115373Sdefan@nginx.com
116373Sdefan@nginx.comexport CR=\\n
117373Sdefan@nginx.com
118373Sdefan@nginx.comdefault:
119501Sdefan@nginx.com	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) test test-debug clean"
120373Sdefan@nginx.com
121559Sdefan@nginx.comall: check-build-depends-all unit modules
122373Sdefan@nginx.com
123373Sdefan@nginx.commodules: $(addprefix unit-, $(MODULES))
124373Sdefan@nginx.com
125559Sdefan@nginx.comcheck-build-depends-%:
126373Sdefan@nginx.com	@{ \
127559Sdefan@nginx.com	case "$*" in \
128559Sdefan@nginx.com		all) pkgs="$(BUILD_DEPENDS)" ;; \
129559Sdefan@nginx.com		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
130559Sdefan@nginx.com		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
131559Sdefan@nginx.com	esac ; \
132373Sdefan@nginx.com	not_installed= ; \
133559Sdefan@nginx.com	for pkg in $${pkgs}; do \
134*1994Sdefan@nginx.com		dpkg-query -W $${pkg} >/dev/null 2>&1 ; \
135373Sdefan@nginx.com		if [ $$? -ne 0 ]; then \
136373Sdefan@nginx.com			not_installed="$${not_installed} $${pkg}" ; \
137373Sdefan@nginx.com		fi ; \
138373Sdefan@nginx.com	done ; \
139373Sdefan@nginx.com	if test -n "$${not_installed}" ; then \
140373Sdefan@nginx.com		echo "" >&2 ; \
141373Sdefan@nginx.com		echo "The following packages are required in order to proceed:" >&2 ; \
142373Sdefan@nginx.com		echo "" >&2 ; \
143373Sdefan@nginx.com		echo $${not_installed} >&2 ; \
144373Sdefan@nginx.com		echo "" >&2 ; \
145373Sdefan@nginx.com		exit 1 ; \
146373Sdefan@nginx.com	fi \
147373Sdefan@nginx.com	}
148559Sdefan@nginx.com	touch $@
149489Sdefan@nginx.com
150373Sdefan@nginx.comdebuild/$(SRCDIR)/debian:
151373Sdefan@nginx.com	@{ \
152373Sdefan@nginx.com	set -e ; \
153373Sdefan@nginx.com	mkdir -p debuild/$(SRCDIR) ; \
154373Sdefan@nginx.com	cp -pr debian debuild/$(SRCDIR) ; \
1551974Sdefan@nginx.com	echo '11' > debuild/$(SRCDIR)/debian/compat ; \
156373Sdefan@nginx.com	mkdir -p debuild/$(SRCDIR)/debian/source ; \
157373Sdefan@nginx.com	echo '3.0 (quilt)' > debuild/$(SRCDIR)/debian/source/format ; \
1581853Sdefan@nginx.com	cat debian/control.in | sed \
1591853Sdefan@nginx.com		-e "s#%%PACKAGE_VENDOR%%#$(PACKAGE_VENDOR)#g" \
1601853Sdefan@nginx.com	> debuild/$(SRCDIR)/debian/control ; \
161373Sdefan@nginx.com        cat debian/rules.in | sed \
162373Sdefan@nginx.com                -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
163373Sdefan@nginx.com        > debuild/$(SRCDIR)/debian/rules ; \
1641750Sdefan@nginx.com	chmod +x debuild/$(SRCDIR)/debian/rules ; \
165373Sdefan@nginx.com	}
166373Sdefan@nginx.com
167373Sdefan@nginx.comdebuild/$(SRCDIR)/debian/changelog: ../../docs/changes.xml | debuild/$(SRCDIR)/debian
168373Sdefan@nginx.com	cd ../../docs && make ../build/unit.deb-changelog
169373Sdefan@nginx.comifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
170373Sdefan@nginx.com	cat ../../build/unit.deb-changelog | sed \
171373Sdefan@nginx.com		-e "s/unit ($(DEFAULT_VERSION)-$(DEFAULT_RELEASE)~/unit ($(VERSION)-$(RELEASE)~/" \
172373Sdefan@nginx.com		-e "s#%%CODENAME%%#$(CODENAME)#g" \
173373Sdefan@nginx.com		> debuild/$(SRCDIR)/debian/changelog
174373Sdefan@nginx.comelse
175373Sdefan@nginx.com	cat ../../build/unit.deb-changelog | sed \
176373Sdefan@nginx.com		-e "s#%%CODENAME%%#$(CODENAME)#g" \
177373Sdefan@nginx.com		> debuild/$(SRCDIR)/debian/changelog
178373Sdefan@nginx.comendif
179373Sdefan@nginx.com
180373Sdefan@nginx.comdebuild/unit_$(VERSION).orig.tar.gz: | debuild/$(SRCDIR)/debian
181373Sdefan@nginx.com	cd ../.. && tar -czf pkg/deb/debuild/$(SRCDIR).tar.gz \
182373Sdefan@nginx.com		--transform "s#^#$(SRCDIR)/#" \
1831826Sthresh@nginx.com		LICENSE NOTICE CHANGES README configure auto src test version go docs/man/unitd.8.in
184373Sdefan@nginx.com	mv debuild/$(SRCDIR).tar.gz debuild/unit_$(VERSION).orig.tar.gz
185373Sdefan@nginx.com	cd debuild && tar zxf unit_$(VERSION).orig.tar.gz
186373Sdefan@nginx.com
187489Sdefan@nginx.comunit: check-build-depends-unit debuild/unit_$(VERSION).orig.tar.gz debuild/$(SRCDIR)/debian/changelog
188373Sdefan@nginx.com	@echo "===> Building $@ package"
189373Sdefan@nginx.com	cd debuild/$(SRCDIR) && debuild -us -uc
190373Sdefan@nginx.com	mkdir -p debs
191373Sdefan@nginx.com	find debuild/ -maxdepth 1 -type f -exec cp {} debs/ \;
192373Sdefan@nginx.com	ln -s debuild/$(SRCDIR)/build $@
193373Sdefan@nginx.com
194373Sdefan@nginx.comdebuild-%: debuild/unit_$(VERSION).orig.tar.gz ../../docs/changes.xml
195373Sdefan@nginx.com	mkdir $@
196373Sdefan@nginx.com	cp debuild/unit_$(VERSION).orig.tar.gz debuild-$*/unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz
197373Sdefan@nginx.com	cd $@ && tar zxf unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz
198373Sdefan@nginx.com	mkdir $@/$(SRCDIR)/debian
1991974Sdefan@nginx.com	echo '11' > $@/$(SRCDIR)/debian/compat
200373Sdefan@nginx.com	mkdir $@/$(SRCDIR)/debian/source
201373Sdefan@nginx.com	echo '3.0 (quilt)' > $@/$(SRCDIR)/debian/source/format
202373Sdefan@nginx.com	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).deb-changelog
203525Sdefan@nginx.comifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
204525Sdefan@nginx.com	cat ../../build/unit-$(MODULE_SUFFIX_$*).deb-changelog | sed \
205525Sdefan@nginx.com		-e "s/unit-$* ($(DEFAULT_VERSION)-$(DEFAULT_RELEASE)~/unit-$* ($(VERSION)-$(RELEASE)~/" \
206525Sdefan@nginx.com		-e "s#%%CODENAME%%#$(CODENAME)#g" \
207525Sdefan@nginx.com		> $@/$(SRCDIR)/debian/changelog
208525Sdefan@nginx.comelse
209373Sdefan@nginx.com	cat ../../build/unit-$(MODULE_SUFFIX_$*).deb-changelog | sed \
210373Sdefan@nginx.com		-e "s#%%CODENAME%%#$(CODENAME)#g" \
211373Sdefan@nginx.com		> $@/$(SRCDIR)/debian/changelog
212525Sdefan@nginx.comendif
213980Sdefan@nginx.com	if [ -f debian.module/copyright.unit-$(MODULE_SUFFIX_$*) ]; then \
214980Sdefan@nginx.com		cp debian.module/copyright.unit-$(MODULE_SUFFIX_$*) debuild-$*/$(SRCDIR)/debian/copyright ; \
215980Sdefan@nginx.com	else \
216980Sdefan@nginx.com		cp debian/copyright debuild-$*/$(SRCDIR)/debian/ ; \
217980Sdefan@nginx.com	fi
218373Sdefan@nginx.com	@{ \
219399Smax.romanov@nginx.com	set -e ; \
220373Sdefan@nginx.com	for src in $(MODULE_SOURCES_$*); do \
221373Sdefan@nginx.com		cp debian.module/$${src} $@/$(SRCDIR)/debian/ ; \
222373Sdefan@nginx.com	done ; \
223373Sdefan@nginx.com	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
224373Sdefan@nginx.com	prebuild=`echo "$$MODULE_PREBUILD_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
225373Sdefan@nginx.com	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
226980Sdefan@nginx.com	postinstall=`echo "$$MODULE_POSTINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
227373Sdefan@nginx.com	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
228980Sdefan@nginx.com	cat debian.module/$(if $(MODULE_NOARCH_$*),control-noarch.in,control.in) | sed \
229373Sdefan@nginx.com                -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \
230373Sdefan@nginx.com                -e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
231373Sdefan@nginx.com                -e "s#%%CODENAME%%#$(CODENAME)#g" \
232373Sdefan@nginx.com                -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
233373Sdefan@nginx.com                -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
234373Sdefan@nginx.com                -e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
235373Sdefan@nginx.com                -e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
2361853Sdefan@nginx.com                -e "s#%%PACKAGE_VENDOR%%#$(PACKAGE_VENDOR)#g" \
237373Sdefan@nginx.com                -e "s#%%MODULE_BUILD_DEPENDS%%#$(MODULE_BUILD_DEPENDS_$*)#g" \
238373Sdefan@nginx.com                -e "s#%%MODULE_DEPENDS%%#$(MODULE_DEPENDS_$*)#g" \
239373Sdefan@nginx.com        > $@/$(SRCDIR)/debian/control ; \
240980Sdefan@nginx.com        cat debian.module/$(if $(MODULE_NOARCH_$*),rules-noarch.in,rules.in) | sed \
241373Sdefan@nginx.com                -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \
242373Sdefan@nginx.com                -e "s#%%CODENAME%%#$(CODENAME)#g" \
243373Sdefan@nginx.com                -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
244373Sdefan@nginx.com                -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
245373Sdefan@nginx.com                -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
246373Sdefan@nginx.com                -e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
247373Sdefan@nginx.com                -e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
248373Sdefan@nginx.com                -e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
249373Sdefan@nginx.com                -e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
250373Sdefan@nginx.com                -e "s#%%MODULE_PREBUILD%%#$${prebuild}#g" \
251373Sdefan@nginx.com                -e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
252980Sdefan@nginx.com                -e "s#%%MODULE_POSTINSTALL%%#$${postinstall}#g" \
253373Sdefan@nginx.com        > $@/$(SRCDIR)/debian/rules ; \
254373Sdefan@nginx.com        cat debian.module/preinst.in | sed \
255373Sdefan@nginx.com                -e "s#%%MODULE_POST%%#$$post#g" \
256373Sdefan@nginx.com        > $@/$(SRCDIR)/debian/preinst ; \
257373Sdefan@nginx.com        chmod +x $@/$(SRCDIR)/debian/rules ; \
258373Sdefan@nginx.com	}
259373Sdefan@nginx.com
260489Sdefan@nginx.comunit-%: check-build-depends-% | debuild-%
261373Sdefan@nginx.com	@echo "===> Building $@ package"
262373Sdefan@nginx.com	cd debuild-$*/$(SRCDIR) && debuild -us -uc
263373Sdefan@nginx.com	mkdir -p debs
264373Sdefan@nginx.com	find debuild-$*/ -maxdepth 1 -type f -exec cp {} debs/ \;
265373Sdefan@nginx.com	ln -s debuild-$*/$(SRCDIR)/build $@
266373Sdefan@nginx.com
267501Sdefan@nginx.comtest: unit modules
268501Sdefan@nginx.com	@{ \
269980Sdefan@nginx.com	for so in `find debuild-*/unit-$(VERSION)/debian/build-unit/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
270501Sdefan@nginx.com		soname=`basename $${so}` ; \
271980Sdefan@nginx.com		test "$${soname}" = "java.unit.so" && continue ; \
272501Sdefan@nginx.com		test -h debuild/unit-$(VERSION)/debian/build-unit/build/$${soname} || \
273501Sdefan@nginx.com		ln -fs `pwd`/$${so} debuild/unit-$(VERSION)/debian/build-unit/build/$${soname} ; \
274501Sdefan@nginx.com	done ; \
2751762Sdefan@nginx.com	( cd debuild/unit-$(VERSION)/debian/build-unit && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
276501Sdefan@nginx.com	}
277501Sdefan@nginx.com
278501Sdefan@nginx.comtest-debug: unit modules
279501Sdefan@nginx.com	@{ \
280980Sdefan@nginx.com	for so in `find debuild-*/unit-$(VERSION)/debian/build-unit-debug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
281501Sdefan@nginx.com		soname=`basename $${so}` ; \
282980Sdefan@nginx.com		test "$${soname}" = "java.unit.so" && continue ; \
283501Sdefan@nginx.com		test -h debuild/unit-$(VERSION)/debian/build-unit-debug/build/$${soname} || \
284501Sdefan@nginx.com		ln -fs `pwd`/$${so} debuild/unit-$(VERSION)/debian/build-unit-debug/build/$${soname} ; \
285501Sdefan@nginx.com	done ; \
2861762Sdefan@nginx.com	( cd debuild/unit-$(VERSION)/debian/build-unit-debug && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
287501Sdefan@nginx.com	}
288501Sdefan@nginx.com
289373Sdefan@nginx.comclean:
290373Sdefan@nginx.com	rm -rf debuild debuild-* debs ../../build
291559Sdefan@nginx.com	rm -f check-build-depends-*
292373Sdefan@nginx.com	find . -maxdepth 1 -type l -delete
293373Sdefan@nginx.com
294559Sdefan@nginx.com.PHONY: default all modules test test-debug clean
295373Sdefan@nginx.com
296559Sdefan@nginx.com.SECONDARY: $(addprefix check-build-depends-, $(MODULES)) $(addprefix debuild-, $(MODULES))
297