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

name = myproxy

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed -Wl,-z,defs

INSTALLDIR = debian/tmp

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

%:
	dh $@

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure -- \
	   --disable-static \
	   --includedir=/usr/include/globus \
	   --with-voms=/usr \
	   --with-openldap=/usr \
	   --with-kerberos5=/usr \
	   --with-sasl2=/usr

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 \
	  myproxy-server.service myproxy-server.conf 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
	install -p -m 644 systemd/myproxy-server.service \
	    debian/myproxy-server.service
	install -p -m 644 systemd/myproxy-server.conf \
	    debian/myproxy-server.tmpfiles

override_dh_installinit:
	dh_installinit --no-enable

override_dh_installsystemd:
	dh_installsystemd --no-enable

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)
