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

name = myproxy

INSTALLDIR = debian/tmp

_docdir = /usr/share/doc/$(name)

%:
	dh $@

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	LDFLAGS="$(LDFLAGS) -Wl,--as-needed -Wl,-z,defs" \
	dh_auto_configure -- \
	   --disable-static \
	   --includedir=/usr/include/globus \
	   --with-voms=/usr \
	   --with-openldap=/usr \
	   --with-kerberos5=/usr \
	   --with-sasl2=/usr

override_dh_auto_test:
	dh_auto_test -- VERBOSE=1

override_dh_auto_install:
	dh_auto_install

	# Remove libtool archives (.la files)
	rm $(INSTALLDIR)/usr/lib/*/*.la

	# No need for myproxy-server-setup since the debian package will
	# perform the needed setup
	rm $(INSTALLDIR)/usr/sbin/myproxy-server-setup

	# Move documentation to default debian location
	mkdir -p $(INSTALLDIR)$(_docdir)/extras
	for FILE in login.html myproxy-accepted-credentials-mapapp \
	  myproxy-cert-checker myproxy-certificate-mapapp \
	  myproxy-certreq-checker myproxy-crl.cron myproxy.cron \
	  myproxy-get-delegation.cgi myproxy-get-trustroots.cron \
	  myproxy-passphrase-policy myproxy-revoke ; do \
	  mv $(INSTALLDIR)/usr/share/$(name)/$$FILE \
	     $(INSTALLDIR)$(_docdir)/extras ; \
	done

	for FILE in PROTOCOL README.sasl REPOSITORY VERSION ; do \
	  mv $(INSTALLDIR)/usr/share/$(name)/$$FILE \
	    $(INSTALLDIR)$(_docdir) ; \
	done

	# Remove irrelevant example configuration files
	for FILE in etc.inetd.conf.modifications etc.init.d.myproxy.nonroot \
	  etc.services.modifications etc.xinetd.myproxy \
	  etc.init.d.myproxy LICENSE* ; do \
	  rm $(INSTALLDIR)/usr/share/$(name)/$$FILE ; \
	done

	# Move example configuration file into place
	mkdir -p $(INSTALLDIR)/etc
	mv $(INSTALLDIR)/usr/share/$(name)/myproxy-server.config \
	   $(INSTALLDIR)/etc

	mkdir -p $(INSTALLDIR)/var/lib/$(name)
	chmod 700 $(INSTALLDIR)/var/lib/$(name)

	# Create a directory to hold myproxy owned host certificates
	mkdir -p $(INSTALLDIR)/etc/grid-security/$(name)

	# systemd unit files
	mv $(INSTALLDIR)/usr/share/$(name)/myproxy-server.service debian
	mv $(INSTALLDIR)/usr/share/$(name)/myproxy-server.conf \
	   debian/myproxy-server.tmpfile

override_dh_systemd_enable:
	dh_systemd_enable --no-enable

override_dh_installinit:
	dh_installinit --no-enable

override_dh_missing:
	dh_missing --fail-missing

override_dh_strip:
	dh_strip --dbgsym-migration='lib$(name)-dbg (<< 6.1.28-2~), $(name)-dbg (<< 6.1.28-2~)'

override_dh_fixperms:
	dh_fixperms -X /var/lib/$(name)
