#!/usr/bin/make -f
#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_BUILD_ARCH	    ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)


CFLAGS = -Wall -fPIC

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

# Use soft-float and thumb mode if it enabled.
ifneq (,$(findstring thumb,$(DEB_BUILD_OPTIONS)))
       CFLAGS += -mthumb
endif

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


gst_major=0
gst_minor=10
gst_micro=9
gst_abi=$(gst_major).$(gst_minor)
gst_lib_dev_dep=libgstreamer-plugins-base$(gst_abi)-0 (>= 0.10.12)

configure:
	#autoreconf -v --install
	autopoint --force
	aclocal -I m4 -I common/m4
	libtoolize --copy --force
	autoheader
	echo timestamp > stamp-h.in 2> /dev/null
	autoconf
	automake -a -c

config.status: configure
	dh_testdir
	# Coping right installation file for extra packag
ifneq (,$(findstring armel,$(DEB_BUILD_ARCH)))
	cp debian/gstreamer0.10-plugins-base-extra.armel.install debian/gstreamer0.10-plugins-base-extra.install
else
	cp debian/gstreamer0.10-plugins-base-extra.i386.install debian/gstreamer0.10-plugins-base-extra.install
endif

	# Add here commands to configure the package.
	CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) \
	--build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --enable-debug \
	--disable-examples --disable-static --disable-nls \
	--enable-pango \
	--disable-cdparanoia --disable-freetypetest \
	--disable-libvisual --enable-theora \
	--enable-ogg --disable-oggtest \
	--disable-vorbis --disable-vorbistest

build: build-stamp
build-stamp:  config.status
	dh_testdir
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	-$(MAKE) distclean
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif


	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp


binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_install --sourcedir=debian/tmp
	dh_installman
	dh_link
	dh_strip --dbg-package=libgstreamer-plugins-base0.10-0  --dbg-package=gstreamer0.10-gnomevfs --dbg-package=gstreamer0.10-plugins-base  --dbg-package=gstreamer0.10-plugins-base-extra
	dh_compress
	dh_fixperms
	dh_makeshlibs -V '$(gst_lib_dev_dep)'
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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