debian: Fix build with old versions of dpkg-buildflags.
[cascardo/ovs.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 ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
26 CFLAGS += -O0
27 else
28 CFLAGS += -O2
29 endif
30
31 # Old versions of dpkg-buildflags do not understand --export=configure.
32 # When dpkg-buildflags does not understand an option, it prints its full
33 # --help output on stdout, so we have to avoid that here.
34 buildflags := $(shell if dpkg-buildflags --export=configure >/dev/null 2>&1; \
35                       then dpkg-buildflags --export=configure; fi)
36
37 configure: configure-stamp
38 configure-stamp:
39         dh_testdir
40         test -e configure || ./boot.sh
41         test -d _debian || mkdir _debian
42         echo $(DEB_BUILD_OPTIONS)
43         echo $$CC
44         cd _debian && ( \
45                 test -e Makefile || \
46                 ../configure --prefix=/usr --localstatedir=/var --enable-ssl \
47                         --sysconfdir=/etc CFLAGS="$(CFLAGS)" \
48                         $(buildflags) $(DATAPATH_CONFIGURE_OPTS))
49         touch configure-stamp
50
51 #Architecture 
52 build: build-arch build-indep
53
54 build-arch: build-arch-stamp
55 build-arch-stamp: configure-stamp 
56         $(MAKE) -C _debian
57 ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
58         if $(MAKE) -C _debian check TESTSUITEFLAGS='$(PARALLEL)'; then :; \
59         else \
60                 cat _debian/tests/testsuite.log; \
61                 exit 1; \
62         fi
63 endif
64         touch $@
65
66 build-indep: build-indep-stamp
67 build-indep-stamp: configure-stamp 
68         $(MAKE) -C _debian dist distdir=openvswitch
69         touch $@
70
71 clean:
72         dh_testdir
73         dh_testroot
74         rm -f build-arch-stamp build-indep-stamp configure-stamp
75         rm -rf _debian
76         [ ! -f Makefile ] || $(MAKE) distclean
77         dh_clean 
78         rm -f python/ovs/*.pyc python/ovs/db/*.pyc
79
80 install: install-indep install-arch
81 install-indep: build-indep
82         dh_testdir
83         dh_testroot
84         dh_prep -i
85         dh_installdirs -i
86         $(MAKE) -C _debian DESTDIR=$(CURDIR)/debian/tmp install
87         dh_install -i
88         cp debian/rules.modules debian/openvswitch-datapath-source/usr/src/modules/openvswitch-datapath/debian/rules
89         chmod 755 debian/openvswitch-datapath-source/usr/src/modules/openvswitch-datapath/debian/rules
90         cd debian/openvswitch-datapath-source/usr/src && tar -c modules | bzip2 -9 > openvswitch-datapath.tar.bz2 && rm -rf modules
91
92         #dkms stuff
93         # setup the dirs
94         dh_installdirs -p$(pdkms) usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)
95
96         # copy the source
97         cd debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION) && tar xvzf $(CURDIR)/_debian/openvswitch.tar.gz && mv openvswitch/* . && rmdir openvswitch
98
99         # Prepare dkms.conf from the dkms.conf.in template
100         sed "s/__VERSION__/$(DEB_UPSTREAM_VERSION)/g" debian/dkms.conf.in > debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/dkms.conf
101
102         # We don't need the debian folder in there, just upstream sources...
103         rm -rf debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/debian
104         # We don't need the rhel stuff in there either
105         rm -rf debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/rhel
106         # And we should also clean useless license files, which are already
107         # descriped in our debian/copyright anyway.
108         rm -f debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/COPYING \
109                 debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/ovsdb/ovsdbmonitor/COPYING \
110                 debian/$(pdkms)/usr/src/$(PACKAGE)-$(DEB_UPSTREAM_VERSION)/xenserver/LICENSE
111
112 install-arch: build-arch
113         dh_testdir
114         dh_testroot
115         dh_prep -s
116         dh_installdirs -s
117         $(MAKE) -C _debian DESTDIR=$(CURDIR)/debian/tmp install
118         cp debian/openvswitch-switch.template debian/openvswitch-switch/usr/share/openvswitch/switch/default.template
119         dh_install -s
120         dh_link -s
121
122 # Must not depend on anything. This is to be called by
123 # binary-arch/binary-indep
124 # in another 'make' thread.
125 binary-common:
126         dh_testdir
127         dh_testroot
128         dh_installchangelogs 
129         dh_installdocs
130         dh_installexamples
131         dh_installdebconf
132         dh_installlogrotate
133         dh_installinit -R
134         dh_installcron
135         dh_installman --language=C
136         dh_link
137         dh_strip --dbg-package=openvswitch-dbg
138         dh_compress 
139         dh_fixperms
140         dh_python2
141         dh_perl
142         dh_makeshlibs
143         dh_installdeb
144         dh_shlibdeps
145         dh_gencontrol
146         dh_md5sums
147         dh_builddeb
148 binary-indep: install-indep
149         $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
150 binary-arch: install-arch
151         $(MAKE) -f debian/rules DH_OPTIONS=-s binary-common
152
153 binary: binary-arch binary-indep
154 .PHONY: build clean binary-indep binary-arch binary install install-indep install-arch configure
155
156 # This GNU make extensions disables parallel builds for the current Makefile
157 # but not for sub-Makefiles.  This is appropriate here because build-arch and
158 # build-indep both invoke "make" on OVS, which can update some of the same
159 # targets in ways that conflict (e.g. both update tests/testsuite).
160 .NOTPARALLEL: