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