#!/usr/bin/make -f

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

include /usr/share/dpatch/dpatch.make

# CFLAGS = -Wall -fPIC -g
CFLAGS = -Wall -fPIC -g

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

config.status: configure.in patch-stamp
	dh_testdir
	mv -f configure configure.orig
	mv -f aclocal.m4 aclocal.m4.orig
	aclocal -I . -I tclconfig
	autoconf
	CC=g++ ./configure --prefix=/usr --with-tcl=/usr/lib/tcl8.4 --with-tclinclude=/usr/include/tcl8.4 CFLAGS="$(CFLAGS)"
	mv -f configure.orig configure
	mv -f aclocal.m4.orig aclocal.m4

build: build-stamp
build-stamp: config.status
	dh_testdir
	$(MAKE)
clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean 

install:
	dh_testdir
	dh_testroot
	dh_clean -k
	$(MAKE) DESTDIR=debian/tmp install

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_install --sourcedir=debian/tmp
	dh_link
	dh_strip
	dh_compress -s
	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
