#!/usr/bin/make -f

include /usr/share/dpkg/default.mk
include /usr/share/debhelper/dh_package_notes/package-notes.mk

export DEB_BUILD_MAINT_OPTIONS=hardening=+all
export PREFIX=/usr
export LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)
export FORCE_SYSTEM_LIBBPF=1
export PRODUCTION=1
# For asm/types.h
export BPF_CFLAGS=-Wno-visibility -I/usr/include/$(DEB_HOST_MULTIARCH)
# Workaround for LP: #2103416
export BPF_CFLAGS+=-Wno-unused-command-line-argument
ifneq (,$(filter $(DEB_HOST_MULTIARCH), mips64el-linux-gnuabi64 mipsel-linux-gnu))
export BPF_CFLAGS+= -D__MIPSEL__=1
endif

ifneq (,$(findstring terse,$(DEB_BUILD_OPTIONS)))
export VERBOSE=0
else
export VERBOSE=1
endif

# On Ubuntu, the `bpftool` in path is a shell wrapper pointing at
# the binary corresponding to runtime kernel version.
#
# We do not know the kernel version being used on the system building
# this package, and in sbuild/container environments uname might not
# even match anything available to the build.
# Gladly for the build we only need the tool to generate skeleton code.
#
# If any /usr/lib/linux-tools/*/bpftool exists, locate the most recent
# version and point to that, otherwise `bpftool` from PATH will be
# used.
bpftool_binary := $(shell find -L /usr/lib/linux-tools/ -name 'bpftool' -perm /u=x 2>/dev/null | sort | head -n1)
ifneq ($(bpftool_binary),)
export BPFTOOL=$(bpftool_binary)
endif

%:
	dh $@

# Tests require root and break the testbed
override_dh_auto_test:
