#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. 
# GNU copyright 1997 by Joey Hess.
#
# This files is based on the example generated by dh_make

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

# This is the debhelper compatability version to use.
export DH_COMPAT=3

# This has to be exported to make some magic below work.
export DH_OPTIONS

# check to see if we want debugging symbols compiled in
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
CFLAGS = -g -O3 -ffast-math
else
CFLAGS = -O3 -ffast-math
endif
export CFLAGS

build: build-stamp
build-stamp:
	dh_testdir
	
	aclocal
	autoconf
	automake 

	# build the binaries
	./configure --prefix=/usr \
	            --mandir=\$${prefix}/share/man \
		    --infodir=\$${prefix}/share/info \
		    --libdir=\$${prefix}/lib/freesci \
		    --bindir=\$${prefix}/games
	$(MAKE)

	# build the docs
	cd doc && sgmltools -b html sci.sgml 
	cd doc && sgmltools -b lynx sci.sgml 

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	-$(MAKE) distclean
	rm -rf doc/sci/ doc/sci.txt
	rm -f config.cache

	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# install binary into debian/freesci
	$(MAKE) install prefix=`pwd`/debian/freesci/usr

	mkdir -p -m 0755   debian/freesci-doc/usr/share/doc/freesci-doc
	cp -a doc/misc/    debian/freesci-doc/usr/share/doc/freesci-doc/
	cp -a doc/sci/     debian/freesci-doc/usr/share/doc/freesci-doc/
	cp -a doc/sci.txt  debian/freesci-doc/usr/share/doc/freesci-doc/
	cp -a doc/sci.sgml debian/freesci-doc/usr/share/doc/freesci-doc/

# Build architecture-independent files here.
binary-indep: DH_OPTIONS=-i
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	ln -s freesci-tools.6.gz \
	  debian/freesci/usr/share/man/man6/sciunpack.6.gz
	ln -s freesci-tools.6.gz \
	  debian/freesci/usr/share/man/man6/sciconsole.6.gz
	ln -s freesci-tools.6.gz \
	  debian/freesci/usr/share/man/man6/scidisasm.6.gz
	dh_installchangelogs ChangeLog
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: DH_OPTIONS=-a
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installmenu
	dh_installchangelogs ChangeLog
	dh_strip
	dh_link
	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
