#!/usr/bin/make -f

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

include /usr/share/quilt/quilt.make

CFLAGS := -pipe -Wall -g -fpermissive

ifeq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -DNDEBUG
endif
ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O3
endif

VERSION := $(shell dpkg-parsechangelog | sed 's/^Version: //; t; d')
UPSTREAM_VERSION := $(shell dpkg-parsechangelog | sed -n 's/Version:\s\(.*\)-.*/\1/p')

CONFIGURE_OPTIONS := --launcher=external --prefix=/usr --kernel_sources=/usr \
	--cflags="$(CFLAGS)" --version="$(VERSION)"

get-orig-source:
	wget http://bonrom.cbbknet.com/files/RutilTv$(UPSTREAM_VERSION).tar.gz
	mv RutilTv$(UPSTREAM_VERSION).tar.gz ../rutilt_$(UPSTREAM_VERSION).orig.tar.gz

configure: configure-stamp
configure-stamp: $(QUILT_STAMPFN)
	dh_testdir

	./configure.sh $(CONFIGURE_OPTIONS)

	touch configure-stamp

build: build-stamp

build-stamp: configure-stamp
	dh_testdir

	$(MAKE)

	touch $@

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	[ ! -f Makefile -o ! -f Makefile_cst ] || $(MAKE) clean

#clean-up files left by upstream installer
	rm -f helper_launcher.sh rutilt.desktop Makefile_cst \
		include/StaticSettings.h

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 

	$(MAKE) DESTDIR=$(CURDIR)/debian/rutilt install

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installmenu
	dh_install
	dh_icons
	dh_strip
	dh_compress
	dh_fixperms
	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
