xref: /unit/pkg/deb/Makefile (revision 980:e1c4434c1060)
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 18.10
20ifeq ($(CODENAME),cosmic)
21include Makefile.php
22include Makefile.python27
23include Makefile.python36
24include Makefile.python37
25include Makefile.go19
26include Makefile.go110
27include Makefile.perl
28include Makefile.ruby
29include Makefile.jsc-common
30include Makefile.jsc8
31include Makefile.jsc11
32endif
33
34# Ubuntu 18.04
35ifeq ($(CODENAME),bionic)
36include Makefile.php
37include Makefile.python27
38include Makefile.python36
39include Makefile.go19
40include Makefile.go110
41include Makefile.perl
42include Makefile.ruby
43include Makefile.jsc-common
44include Makefile.jsc8
45include Makefile.jsc10
46endif
47
48# Ubuntu 17.10
49ifeq ($(CODENAME),artful)
50include Makefile.php
51include Makefile.python27
52include Makefile.python36
53include Makefile.go18
54include Makefile.go19
55include Makefile.perl
56include Makefile.ruby
57endif
58
59# Ubuntu 17.04
60ifeq ($(CODENAME),zesty)
61include Makefile.php
62include Makefile.python27
63include Makefile.python35
64include Makefile.go17
65include Makefile.go18
66include Makefile.perl
67include Makefile.ruby
68endif
69
70# Ubuntu 16.04
71ifeq ($(CODENAME),xenial)
72include Makefile.php
73include Makefile.python27
74include Makefile.python35
75include Makefile.go
76include Makefile.perl
77include Makefile.ruby
78include Makefile.jsc-common
79include Makefile.jsc8
80endif
81
82# Ubuntu 14.04
83ifeq ($(CODENAME),trusty)
84include Makefile.php
85include Makefile.python
86include Makefile.perl
87endif
88
89# Debian 9
90ifeq ($(CODENAME),stretch)
91include Makefile.php
92include Makefile.python27
93include Makefile.python35
94include Makefile.go17
95include Makefile.go18
96include Makefile.perl
97include Makefile.ruby
98include Makefile.jsc-common
99include Makefile.jsc8
100endif
101
102# Debian 8
103ifeq ($(CODENAME),jessie)
104include Makefile.php
105include Makefile.python27
106include Makefile.python34
107include Makefile.perl
108include Makefile.ruby
109endif
110
111CONFIGURE_ARGS=\
112	--prefix=/usr \
113	--state=/var/lib/unit \
114	--control="unix:/var/run/control.unit.sock" \
115	--pid=/var/run/unit.pid \
116	--log=/var/log/unit.log \
117	--tests \
118	--openssl
119
120export CR=\\n
121
122default:
123	@echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) test test-debug clean"
124
125all: check-build-depends-all unit modules
126
127modules: $(addprefix unit-, $(MODULES))
128
129check-build-depends-%:
130	@{ \
131	case "$*" in \
132		all) pkgs="$(BUILD_DEPENDS)" ;; \
133		unit) pkgs="$(BUILD_DEPENDS_unit)" ;; \
134		*) pkgs="$(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*)" ;; \
135	esac ; \
136	not_installed= ; \
137	for pkg in $${pkgs}; do \
138		dpkg -s $${pkg} >/dev/null 2>&1 ; \
139		if [ $$? -ne 0 ]; then \
140			not_installed="$${not_installed} $${pkg}" ; \
141		fi ; \
142	done ; \
143	if test -n "$${not_installed}" ; then \
144		echo "" >&2 ; \
145		echo "The following packages are required in order to proceed:" >&2 ; \
146		echo "" >&2 ; \
147		echo $${not_installed} >&2 ; \
148		echo "" >&2 ; \
149		exit 1 ; \
150	fi \
151	}
152	touch $@
153
154debuild/$(SRCDIR)/debian:
155	@{ \
156	set -e ; \
157	mkdir -p debuild/$(SRCDIR) ; \
158	cp -pr debian debuild/$(SRCDIR) ; \
159	echo '9' > debuild/$(SRCDIR)/debian/compat ; \
160	mkdir -p debuild/$(SRCDIR)/debian/source ; \
161	echo '3.0 (quilt)' > debuild/$(SRCDIR)/debian/source/format ; \
162        cat debian/rules.in | sed \
163                -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \
164        > debuild/$(SRCDIR)/debian/rules ; \
165	}
166
167debuild/$(SRCDIR)/debian/changelog: ../../docs/changes.xml | debuild/$(SRCDIR)/debian
168	cd ../../docs && make ../build/unit.deb-changelog
169ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
170	cat ../../build/unit.deb-changelog | sed \
171		-e "s/unit ($(DEFAULT_VERSION)-$(DEFAULT_RELEASE)~/unit ($(VERSION)-$(RELEASE)~/" \
172		-e "s#%%CODENAME%%#$(CODENAME)#g" \
173		> debuild/$(SRCDIR)/debian/changelog
174else
175	cat ../../build/unit.deb-changelog | sed \
176		-e "s#%%CODENAME%%#$(CODENAME)#g" \
177		> debuild/$(SRCDIR)/debian/changelog
178endif
179
180debuild/unit_$(VERSION).orig.tar.gz: | debuild/$(SRCDIR)/debian
181	cd ../.. && tar -czf pkg/deb/debuild/$(SRCDIR).tar.gz \
182		--transform "s#^#$(SRCDIR)/#" \
183		LICENSE NOTICE CHANGES README configure auto src test version
184	mv debuild/$(SRCDIR).tar.gz debuild/unit_$(VERSION).orig.tar.gz
185	cd debuild && tar zxf unit_$(VERSION).orig.tar.gz
186
187unit: check-build-depends-unit debuild/unit_$(VERSION).orig.tar.gz debuild/$(SRCDIR)/debian/changelog
188	@echo "===> Building $@ package"
189	cd debuild/$(SRCDIR) && debuild -us -uc
190	mkdir -p debs
191	find debuild/ -maxdepth 1 -type f -exec cp {} debs/ \;
192	ln -s debuild/$(SRCDIR)/build $@
193
194debuild-%: debuild/unit_$(VERSION).orig.tar.gz ../../docs/changes.xml
195	mkdir $@
196	cp debuild/unit_$(VERSION).orig.tar.gz debuild-$*/unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz
197	cd $@ && tar zxf unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz
198	mkdir $@/$(SRCDIR)/debian
199	echo '9' > $@/$(SRCDIR)/debian/compat
200	mkdir $@/$(SRCDIR)/debian/source
201	echo '3.0 (quilt)' > $@/$(SRCDIR)/debian/source/format
202	cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).deb-changelog
203ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE))
204	cat ../../build/unit-$(MODULE_SUFFIX_$*).deb-changelog | sed \
205		-e "s/unit-$* ($(DEFAULT_VERSION)-$(DEFAULT_RELEASE)~/unit-$* ($(VERSION)-$(RELEASE)~/" \
206		-e "s#%%CODENAME%%#$(CODENAME)#g" \
207		> $@/$(SRCDIR)/debian/changelog
208else
209	cat ../../build/unit-$(MODULE_SUFFIX_$*).deb-changelog | sed \
210		-e "s#%%CODENAME%%#$(CODENAME)#g" \
211		> $@/$(SRCDIR)/debian/changelog
212endif
213	if [ -f debian.module/copyright.unit-$(MODULE_SUFFIX_$*) ]; then \
214		cp debian.module/copyright.unit-$(MODULE_SUFFIX_$*) debuild-$*/$(SRCDIR)/debian/copyright ; \
215	else \
216		cp debian/copyright debuild-$*/$(SRCDIR)/debian/ ; \
217	fi
218	@{ \
219	set -e ; \
220	for src in $(MODULE_SOURCES_$*); do \
221		cp debian.module/$${src} $@/$(SRCDIR)/debian/ ; \
222	done ; \
223	definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
224	prebuild=`echo "$$MODULE_PREBUILD_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
225	preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
226	postinstall=`echo "$$MODULE_POSTINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
227	post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
228	cat debian.module/$(if $(MODULE_NOARCH_$*),control-noarch.in,control.in) | sed \
229                -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \
230                -e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \
231                -e "s#%%CODENAME%%#$(CODENAME)#g" \
232                -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \
233                -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \
234                -e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \
235                -e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#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 && ./test/run.py ) ; \
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 && ./test/run.py ) ; \
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