xref: /unit/pkg/deb/debian/rules.in (revision 2027:04ae78e6813d)
1#!/usr/bin/make -f
2
3# Uncomment this to turn on verbose mode.
4#export DH_VERBOSE=1
5
6export DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
7export DEB_CFLAGS_MAINT_APPEND=-Wp,-D_FORTIFY_SOURCE=2 -fPIC
8export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed -pie
9DPKG_EXPORT_BUILDFLAGS = 1
10include /usr/share/dpkg/buildflags.mk
11
12DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
13CODENAME := $(shell lsb_release -cs)
14
15BUILDDIR_unit = $(CURDIR)/debian/build-unit
16BUILDDIR_unit_debug = $(CURDIR)/debian/build-unit-debug
17INSTALLDIR = $(CURDIR)/debian/unit
18INSTALLDIR_dev = $(CURDIR)/debian/unit-dev
19BASEDIR = $(CURDIR)
20
21DOTESTS = 0
22
23config.env.%:
24	dh_testdir
25	mkdir -p $(BUILDDIR_$*)
26	cp -Pa $(CURDIR)/auto $(BUILDDIR_$*)/
27	cp -Pa $(CURDIR)/configure $(BUILDDIR_$*)/
28	cp -Pa $(CURDIR)/src $(BUILDDIR_$*)/
29	cp -Pa $(CURDIR)/test $(BUILDDIR_$*)/
30	cp -Pa $(CURDIR)/version $(BUILDDIR_$*)/
31	cp -Pa $(CURDIR)/CHANGES $(BUILDDIR_$*)/
32	cp -Pa $(CURDIR)/LICENSE $(BUILDDIR_$*)/
33	cp -Pa $(CURDIR)/NOTICE $(BUILDDIR_$*)/
34	cp -Pa $(CURDIR)/README $(BUILDDIR_$*)/
35	cp -Pa $(CURDIR)/go $(BUILDDIR_$*)/
36	mkdir -p $(BUILDDIR_$*)/docs/man
37	cp -Pa $(CURDIR)/docs/man/unitd.8.in $(BUILDDIR_$*)/docs/man/
38	touch $@
39
40configure.unit: config.env.unit
41	cd $(BUILDDIR_unit) && \
42	CFLAGS= ./configure \
43		%%CONFIGURE_ARGS%% \
44		--modules=/usr/lib/unit/modules \
45		--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
46		--cc-opt="$(CFLAGS)" \
47		--ld-opt="$(LDFLAGS)"
48	touch $@
49
50configure.unit_debug: config.env.unit_debug
51	cd $(BUILDDIR_unit_debug) && \
52	CFLAGS= ./configure \
53		%%CONFIGURE_ARGS%% \
54		--modules=/usr/lib/unit/debug-modules \
55		--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
56		--cc-opt="$(CFLAGS)" \
57		--ld-opt="$(LDFLAGS)" \
58		--debug
59	touch $@
60
61build-arch.%: configure.%
62	dh_testdir
63	$(MAKE) -C $(BUILDDIR_$*)
64	$(MAKE) -C $(BUILDDIR_$*) build/libunit.a
65ifeq ($(DOTESTS), 1)
66	$(MAKE) -C $(BUILDDIR_$*) tests
67endif
68	touch $@
69
70do.tests: build
71	dh_testdir
72ifeq ($(DOTESTS), 1)
73	cd $(BUILDDIR_unit) && ./build/tests
74	cd $(BUILDDIR_unit_debug) && ./build/tests
75endif
76	touch $@
77
78build-indep:
79	dh_testdir
80	touch $@
81
82build-arch: build-arch.unit build-arch.unit_debug
83	dh_testdir
84	touch $@
85
86build: build-arch build-indep
87	dh_testdir
88	touch $@
89
90clean:
91	dh_testdir
92	dh_testroot
93	dh_clean
94	find $(CURDIR) -maxdepth 1 -size 0 -delete
95	rm -rf $(BUILDDIR_unit) $(BUILDDIR_unit_debug)
96
97install: build do.tests
98	dh_testdir
99	dh_testroot
100	dh_prep
101	dh_installdirs
102	dh_installsystemd -punit --name=unit unit.service
103	dh_installsystemd -punit --name=unit-debug --no-start --no-enable unit-debug.service
104	dh_installlogrotate
105	cd $(BUILDDIR_unit) && DESTDIR=$(INSTALLDIR) make install
106	cd $(BUILDDIR_unit) && DESTDIR=$(INSTALLDIR_dev) make libunit-install
107	install -m 755 $(BUILDDIR_unit_debug)/build/unitd $(INSTALLDIR)/usr/sbin/unitd-debug
108	install -m 644 $(BUILDDIR_unit_debug)/build/libunit.a $(INSTALLDIR_dev)/usr/lib/$(DEB_HOST_MULTIARCH)/libunit-debug.a
109	mkdir -p $(INSTALLDIR)/usr/share/doc/unit/examples
110	install -m 644 debian/unit.example.config $(INSTALLDIR)/usr/share/doc/unit/examples/example.config
111	install -m 644 CHANGES $(INSTALLDIR)/usr/share/doc/unit/changelog
112	install -m 644 README $(INSTALLDIR)/usr/share/doc/unit/
113	install -m 644 NOTICE $(INSTALLDIR)/usr/share/doc/unit/
114
115binary-indep: build install
116	dh_testdir
117	dh_testroot
118	dh_installdocs
119	dh_installchangelogs
120	dh_link
121	dh_strip --dbg-package=unit-dbg
122	dh_shlibdeps
123	dh_compress
124	dh_fixperms
125	dh_installdeb
126	dh_perl
127	dh_gencontrol
128	dh_md5sums
129	dh_builddeb
130
131binary-arch: install
132
133binary: binary-indep binary-arch
134
135.PHONY: clean binary-indep binary-arch binary install build
136