+# now stable with parallel comilation, so support -j
+ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+ PAR := $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+ MAKEFLAGS += -j$(PAR)
+endif
+
+ifneq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
+BUILD_DOCS=n
+else
+BUILD_DOCS=y
+endif
+
+ifneq (,$(findstring nostatic,$(DEB_BUILD_OPTIONS)))
+BUILD_STATIC_LIB=n
+else
+BUILD_STATIC_LIB=y
+endif
+
+# kernel_modules can be passed via DEB_BUILD_OPTIONS to enable building the
+# optional binary kernel modules package. By default it will be built against
+# the current kernel, or ksrc can be passed with a path to the target kernel
+# sources instead.
+ifeq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
+DPDK_CONFIG_BUILD_KMOD=n
+KSRC=""
+else
+ifneq (,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
+ KSRC := $(patsubst ksrc=%,%,$(filter ksrc=%,$(DEB_BUILD_OPTIONS)))
+else
+ KSRC := /lib/modules/$(shell uname -r)/build
+endif
+
+KVERS := $(shell perl debian/kernel-version $(KSRC))
+export KVERS
+export MODULE_CFLAGS=-fno-PIE
+
+DPDK_CONFIG_BUILD_KMOD=y
+
+# Since the binary module package is generated at build time depending on the
+# local kernel version, we have to append the new package in d/control.
+# We cannot use a separate control file since that wouldn't work with
+# dpkg-genchanges, and also would require a lot of overrides for debhelpers.
+get_built_using ?= $(filter-out (=),$(shell dpkg-query -f='$${source:Package} (=$${source:Version})' -W $1))
+
+build:
+ @if [ x"$(KVERS)" = x ] ; then \
+ echo 'No version in $(KSRC)/include/linux/version.h' >&2; \
+ exit 1; \
+ fi
+ sh debian/prep-modules $(KSRC)
+ cat debian/control.modules >> debian/control
+ dh $@ --with python2,dkms
+endif
+
+%:
+ dh $@ --with python2,dkms
+
+override_dh_gencontrol:
+ dh_gencontrol
+ # debian/files will not exist until dh_gencontrol has ran at least once,
+ # so we need to run gencontrol for libdpdk-dev and libdpdk-dbgsym after.
+ # The list of libraries and PMDs is everchanging, so generate the dependency
+ # list for libdpdk-dev to avoid having to maintain it manually.
+ # Same for the recommends list for dpdk, were we want the PMDs and the mempools.
+ 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'`"
+ 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'`"
+ifneq (,$(findstring kernel_modules,$(DEB_BUILD_OPTIONS)))
+ dh_gencontrol -p dpdk-modules-$(KVERS) -- \
+ -v`cat debian/VERSION` \
+ -V'built:using:kernel=$(call get_built_using,linux-headers-$(KVERS))'
+endif
+ifneq (,$(findstring dbgsym_meta,$(DEB_BUILD_OPTIONS)))
+ ./debian/dh-dbgsym-metapkg libdpdk$(DPDK_ABI)-dbgsym
+endif
+
+# dbgsym_meta can be passed via DEB_BUILD_OPTIONS to enable building the
+# optional dbgsym meta package libdpdk<ABI>-dbgsym.
+# This is not built by default as it would go in main but depend on
+# packages in the debian-debug archive.
+# Debian Developers and FTP masters strongly discourage this.
+# We provide this optional flag as a convenience for rebuilders.
+ifneq (,$(findstring dbgsym_meta,$(DEB_BUILD_OPTIONS)))
+override_dh_builddeb:
+ dh_builddeb
+ dh_builddeb -plibdpdk$(DPDK_ABI)-dbgsym
+endif