#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

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

dc       := ${shell cat ctk/configure.in | egrep "^CTK_DEATH_COUNT=[0-9]+$$" | cut -d= -f2}
current  := ${shell cat ctk/configure.in | egrep "^CTK_CURRENT=[0-9]+$$"     | cut -d= -f2}
age      := ${shell cat ctk/configure.in | egrep "^CTK_AGE=[0-9]+$$"         | cut -d= -f2}
revision := ${shell cat ctk/configure.in | egrep "^CTK_REVISION=[0-9]+$$"    | cut -d= -f2}
major    := ${shell expr $(current) - $(age)}

build: build-stamp
build-stamp:
	dh_testdir

	(cd ctk && chmod +x autogen.sh config.guess config.sub install-sh \
		ltconfig missing mkinstalldirs)
	(cd ctk && automake && autoconf && ./configure --prefix=/usr && SED=/bin/sed $(MAKE))
	
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Add here commands to clean up after the build process.
	-(cd ctk/ && if [ -e Makefile ]; then $(MAKE) clean; fi; )
	-(cd ctk/ && rm -f Makefile config.cache config.status config.log libtool )
	
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/tmp.
	# (cd ctk && $(MAKE) prefix=`pwd`/../debian/tmp/usr install)
	
	# This is what goes in libctk<dc>
	install -m0755 ctk/.libs/libctk-$(dc).so.$(major).$(age).$(revision) \
		`pwd`/debian/tmp/usr/lib
	(cd debian/tmp/usr/lib; \
	 ln -s libctk-$(dc).so.$(major).$(age).$(revision) libctk-$(dc).so.$(major))

	# These files go into libctk<dc>-dev
	install -d `pwd`/debian/libctk$(dc)-dev/usr/include/ctk-$(dc)
	install -d `pwd`/debian/libctk$(dc)-dev/usr/lib
	install -m0644 ctk/*.h \
	 `pwd`/debian/libctk$(dc)-dev/usr/include/ctk-$(dc)
	install -m0644 ctk/.libs/libctk.a \
	 `pwd`/debian/libctk$(dc)-dev/usr/lib/libctk-$(dc).a.$(major).$(age).$(revision)
	install -m0644 ctk/.libs/libctk.lai \
	 `pwd`/debian/libctk$(dc)-dev/usr/lib/libctk-$(dc).la.$(major).$(age).$(revision)
	(cd debian/libctk$(dc)-dev/usr/lib; \
	 ln -s libctk-$(dc).so.$(major).$(age).$(revision) libctk-$(dc).so; \
	 ln -s libctk-$(dc).a.$(major).$(age).$(revision) libctk-$(dc).a;   \
	 ln -s libctk-$(dc).la.$(major).$(age).$(revision) libctk-$(dc).la)

	# These files go into libctk-dev
	install -d `pwd`/debian/libctk-dev/usr/include
	install -d `pwd`/debian/libctk-dev/usr/lib
	(cd debian/libctk-dev/usr/include; ln -s ctk-$(dc) ctk)
	(cd debian/libctk-dev/usr/lib; \
	 ln -s libctk-$(dc).so libctk.so; \
	 ln -s libctk-$(dc).la libctk.la; \
	 ln -s libctk-$(dc).a  libctk.a)
	
# 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_testversion
	dh_testdir
	dh_testroot
	#
	# build libctk${major} package by moving files from libctk-dev
	#
	#dh_movefiles -plibctk$(major)             \
	#       usr/lib/libctk.so.$(major)        \
	#       usr/lib/libctk.so.$(version)

	dh_movefiles -plibctk-dev
	dh_movefiles -plibctk$(dc)-dev
#	dh_installdebconf	
	dh_installdocs
	dh_installexamples -plibctk3-dev examples/*.c examples/Makefile
#	dh_installmenu
#	dh_installemacsen
#	dh_installpam
#	dh_installinit
#	dh_installcron
#	dh_installmanpages
#	dh_installinfo
#	dh_undocumented
	dh_installchangelogs 
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	# You may want to make some executables suid here.
#	dh_suidregister
	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
