#!/usr/bin/make -f

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

# This is the debhelper compatability version to use.
export DH_COMPAT=3

export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
# FOR AUTOCONF 2.52 AND NEWER ONLY
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
    

INSTALL=$(CURDIR)/debian/tmp

configure: configure-stamp
configure-stamp:
	dh_testdir
	aclocal
	autoconf
	automake
	# Add here commands to configure the package.
	# --enable-SSE apparently only works for i386 platforms
	chmod 744 configure
	./configure $(confflags) --disable-rpath --prefix=/usr --bindir=\$${prefix}/bin \
	--mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info \
	--libdir=\$${prefix}/lib --includedir=\$${prefix}/include \
	--enable-jack-support

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.

	# The LADCCA pkgconfig file forces an RPATH setting that is
	# useless in the scope of a Debian package, and might introduce
	# subtle errors. Remove it. [dk]
	#DEB_OVERRIDE_LADCCA_LIBS="`sed -ne 's@^LADCCA_LIBS[[:space:]]*=[[:space:]]-Wl,--rpath -Wl,/usr/lib \(.*\)@LADCCA_LIBS = \1@p' < Makefile`"; \
	#$(MAKE) "$$DEB_OVERRIDE_LADCCA_LIBS"

	$(MAKE)

	#/usr/bin/docbook-to-man debian/iiwusynth.sgml > iiwusynth.1

	touch build-stamp

clean: autotools
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean
	dh_clean
	find . -name '*.[oa]' -print |xargs rm -rf
	find . -name '*.l[oa]' -print |xargs rm -rf
	find . -name '*.s[oa]' -print |xargs rm -rf
	-rm config.{cache,status,log}
	-rm Makefile
	-rm debian/files
	#-rm src/iiwusynth
	#-rm src/iiwuplay
	-rm -rf src/.libs
	-test -r /usr/share/misc/config.sub && \
	   cp -f /usr/share/misc/config.sub config.sub
	-test -r /usr/share/misc/config.guess && \
	   cp -f /usr/share/misc/config.guess config.guess


install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/(lib)?fluidsynth(-dev)?
	$(MAKE) install DESTDIR=$(INSTALL)
	dh_movefiles --sourcedir=debian/tmp
	
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installlogrotate
#	dh_installinit
#	dh_installcron
	#dh_installman
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs ChangeLog
	dh_link
	dh_makeshlibs
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps -ldebian/libfluidsynth1/usr/lib/
	dh_gencontrol
	dh_md5sums
	dh_builddeb

autotools:
	OLDDATESUB=`./config.sub -t | tr -d -` ;\
	OLDDATEGUESS=`./config.guess -t | tr -d -` ;\
	NEWDATESUB=`/usr/share/misc/config.sub -t | tr -d -` ;\
	NEWDATEGUESS=`/usr/share/misc/config.guess -t | tr -d -` ;\
	if [ $$OLDDATESUB -lt $$NEWDATESUB -o \
	     $$OLDDATEGUESS -lt $$NEWDATEGUESS ]; then \
	   dch -a -p "GNU config automated update: config.sub\
	     ($$OLDDATESUB to $$NEWDATESUB), config.guess\
	     ($$OLDDATEGUESS to $$NEWDATEGUESS)" ;\
	   cp -f /usr/share/misc/config.sub config.sub ;\
	   cp -f /usr/share/misc/config.guess config.guess ;\
	   echo WARNING: GNU config scripts updated from master copies 1>&2 ;\
	fi


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