xref: /unit/pkg/deb/debian/rules.in (revision 2103:6e61a013417e)
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.md $(BUILDDIR_$*)/
35	cp -Pa $(CURDIR)/CONTRIBUTING.md $(BUILDDIR_$*)/
36	cp -Pa $(CURDIR)/go $(BUILDDIR_$*)/
37	mkdir -p $(BUILDDIR_$*)/docs/man
38	cp -Pa $(CURDIR)/docs/man/unitd.8.in $(BUILDDIR_$*)/docs/man/
39	touch $@
40
41configure.unit: config.env.unit
42	cd $(BUILDDIR_unit) && \
43	CFLAGS= ./configure \
44		%%CONFIGURE_ARGS%% \
45		--modules=/usr/lib/unit/modules \
46		--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
47		--cc-opt="$(CFLAGS)" \
48		--ld-opt="$(LDFLAGS)"
49	touch $@
50
51configure.unit_debug: config.env.unit_debug
52	cd $(BUILDDIR_unit_debug) && \
53	CFLAGS= ./configure \
54		%%CONFIGURE_ARGS%% \
55		--modules=/usr/lib/unit/debug-modules \
56		--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
57		--cc-opt="$(CFLAGS)" \
58		--ld-opt="$(LDFLAGS)" \
59		--debug
60	touch $@
61
62build-arch.%: configure.%
63	dh_testdir
64	$(MAKE) -C $(BUILDDIR_$*)
65	$(MAKE) -C $(BUILDDIR_$*) build/libunit.a
66ifeq ($(DOTESTS), 1)
67	$(MAKE) -C $(BUILDDIR_$*) tests
68endif
69	touch $@
70
71do.tests: build
72	dh_testdir
73ifeq ($(DOTESTS), 1)
74	cd $(BUILDDIR_unit) && ./build/tests
75	cd $(BUILDDIR_unit_debug) && ./build/tests
76endif
77	touch $@
78
79build-indep:
80	dh_testdir
81	touch $@
82
83build-arch: build-arch.unit build-arch.unit_debug
84	dh_testdir
85	touch $@
86
87build: build-arch build-indep
88	dh_testdir
89	touch $@
90
91clean:
92	dh_testdir
93	dh_testroot
94	dh_clean
95	find $(CURDIR) -maxdepth 1 -size 0 -delete
96	rm -rf $(BUILDDIR_unit) $(BUILDDIR_unit_debug)
97
98install: build do.tests
99	dh_testdir
100	dh_testroot
101	dh_prep
102	dh_installdirs
103	dh_installsystemd -punit --name=unit unit.service
104	dh_installsystemd -punit --name=unit-debug --no-start --no-enable unit-debug.service
105	dh_installlogrotate
106	cd $(BUILDDIR_unit) && DESTDIR=$(INSTALLDIR) make install
107	cd $(BUILDDIR_unit) && DESTDIR=$(INSTALLDIR_dev) make libunit-install
108	install -m 755 $(BUILDDIR_unit_debug)/build/unitd $(INSTALLDIR)/usr/sbin/unitd-debug
109	install -m 644 $(BUILDDIR_unit_debug)/build/libunit.a $(INSTALLDIR_dev)/usr/lib/$(DEB_HOST_MULTIARCH)/libunit-debug.a
110	mkdir -p $(INSTALLDIR)/usr/share/doc/unit/examples
111	install -m 644 debian/unit.example.config $(INSTALLDIR)/usr/share/doc/unit/examples/example.config
112	install -m 644 CHANGES $(INSTALLDIR)/usr/share/doc/unit/changelog
113	install -m 644 README.md $(INSTALLDIR)/usr/share/doc/unit/
114	install -m 644 CONTRIBUTING.md $(INSTALLDIR)/usr/share/doc/unit/
115	install -m 644 NOTICE $(INSTALLDIR)/usr/share/doc/unit/
116
117binary-indep: build install
118	dh_testdir
119	dh_testroot
120	dh_installdocs
121	dh_installchangelogs
122	dh_link
123	dh_strip --dbg-package=unit-dbg
124	dh_shlibdeps
125	dh_compress
126	dh_fixperms
127	dh_installdeb
128	dh_perl
129	dh_gencontrol
130	dh_md5sums
131	dh_builddeb
132
133binary-arch: install
134
135binary: binary-indep binary-arch
136
137.PHONY: clean binary-indep binary-arch binary install build
138