#!/usr/bin/make -f
# -*- makefile -*-

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

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
	CROSS= --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
else
	CROSS= --build $(DEB_BUILD_GNU_TYPE)
endif

configure-flags=$(CROSS) --prefix=/usr --mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info

config-common:
	dh_testdir
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif
	dh_autoreconf
	touch $@

build-%/config-stamp: config-common
	dh_testdir
	mkdir -p build-$*
	cd build-$* && \
		CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs -Wl,--as-needed" \
		$(CURDIR)/configure $(configure-flags) --with-port=$* \
		--program-suffix=-$*
	touch $@

build-%-stamp: build-%/config-stamp
	dh_testdir
	$(MAKE) -C build-$*
	touch $@

build: build-gtk-stamp build-qt-stamp

clean:
	dh_testdir
	dh_testroot

	$(RM) -r build-gtk build-qt

	dh_autoreconf_clean
	dh_clean config-common config.sub config.guess

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	$(MAKE) -C build-gtk install DESTDIR=$(CURDIR)/debian/tmp
	$(MAKE) -C build-qt install DESTDIR=$(CURDIR)/debian/tmp

	dh_install

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

# Build architecture-dependent files here.
binary-arch: install
	dh binary-arch

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