#!/usr/bin/make -f

# 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)


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

CFLAGS = -Wall -g

ifneq (,$(findstring alpha,$(DEB_BUILD_GNU_TYPE)))
	CFLAGS += -mieee
endif

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

config.status: configure
	dh_testdir
	# Add here commands to configure the package.
	CFLAGS="$(CFLAGS)" ./configure $(confflags) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --bindir=\$${prefix}/lib/xmms-goom --libdir=\$${prefix}/lib/xmms-goom


build: build-arch build-indep

build-arch: build-stamp

build-indep:
#We aren't building a binary-indep package

build-stamp: config.status
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)

	# libtool massively overlinks the goom2 application.
	# This results in segfaults when glib2 and glib1.2 are linked
	# at the same time.  We'll relink it here
	
	cd sdl-goom && gcc -Wall -g -O2 -o .libs/goom2 -rdynamic frame_rate_tester.o gmtimer.o gtk-callbacks.o gtk-interface.o gtk-support.o pixeldoubler.o readme.o sdl_goom.o sdl_pixeldoubler.o surface.o  `sdl-config --libs` `gtk-config --libs` ../src/.libs/libgoom2.so -Wl,--rpath -Wl,/usr/lib/xmms-goom/
	#/usr/bin/docbook-to-man debian/xmms-goom.sgml > xmms-goom.1

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean
	-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
	
	# Fix any timestamp skew	
	touch configure.in && \
	touch aclocal.m4 && \
	touch Makefile.in src\Makefile.in xmms-goom/Makefile.in sdl-goom/Makefile.in && \
	touch configure
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/xmms-goom.
	$(MAKE) install DESTDIR=$(CURDIR)/debian/xmms-goom

	# remove extra files
	rm -rf $(CURDIR)/debian/xmms-goom/usr/include/
	rm -f $(CURDIR)/debian/xmms-goom/usr/lib/xmms-goom/libgoom2.la
	rm -rf $(CURDIR)/debian/xmms-goom/usr/lib/xmms-goom/pkgconfig/
	rm -f $(CURDIR)/debian/xmms-goom/usr/lib/xmms/Visualization/libxmmsgoom2.la


# Build architecture-independent files here.
binary-indep:
# We aren't making a binary-indep package.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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