debian: Apply hardening options to build.
[sliver-openvswitch.git] / debian / rules
1 #!/usr/bin/make -f
2 # -*- makefile -*-
3 # Sample debian/rules that uses debhelper.
4 #
5 # This file was originally written by Joey Hess and Craig Small.
6 # As a special exception, when this file is copied by dh-make into a
7 # dh-make output file, you may use that output file without restriction.
8 # This special exception was added by Craig Small in version 0.37 of dh-make.
9 #
10 # Modified to make a template file for a multi-binary package with separated
11 # build-arch and build-indep targets  by Bill Allombert 2001
12
13 PACKAGE=openvswitch
14 pdkms=openvswitch-datapath-dkms
15 DEB_UPSTREAM_VERSION=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([0-9]:)*([^-]+).*,\2,p')
16 srcfiles := $(filter-out debian, $(wildcard * .[^.]*))
17
18 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
19 PARALLEL = -j$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
20 else
21 PARALLEL =
22 endif
23 MAKEFLAGS += $(PARALLEL)
24
25 CFLAGS += -g
26 ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
27 CFLAGS += -O0
28 else
29 CFLAGS += -O2
30 endif
31
32 configure: configure-stamp
33 configure-stamp:
34         dh_testdir
35         test -e configure || ./boot.sh
36         test -d _debian || mkdir _debian
37         echo $(DEB_BUILD_OPTIONS)
38         echo $$CC
39         cd _debian && ( \
40                 test -e Makefile || \
41                 ../configure --prefix=/usr --localstatedir=/var --enable-ssl \
42                         --sysconfdir=/etc CFLAGS="$(CFLAGS)" \
43                         $(shell dpkg-buildflags --export=configure) \
44                         $(DATAPATH_CONFIGURE_OPTS))
45         touch configure-stamp
46
47 #Architecture 
48 build: build-arch build-indep
49
50 build-arch: build-arch-stamp
51 build-arch-stamp: configure-stamp 
52         $(MAKE) -C _debian
53 ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
54         if $(MAKE) -C _debian check TESTSUITEFLAGS='$(PARALLEL)'; then :; \
55         else \
56                 cat _debian/tests/testsuite.log; \
57                 exit 1; \
58         fi
59 endif
60         touch $@
61
62 build-indep: build-indep-stamp
63 build-indep-stamp: configure-stamp 
64         $(MAKE) -C _debian dist distdir=openvswitch
65         touch $@
66
67 clean:
68         dh_testdir
69         dh_testroot
70         rm -f build-arch-stamp build-indep-stamp configure-stamp
71         rm -rf _debian
72         [ ! -f Makefile ] || $(MAKE) distclean
73         dh_clean 
74         rm -f python/ovs/*.pyc python/ovs/db/*.pyc
75
76 install: install-indep install-arch
77 install-indep: build-indep
78         dh_testdir
79         dh_testroot
80         dh_prep -i
81         dh_installdirs -i
82         $(MAKE) -C _debian DESTDIR=$(CURDIR)/debian/tmp install
83         dh_install -i
84         cp debian/rules.modules debian/openvswitch-datapath-source/usr/src/modules/openvswitch-datapath/debian/rules
85         chmod 755 debian/openvswitch-datapath-source/usr/src/modules/openvswitch-datapath/debian/rules
86         cd debian/openvswitch-datapath-source/usr/src && tar -c modules | bzip2 -9 > openvswitch-datapath.tar.bz2 && rm -rf modules
87
88         #dkms stuff
89         # setup the dirs
90         dh_installdirs -p$(pdkms) usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)
91
92         # copy the source
93         cd debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION) && tar xvzf $(CURDIR)/_debian/openvswitch.tar.gz && mv openvswitch/* . && rmdir openvswitch
94
95         # Prepare dkms.conf from the dkms.conf.in template
96         sed "s/__VERSION__/$(DEB_UPSTREAM_VERSION)/g" debian/dkms.conf.in > debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/dkms.conf
97
98         # We don't need the debian folder in there, just upstream sources...
99         rm -rf debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/debian
100         # We don't need the rhel stuff in there either
101         rm -rf debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/rhel
102         # And we should also clean useless license files, which are already
103         # descriped in our debian/copyright anyway.
104         rm -f debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/COPYING \
105                 debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/ovsdb/ovsdbmonitor/COPYING \
106                 debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/xenserver/LICENSE
107
108 install-arch: build-arch
109         dh_testdir
110         dh_testroot
111         dh_prep -s
112         dh_installdirs -s
113         $(MAKE) -C _debian DESTDIR=$(CURDIR)/debian/tmp install
114         cp debian/openvswitch-switch.template debian/openvswitch-switch/usr/share/openvswitch/switch/default.template
115         dh_install -s
116         dh_link -s
117
118 # Must not depend on anything. This is to be called by
119 # binary-arch/binary-indep
120 # in another 'make' thread.
121 binary-common:
122         dh_testdir
123         dh_testroot
124         dh_installchangelogs 
125         dh_installdocs
126         dh_installexamples
127         dh_installdebconf
128         dh_installlogrotate
129         dh_installinit -R
130         dh_installcron
131         dh_installman --language=C
132         dh_link
133         dh_strip --dbg-package=openvswitch-dbg
134         dh_compress 
135         dh_fixperms
136         dh_python2
137         dh_perl
138         dh_makeshlibs
139         dh_installdeb
140         dh_shlibdeps
141         dh_gencontrol
142         dh_md5sums
143         dh_builddeb
144 binary-indep: install-indep
145         $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
146 binary-arch: install-arch
147         $(MAKE) -f debian/rules DH_OPTIONS=-s binary-common
148
149 binary: binary-arch binary-indep
150 .PHONY: build clean binary-indep binary-arch binary install install-indep install-arch configure
151
152 # This GNU make extensions disables parallel builds for the current Makefile
153 # but not for sub-Makefiles.  This is appropriate here because build-arch and
154 # build-indep both invoke "make" on OVS, which can update some of the same
155 # targets in ways that conflict (e.g. both update tests/testsuite).
156 .NOTPARALLEL: