#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1
export QT_SELECT=qt5
export USE_SYSTEM=true

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	cd dvrescue/Project/GNU/CLI && chmod u+x autogen
	cd dvrescue/Project/GNU/CLI && ./autogen
	cd dvrescue/Project/GNU/CLI && ./configure --prefix=/usr

	cd ffmpeg && ./configure --enable-gpl --disable-autodetect --enable-libfreetype --enable-alsa --disable-doc --disable-debug --enable-pic --enable-static --disable-shared --prefix=`pwd`
	cd ffmpeg && $(MAKE) install
	cd ZenLib/Project/GNU/Library && ./configure --enable-static --disable-shared
	cd ZenLib/Project/GNU/Library && $(MAKE)
	cd MediaInfoLib/Project/GNU/Library && ./configure --enable-static --disable-shared --enable-staticlibs
	cd MediaInfoLib/Project/GNU/Library && $(MAKE)
	cd MediaInfo/Project/GNU/CLI && ./configure --enable-staticlibs
	cd MediaInfo/Project/GNU/CLI && $(MAKE)
#	cd xmlstarlet && ./configure

	mkdir -p dvrescue/Source/GUI/dvrescue/build
	cd dvrescue/Source/GUI/dvrescue/build && qmake .. BINDIR=/usr/bin

	touch $@

build: build-stamp
build-stamp: configure-stamp
	dh_testdir

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

	cd dvrescue/Project/GNU/CLI && $(MAKE)
	cd dvrescue/Source/GUI/dvrescue/build && $(MAKE)

	touch $@

clean:
	dh_testdir
	dh_testroot

	# Add here commands to clean up after the build process.
	# $(MAKE) clean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/tmp
	cd dvrescue/Project/GNU/CLI && $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

	install -D -m 755 ffmpeg/ffmpeg $(CURDIR)/debian/tmp/usr/lib/dvrescue/bin/ffmpeg
#	install -D -m 755 xmlstarlet/xml $(CURDIR)/debian/tmp/usr/lib/dvrescue/bin/xmlstarlet
	install -D -m 755 dvrescue/Project/GNU/CLI/dvrescue $(CURDIR)/debian/tmp/usr/lib/dvrescue/bin/dvrescue
	install -D -m 755 MediaInfo/Project/GNU/CLI/mediainfo $(CURDIR)/debian/tmp/usr/lib/dvrescue/bin/mediainfo

	install -D -m 644 dvrescue/LICENSE.txt $(CURDIR)/debian/tmp/usr/share/doc/dvrescue/LICENSE.txt

	install -D -m 644 dvrescue/LICENSE.txt $(CURDIR)/debian/tmp/usr/share/doc/dvrescue-gui/LICENSE.txt
	install -D -m 755 dvrescue/Source/GUI/dvrescue/build/dvrescue/dvrescue $(CURDIR)/debian/tmp/usr/bin/dvrescue-gui

	install -D -m 644 dvrescue/Source/GUI/dvrescue/dvrescue/icons/icon.png $(CURDIR)/debian/tmp/usr/share/pixmaps/dvrescue.png
	install -D -m 644 dvrescue/Project/GNU/GUI/dvrescue-gui.desktop $(CURDIR)/debian/tmp/usr/share/applications/dvrescue-gui.desktop
	install -D -m 644 dvrescue/Project/GNU/GUI/dvrescue-gui.metainfo.xml $(CURDIR)/debian/tmp/usr/share/metainfo/dvrescue-gui.metainfo.xml

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_install --sourcedir=debian/tmp
	dh_installchangelogs -p dvrescue dvrescue/History.txt
	dh_installchangelogs -p dvrescue-gui dvrescue/History.txt
	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 -p dvrescue --dbg-package=dvrescue-dbg
	dh_strip -p dvrescue-gui --dbg-package=dvrescue-gui-dbg
	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 configure
