#!/usr/bin/make -f
#
# Run as "fakeroot debian/rules binary"
#

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

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

configure: debian/configure-stamp
debian/configure-stamp:
	dh_testdir

	#./configure
	touch debian/configure-stamp

ifeq ($(CORAL_VERSION),)
CORAL_VERSION:=0.$(shell date '+%Y%m%d')
endif
export CORAL_VERSION

.PHONY: debian/files debian/changelog

debian/changelog: debian/changelog.in
	sed -e 's/@coral_version@/$(CORAL_VERSION)/g;' $< > $@

debian/files: debian/files.in
	sed -e 's/@coral_version@/$(CORAL_VERSION)/g;' $< > $@

build: debian/configure-stamp debian/build-stamp

debian/build-stamp: debian/files debian/changelog
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)
	touch debian/build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f debian/build-stamp debian/configure-stamp files

	# Add here commands to clean up after the build process.
	#-$(MAKE) distclean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/coral.
	cp LICENSE coral/modeler/doc/license.html
	$(MAKE) install DESTDIR=$(CURDIR)/debian/coral/
	# Smaller library on debian...
	strip $(CURDIR)/debian/coral/usr/lib/coral/libcoral.so.1.0.0
	mkdir $(CURDIR)/debian/coral/usr || true
	mkdir $(CURDIR)/debian/coral/usr/share || true
	mkdir $(CURDIR)/debian/coral/usr/share/man || true
	mkdir $(CURDIR)/debian/coral/usr/share/man/man1 || true
	gzip -9 -c packaging/man/coral.1 > $(CURDIR)/debian/coral/usr/share/man/man1/coral.1.gz
	gzip -9 -c packaging/man/coral-start.1 > $(CURDIR)/debian/coral/usr/share/man/man1/coral-start.1.gz
	#(cd $(CURDIR)/debian/coral/usr/share/man/man1; ln -s coral.1.gz coral-start.1.gz)

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs
#	dh_installexamples
#	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installman
#	dh_installinfo
#	dh_undocumented
## uncomment to get changelog..
#	dh_installchangelogs ChangeLog
	dh_link
#	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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