#!/usr/bin/make -f

# DEB_BUILD_OPTIONS support.
CFLAGS=-O2 -Wall
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
CFLAGS += -g
endif

INSTALL_PROGRAM=install
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
INSTALL_PROGRAM += -s
endif

build: link-stamp build-stamp
build-stamp:
	dh_testdir
	./configure --prefix=/usr --mandir=/usr/share/man CFLAGS="$(CFLAGS)"
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp link-stamp
	-$(MAKE) distclean
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) INSTALL_PREFIX=`pwd`/debian/ticker \
		INSTALL_PROGRAM="$(INSTALL_PROGRAM)" install

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs README
	dh_installexamples sysinfo-ticker
	dh_installmenu
	dh_installman *.1
	dh_installchangelogs
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Fix links when checking out of cvs by calling this target.
link-stamp:
	sh -e debian/fixlinks
	touch link-stamp

VERSION=$(shell expr "`dpkg-parsechangelog 2>/dev/null |grep Version:`" : '.*Version: \(.*\)')

# Update the web page. Not intended for use by anyone except the
# author.
DIR=/home/web/kitenet.net/programs/ticker
installhook:
	cp debian/changelog $(DIR)/CHANGES
	echo -n $(VERSION) > $(DIR)/LATEST-VERSION-IS
	rm -f $(DIR)/*.tar.gz
	ln -s /home/joey/debian/unstable/ticker_$(VERSION).tar.gz $(DIR)

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