#!/usr/bin/make -f
#-*- makefile -*-
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# This version is for a hypothetical package that builds an
# architecture-dependant package, as well as an architecture-independant
# package.

package=sword

version=$(shell expr `pwd` : '.*-\([0-9.]*\)')
version_major=$(shell expr `pwd` : '.*-\([0-9]*\).[0-9.]*')

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

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

export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

confflags =
# FOR AUTOCONF 2.52 AND NEWER ONLY
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  confflags += --build $(DEB_HOST_GNU_TYPE)
else
  confflags += "--build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)"
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	chmod 755 configure
	./configure $(confflags) --prefix=/usr --mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info --with-zlib \
		--sysconfdir=/etc --enable-shared --with-icu
	touch configure.stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	-test -r /usr/share/misc/config.sub && \
	   cp -f /usr/share/misc/config.sub config.sub
	-test -r /usr/share/misc/config.guess && \
	   cp -f /usr/share/misc/config.guess config.guess
	-$(MAKE) distclean
	rm -f build-stamp configure-stamp install-stamp lib/lib* \
		config.h config.status config.log config.cache
	dh_clean

install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/tmp.
	\$(MAKE) install DESTDIR=`pwd`/debian/tmp

	dh_movefiles -plibsword-dev usr/lib/lib*so usr/lib/lib*.a \
		usr/lib/lib*.la usr/include/*
	dh_movefiles -pdiatheke usr/bin/diatheke
	dh_movefiles -plibsword-runtime usr/bin/*
	dh_movefiles -plibsword-config etc/* usr/share/sword/mods.d/globals.conf \
		usr/share/sword/locales.d/*
	#mkdir -p debian/libsword-dev/usr/share/doc/libsword-dev/html
	#cp -R doc/api-documentation/html debian/libsword-dev/usr/share/doc/libsword-dev
	mkdir -p debian/diatheke/usr/share/doc/diatheke/examples
	cp -a apps/console/diatheke/cgi/index-public.html debian/diatheke/usr/share/doc/diatheke/examples
	cp -a apps/console/diatheke/cgi/*.pl debian/diatheke/usr/lib/cgi-bin
	cp -a apps/console/diatheke/README debian/diatheke/usr/share/doc/diatheke
	touch install-stamp

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir 
	dh_testroot 
	dh_installdocs 
	dh_installexamples 
	dh_installinfo
	dh_installmenu 
	#dh_installmanpages
	dh_installman
	dh_undocumented
	dh_installchangelogs ChangeLog
	dh_strip 
	dh_link 
	dh_compress 
	dh_fixperms 
	dh_installdeb
	dh_makeshlibs -V 'libsword3c102 (>=1.5.5.99-1)'
	dh_perl 
	dh_shlibdeps -ldebian/tmp/usr/lib
	dh_gencontrol 
	dh_md5sums 
	dh_builddeb 

#source diff:                                                                  
#	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

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