xref: /unit/pkg/deb/Makefile (revision 2138:8223904cc4bb)
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
222100Sthresh@nginx.com# Ubuntu 22.04
232100Sthresh@nginx.comifeq ($(CODENAME),jammy)
242100Sthresh@nginx.cominclude Makefile.php
252100Sthresh@nginx.cominclude Makefile.python27
262100Sthresh@nginx.cominclude Makefile.python310
272100Sthresh@nginx.cominclude Makefile.go
282100Sthresh@nginx.cominclude Makefile.perl
292100Sthresh@nginx.cominclude Makefile.ruby
302100Sthresh@nginx.cominclude Makefile.jsc-common
312100Sthresh@nginx.cominclude Makefile.jsc11
322100Sthresh@nginx.cominclude Makefile.jsc17
332100Sthresh@nginx.cominclude Makefile.jsc18
342100Sthresh@nginx.comendif
352100Sthresh@nginx.com
361973Sdefan@nginx.com# Ubuntu 21.10
371973Sdefan@nginx.comifeq ($(CODENAME),impish)
381973Sdefan@nginx.cominclude Makefile.php
391973Sdefan@nginx.cominclude Makefile.python27
401973Sdefan@nginx.cominclude Makefile.python39
411973Sdefan@nginx.cominclude Makefile.python310
421973Sdefan@nginx.cominclude Makefile.go
431973Sdefan@nginx.cominclude Makefile.perl
441973Sdefan@nginx.cominclude Makefile.ruby
451973Sdefan@nginx.cominclude Makefile.jsc-common
461973Sdefan@nginx.cominclude Makefile.jsc11
471973Sdefan@nginx.cominclude Makefile.jsc16
481973Sdefan@nginx.cominclude Makefile.jsc17
491973Sdefan@nginx.cominclude Makefile.jsc18
501973Sdefan@nginx.comendif
511973Sdefan@nginx.com
521466Sdefan@nginx.com# Ubuntu 20.04
531466Sdefan@nginx.comifeq ($(CODENAME),focal)
541466Sdefan@nginx.cominclude Makefile.php
551466Sdefan@nginx.cominclude Makefile.python27
561466Sdefan@nginx.cominclude Makefile.python38
571466Sdefan@nginx.cominclude Makefile.go
581466Sdefan@nginx.cominclude Makefile.perl
591466Sdefan@nginx.cominclude Makefile.ruby
601466Sdefan@nginx.cominclude Makefile.jsc-common
611466Sdefan@nginx.cominclude Makefile.jsc11
621466Sdefan@nginx.comendif
631466Sdefan@nginx.com
64672Sdefan@nginx.com# Ubuntu 18.04
65672Sdefan@nginx.comifeq ($(CODENAME),bionic)
66672Sdefan@nginx.cominclude Makefile.php
67672Sdefan@nginx.cominclude Makefile.python27
68672Sdefan@nginx.cominclude Makefile.python36
691074Sdefan@nginx.cominclude Makefile.python37
701289Sdefan@nginx.cominclude Makefile.python38
711314Smax.romanov@nginx.cominclude Makefile.go
72672Sdefan@nginx.cominclude Makefile.perl
73672Sdefan@nginx.cominclude Makefile.ruby
74980Sdefan@nginx.cominclude Makefile.jsc-common
75980Sdefan@nginx.cominclude Makefile.jsc8
761076Sdefan@nginx.cominclude Makefile.jsc11
77672Sdefan@nginx.comendif
78672Sdefan@nginx.com
791941Sdefan@nginx.com# Debian 11
801941Sdefan@nginx.comifeq ($(CODENAME),bullseye)
811941Sdefan@nginx.cominclude Makefile.php
821941Sdefan@nginx.cominclude Makefile.python27
831941Sdefan@nginx.cominclude Makefile.python39
841941Sdefan@nginx.cominclude Makefile.go
851941Sdefan@nginx.cominclude Makefile.perl
861941Sdefan@nginx.cominclude Makefile.ruby
871941Sdefan@nginx.cominclude Makefile.jsc-common
881941Sdefan@nginx.cominclude Makefile.jsc11
891941Sdefan@nginx.comendif
901941Sdefan@nginx.com
911094Sdefan@nginx.com# Debian 10
921094Sdefan@nginx.comifeq ($(CODENAME),buster)
931094Sdefan@nginx.cominclude Makefile.php
941094Sdefan@nginx.cominclude Makefile.python27
951094Sdefan@nginx.cominclude Makefile.python37
961314Smax.romanov@nginx.cominclude Makefile.go
971094Sdefan@nginx.cominclude Makefile.perl
981094Sdefan@nginx.cominclude Makefile.ruby
991094Sdefan@nginx.cominclude Makefile.jsc-common
1001094Sdefan@nginx.cominclude Makefile.jsc11
1011094Sdefan@nginx.comendif
1021094Sdefan@nginx.com
103373Sdefan@nginx.comCONFIGURE_ARGS=\
104373Sdefan@nginx.com	--prefix=/usr \
105373Sdefan@nginx.com	--state=/var/lib/unit \
106373Sdefan@nginx.com	--control="unix:/var/run/control.unit.sock" \
107373Sdefan@nginx.com	--pid=/var/run/unit.pid \
108373Sdefan@nginx.com	--log=/var/log/unit.log \
1091403Smax.romanov@nginx.com	--tmp=/var/tmp \
1101753Sdefan@nginx.com	--user=unit \
1111753Sdefan@nginx.com	--group=unit \
112778Sdefan@nginx.com	--tests \
113778Sdefan@nginx.com	--openssl
114373Sdefan@nginx.com
115373Sdefan@nginx.comexport CR=\\n
116373Sdefan@nginx.com
117373Sdefan@nginx.comdefault:
118501Sdefan@nginx.com	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) test test-debug clean"
119373Sdefan@nginx.com
120559Sdefan@nginx.comall: check-build-depends-all unit modules
121373Sdefan@nginx.com
122373Sdefan@nginx.commodules: $(addprefix unit-, $(MODULES))
123373Sdefan@nginx.com
124559Sdefan@nginx.comcheck-build-depends-%:
125373Sdefan@nginx.com	@{ \
126559Sdefan@nginx.com	case "$*" in \
127559Sdefan@nginx.com		all) pkgs="$(BUILD_DEPENDS)" ;; \
128559Sdefan@nginx.com		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
129559Sdefan@nginx.com		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
130559Sdefan@nginx.com	esac ; \
131373Sdefan@nginx.com	not_installed= ; \
132559Sdefan@nginx.com	for pkg in $${pkgs}; do \
1331994Sdefan@nginx.com		dpkg-query -W $${pkg} >/dev/null 2>&1 ; \
134373Sdefan@nginx.com		if [ $$? -ne 0 ]; then \
135373Sdefan@nginx.com			not_installed="$${not_installed} $${pkg}" ; \
136373Sdefan@nginx.com		fi ; \
137373Sdefan@nginx.com	done ; \
138373Sdefan@nginx.com	if test -n "$${not_installed}" ; then \
139373Sdefan@nginx.com		echo "" >&2 ; \
140373Sdefan@nginx.com		echo "The following packages are required in order to proceed:" >&2 ; \
141373Sdefan@nginx.com		echo "" >&2 ; \
142373Sdefan@nginx.com		echo $${not_installed} >&2 ; \
143373Sdefan@nginx.com		echo "" >&2 ; \
144373Sdefan@nginx.com		exit 1 ; \
145373Sdefan@nginx.com	fi \
146373Sdefan@nginx.com	}
147559Sdefan@nginx.com	touch $@
148489Sdefan@nginx.com
149373Sdefan@nginx.comdebuild/$(SRCDIR)/debian:
150373Sdefan@nginx.com	@{ \
151373Sdefan@nginx.com	set -e ; \
152373Sdefan@nginx.com	mkdir -p debuild/$(SRCDIR) ; \
153373Sdefan@nginx.com	cp -pr debian debuild/$(SRCDIR) ; \
1541974Sdefan@nginx.com	echo '11' > debuild/$(SRCDIR)/debian/compat ; \
155373Sdefan@nginx.com	mkdir -p debuild/$(SRCDIR)/debian/source ; \
156373Sdefan@nginx.com	echo '3.0 (quilt)' > debuild/$(SRCDIR)/debian/source/format ; \
1571853Sdefan@nginx.com	cat debian/control.in | sed \
1581853Sdefan@nginx.com		-e "s#%%PACKAGE_VENDOR%%#$(PACKAGE_VENDOR)#g" \
1591853Sdefan@nginx.com	> debuild/$(SRCDIR)/debian/control ; \
160373Sdefan@nginx.com        cat debian/rules.in | sed \
161373Sdefan@nginx.com                -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
162373Sdefan@nginx.com        > debuild/$(SRCDIR)/debian/rules ; \
1631750Sdefan@nginx.com	chmod +x debuild/$(SRCDIR)/debian/rules ; \
164373Sdefan@nginx.com	}
165373Sdefan@nginx.com
166373Sdefan@nginx.comdebuild/$(SRCDIR)/debian/changelog: ../../docs/changes.xml | debuild/$(SRCDIR)/debian
167373Sdefan@nginx.com	cd ../../docs && make ../build/unit.deb-changelog
168373Sdefan@nginx.comifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
169373Sdefan@nginx.com	cat ../../build/unit.deb-changelog | sed \
170373Sdefan@nginx.com		-e "s/unit ($(DEFAULT_VERSION)-$(DEFAULT_RELEASE)~/unit ($(VERSION)-$(RELEASE)~/" \
171373Sdefan@nginx.com		-e "s#%%CODENAME%%#$(CODENAME)#g" \
172373Sdefan@nginx.com		> debuild/$(SRCDIR)/debian/changelog
173373Sdefan@nginx.comelse
174373Sdefan@nginx.com	cat ../../build/unit.deb-changelog | sed \
175373Sdefan@nginx.com		-e "s#%%CODENAME%%#$(CODENAME)#g" \
176373Sdefan@nginx.com		> debuild/$(SRCDIR)/debian/changelog
177373Sdefan@nginx.comendif
178373Sdefan@nginx.com
179373Sdefan@nginx.comdebuild/unit_$(VERSION).orig.tar.gz: | debuild/$(SRCDIR)/debian
180373Sdefan@nginx.com	cd ../.. && tar -czf pkg/deb/debuild/$(SRCDIR).tar.gz \
181373Sdefan@nginx.com		--transform "s#^#$(SRCDIR)/#" \
182*2103Sthresh@nginx.com		LICENSE NOTICE CHANGES README.md CONTRIBUTING.md configure auto src test version go docs/man/unitd.8.in
183373Sdefan@nginx.com	mv debuild/$(SRCDIR).tar.gz debuild/unit_$(VERSION).orig.tar.gz
184373Sdefan@nginx.com	cd debuild && tar zxf unit_$(VERSION).orig.tar.gz
185373Sdefan@nginx.com
186489Sdefan@nginx.comunit: check-build-depends-unit debuild/unit_$(VERSION).orig.tar.gz debuild/$(SRCDIR)/debian/changelog
187373Sdefan@nginx.com	@echo "===> Building $@ package"
188373Sdefan@nginx.com	cd debuild/$(SRCDIR) && debuild -us -uc
189373Sdefan@nginx.com	mkdir -p debs
190373Sdefan@nginx.com	find debuild/ -maxdepth 1 -type f -exec cp {} debs/ \;
191373Sdefan@nginx.com	ln -s debuild/$(SRCDIR)/build $@
192373Sdefan@nginx.com
193373Sdefan@nginx.comdebuild-%: debuild/unit_$(VERSION).orig.tar.gz ../../docs/changes.xml
194373Sdefan@nginx.com	mkdir $@
195373Sdefan@nginx.com	cp debuild/unit_$(VERSION).orig.tar.gz debuild-$*/unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz
196373Sdefan@nginx.com	cd $@ && tar zxf unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz
197373Sdefan@nginx.com	mkdir $@/$(SRCDIR)/debian
1981974Sdefan@nginx.com	echo '11' > $@/$(SRCDIR)/debian/compat
199373Sdefan@nginx.com	mkdir $@/$(SRCDIR)/debian/source
200373Sdefan@nginx.com	echo '3.0 (quilt)' > $@/$(SRCDIR)/debian/source/format
201373Sdefan@nginx.com	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).deb-changelog
202525Sdefan@nginx.comifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
203525Sdefan@nginx.com	cat ../../build/unit-$(MODULE_SUFFIX_$*).deb-changelog | sed \
204525Sdefan@nginx.com		-e "s/unit-$* ($(DEFAULT_VERSION)-$(DEFAULT_RELEASE)~/unit-$* ($(VERSION)-$(RELEASE)~/" \
205525Sdefan@nginx.com		-e "s#%%CODENAME%%#$(CODENAME)#g" \
206525Sdefan@nginx.com		> $@/$(SRCDIR)/debian/changelog
207525Sdefan@nginx.comelse
208373Sdefan@nginx.com	cat ../../build/unit-$(MODULE_SUFFIX_$*).deb-changelog | sed \
209373Sdefan@nginx.com		-e "s#%%CODENAME%%#$(CODENAME)#g" \
210373Sdefan@nginx.com		> $@/$(SRCDIR)/debian/changelog
211525Sdefan@nginx.comendif
212980Sdefan@nginx.com	if [ -f debian.module/copyright.unit-$(MODULE_SUFFIX_$*) ]; then \
213980Sdefan@nginx.com		cp debian.module/copyright.unit-$(MODULE_SUFFIX_$*) debuild-$*/$(SRCDIR)/debian/copyright ; \
214980Sdefan@nginx.com	else \
215980Sdefan@nginx.com		cp debian/copyright debuild-$*/$(SRCDIR)/debian/ ; \
216980Sdefan@nginx.com	fi
217373Sdefan@nginx.com	@{ \
218399Smax.romanov@nginx.com	set -e ; \
219373Sdefan@nginx.com	for src in $(MODULE_SOURCES_$*); do \
220373Sdefan@nginx.com		cp debian.module/$${src} $@/$(SRCDIR)/debian/ ; \
221373Sdefan@nginx.com	done ; \
222373Sdefan@nginx.com	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
223373Sdefan@nginx.com	prebuild=`echo "$$MODULE_PREBUILD_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
224373Sdefan@nginx.com	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
225980Sdefan@nginx.com	postinstall=`echo "$$MODULE_POSTINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
226373Sdefan@nginx.com	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
227980Sdefan@nginx.com	cat debian.module/$(if $(MODULE_NOARCH_$*),control-noarch.in,control.in) | sed \
228373Sdefan@nginx.com                -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \
229373Sdefan@nginx.com                -e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
230373Sdefan@nginx.com                -e "s#%%CODENAME%%#$(CODENAME)#g" \
231373Sdefan@nginx.com                -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
232373Sdefan@nginx.com                -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
233373Sdefan@nginx.com                -e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
234373Sdefan@nginx.com                -e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \
2351853Sdefan@nginx.com                -e "s#%%PACKAGE_VENDOR%%#$(PACKAGE_VENDOR)#g" \
236373Sdefan@nginx.com                -e "s#%%MODULE_BUILD_DEPENDS%%#$(MODULE_BUILD_DEPENDS_$*)#g" \
237373Sdefan@nginx.com                -e "s#%%MODULE_DEPENDS%%#$(MODULE_DEPENDS_$*)#g" \
238373Sdefan@nginx.com        > $@/$(SRCDIR)/debian/control ; \
239980Sdefan@nginx.com        cat debian.module/$(if $(MODULE_NOARCH_$*),rules-noarch.in,rules.in) | sed \
240373Sdefan@nginx.com                -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \
241373Sdefan@nginx.com                -e "s#%%CODENAME%%#$(CODENAME)#g" \
242373Sdefan@nginx.com                -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
243373Sdefan@nginx.com                -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
244373Sdefan@nginx.com                -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
245373Sdefan@nginx.com                -e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \
246373Sdefan@nginx.com                -e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \
247373Sdefan@nginx.com                -e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \
248373Sdefan@nginx.com                -e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
249373Sdefan@nginx.com                -e "s#%%MODULE_PREBUILD%%#$${prebuild}#g" \
250373Sdefan@nginx.com                -e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
251980Sdefan@nginx.com                -e "s#%%MODULE_POSTINSTALL%%#$${postinstall}#g" \
252373Sdefan@nginx.com        > $@/$(SRCDIR)/debian/rules ; \
253373Sdefan@nginx.com        cat debian.module/preinst.in | sed \
254373Sdefan@nginx.com                -e "s#%%MODULE_POST%%#$$post#g" \
255373Sdefan@nginx.com        > $@/$(SRCDIR)/debian/preinst ; \
256373Sdefan@nginx.com        chmod +x $@/$(SRCDIR)/debian/rules ; \
257373Sdefan@nginx.com	}
258373Sdefan@nginx.com
259489Sdefan@nginx.comunit-%: check-build-depends-% | debuild-%
260373Sdefan@nginx.com	@echo "===> Building $@ package"
261373Sdefan@nginx.com	cd debuild-$*/$(SRCDIR) && debuild -us -uc
262373Sdefan@nginx.com	mkdir -p debs
263373Sdefan@nginx.com	find debuild-$*/ -maxdepth 1 -type f -exec cp {} debs/ \;
264373Sdefan@nginx.com	ln -s debuild-$*/$(SRCDIR)/build $@
265373Sdefan@nginx.com
266501Sdefan@nginx.comtest: unit modules
267501Sdefan@nginx.com	@{ \
268980Sdefan@nginx.com	for so in `find debuild-*/unit-$(VERSION)/debian/build-unit/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
269501Sdefan@nginx.com		soname=`basename $${so}` ; \
270980Sdefan@nginx.com		test "$${soname}" = "java.unit.so" && continue ; \
271501Sdefan@nginx.com		test -h debuild/unit-$(VERSION)/debian/build-unit/build/$${soname} || \
272501Sdefan@nginx.com		ln -fs `pwd`/$${so} debuild/unit-$(VERSION)/debian/build-unit/build/$${soname} ; \
273501Sdefan@nginx.com	done ; \
2741762Sdefan@nginx.com	( cd debuild/unit-$(VERSION)/debian/build-unit && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
275501Sdefan@nginx.com	}
276501Sdefan@nginx.com
277501Sdefan@nginx.comtest-debug: unit modules
278501Sdefan@nginx.com	@{ \
279980Sdefan@nginx.com	for so in `find debuild-*/unit-$(VERSION)/debian/build-unit-debug/ -type f \( -name "*.so" -o -name "*.jar" \)`; do \
280501Sdefan@nginx.com		soname=`basename $${so}` ; \
281980Sdefan@nginx.com		test "$${soname}" = "java.unit.so" && continue ; \
282501Sdefan@nginx.com		test -h debuild/unit-$(VERSION)/debian/build-unit-debug/build/$${soname} || \
283501Sdefan@nginx.com		ln -fs `pwd`/$${so} debuild/unit-$(VERSION)/debian/build-unit-debug/build/$${soname} ; \
284501Sdefan@nginx.com	done ; \
2851762Sdefan@nginx.com	( cd debuild/unit-$(VERSION)/debian/build-unit-debug && env python3 -m pytest --user=nobody $(PYTEST_ARGS) ) ; \
286501Sdefan@nginx.com	}
287501Sdefan@nginx.com
288373Sdefan@nginx.comclean:
289373Sdefan@nginx.com	rm -rf debuild debuild-* debs ../../build
290559Sdefan@nginx.com	rm -f check-build-depends-*
291373Sdefan@nginx.com	find . -maxdepth 1 -type l -delete
292373Sdefan@nginx.com
293559Sdefan@nginx.com.PHONY: default all modules test test-debug clean
294373Sdefan@nginx.com
295559Sdefan@nginx.com.SECONDARY: $(addprefix check-build-depends-, $(MODULES)) $(addprefix debuild-, $(MODULES))
296