#!/usr/bin/make -f
# -*- makefile -*-

name = globus-simple-ca
_name = globus_simple_ca

INSTALLDIR = $(CURDIR)/debian/tmp
GLOBUSPACKAGEDIR = $(INSTALLDIR)$(_datadir)/globus/packages

_prefix = /usr
_bindir = $(_prefix)/bin
_sbindir = $(_prefix)/sbin
_libdir = $(_prefix)/lib
_datadir = $(_prefix)/share
_mandir = $(_datadir)/man
_docdir = $(_datadir)/doc/$(name)

configure: configure-stamp

configure-stamp:
	dh_testdir

	dh_autotools-dev_updateconfig

	/usr/share/globus/globus-bootstrap.sh

	./configure \
	   --disable-static \
	   --without-flavor \
	   --with-docdir=$(_docdir)

	touch $@

build: build-arch build-indep

build-arch:

build-indep: build-stamp

build-stamp: configure-stamp
	dh_testdir

	$(MAKE)

	touch $@

clean:
	dh_testdir
	dh_testroot

	if [ -r Makefile ] ; then $(MAKE) distclean ; fi

	dh_autotools-dev_restoreconfig

	# Remove autogenerated files

	rm -f aclocal.m4
	rm -f compile
	rm -f configure
	rm -f install-sh
	rm -f ltmain.sh
	rm -f missing
	rm -f mkinstalldirs

	rm -f doxygen/Doxyfile*
	rm -f doxygen/Makefile.am
	rm -f pkgdata/Makefile.am
	rm -f pkgdata/*.filelist
	rm -f pkgdata/*.gpt
	rm -f pkgdata/$(name).pc
	rm -f pkgdata/pkg_data_src.pc.in
	rm -f gptdata.sh
	rm -f globus_automake*
	rm -rf autom4te.cache

	find . -name Makefile.in -exec rm {} ';'

	rm -f build-stamp configure-stamp

	dh_clean debian/*.install

install: build-stamp
	dh_testdir
	dh_testroot
	dh_prep

	$(MAKE) install DESTDIR=$(INSTALLDIR)

	# Remove installed license file
	rm -f $(INSTALLDIR)$(_docdir)/GLOBUS_LICENSE
	sed /GLOBUS_LICENSE/d \
	  -i $(GLOBUSPACKAGEDIR)/$(_name)/noflavor_doc.filelist

	# Generate package filelists
	cat $(GLOBUSPACKAGEDIR)/$(_name)/noflavor_pgm.filelist \
	    $(GLOBUSPACKAGEDIR)/$(_name)/noflavor_data.filelist \
	    $(GLOBUSPACKAGEDIR)/$(_name)/noflavor_doc.filelist \
	  | sed s!^!debian/tmp$(_prefix)! > debian/$(name).install

binary: binary-arch binary-indep

binary-arch:

binary-indep: install
	dh_testdir
	dh_testroot
	dh_installdocs debian/README
	dh_installchangelogs
	dh_install --fail-missing
	dh_installman
	dh_link
	dh_compress
	dh_fixperms
	dh_perl
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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