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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/default.mk  # provides DEB_VERSION

%:
	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:
	$(MAKE) -C util/bucts # only good for ThinkPad X60/T60
	$(MAKE) -C util/msrtool # see 784120
	$(MAKE) -C util/cbfstool
	$(MAKE) -C util/inteltool
	$(MAKE) -C util/nvramtool
	$(MAKE) -C util/superiotool
	$(MAKE) -C util/pmh7tool
	$(MAKE) -C util/kbc1126
	$(MAKE) -C util/intelvbttool
	$(MAKE) -C util/intelmetool
	$(MAKE) -C util/ifdtool
	$(MAKE) -C util/ectool
	$(MAKE) -C util/cbmem
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	# Build docs
	# Hack the Debian package version into the "release = " variable in Documentation/conf.py
	sed -i 's/^release =.*/release = "$(DEB_VERSION)"/' Documentation/conf.py
	PYTHONPATH=. http_proxy='http://127.0.0.1:9/' sphinx-build -N -E -bhtml Documentation build/html
endif


override_dh_installman-arch:
	mkdir -p debian/tmp
	# some executables do not support --help: fmaptool msrtool nvramtool
	for f in bucts cbfs-compression-tool cbfstool ectool ifdtool ifittool ifwitool intelmetool inteltool intelvbttool pmh7tool rmodtool superiotool; do \
		help2man -s8 -N -n "" -o debian/tmp/$$f.1 debian/coreboot-utils/usr/sbin/$$f; \
	done;
	dh_installman

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