Enable PIE hardening
[deb_dpdk.git] / debian / rules
1 #!/usr/bin/make -f
2
3 # see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
4 DPKG_EXPORT_BUILDFLAGS = 1
5 export DEB_BUILD_MAINT_OPTIONS = hardening=+all
6 include /usr/share/dpkg/default.mk
7
8 DPDK_ABI := $(shell echo $(DEB_VERSION_UPSTREAM) | cut -d '-' -f1 | cut -d '.'  -f1-2 | cut -d '~' -f1)
9
10 ifeq (,$(findstring terse,$(DEB_BUILD_OPTIONS)))
11         export DH_VERBOSE=1
12         export DH_OPTIONS=-v
13 endif
14
15 # now stable with parallel comilation, so support -j
16 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
17     PAR := $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
18     MAKEFLAGS += -j$(PAR)
19 endif
20
21 ifneq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
22 BUILD_DOCS=n
23 else
24 ifneq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
25 BUILD_DOCS=n
26 # to stop dh_installdoc from running
27 export DEB_BUILD_PROFILES += nodoc
28 else
29 BUILD_DOCS=y
30 endif
31 endif
32
33 # kernel_modules can be passed via DEB_BUILD_OPTIONS to enable building the
34 # optional binary kernel modules package. By default it will be built against
35 # the current kernel, or ksrc can be passed with a path to the target kernel
36 # sources instead.
37 ifeq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
38 DPDK_CONFIG_BUILD_KMOD=false
39 KSRC=""
40 else
41 ifneq (,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
42     KSRC := $(patsubst ksrc=%,%,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
43 else
44     KSRC := /lib/modules/$(shell uname -r)/build
45 endif
46
47 KVERS := $(shell perl debian/kernel-version $(KSRC))
48 export KVERS
49 export MODULE_CFLAGS=-fno-PIE
50
51 DPDK_CONFIG_BUILD_KMOD=true
52
53 # Since the binary module package is generated at build time depending on the
54 # local kernel version, we have to append the new package in d/control.
55 # We cannot use a separate control file since that wouldn't work with
56 # dpkg-genchanges, and also would require a lot of overrides for debhelpers.
57 get_built_using ?= $(filter-out (=),$(shell dpkg-query -f='$${source:Package} (=$${source:Version})' -W $1))
58
59 build:
60         @if [ x"$(KVERS)" = x ] ; then \
61             echo 'No version in $(KSRC)/include/linux/version.h' >&2; \
62             exit 1; \
63         fi
64         sh debian/prep-modules $(KSRC)
65         cat debian/control.modules >> debian/control
66         dh $@ --with python3,dkms,systemd --buildsystem=meson
67 endif
68
69 %:
70         dh $@ --with python3,dkms,systemd --buildsystem=meson
71
72 override_dh_gencontrol:
73         dh_gencontrol
74         # debian/files will not exist until dh_gencontrol has ran at least once,
75         # so we need to run gencontrol for libdpdk-dev after.
76         # The list of libraries and PMDs is everchanging, so generate the dependency
77         # list for libdpdk-dev to avoid having to maintain it manually.
78         # Same for the recommends list for dpdk, were we want the PMDs and the mempools.
79         dh_gencontrol -p libdpdk-dev -- -V"librte:Depends=`grep -E 'librte-*' ./debian/files | grep -v dbgsym | tr '_' ' ' | awk '{ print $$1,"(=",$$2 ")" }' | paste -sd ',' - | sed -e 's/,/, /g'`"
80         dh_gencontrol -p dpdk -- -V"librte:Recommends=`grep -E 'librte-(pmd|mempool).*' ./debian/files | grep -v dbgsym | tr '_' ' ' | awk '{ print $$1,"(=",$$2 ")" }' | paste -sd ',' - | sed -e 's/,/, /g'`"
81 ifneq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
82         dh_gencontrol -p dpdk-modules-$(KVERS) -- \
83                 -v`cat debian/VERSION` \
84                 -V'built:using:kernel=$(call get_built_using,linux-headers-$(KVERS))'
85 endif
86
87 override_dh_auto_clean:
88         rm -rf debian/build debian/tmp debian/dpdk-modules-* \
89                 debian/control.modules debian/VERSION
90         sed -i '/Package: dpdk-modules-/,/`tail -n1 debian/control.modules.in`/d' debian/control
91         rm -f debian/dpdk-igb-uio-dkms.dkms debian/dpdk-rte-kni-dkms.dkms
92         dh_auto_clean
93
94 override_dh_auto_configure:
95         dh_auto_configure -- \
96                 --includedir=include/dpdk \
97                 -Dper_library_versions=false \
98                 -Dinclude_subdir_arch=../$(DEB_HOST_MULTIARCH)/dpdk \
99                 -Dmachine=corei7 \
100                 -Dkernel_dir=$(KSRC) \
101                 -Denable_kmods=$(DPDK_CONFIG_BUILD_KMOD)
102
103 override_dh_auto_build-indep:
104 ifeq (y,$(BUILD_DOCS))
105         dh_auto_build -- doc
106         # NINJA DOC INSTALL DOES NOT WORK - .buildinfo present, css missing
107         rm -f obj-$(DEB_HOST_MULTIARCH)/doc/guides/guides/.buildinfo
108 endif
109
110 # ninja install doc does not work, will rebuild everything,
111 # only dpdk-doc as arch: all so just skip it
112 override_dh_auto_install-indep:
113
114 override_dh_auto_install-arch:
115         dh_auto_install
116         # have the DKMS build include the correct per-arch directory
117         sed "s/@@DEB_HOST_MULTIARCH@@/$(DEB_HOST_MULTIARCH)/g" debian/dpdk-igb-uio-dkms.dkms.in > debian/dpdk-igb-uio-dkms.dkms
118         sed "s/@@DEB_HOST_MULTIARCH@@/$(DEB_HOST_MULTIARCH)/g" debian/dpdk-rte-kni-dkms.dkms.in > debian/dpdk-rte-kni-dkms.dkms
119         # Package(s): libdpdk-<NAME><VER> (bare runtime libs and PMDs)
120         for lib in $$(ls -1 debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/*.so.*); do \
121           LN=$$(basename $${lib} | sed -e 's/\.so\.[0-9\.]*$$//' | tr '_' '-'); \
122           if echo $${LN} | grep -q ".*[0-9]$$"; then \
123             PKG=$${LN}-$(DPDK_ABI); \
124           else \
125             PKG=$${LN}$(DPDK_ABI); \
126           fi; \
127           LIBF="$$(basename $${lib})"; \
128           dh_install -p $${PKG} usr/lib/$(DEB_HOST_MULTIARCH)/$${LIBF}; \
129           if [ -f debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/*/*/$${LIBF} ]; then \
130             dh_install -p $${PKG} usr/lib/$(DEB_HOST_MULTIARCH)/*/*/$${LIBF}; \
131           fi; \
132         done
133         # Package: dpdk-igb-uio-dkms
134         dh_install -p dpdk-igb-uio-dkms kernel/linux/igb_uio/* \
135                 usr/src/dpdk-igb-uio-$(DEB_VERSION_UPSTREAM)
136         # Package: dpdk-rte-kni-dkms
137         dh_install -p dpdk-rte-kni-dkms kernel/linux/kni/* \
138                 usr/src/dpdk-rte-kni-$(DEB_VERSION_UPSTREAM)
139 ifneq (,$(KVERS))
140         # Package: dpdk-modules-<kernel version>
141         dh_install -p dpdk-modules-$(KVERS) lib/modules
142 endif
143
144 override_dh_dkms:
145         dh_dkms -V $(DEB_VERSION_UPSTREAM)
146
147 override_dh_installinit:
148         dh_installinit --no-start --no-stop-on-upgrade
149
150 override_dh_systemd_start:
151         dh_systemd_start --no-start --no-stop-on-upgrade
152
153 override_dh_auto_test:
154
155 override_dh_python3:
156         # dh_python only looks in /usr/share/package_name but dpdk-doc installs in
157         # /usr/share/dpdk, so pass /usr to catch all
158         dh_python3 --shebang=/usr/bin/python3 /usr
159
160 override_dh_missing:
161         dh_missing --fail-missing