#!/usr/bin/make -f
# This file is public domain software, originally written by Joey Hess. 

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

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

ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
	confflags = --build $(DEB_HOST_GNU_TYPE)
else
	confflags = --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif


build: build-stamp
build-stamp: obj-$(DEB_BUILD_GNU_TYPE)/config.status
	dh_testdir

	cd obj-$(DEB_BUILD_GNU_TYPE) && $(MAKE)

	touch build-stamp

obj-$(DEB_BUILD_GNU_TYPE)/config.status: configure
	dh_testdir
	mkdir obj-$(DEB_BUILD_GNU_TYPE)
	cd obj-$(DEB_BUILD_GNU_TYPE) && ../configure --prefix=/usr $(confflags)

configure: configure.ac
	autoreconf -vfi

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	rm -rf obj-*
	rm -f Makefile.in */Makefile.in
	rm -f aclocal.m4 config.guess config.sub config.h.in configure
	rm -f depcomp install-sh missing
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	cd obj-$(DEB_BUILD_GNU_TYPE) && \
		$(MAKE) DESTDIR=$(CURDIR)/debian/xinput install

# Build architecture-independent files here.
binary-indep: build install

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs README
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
