#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/cmake.mk
#include /usr/share/cdbs/1/rules/patchsys-quilt.mk

#DEB_CMAKE_EXTRA_FLAGS += -DOPT_FLAGS="" 

O_LD_PATH := $(LD_LIBRARY_PATH)
export LD_LIBRARY_PATH = $(O_LD_PATH):/opt/trinity/lib

DEB_CONFIGURE_INCLUDEDIR := /opt/trinity/include
DEB_CONFIGURE_MANDIR := /opt/trinity/share/man
DEB_CONFIGURE_PREFIX := /opt/trinity
DEB_CONFIGURE_INFODIR := /opt/trinity/share/info

cdbs_configure_flags := --with-qt-dir=/usr/share/qt3 --disable-rpath --with-xinerama $(cdbs_kde_enable_final) $(cdbs_kde_enable_debug)

DEB_CONFIGURE_EXTRA_FLAGS := --prefix=/opt/trinity --with-extra-libs=/opt/trinity/lib

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

DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
ifeq ($(DEB_HOST_ARCH),arm)
# TODO workaround for g++ breakage on arm; debian bug #487406
export CC=gcc-4.2
export CXX=g++-4.2
else
# TODO workaround for cmake breakage; debian bug #459207
export CXX = /usr/bin/g++
export CC = /usr/bin/gcc
endif

# DEB_MAKE_CHECK_TARGET := check

DEB_DH_MAKESHLIBS_ARGS_libept0 = -V

# comment out CONFIGURE and uncomment CMAKE flags to use cmake
#DEB_CONFIGURE_EXTRA_FLAGS += --disable-shared --with-pic
#DEB_CMAKE_EXTRA_FLAGS += -DBUILD_TESTING=ON

# Store build information
common-binary-post-install-arch common-binary-post-install-indep::
	dh_buildinfo

install/libept-trinity-dev::
	mkdir -p debian/tmp/opt/trinity/
	cp -Rp debian/tmp/usr/* debian/tmp/opt/trinity/
	rm -rf debian/tmp/usr/*

build/libept-trinity-dev::
	make -C ${DEB_BUILDDIR} doc

install/libept-trinity-dev::
	mkdir -p debian/tmp/opt/trinity/share/doc/libept-dev/
	cp -r ${DEB_BUILDDIR}/doc/html debian/tmp/opt/trinity/share/doc/libept-dev/
	cp ${DEB_BUILDDIR}/doc/libept.doxytags debian/tmp/opt/trinity/share/doc/libept-dev/
	gzip -9 debian/tmp/opt/trinity/share/doc/libept-dev/libept.doxytags
