#!/usr/bin/make -f
export DH_VERBOSE=1
export TF_CFLAGS += -ffile-prefix-map=$(CURDIR)=.

# Enable verbose build by default, disable when terse is specified.
ifneq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
VERBOSE=0
else
VERBOSE=1
endif

%:
	dh $@

override_dh_auto_build:
# Disable building of arm-trusted-firmware-tools
ifeq ($(filter pkg.arm-trusted-firmware.notools,$(DEB_BUILD_PROFILES)),)
	dh_auto_build --sourcedir=tools/fiptool     -- DEBUG=1 V=$(VERBOSE) HOSTCCFLAGS="$(CFLAGS) $(CPPFLAGS)"
	dh_auto_build --sourcedir=tools/cert_create -- DEBUG=1 V=$(VERBOSE) HOSTCCFLAGS="$(CFLAGS) $(CPPFLAGS) -std=c99 -DUSE_TBBR_DEFS=1"
endif
# Only build firmware on arm64.
ifeq ($(DEB_HOST_ARCH),arm64)
	# Always set CROSS_COMPILE, which also works for native builds.
	grep -v '^#' debian/targets | while read plat targets ; do \
		CROSS_COMPILE=aarch64-linux-gnu- CFLAGS= LDFLAGS= dh_auto_build -- V=$(VERBOSE) DEBUG=1 PLAT=$$plat bl31 ; \
	done
endif

override_dh_installchangelogs:
	dh_installchangelogs -parm-trusted-firmware docs/change-log.rst
	dh_installchangelogs -parm-trusted-firmware-tools
