#!/usr/bin/make -f

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

package=xtide

build:
	$(checkdir)
#ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
#	extracxxflags=-g ./configure --with-xttpd-group=nogroup
#else
#	./configure --with-xttpd-group=nogroup
#endif
	dh_autoreconf
	dh_auto_configure -- --with-xttpd-group=nogroup
	make
#ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
#	CFLAGS = -O2 -g -I$(LIBTCD_DIR)
#endif
	build_tide_db harmonics-initial.tcd debian/harmonics-initial.txt 
	uudecode < debian/icons.tar.uu 

clean:
	$(checkdir)
	rm -f build
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f Makefile Makefile.bak
	rm -f config.log config.status config.cache
	rm -f harmonics.tcd harmonics-initial.tcd
	rm -fR .deps
	rm -f icons.tar
	dh_clean

binary-indep: checkroot build
	$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch: checkroot build
	$(checkdir)
	-rm -rf debian/xtide
	dh_installdirs usr/lib/x86_64-linux-gnu usr/bin usr/sbin usr/share/$(package) etc/logrotate.d
	make DESTDIR=`pwd`/debian/xtide install
# Need to build harmonics-initial.tcd first...
	install -m 644 harmonics-initial.tcd debian/xtide/usr/share/$(package)
	install -m 644 debian/xtide.conf  debian/xtide/etc/xtide.conf
	install -m 644 debian/logrotate   debian/xtide/etc/logrotate.d/xttpd
	tar -xf icons.tar -C debian/xtide
	dh_installdocs
	dh_installchangelogs
	dh_installmenu
	dh_installman -pxtide tide.1 xtide.1 xttpd.8
	dh_installinit  -pxtide  --init-script=xttpd 
	dh_install debian/xtide.desktop usr/share/applications
	dh_icons
	dh_installcron
	dh_strip
	dh_compress
	dh_fixperms
	dh_shlibdeps
	dh_gencontrol
	dh_installdeb
	dh_md5sums
	dh_builddeb

define checkdir
	test -f debian/rules
endef

binary: binary-indep binary-arch

checkroot:
	$(checkdir)
	test root = "`whoami`"

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