#!/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:
	make DEBUG=1 V=$(VERBOSE) HOSTCCFLAGS="$(CFLAGS) $(CPPFLAGS)" -C tools/fiptool
	make DEBUG=1 V=$(VERBOSE) HOSTCCFLAGS="$(CFLAGS) $(CPPFLAGS) -std=c99 -DUSE_TBBR_DEFS=1" -C tools/cert_create
# 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= make V=$(VERBOSE) DEBUG=1 PLAT=$$plat bl31 ; \
	done
endif

override_dh_installdocs:
	# Rename changelog to comply with debian policy.
	cp docs/change-log.rst docs/changelog
	dh_installdocs
	rm docs/changelog
