#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

TARFILE=$(CURDIR)/binutils-2.23.1.tar.xz
BUILD_DIR=$(CURDIR)/build

binutils_src := $(shell dpkg-query -W \
	-f='$${source:Package} (= $${source:Version})' binutils-source)

%:
	dh $@ -B$(BUILD_DIR)

override_dh_auto_configure:
	mkdir -p $(BUILD_DIR)
	cd $(BUILD_DIR) && xzcat $(TARFILE) | tar x --strip-components=1
	# Fix compilation problems
	patch $(BUILD_DIR)/gas/config/tc-z80.c < $(CURDIR)/debian/tc-z80.c.diff
	dh_auto_configure -D$(BUILD_DIR) -- --target=z80-unknown-coff

override_dh_auto_install:
	dh_auto_install --destdir=$(CURDIR)/debian/tmp

override_dh_gencontrol-arch:
	dh_gencontrol -a -- '-Vbu:binutils-source=$(binutils_src)'
