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