#!/usr/bin/make -f

export DH_VERBOSE=1

TDIR=debian/environment-modules
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
LIBDIR:=/usr/lib/$(DEB_HOST_MULTIARCH)

DEB_BUILD_MAINT_OPTIONS:=hardening=+all
DEB_CFLAGS_MAINT_APPEND:= -Wall -pedantic
DEB_LDFLAGS_MAINT_APPEND:= -Wl,--as-needed
export  DEB_BUILD_MAINT_OPTIONS DEB_CFLAGS_MAINT_APPEND DEB_LDFLAGS_MAINT_APPEND

# The magic debhelper  rule
%:
	dh $@ 

override_dh_auto_clean:
	$(MAKE) clean || echo "Make clean skipped"
	rm -f stamp-h

override_dh_auto_configure:
	dh_auto_configure -- \
                --prefix=/usr/share/modules \
		--libexecdir=$(LIBDIR) \
		--mandir=/usr/share/man \
		--etcdir=/etc/environment-modules \
		--initdir=/usr/share/modules/init \
		--with-version-path=/usr/share/modules/versions \
		--with-module-path=/usr/share/modules/modulefiles \
		--with-tcl-ver=8.6 \
		--enable-logging \
		--bindir=/usr/bin #LDFLAGS='$(LDFLAGS) -Wl,--as-needed' CFLAGS='$(CFLAGS) '

override_dh_auto_test:
	-dh_auto_test || echo "Ignoring known test failures in autoinit regexps"

override_dh_auto_install:
	dh_auto_install
	mv $(TDIR)/usr/share/modules/share/doc/* $(TDIR)/usr/share/doc/environment-modules
	rm -rf $(TDIR)/usr/share/modules/share
	rm $(TDIR)/usr/share/doc/environment-modules/COPYING.GPLv2* $(TDIR)/usr/share/doc/environment-modules/INSTALL.txt*
	rm $(TDIR)/usr/share/doc/environment-modules/ChangeLog
	cp debian/profile.sh $(TDIR)/etc/profile.d/modules.sh
	cp debian/modulespath site.exp $(TDIR)/etc/environment-modules
	dh_link /etc/environment-modules/modulespath /usr/share/modules/init/.modulespath 
	dh_link $(LIBDIR)/modulecmd.tcl /usr/lib/modulecmd.tcl
	dh_link /usr/share/modules/init/csh		/etc/csh/login.d/modules
	dh_link /usr/share/modules/init/bash_completion /usr/share/bash-completion/completions/modules
