#!/usr/bin/make -f
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Some lines taken from debmake, by Cristoph Lameter.

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

CFLAGS=-O2 -Wall
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
CFLAGS += -g
endif
# `nostrip' handled by dh_strip...

datumgrids: datumgrids-stamp
datumgrids-stamp:
	unshar -c -d $(CURDIR)/nad $(CURDIR)/debian/datumgrids.shar
	unshar -c -d $(CURDIR)/nad $(CURDIR)/debian/datumgrids-ch.shar
	touch $@

config: datumgrids config.status
config.status: 
	./configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man

build: config build-stamp
build-stamp:
	dh_testdir
	$(MAKE) CFLAGS="$(CFLAGS)"
	touch $@

clean: 
	dh_testdir
	dh_testroot
	( cd $(CURDIR)/nad && cat $(CURDIR)/debian/datumgrids.list $(CURDIR)/debian/datumgrids-ch.list | xargs rm -f )
	rm -f datumgrids-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f $(CURDIR)/debian/*.log
	dh_clean

install: build install-stamp
install-stamp:
	dh_testdir
	dh_testroot
	dh_installdirs
	dh_prep 
	
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install 
	
	# Fix manpages 
	for man in $(CURDIR)/debian/tmp/usr/share/man/man1/*.1 $(CURDIR)/debian/tmp/usr/share/man/man3/*.3; \
	do \
		sed -i -e 's/^\.nr LL 5.5i$$/\.\\"/' $$man; \
	done
	# Fixating man section in pj_init.3
	sed -i -e 's/\(.TH PJ_INIT\) 3U\(.*\)/\1 3\2/' $(CURDIR)/debian/tmp/usr/share/man/man3/pj_init.3
	touch $@

install-data: build install-data-stamp
install-data-stamp:
	dh_testdir
	dh_testroot
	dh_installdirs
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install-data
	touch $@

# Build architecture-independent files here.
binary-indep: 
	dh_testdir -i
	dh_testroot -i
	dh_install -i
	dh_installdocs -i
	dh_installchangelogs -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: install 
	dh_testdir -a
	dh_testroot -a
	dh_install -a
	dh_installdocs -a AUTHORS README
	dh_installexamples -a
	dh_installman -a
	dh_link -a
	dh_installchangelogs -a ChangeLog upstream
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -a
	dh_shlibdeps -a
	dh_installdeb -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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 datumgrids config install
