#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

# FIXME: use cdbs-dh7 and cmake magic stuff instead

CFLAGS = -Wall -g
CMAKEFLAGS = -DCMAKE_PREFIX_PATH=/usr/bin -DCMAKE_INSTALL_PREFIX=/opt/serieswatcher \
	-DQTTVDB_LIBRARY_DIRS=$(CURDIR)/build-qttvdb/lib/ -DQTTVDB_INCLUDE_DIRS=$(CURDIR)/qttvdb/src/

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

configure: configure-stamp
configure-stamp:
	dh_testdir

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp
	dh_testdir

	mkdir -p $(CURDIR)/build-qttvdb
	mkdir -p $(CURDIR)/build

	cd $(CURDIR)/build-qttvdb && cmake $(CMAKEFLAGS) $(CURDIR)/qttvdb/ && $(MAKE)
	cd $(CURDIR)/build && cmake $(CMAKEFLAGS) $(CURDIR) && $(MAKE)

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	rm -rf $(CURDIR)/build-qttvdb
	rm -rf $(CURDIR)/build
	dh_clean debian/shlibs.local
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	cd $(CURDIR)/build-qttvdb && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
	cd $(CURDIR)/build && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install

	chmod +x debian/tmp/opt/serieswatcher/bin/serieswatcher-wrapper

# 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_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	LD_LIBRARY_PATH=debian/opt/serieswatcher/lib:debian/serieswatcher/opt/serieswatcher/lib/ dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
