#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

version=1.0.0

# this is ugly.
# but necessary. I was adviced to modify the rules in that way that an
# ordinary user would not compile msql/mysql per default.
# Here we are...
ifeq ($(shell ls ../--with-mysql),../--with-mysql) 
	ch1:=--with-mysql
endif
ifeq ($(shell ls ../--with-msql),../--with-msql)
	ch2:=--with-msql
endif

build: build-stamp
build-stamp:
	dh_testdir
	./configure --prefix=/usr --with-pgsql $(ch1) $(ch2)
	make
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	-make distclean
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp `find debian/* -type d ! -name CVS` debian/files* core
	-rm -f debian/*substvars
	-rm -rf src/.libs src/.deps
	dh_clean

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

binary-arch: build
	dh_testversion
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# libch
	(cd debian/tmp/usr/lib && \
	cp ../../../../src/.libs/libch.so.1.0.0 . && \
	cp ../../../../src/.libs/libchpgsql.so.1.0.0 . && \
	strip * && \
	ln -sf libch.so.1.0.0 libch.so.1 && \
	ln -sf libchpgsql.so.1.0.0 libchpgsql.so.1;)
	
	# libch-dev
	install -s -m644 src/.libs/libch.a debian/libch-dev/usr/lib
	install -s -m644 src/.libs/libchpgsql.a debian/libch-dev/usr/lib
	install -m664 src/libch.h debian/libch-dev/usr/include

	# libchmsql-mysql
	(cd debian/libchmsql-mysql/usr/lib && \
	cp ../../../../src/.libs/libchm*.so.1.0.0 . && \
	cp ../../../../src/.libs/libchm*.a . && \
	strip * && \
	ln -sf libchmsql.so.1.0.0 libchmsql.so.1 && \
	ln -sf libchmysql.so.1.0.0 libchmysql.so.1)
	
	dh_installdocs
	dh_installdocs -plibch README THANKS TODO
	dh_installmanpages -plibch-dev man/libch.3
	dh_installchangelogs
	dh_fixperms
	dh_compress
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_makeshlibs
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

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

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