#! /usr/bin/make -f
%:
	dh $@

CFLAGS := $(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS += $(shell dpkg-buildflags --get CFLAGS)
LFLAGS := $(shell dpkg-buildflags --get LDFLAGS)
buildflags := CFLAGS="$(CFLAGS)" LFLAGS="$(LFLAGS)"

DEB_BUILD_GNU_TYPE := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_TYPE  := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

override_dh_auto_build:
ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
	$(buildflags) dh_auto_build
	$(MAKE) -C doc
else
	$(buildflags) dh_auto_build -- CC=$(DEB_HOST_GNU_TYPE)-gcc
	$(buildflags) $(MAKE) BUILDDIR=build-native
	$(MAKE) -C doc HALIBUT=../build-native/halibut
endif

override_dh_auto_clean:
	$(MAKE) -C doc clean
	dh_auto_clean
	rm -rf build build-native

# Not worth the hassle; we do this ourselves.
override_dh_auto_install:
	:
