#!/usr/bin/make -f
# -*- makefile -*-
#
# debian package by Alessandro Amici 2002-2003.
# Based on: GNU copyright 1997 to 1999 by Joey Hess.

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

# This is the debhelper compatibility version to use.
export DH_COMPAT=4

# extract the non-prefix part of INST_PYMOD
inst_pymod=$(shell awk -F '/usr' '/INST_PYMOD/ {print $$2}' GDALmake.opt)

config.status:
	dh_testdir

	./configure --prefix=/usr \
		--mandir=\$$\{prefix\}/share/man \
		--with-threads \
		--with-grass=no \
		--with-geotiff=internal \
		--with-jasper \
		--with-netcdf \
		--with-xerces \
		--with-sqlite

	# Patch the generated libtool to avoid passing -rpath when linking,
	# and to explicitly link libraries against the libraries they
	# depend on.
	sed < libtool > libtool-2 \
	-e 's/^hardcode_libdir_flag_spec.*$$/hardcode_libdir_flag_spec=" -D__LIBTOOL_IS_A_FOOL__ "/' \
	-e '/^archive_cmds="/s/"$$/ \\$$deplibs"/' \
	-e 's/^hardcode_into_libs.*$$/hardcode_into_libs=no/'
	mv libtool-2 libtool
	chmod 755 libtool 


build: build-stamp
build-stamp: config.status
	dh_testdir

	$(MAKE)
	$(MAKE) docs

	touch build-stamp

clean:
	# reminiscence to old procedure of building man pages, will now created
	# by doxygen. This rm will be deleted in further releases of gdal
	sh -c "if (test -d man/man1) then rm -r man/man1; fi"

	dh_testdir
	dh_testroot

	-$(MAKE) distclean

	dh_clean build-stamp configure-stamp

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) install prefix=$(CURDIR)/debian/tmp/usr \
		"INST_PYMOD=\$$(prefix)$(inst_pymod)"
	$(MAKE) install-docs prefix=$(CURDIR)/debian/tmp/usr \
		"INST_DOCS=\$$(prefix)/share/doc/libgdal-doc"\
		"INST_MAN=\$$(prefix)/share/man"

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_movefiles
	dh_installdocs
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs -V'libgdal1 (>= 1.2.0)'
	dh_installdeb
	dh_shlibdeps -l.
	dh_python
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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