#!/usr/bin/make -f
export DH_VERBOSE = 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export TOOLCFLAGS = -Wno-error -g

include /usr/share/dpkg/default.mk

COREBOOT_UTILS = cbfstool cbmem ifdtool intelvbttool kbc1126 nvramtool
ifneq (,$(findstring $(DEB_HOST_ARCH), amd64 i386 x32))
COREBOOT_UTILS += bucts ectool intelmetool inteltool msrtool pmh7tool superiotool
endif

%:
	dh $@ --with sphinxdoc

# this might become needed for other tools in the future
override_dh_auto_configure:
	@echo RUN CONFIGURE KEEPS FAILING ELEGANT WORKAROUND
#	$(SHELL export PREFIX=/usr;cd util/msrtool;./configure)
	cp debian/Makefile util/msrtool

override_dh_auto_build:
	set -e; \
	for f in $(COREBOOT_UTILS); do \
		$(MAKE) -C util/$$f;   \
	done
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	# Build docs
	PYTHONPATH=. DEB_VERSION=$(DEB_VERSION) http_proxy='http://127.0.0.1:9/' \
			sphinx-build -N -E -bhtml Documentation build/html
endif

override_dh_clean:
	# TAGS gets cleaned by builtin db_clean, but this is upstream tracked
	dh_auto_clean
	dh_clean --exclude=src/sbom/TAGS

execute_before_dh_install-arch:
ifneq (,$(findstring $(DEB_HOST_ARCH), amd64 i386 x32))
	dh_install util/bucts/bucts usr/sbin
endif

override_dh_sphinxdoc:
ifeq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
	dh_sphinxdoc -p coreboot-utils-doc
endif
