#!/usr/bin/make -f

# Set LD_LIBRARY_PATH to the installed library directory to allow dh_shlibdeps to function
# Also include the main Trinity path
ifeq ("$(LD_LIBRARY_PATH)", "")
LD_LIBRARY_PATH=debian/tmp/opt/trinity/lib
else
LD_LIBRARY_PATH += :debian/tmp/opt/trinity/lib
endif
export LD_LIBRARY_PATH

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/cmake.mk
include debian/cdbs/debian-tde.mk

DEB_CMAKE_EXTRA_FLAGS := \
 -DCMAKE_EXPORT_COMPILE_COMMANDS="ON" \
 -DLIB_SUFFIX="" \
 -DCMAKE_INSTALL_PREFIX="/opt/trinity" \
 -DCONFIG_INSTALL_DIR="/etc/trinity" \
 -DSYSCONF_INSTALL_DIR="/etc/trinity" \
 -DXDG_MENU_INSTALL_DIR="/etc/xdg/menus" \
 -DCMAKE_LIBRARY_PATH="/opt/trinity/lib" \
 -DCMAKE_INCLUDE_PATH="/opt/trinity/include/" \
 -DCMAKE_VERBOSE_MAKEFILE="ON" \
 -DCMAKE_SKIP_RPATH="OFF" \
 -DCMAKE_BUILD_TYPE=RelWithDebInfo \
 -DBUILD_ALL="ON" \
 -DWITH_TIFF="ON" \
 -DWITH_OPENEXR="ON" \
 -DWITH_PDF="ON"

DEB_DH_STRIP_ARGS  := --dbg-package=tdegraphics-trinity-dbg

DEB_DH_BUILDDEB_ARGS += -- -Z$(shell dpkg-deb --help | grep -q ":.* xz[,.]" \
                               && echo xz || echo bzip2)

PACKAGES_WITH_LIBS := kfaxview-trinity kghostview-trinity kpovmodeler-trinity ksvg-trinity \
			kuickshow-trinity kview-trinity kviewshell-trinity libkscan1-trinity

DEB_DH_MAKESHLIBS_ARGS_kghostview-trinity	:= -V'kghostview-trinity (>= 4:3.5.5-1)'
DEB_DH_MAKESHLIBS_ARGS_kpovmodeler-trinity	:= -V'kpovmodeler-trinity (>= 4:3.5.5-1)'
DEB_DH_MAKESHLIBS_ARGS_ksvg-trinity	:= -V'ksvg-trinity (>= 4:3.5.5-1)'
DEB_DH_MAKESHLIBS_ARGS_kview-trinity	:= -V'kview-trinity (>= 4:3.5.5-1)'
DEB_DH_MAKESHLIBS_ARGS_kviewshell-trinity	:= -V'kviewshell-trinity (>= 4:3.5.5-1)'
DEB_DH_MAKESHLIBS_ARGS_libkscan1-trinity	:= -V'libkscan1-trinity (>= 4:3.5.5-1)'

binary-post-install/kuickshow-trinity::
ifeq ($(DEB_HOST_ARCH), powerpc)
	chrpath -d -k debian/kuickshow-trinity/opt/trinity/lib/libtdeinit_kuickshow.so
endif

#shlibs_ver = 4:3.5.0-1
#$(foreach p,$(PACKAGES_WITH_LIBS),$(eval DEB_DH_MAKESHLIBS_ARGS_$(p) := -V'$(p) (>= $(shlibs_ver))'))

binary-post-install/kpdf-trinity::
	mv debian/kpdf-trinity/usr/share/man debian/kpdf-trinity/opt/trinity/share/

binary-post-install/kghostview-trinity::
	mv debian/kghostview-trinity/usr/share/man debian/kghostview-trinity/opt/trinity/share/

binary-post-install/kcolorchooser-trinity::
	mv debian/kcolorchooser-trinity/usr/share/man debian/kcolorchooser-trinity/opt/trinity/share/

binary-post-install/kdvi-trinity::
	mv debian/kdvi-trinity/usr/share/man debian/kdvi-trinity/opt/trinity/share/

binary-post-install/kfaxview-trinity::
	mv debian/kfaxview-trinity/usr/share/man debian/kfaxview-trinity/opt/trinity/share/

binary-post-install/tdeiconedit-trinity::
	mv debian/tdeiconedit-trinity/usr/share/man debian/tdeiconedit-trinity/opt/trinity/share/

binary-post-install/kooka-trinity::
	mv debian/kooka-trinity/usr/share/man debian/kooka-trinity/opt/trinity/share/

binary-post-install/kpovmodeler-trinity::
	mv debian/kpovmodeler-trinity/usr/share/man debian/kpovmodeler-trinity/opt/trinity/share/

binary-post-install/ksnapshot-trinity::
	mv debian/ksnapshot-trinity/usr/share/man debian/ksnapshot-trinity/opt/trinity/share/

binary-post-install/kview-trinity::
	mv debian/kview-trinity/usr/share/man debian/kview-trinity/opt/trinity/share/

binary-post-install/kcoloredit-trinity::
	mv debian/kcoloredit-trinity/usr/share/man debian/kcoloredit-trinity/opt/trinity/share/

binary-post-install/kfax-trinity::
	mv debian/kfax-trinity/usr/share/man debian/kfax-trinity/opt/trinity/share/

binary-post-install/kolourpaint-trinity::
	mv debian/kolourpaint-trinity/usr/share/man debian/kolourpaint-trinity/opt/trinity/share/

binary-post-install/kruler-trinity::
	mv debian/kruler-trinity/usr/share/man debian/kruler-trinity/opt/trinity/share/

binary-post-install/kuickshow-trinity::
	mv debian/kuickshow-trinity/usr/share/man debian/kuickshow-trinity/opt/trinity/share/

binary-post-install/kviewshell-trinity::
	mv debian/kviewshell-trinity/usr/share/man debian/kviewshell-trinity/opt/trinity/share/