+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
+
+override_dh_auto_clean:
+ rm -rf debian/build debian/tmp debian/dpdk-modules-* \
+ debian/control.modules debian/VERSION
+ sed -i '/Package: dpdk-modules-/,/`tail -n1 debian/control.modules.in`/d' debian/control
+ test -L config/defconfig_$(DPDK_CONFIG) && rm -f config/defconfig_$(DPDK_CONFIG) || true
+ rm -f debian/dpdk-igb-uio-dkms.dkms debian/dpdk-rte-kni-dkms.dkms
+ rm -f debian/dpdk-dev.preinst
+
+override_dh_auto_configure:
+ # Add support for a custom defconfig file in the debian directory.
+ifneq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))
+ test -e config/defconfig_$(DPDK_CONFIG) || ln -fs ../debian/defconfig_$(DPDK_CONFIG) config/defconfig_$(DPDK_CONFIG)
+endif
+ # report dpkg-buildflags status to build log
+ dpkg-buildflags --status
+ echo EXTRA_CFLAGS $$EXTRA_CFLAGS
+ echo EXTRA_LDFLAGS: $$EXTRA_LDFLAGS
+ $(MAKE) V=$(DH_VERBOSE) O=$(DPDK_STATIC_DIR) T=$(DPDK_CONFIG) config
+ifeq (,$(filter dpdk_config=%,$(DEB_BUILD_OPTIONS)))