#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

%:
	dh $@ --with quilt

override_dh_auto_install :
	make install DESTDIR=$(CURDIR)/debian/mira-assembler
	#There is no installation target for the docs
	mkdir -p $(CURDIR)/debian/tmp/usr/share/doc/mira-assembler
	cp -r -t $(CURDIR)/debian/tmp/usr/share/doc/mira-assembler doc/docbook/bookfigures doc/docbook/images \
	    doc/docbook/doccss doc/docbook/DefinitiveGuideToMIRA.html || true

override_dh_auto_test:
	make check

#Make the docs
override_dh_auto_build:
	dh_auto_build
ifneq (,$(findstring mira-doc, $(shell dh_listpackages)))
	dh_auto_build --sourcedir=doc
endif

#Remove unneeded .tcl extensions from scripts
override_dh_install:
	dh_install
	if [ -d debian/mira-assembler ] ; then \
	  for f in $$(ls debian/mira-assembler/usr/bin/*.tcl) ; do mv "$$f" "$${f%.tcl}"; done \
	fi

#Hacky thing to allow building against tcmalloc without installing
#troublesome libbgoogle-perftools-dev, see README.Debian
export LDFLAGS=-L$(CURDIR)/lib

#Must clean up the docs before cleaning out config.status
#Then scrub some junk not picked up by 'make clean'
override_dh_auto_clean:
	( cd doc ; make clean ) || true
	dh_auto_clean
	find * -name Makefile -exec rm '{}' ';'
	find * -name '*.xxd.H' -exec rm '{}' ';'
	find * -name '*.par.H' -exec rm '{}' ';'
	find * -name 'compileinfo.*' -exec rm '{}' ';'

override_dh_clean:
	dh_clean
	rm -rf lib

override_dh_auto_configure :
	mkdir lib
	ln -s /usr/lib/libtcmalloc_minimal.so.0 lib/libtcmalloc_minimal.so
	dh_auto_configure

