#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/dpatch/dpatch.make

DEB_CONFIGURE_INCLUDEDIR := /opt/trinity/include/kde
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_BUILD_ARCH := $(shell dpkg --print-installation-architecture)
ARCH=$(DEB_BUILD_ARCH)

ifeq ($(ARCH),alpha)
CXXFLAGS+=-O0 -mieee
else
CXXFLAGS+=-O2
endif

# DEBUGGING FLAGS.
# CXXFLAGS+=-g3 -gstabs+ -fexceptions
# DEB_BUILD_OPTIONS+=nostrip
# export CXXFLAGS
# export DEB_BUILD_OPTIONS

###

configure: configure-stamp

configure-stamp:
	dh_testdir
	env PATH=/opt/trinity/bin:$(PATH) CMAKE_LIBRARY_PATH=/opt/trinity/lib CMAKE_INCLUDE_PATH=/opt/trinity/include/kde CMAKE_INSTALL_PREFIX=/usr cmake .
	touch configure-stamp

build: build-stamp

build-stamp: configure-stamp patch-stamp 
	dh_testdir
	env PATH=/opt/trinity/bin:$(PATH) CMAKE_LIBRARY_PATH=/opt/trinity/lib CMAKE_INCLUDE_PATH=/opt/trinity/include/kde make
	touch build-stamp

clean: unpatch
	dh_testdir
	dh_testroot

	[ ! -f Makefile ] || make clean
	rm -rf RGbuild
	rm -rf CMakeCache.txt
	rm -rf CMakeFiles
	rm -f build-stamp
	rm -f configure-stamp
	rm -f config.log
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	env PATH=/opt/trinity/bin:$(PATH) CMAKE_LIBRARY_PATH=/opt/trinity/lib CMAKE_INCLUDE_PATH=/opt/trinity/include/kde make install DESTDIR=`pwd`/debian/tmp 
	find debian/tmp/opt/trinity/share -type f -exec chmod 664 {} \;

# 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
	mkdir -p debian/rosegarden-trinity/opt/trinity/share/
	cp -Rp debian/rosegarden-trinity/usr/share/* debian/rosegarden-trinity/opt/trinity/share/
	rm -rf debian/rosegarden-trinity/usr/share/*
	dh_testdir
	dh_testroot
	dh_installexamples
	find debian/rosegarden-trinity/opt/trinity/share/doc/rosegarden -type f -exec chmod 664 {} \;
	dh_installdirs
	dh_installdocs
	dh_installmenu
	dh_installmime
	dh_installcron
	dh_installman debian/rosegarden.1 debian/rosegarden-lilypondview.1 debian/rosegarden-project-package.1 debian/rosegarden-audiofile-importer.1
	dh_desktop
	cp debian/lintianoverrides debian/rosegarden-trinity/opt/trinity/share/lintian/overrides/rosegarden
	dh_installinfo
	dh_installchangelogs
	dh_install
	dh_link
	dh_strip
	dh_compress -X.rg -X.wav -X.docbook
	dh_fixperms
	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
