#!/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  --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:
	@echo "Tests currently disabled - csh based test failing"

override_dh_auto_install:
	dh_auto_install
	# Fix brain-dead install locations.
	mv $(TDIR)/usr/modulefiles $(TDIR)/usr/share/modules
	mkdir -p $(TDIR)/usr/share/environment-modules
	mv $(TDIR)/usr/share/doc/* $(TDIR)/usr/share/environment-modules
	mv $(TDIR)/usr/share/environment-modules $(TDIR)/usr/share/doc
	mv $(TDIR)/usr/init $(TDIR)/usr/share/modules/init
	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
	dh_link /etc/environment-modules/modulespath /usr/share/modules/init/.modulespath 
	dh_link $(LIBDIR)/modulecmd.tcl /usr/lib/modulecmd.tcl
