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

export DH_VERBOSE=1

export DEB_LDFLAGS_MAINT_APPEND = -Wl,-z,defs -Wl,--as-needed
export QT_SELECT = qt5

paths = \
	Project/GNU/CLI/ \
	Project/GNU/Server/ \
	Project/GNU/Library/ \
	Project/Qt/

auto_build_cmd =				\
	for path in $(paths); do		\
		$(1) -D"$$path";		\
	done

%:
	dh $@ --with=autoreconf

override_dh_auto_configure:
	dh_auto_configure -DProject/GNU/CLI
	dh_auto_configure -DProject/GNU/Server
	dh_auto_configure -DProject/GNU/Library
	dh_auto_configure -DProject/Qt -- USE_WEBKIT=1

override_dh_auto_build:
	$(call auto_build_cmd,dh_auto_build)

override_dh_auto_install:
	$(call auto_build_cmd,dh_auto_install)
	install -dm 755 $(CURDIR)/debian/tmp/usr/bin
	install -m 755 Project/Qt/mediaconch-gui $(CURDIR)/debian/tmp/usr/bin
	install -dm 755 $(CURDIR)/debian/tmp/usr/share/pixmaps
	install -m 644 Source/Resource/Image/MediaConch.xpm $(CURDIR)/debian/tmp/usr/share/pixmaps/mediaconch.xpm
	install -dm 755 $(CURDIR)/debian/tmp/usr/share/icons/hicolor
	install -m 644 Source/Resource/Image/MediaConchBig.png $(CURDIR)/debian/tmp/usr/share/icons/hicolor/mediaconch.png
	install -dm 755 $(CURDIR)/debian/tmp/usr/share/icons/hicolor/256x256/apps
	install -m 644 Source/Resource/Image/MediaConch.png $(CURDIR)/debian/tmp/usr/share/icons/hicolor/256x256/apps/mediaconch.png
	install -dm 755 $(CURDIR)/debian/tmp/usr/share/icons/hicolor/scalable/apps
	install -m 644 Source/Resource/Image/MediaConch.svg $(CURDIR)/debian/tmp/usr/share/icons/hicolor/scalable/apps/mediaconch.svg
	install -dm 755 $(CURDIR)/debian/tmp/usr/share/applications
	install -m 644 Project/GNU/GUI/mediaconch-gui.desktop $(CURDIR)/debian/tmp/usr/share/applications
	install -dm 755 $(CURDIR)/debian/tmp/usr/share/apps/konqueror/servicemenus/
	install -m 644 Project/GNU/GUI/mediaconch-gui.kde3.desktop $(CURDIR)/debian/tmp/usr/share/apps/konqueror/servicemenus/mediaconch-gui.desktop
	install -dm 755 $(CURDIR)/debian/tmp/usr/share/kde4/services/ServiceMenus/
	install -m 644 Project/GNU/GUI/mediaconch-gui.kde4.desktop $(CURDIR)/debian/tmp/usr/share/kde4/services/ServiceMenus/mediaconch-gui.desktop
	install -dm 755 $(CURDIR)/debian/tmp/usr/share/kservices5/ServiceMenus/
	install -m 644 Project/GNU/GUI/mediaconch-gui.kde4.desktop $(CURDIR)/debian/tmp/usr/share/kservices5/ServiceMenus/mediaconch-gui.desktop
	install -dm 755 $(CURDIR)/debian/tmp/usr/share/metainfo
	install -m 644 Project/GNU/GUI/mediaconch-gui.metainfo.xml $(CURDIR)/debian/tmp/usr/share/metainfo

override_dh_auto_clean:
	$(call auto_build_cmd,dh_auto_clean)

override_dh_installman: debian/mediaconch.1
	dh_installman

override_dh_installchangelogs:
	fromdos      *.txt
	chmod 644    *.txt
	dh_installchangelogs -p mediaconch History_CLI.txt
	dh_installchangelogs -p mediaconch-gui History_GUI.txt

override_dh_strip:
	dh_strip -p mediaconch --dbg-package=mediaconch-dbg
	dh_strip -p mediaconch-server --dbg-package=mediaconch-server-dbg
	dh_strip -p libmediaconch0 --dbg-package=libmediaconch0-dbg
	dh_strip -p mediaconch-gui --dbg-package=mediaconch-gui-dbg

clean:
	rm -f debian/*.1
	dh clean --with=autoreconf

%.1: %.pod
	pod2man --center "User Commands" --release=MediaConch\ $(DEB_VERSION_UPSTREAM) $< > $@
