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