#!/usr/bin/make -f
# -*- makefile -*-
# 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


CFLAGS = -Wall -g

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

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	STRIP=strip
else
	STRIP=true
endif

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
        NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
        MAKEFLAGS += -j$(NUMJOBS)
endif


configure: configure-stamp
configure-stamp:
	dh_testdir
	#cd src && qmake-qt4 cdcat.pro DEFINES+=MEDIAINFO_STATIC
	cd src &&  qmake-qt4 cdcat.pro
	perl -pe s/usr.local/usr/g -i src/Makefile
	touch configure-stamp

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: configure-stamp
	dh_testdir
	cd src && $(MAKE) $(MAKEFLAGS) && lrelease-qt4 cdcat.pro
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp src/cdcat
	-test -f src/Makefile || ./debian/rules configure 
	-cd src && $(MAKE) clean && rm Makefile
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	cd src && $(MAKE) install INSTALL_ROOT=$(CURDIR)/debian/tmp STRIP=$(STRIP)

binary-indep: build install
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_install
	dh_installchangelogs ChangeLog
	cp debian/cdcat.desktop debian/cdcat/usr/share/applications
	cp cdcat.png debian/cdcat/usr/share/icons
	dh_installdocs
	dh_installman debian/cdcat.1
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installmenu
	-dh_icons
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb -- -Zxz

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