3 # see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
4 include /usr/share/dpkg/default.mk
6 DPDK_ABI := $(shell echo $(DEB_VERSION_UPSTREAM) | cut -d '-' -f1 | cut -d '.' -f1-2 | cut -d '~' -f1)
7 DPDK_DRIVER_DIR ?= dpdk-$(DPDK_ABI)-drivers
9 # see FEATURE AREAS in dpkg-buildflags(1)
10 export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie
12 # see ENVIRONMENT in dpkg-buildflags(1)
13 DPKG_EXPORT_BUILDFLAGS = 1
14 include /usr/share/dpkg/buildflags.mk
16 ifeq (,$(findstring terse,$(DEB_BUILD_OPTIONS)))
21 # Support backporting to jessie
22 dpkg_version_lt = $(shell dpkg --compare-versions $$(dpkg --status dpkg-dev | grep Version | cut -d' ' -f2) lt-nl "1.18.11" && echo yes)
23 ifeq (yes, $(dpkg_version_lt))
24 # package maintainers to append CFLAGS
25 # For Debian, dpkg-dev >= 1.18.11 and gcc 6.x, dpkg-buildflags and gcc
26 # handle -fPIC and related flags relying on specs files
27 # (/usr/share/dpkg/*specs)
28 export DEB_CFLAGS_MAINT_APPEND = -fPIC
29 export EXTRA_CFLAGS=$(CFLAGS)
30 export EXTRA_CPPFLAGS=$(CPPFLAGS)
31 export HOST_EXTRA_CFLAGS=$(CFLAGS)
32 export HOST_EXTRA_CPPFLAGS=$(CPPFLAGS)
33 # need to be stripped as DPDK build system adds them and it would be -Wl,-Wl,opt
34 export EXTRA_LDFLAGS=$(shell echo $(LDFLAGS) | sed 's/-Wl,//g')
35 # HOST_CC build system does not add -Wl ...
36 export EXTRA_HOST_LDFLAGS=$(LDFLAGS)
39 export RTE_DEVEL_BUILD=n
40 export EXTRA_CFLAGS+=-g
42 # People rebuilding this package can overwrite DPDK_CONFIG, RTE_MACHINE and
43 # RTE_TARGET via DEB_BUILD_OPTIONS if they like
44 ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
45 DPDK_CONFIG ?= $(patsubst dpdk_config=%,%,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
47 ifneq (,$(filter rte_machine=%,$(DEB_BUILD_OPTIONS)))
48 RTE_MACHINE ?= $(patsubst rte_machine=%,%,$(filter rte_machine=%,$(DEB_BUILD_OPTIONS)))
50 ifneq (,$(filter rte_target=%,$(DEB_BUILD_OPTIONS)))
51 RTE_TARGET ?= $(patsubst rte_target=%,%,$(filter rte_target=%,$(DEB_BUILD_OPTIONS)))
54 ifneq (,$(filter $(DEB_HOST_ARCH), arm64))
55 DPDK_CONFIG ?= "arm64-armv8a-linuxapp-gcc"
56 RTE_MACHINE ?= "armv8a"
57 RTE_TARGET ?= "arm64-armv8a-linuxapp-gcc"
60 ifneq (,$(filter $(DEB_HOST_ARCH), armhf))
61 DPDK_CONFIG ?= "arm-armv7a-linuxapp-gcc"
62 RTE_MACHINE ?= "armv7a"
63 RTE_TARGET ?= "arm-armv7a-linuxapp-gcc"
66 ifneq (,$(filter $(DEB_HOST_ARCH), ppc64el))
67 DPDK_CONFIG ?= "ppc_64-power8-linuxapp-gcc"
68 RTE_MACHINE ?= "power8"
69 RTE_TARGET ?= "ppc_64-power8-linuxapp-gcc"
70 INCLUDE_ARCH := ppc_64
72 DPDK_CONFIG ?= "$(DEB_HOST_GNU_CPU)-native-linuxapp-gcc"
73 RTE_MACHINE ?= "default"
74 RTE_TARGET ?= "$(DEB_HOST_GNU_CPU)-default-linuxapp-gcc"
79 DPDK_STATIC_DIR = "debian/build/static-root"
80 DPDK_SHARED_DIR = "debian/build/shared-root"
82 # now stable with parallel comilation, so support -j
83 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
84 PAR := $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
88 ifneq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
94 ifneq (,$(findstring nostatic,$(DEB_BUILD_OPTIONS)))
100 # kernel_modules can be passed via DEB_BUILD_OPTIONS to enable building the
101 # optional binary kernel modules package. By default it will be built against
102 # the current kernel, or ksrc can be passed with a path to the target kernel
104 ifeq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
105 DPDK_CONFIG_BUILD_KMOD=n
108 ifneq (,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
109 KSRC := $(patsubst ksrc=%,%,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
111 KSRC := /lib/modules/$(shell uname -r)/build
114 KVERS := $(shell perl debian/kernel-version $(KSRC))
116 export MODULE_CFLAGS=-fno-PIE
118 DPDK_CONFIG_BUILD_KMOD=y
120 # Since the binary module package is generated at build time depending on the
121 # local kernel version, we have to append the new package in d/control.
122 # We cannot use a separate control file since that wouldn't work with
123 # dpkg-genchanges, and also would require a lot of overrides for debhelpers.
124 get_built_using ?= $(filter-out (=),$(shell dpkg-query -f='$${source:Package} (=$${source:Version})' -W $1))
127 @if [ x"$(KVERS)" = x ] ; then \
128 echo 'No version in $(KSRC)/include/linux/version.h' >&2; \
131 sh debian/prep-modules $(KSRC)
132 cat debian/control.modules >> debian/control
133 dh $@ --with python3,dkms,systemd
137 dh $@ --with python3,dkms,systemd
139 override_dh_gencontrol:
141 # debian/files will not exist until dh_gencontrol has ran at least once,
142 # so we need to run gencontrol for libdpdk-dev and libdpdk-dbgsym after.
143 # The list of libraries and PMDs is everchanging, so generate the dependency
144 # list for libdpdk-dev to avoid having to maintain it manually.
145 # Same for the recommends list for dpdk, were we want the PMDs and the mempools.
146 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'`"
147 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'`"
148 ifneq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
149 dh_gencontrol -p dpdk-modules-$(KVERS) -- \
150 -v`cat debian/VERSION` \
151 -V'built:using:kernel=$(call get_built_using,linux-headers-$(KVERS))'
153 ifneq (,$(findstring dbgsym_meta,$(DEB_BUILD_OPTIONS)))
154 ./debian/dh-dbgsym-metapkg libdpdk$(DPDK_ABI)-dbgsym
157 # dbgsym_meta can be passed via DEB_BUILD_OPTIONS to enable building the
158 # optional dbgsym meta package libdpdk<ABI>-dbgsym.
159 # This is not built by default as it would go in main but depend on
160 # packages in the debian-debug archive.
161 # Debian Developers and FTP masters strongly discourage this.
162 # We provide this optional flag as a convenience for rebuilders.
163 ifneq (,$(findstring dbgsym_meta,$(DEB_BUILD_OPTIONS)))
164 override_dh_builddeb:
166 dh_builddeb -plibdpdk$(DPDK_ABI)-dbgsym
169 override_dh_auto_clean:
170 rm -rf debian/build debian/tmp debian/dpdk-modules-* \
171 debian/control.modules debian/VERSION
172 sed -i '/Package: dpdk-modules-/,/`tail -n1 debian/control.modules.in`/d' debian/control
173 test -L config/defconfig_$(DPDK_CONFIG) && rm -f config/defconfig_$(DPDK_CONFIG) || true
174 rm -f debian/dpdk-igb-uio-dkms.dkms debian/dpdk-rte-kni-dkms.dkms
175 rm -f debian/dpdk-dev.preinst
177 override_dh_auto_configure:
178 # Add support for a custom defconfig file in the debian directory.
179 ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
180 test -e config/defconfig_$(DPDK_CONFIG) || ln -fs ../debian/defconfig_$(DPDK_CONFIG) config/defconfig_$(DPDK_CONFIG)
182 # report dpkg-buildflags status to build log
183 dpkg-buildflags --status
184 echo EXTRA_CFLAGS $$EXTRA_CFLAGS
185 echo EXTRA_LDFLAGS: $$EXTRA_LDFLAGS
186 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) T=$(DPDK_CONFIG) config
187 ifeq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
188 sed -ri -e 's,(RTE_MACHINE=).*,\1$(RTE_MACHINE),' \
189 -e 's,(RTE_NEXT_ABI=).*,\1n,' \
190 -e 's,(CONFIG_RTE_EAL_IGB_UIO=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
191 -e 's,(CONFIG_RTE_KNI_KMOD=).*,\1$(DPDK_CONFIG_BUILD_KMOD),' \
192 -e 's,(LIBRTE_PMD_PCAP=).*,\1y,' \
193 -e 's,(CONFIG_RTE_EAL_PMD_PATH=).*,\1"/usr/lib/$(DEB_HOST_MULTIARCH)/$(DPDK_DRIVER_DIR)/",' \
194 $(DPDK_STATIC_DIR)/.config
195 ifeq (,$(filter $(DEB_HOST_ARCH), armhf))
196 sed -ri -e 's,(CONFIG_RTE_LIBRTE_MLX4_PMD=).*,\1y,' \
197 -e 's,(CONFIG_RTE_LIBRTE_MLX5_PMD=).*,\1y,' \
198 -e 's,(LIBRTE_PMD_OPENSSL=).*,\1y,' \
199 $(DPDK_STATIC_DIR)/.config
202 echo "CONFIG_RTE_MAJOR_ABI=\"$(DPDK_ABI)\"" >> \
203 $(DPDK_STATIC_DIR)/.config
204 # Intel IPSEC library is amd64-only
205 ifneq (,$(filter $(DEB_HOST_ARCH), amd64))
206 sed -ri -e 's,(CONFIG_RTE_LIBRTE_PMD_AESNI_MB=).*,\1y,' \
207 -e 's,(CONFIG_RTE_LIBRTE_PMD_AESNI_GCM=).*,\1y,' \
208 $(DPDK_STATIC_DIR)/.config
212 override_dh_auto_build-indep:
213 ifeq (y,$(BUILD_DOCS))
214 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) doc-api-html doc-guides-html
217 override_dh_auto_install-indep:
219 # All files based on the install-doc rule (includes examples)
220 ifeq (y,$(BUILD_DOCS))
221 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr \
222 DESTDIR=debian/dpdk-doc install-doc
225 override_dh_auto_build-arch:
226 ifeq (y,$(BUILD_STATIC_LIB))
227 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) RTE_KERNELDIR=$(KSRC) build
229 # Unfortunately the decision about having static or shared libraries is
230 # made for the whole build, which then produces only .a or .so files
232 # And the target layout for target selection has no field for the
234 # Right now I hack this by doing a second build which only differs in
235 # the selection of shared libs.
236 # Shared libs should be default, so the previous static build is only
237 # used to get static libraries.
238 cp -a $(DPDK_STATIC_DIR) $(DPDK_SHARED_DIR)
239 sed -ri 's,(RTE_BUILD_SHARED_LIB=).*,\1y,' \
240 $(DPDK_SHARED_DIR)/.config
241 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) RTE_KERNELDIR=$(KSRC) build
242 ifeq (y,$(BUILD_DOCS))
243 # need to be around for dh_installman to be picked up
244 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) RTE_KERNELDIR=$(KSRC) doc-guides-man
246 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) RTE_KERNELDIR=$(KSRC) test-build
248 override_dh_auto_install-arch: LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)
249 override_dh_auto_install-arch:
250 # Package: dpdk (runtime)
251 ifeq (y,$(BUILD_STATIC_LIB))
252 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) prefix=/usr libdir=$(LIBDIR) \
253 DESTDIR=debian/dpdk install-runtime
255 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr libdir=$(LIBDIR) \
256 DESTDIR=debian/dpdk install-runtime
257 mkdir -p debian/dpdk/etc/dpdk
258 cp debian/dpdk.interfaces debian/dpdk/etc/dpdk/interfaces
259 rm debian/dpdk/usr/sbin/dpdk-devbind
260 mkdir -p debian/dpdk/sbin
261 ln -s /usr/share/dpdk/usertools/dpdk-devbind.py \
262 debian/dpdk/sbin/dpdk-devbind
263 # Package: dpdk-dev (build environment)
264 # workaround to fix symbolic link creation
265 mkdir -p debian/dpdk-dev/$(LIBDIR)
266 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) prefix=/usr libdir=$(LIBDIR) \
267 DESTDIR=debian/dpdk-dev install-sdk
269 rm -fr debian/dpdk-dev/usr/lib
270 cp $(DPDK_SHARED_DIR)/.config debian/dpdk-dev/usr/share/dpdk/config
271 sed -e 's/SDK_TARGET/$(RTE_TARGET)/' debian/dpdk-sdk-env.sh.in > \
272 debian/dpdk-dev/usr/share/dpdk/dpdk-sdk-env.sh
273 # include the bundled autotest suite to be usable from the dpdk-dev package
274 if grep -qs 'CONFIG_RTE_APP_TEST=y' $(DPDK_SHARED_DIR)/.config; then \
275 mkdir -p debian/dpdk-dev/usr/share/dpdk/test; \
276 cp -a test/test/autotest* debian/dpdk-dev/usr/share/dpdk/test; \
277 cp $(DPDK_SHARED_DIR)/app/test debian/dpdk-dev/usr/share/dpdk/test/; \
278 cp $(DPDK_SHARED_DIR)/app/testacl debian/dpdk-dev/usr/share/dpdk/test/; \
279 cp $(DPDK_SHARED_DIR)/app/testpipeline debian/dpdk-dev/usr/share/dpdk/test/; \
281 # since we move libs to multiarch dirs update the non aware symlink
282 rm debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/lib
283 ln -rs debian/dpdk-dev/$(LIBDIR)/ \
284 debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/lib
285 # Package: libdpdk-dev (bare headers, static devel libs and linker
287 mkdir -p debian/libdpdk-dev/$(LIBDIR)
289 mv debian/dpdk/$(LIBDIR)/libdpdk.so debian/libdpdk-dev/$(LIBDIR)/
291 # Some headers have architecture-specific content, but the upstream build
292 # system installs them in the same directory, breaking multiarch.
293 # Move them in /usr/include/<arch>/dpdk instead.
294 mkdir -p debian/libdpdk-dev/usr/include/$(DEB_HOST_MULTIARCH)/dpdk
295 # Before moving the files, remove the symlink in usr/share/dpdk and copy them over,
296 # as the SDK subdir is architecture specific and requires the arch-specific headers
298 rm -f debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/include
299 mkdir -p debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/include
300 cp -r debian/dpdk-dev/usr/include/dpdk/* debian/dpdk-dev/usr/share/dpdk/$(RTE_TARGET)/include
301 # genereate the preinst to deal with the symlink -> directory transition smoothly
302 sed "s/@@RTE_TARGET@@/$(RTE_TARGET)/g" debian/dpdk-dev.preinst.in > debian/dpdk-dev.preinst
303 mv $(addprefix debian/dpdk-dev/usr/include/dpdk/,$(notdir $(wildcard lib/librte_eal/common/include/arch/$(INCLUDE_ARCH)/*.h))) \
304 debian/libdpdk-dev/usr/include/$(DEB_HOST_MULTIARCH)/dpdk/
305 mv debian/dpdk-dev/usr/include/dpdk/rte_config.h \
306 debian/libdpdk-dev/usr/include/$(DEB_HOST_MULTIARCH)/dpdk/
307 mv debian/dpdk-dev/usr/include/dpdk debian/libdpdk-dev/usr/include/
308 rmdir debian/dpdk-dev/usr/include
309 # backward compatibility: to ease things for the majority of users,
310 # which are on x86_64, symlink the x86 headers into the global
312 ifeq (x86_64-linux-gnu,$(DEB_HOST_MULTIARCH))
313 ln -rs debian/libdpdk-dev/usr/include/$(DEB_HOST_MULTIARCH)/dpdk/*.h \
314 debian/libdpdk-dev/usr/include/dpdk
316 # have the DKMS build include the correct per-arch directory
317 sed "s/@@DEB_HOST_MULTIARCH@@/$(DEB_HOST_MULTIARCH)/g" debian/dpdk-igb-uio-dkms.dkms.in > debian/dpdk-igb-uio-dkms.dkms
318 sed "s/@@DEB_HOST_MULTIARCH@@/$(DEB_HOST_MULTIARCH)/g" debian/dpdk-rte-kni-dkms.dkms.in > debian/dpdk-rte-kni-dkms.dkms
319 # all static libs are in the dev package
320 ifeq (y,$(BUILD_STATIC_LIB))
321 mv debian/dpdk/$(LIBDIR)/lib*.a debian/libdpdk-dev/$(LIBDIR)/
323 # symlinks to last .so's are in the non versioned libdpdk-dev as well
324 # this allows multiple libdpdk-<NAME><VER> at different VER concurrently
325 # libdpdk-dev depends on all sublibs so symlinks are never broken
326 mv debian/dpdk/$(LIBDIR)/*.so debian/libdpdk-dev/$(LIBDIR)/
327 # Package(s): libdpdk-<NAME><VER> (bare runtime libs)
328 for lib in $$(ls -1 debian/dpdk/$(LIBDIR)/*.so.*); do \
329 BN=$$(basename $${lib}); \
330 LN=$$(echo $${BN} | sed -e 's/\.so\.[0-9\.]*$$//' | tr '_' '-'); \
331 if echo $${LN} | grep -q ".*[0-9]$$"; then \
332 PKG=$${LN}-$(DPDK_ABI); \
334 PKG=$${LN}$(DPDK_ABI); \
336 LIBF="$$(basename $${lib})"; \
337 LIBD="debian/$${PKG}/$(LIBDIR)"; \
338 echo "moving $${lib} to dir $${LIBD} (PKG=$${PKG} BN=$${BN} LN={$${LN} LIBF=$${LIBF} LIBD=$${LIBD})"; \
340 mv $${lib} $${LIBD}; \
341 if [ "$${LIBF#librte_pmd_}x" != "$${LIBF}x" ]; then \
342 mkdir -p $${LIBD}/$(DPDK_DRIVER_DIR); \
343 echo "PMD: linking $${LIBF} into RTE_EAL_PMD_PATH at $${LIBD}/$(DPDK_DRIVER_DIR)/"; \
344 ln -s --relative --target-directory=$${LIBD}/$(DPDK_DRIVER_DIR)/ $${LIBD}/$${LIBF}; \
346 if [ "$${LIBF#librte_mempool_}x" != "$${LIBF}x" ]; then \
347 mkdir -p $${LIBD}/$(DPDK_DRIVER_DIR); \
348 echo "MEMPOOL: linking $${LIBF} into RTE_EAL_PMD_PATH at $${LIBD}/$(DPDK_DRIVER_DIR)/"; \
349 ln -s --relative --target-directory=$${LIBD}/$(DPDK_DRIVER_DIR)/ $${LIBD}/$${LIBF}; \
351 if [ "$${LIBF#librte_ifcvf_}x" != "$${LIBF}x" ]; then \
352 mkdir -p $${LIBD}/$(DPDK_DRIVER_DIR); \
353 echo "IFCVF: linking $${LIBF} into RTE_EAL_PMD_PATH at $${LIBD}/$(DPDK_DRIVER_DIR)/"; \
354 ln -s --relative --target-directory=$${LIBD}/$(DPDK_DRIVER_DIR)/ $${LIBD}/$${LIBF}; \
356 if [ "$${LIBF#librte_eal}x" != "$${LIBF}x" ]; then \
357 mkdir -p $${LIBD}/$(DPDK_DRIVER_DIR); \
361 mkdir -p debian/libdpdk-dev/$(LIBDIR)/pkgconfig
362 LIBS=$$(sed -e 's/GROUP ( \(.*\) )/\1/' -e 's/lib/-l/g' -e 's/\.so//g' \
363 $(CURDIR)/debian/libdpdk-dev/$(LIBDIR)/libdpdk.so); \
364 sed -e "s/@DPDK_LIBS@/$${LIBS}/" -e "s/@VERSION@/$(DEB_VERSION_UPSTREAM)/" \
365 -e "s|@DEB_HOST_MULTIARCH@|$(DEB_HOST_MULTIARCH)|g" \
366 debian/libdpdk.pc.in > debian/libdpdk-dev/$(LIBDIR)/pkgconfig/libdpdk.pc
367 # Package: dpdk-igb-uio-dkms
368 mkdir -p debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(DEB_VERSION_UPSTREAM)
369 cp kernel/linux/igb_uio/* \
370 debian/dpdk-igb-uio-dkms/usr/src/dpdk-igb-uio-$(DEB_VERSION_UPSTREAM)
371 # Package: dpdk-rte-kni-dkms
372 mkdir -p debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(DEB_VERSION_UPSTREAM)
373 cp -a kernel/linux/kni/* \
374 debian/dpdk-rte-kni-dkms/usr/src/dpdk-rte-kni-$(DEB_VERSION_UPSTREAM)
376 # Package: dpdk-modules-<kernel version>
377 $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_SHARED_DIR) \
378 kerneldir=/lib/modules/$(KVERS)/extra/dpdk \
379 DESTDIR=debian/dpdk-modules-$(KVERS) install-kmod
383 dh_dkms -V $(DEB_VERSION_UPSTREAM)
385 override_dh_installinit:
386 dh_installinit --no-start --no-restart-on-upgrade
388 override_dh_systemd_start:
389 dh_systemd_start --no-start --no-restart-on-upgrade
391 override_dh_auto_test:
394 # dh_python only looks in /usr/share/package_name but dpdk-doc installs in
395 # /usr/share/dpdk, so pass /usr to catch all
396 dh_python3 --shebang=/usr/bin/python3 /usr