#!/usr/bin/make -f

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

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

CFLAGS = -Wall -g
LDFLAGS= -Wl,--as-needed

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

ifeq ($(DEB_HOST_ARCH_OS),linux)
       EXTRA_CONF_ARGS=--with-alsa --with-flat-volume
endif

configure: config-stamp

config-stamp:
	dh_testdir
#	dh_quilt_patch

	ln -sf /usr/share/misc/config.sub config.sub
	ln -sf /usr/share/misc/config.guess config.guess

	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
	--prefix=/usr --sysconfdir=\$${prefix}/share \
	--with-gio --with-libnotify --with-gconf \
	--with-libmusicbrainz3 --with-gpm-new-method \
	--disable-schemas-install --disable-nautilus \
	$(EXTRA_CONF_ARGS) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"

	touch $@

build: build-stamp

build-stamp: config-stamp
	dh_testdir

	$(MAKE)

	touch $@

clean:
	dh_testdir
	dh_testroot
#	dh_quilt_unpatch
	rm -f build-stamp config-stamp

	[ ! -f Makefile ] || $(MAKE) distclean

	rm -f po/*.gmo config.sub config.guess
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep

	$(MAKE) DESTDIR=$(CURDIR)/debian/gnome-mplayer install

	# remove docs installed by upstream
	rm -rf $(CURDIR)/debian/gnome-mplayer/usr/share/doc/gnome-mplayer

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installman
	dh_installmenu
	dh_installmime
	dh_install
	dh_gconf
	dh_link
	dh_strip -pgnome-mplayer --dbg-package=gnome-mplayer-dbg
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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