#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
export DH_OPTIONS

include /usr/share/cdbs/1/class/mingw64.mk

configure: configure-stamp
configure-stamp:
	dh_testdir
	
	mkdir -p build/64
	cd build/64 && $(CURDIR)/configure \
		--prefix=/usr \
		--program-prefix=$(MINGW64_TARGET)- \
		--with-pc-path=$(MINGW64_SYSROOT)mingw/lib/pkgconfig:$(MINGW64_SYSROOT)mingw/share/pkgconfig \
                --disable-host-tool
	
	mkdir -p build/32
	cd build/32 && $(CURDIR)/configure \
		--prefix=/usr \
		--program-prefix=$(MINGW32_TARGET)- \
		--with-pc-path=$(MINGW32_SYSROOT)mingw/lib/pkgconfig:$(MINGW32_SYSROOT)mingw/share/pkgconfig \
		--disable-host-tool
	
	touch configure-stamp

build: build-stamp
build-stamp: configure-stamp
	
	cd build/64 && $(MAKE) $(MAKEOPTS)
	cd build/32 && $(MAKE) $(MAKEOPTS)
	
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -rf build-stamp configure-stamp build debian/tmp
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_installdirs
	
	mkdir -p $(BUILD_ROOT)
	cd build/64 && $(MAKE) $(MAKEOPTS) install DESTDIR=$(CURDIR)/$(BUILD_ROOT)/64
	cd build/32 && $(MAKE) $(MAKEOPTS) install DESTDIR=$(CURDIR)/$(BUILD_ROOT)/32
	
	# Files which conflict with the all-native pkg-config
	rm -rf $(BUILD_ROOT)/32/usr/share/aclocal
	rm -rf $(BUILD_ROOT)/64/usr/share/aclocal
	rm -rf $(BUILD_ROOT)/32/usr/share/doc/pkg-config
	rm -rf $(BUILD_ROOT)/64/usr/share/doc/pkg-config

	# Make some links to fool us
binary-indep: build install
	#dh_testdir -i
	#dh_testroot -i
	#dh_movefiles -i
	#dh_installdocs -i
	#dh_installexamples -i
	#dh_install -i
	#dh_link -i
	#dh_fixperms -i
	#dh_makeshlibs -i
	#dh_installdeb -i
	#dh_shlibdeps -i
	#dh_installchangelogs ChangeLog
	#dh_gencontrol -i
	#dh_md5sums -i
	#dh_builddeb -i

binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_movefiles -a
	dh_installdocs -a
	dh_installexamples -a
	dh_install -a
	dh_link -a
	dh_fixperms -a
	dh_makeshlibs -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_installchangelogs ChangeLog
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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