#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

%:
	dh $@

override_dh_auto_configure: MAYBE_HOST_CPU=$(shell \
	if [ "${DEB_BUILD_GNU_CPU}" = "i686" ]; then \
	  echo "host_cpu=\\\"x86\\\"";\
	elif [ "${DEB_BUILD_GNU_CPU}" = "x86_64" ]; then \
	  echo "host_cpu=\\\"x64\\\"";\
	elif [ "${DEB_BUILD_GNU_CPU}" = "aarch64" ]; then \
	  echo "host_cpu=\\\"arm64\\\"";\
	elif [ "${DEB_BUILD_GNU_CPU}" = "arm64" ]; then \
	  echo "host_cpu=\\\"arm64\\\"";\
	elif [ "${DEB_BUILD_GNU_CPU:0:3}" == "arm" ]; then \
	  echo "host_cpu=\\\"arm\\\"";\
	fi\
)
override_dh_auto_configure:
	env
	uname -a
	gn gen out/release --args="is_debug=false use_custom_libcxx=false\
	  is_hermetic_clang=false is_system_compiler=true is_clang=false\
	  skip_buildtools_check=true enable_perfetto_integration_tests=false\
	  enable_perfetto_unittests=false perfetto_use_system_protobuf=true\
	  perfetto_use_system_zlib=true perfetto_enable_git_rev_version_header=false\
	  extra_cflags=\"${CFLAGS}\" extra_cxxflags=\"${CXXFLAGS}\"\
	  extra_ldflags=\"${LDFLAGS}\" cc=\"${CC}\" cxx=\"${CXX}\"\
	  ${MAYBE_HOST_CPU}"

override_dh_auto_build:
	ninja -C out/release perfetto traced traced_probes
	pandoc docs/reference/perfetto-cli.md -s -t man --shift-heading-level-by=-1 >\
	 debian/perfetto.1

override_dh_auto_clean:
	rm -rf out/release