#!/usr/bin/make -f

export CFLAGS = -fdebug-prefix-map=$(CURDIR)=. -g

include /usr/share/dpkg/architecture.mk

CONFIGURE_ARGS += --disable-silent-rules
CONFIGURE_ARGS += --verbose
CONFIGURE_ARGS += --includedir=/usr/include/mes/
CONFIGURE_ARGS += --libdir=/usr/lib/$(DEB_HOST_MULTIARCH)/mes/

ifeq ($(DEB_HOST_ARCH),i386)
CONFIGURE_ARGS += --with-bootstrap
endif
ifeq ($(DEB_HOST_ARCH),armhf)
CONFIGURE_ARGS += --with-bootstrap
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_ARGS)

override_dh_auto_build:
	dh_auto_build -- V=2

override_dh_strip:
	dh_strip --exclude=.go --exclude=mes-mescc-static

override_dh_dwz:
	dh_dwz --exclude=.go --exclude=mes

override_dh_install:
	dh_install
	# MES binaries are static, so rename to reflect this
	mv -v debian/mes/usr/bin/mes-gcc debian/mes/usr/bin/mes-gcc-static
ifeq ($(DEB_HOST_ARCH),i386)
	mv -v debian/mes/usr/bin/mes-mescc debian/mes/usr/bin/mes-mescc-static
endif
ifeq ($(DEB_HOST_ARCH),armhf)
	mv -v debian/mes/usr/bin/mes-mescc debian/mes/usr/bin/mes-mescc-static
endif
	# Remove cruft that does not beling in info/doc directories
	rm -vf debian/mes/usr/share/info/images/gcc-mesboot-graph.dot*
	rm -vf debian/mes/usr/share/info/images/README*
	rm -vf debian/mes/usr/share/info/dir*
	rm -vf debian/mes/usr/share/doc/mes/INSTALL*
	rm -vf debian/mes/usr/share/doc/mes/COPYING*

override_dh_auto_clean:
	dh_auto_clean -- maintainer-clean
