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

CXXFLAGS = -Wall -g
LDFLAGS  = -Wl,-z,defs -Wl,--as-needed

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

CXXFLAGS += -DMOZ_NO_MOZALLOC

configure: configure-stamp
configure-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-plugin-dir=/usr/lib/mozilla/plugins \
		--without-gconf --with-gio --disable-schemas-install \
                --with-xulrunner-sdk=$(shell pkg-config --variable=sdkdir libxul) \
                --enable-new-libxul \
		CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)"

	touch configure-stamp

build: build-stamp

build-stamp: configure-stamp
	dh_testdir

	$(MAKE)

	touch $@

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

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

	rm -f config.sub config.guess
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep

	$(MAKE) DESTDIR=$(CURDIR)/debian/gecko-mediaplayer install

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

build-indep:
build-arch:

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_install
	dh_gconf
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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