#!/usr/bin/make -f

export REPACK_SH=$(CURDIR)/debian/repack.sh

export GPAC_BASE_VER ?= $(shell dpkg-parsechangelog | sed -n 's/Version: \([0-9.]*\)\+.*/\1/p')
export GPAC_SVN_REVISION ?= $(shell dpkg-parsechangelog | grep Version | sed 's/Version:.*+svn\([0-9]\+\).*/\1/')

ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
DEB_CONFIGURE_EXTRA_FLAGS = --disable-opt
endif

%:
	dh $@ --parallel

override_dh_auto_configure:
	dh_auto_configure -- \
	    --prefix=/usr \
	    --libdir=lib \
	    --mandir=\$${prefix}/share/man \
	    --extra-cflags="-Wall -fPIC -DPIC -I/usr/include/mozjs -DXP_UNIX" \
	    --enable-joystick \
	    --enable-debug \
	    --disable-ssl \
	    $(DEB_EXTRA_CONFIGURE_FLAGS)
	echo "#define GPAC_SVN_REVISION	\"$(GPAC_SVN_REVISION)\"" > include/gpac/revision.h
	# workaround broken libav detection
	sed -i 's,CONFIG_LIBAV=no,CONFIG_LIBAV=yes,' config.mak

override_dh_auto_install:
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
	$(MAKE) install-lib DESTDIR=$(CURDIR)/debian/tmp
	mv debian/tmp/usr/share/man/man1/mp4box.1 \
		debian/tmp/usr/share/man/man1/MP4Box.1
	mv debian/tmp/usr/share/man/man1/mp4client.1 \
		debian/tmp/usr/share/man/man1/MP4Client.1

override_dh_auto_clean:
	dh_auto_clean || true

override_dh_clean:
	dh_clean config.h bin/gcc/libgpac*
	dh_clean gpac.pc include/gpac/revision.h
	find $(CURDIR) -name *.opic -delete

override_dh_strip:
	dh_strip -pgpac --dbg-package=gpac-dbg
	dh_strip -pgpac-modules-base --dbg-package=gpac-dbg
	dh_strip -plibgpac3 --dbg-package=libgpac-dbg
	dh_strip --remaining-packages

get-orig-source:
# Use external script
	sh debian/repack.stub `$(dir $_)gpac-$@`
#	uscan --force-download
