#!/usr/bin/make -f

%:
	dh $@

override_dh_auto_configure:
	autoconf
	./configure --with-runtime-dir=/usr/share/matita \
    		--prefix=/usr/ \
    		--with-dbhost=FAKE_HOST

override_dh_auto_clean:
	dh_auto_clean || true
	rm -f Makefile.defs components/extlib/componentsConf.ml config.log config.status configure matita/.depend.opt matita/help/C/version.txt matita/matita.conf.xml matita/matita.glade.utf8

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp
	cp matita/matita.byte debian/matita/usr/bin/ || true
	cp matita/matitac.byte debian/matita/usr/bin/ || true
	cp matita/matita.opt debian/matita/usr/bin/ || true
	cp matita/matitac.opt debian/matita/usr/bin/ || true
	mkdir -p debian/tmp/usr/share/man/man1/
	MATITA_RT_BASE_DIR=debian/tmp/usr/share/matita/ \
	help2man --name="Matita interative theorem prover - batch compiler" -N \
 		debian/tmp/usr/share/matita/matitac \
 		| gzip -9 > debian/tmp/usr/share/man/man1/matitac.1.gz
	MATITA_RT_BASE_DIR=debian/tmp/usr/share/matita/ \
 	help2man --name="Matita interative theorem prover - cleanup tool" -N \
 		debian/tmp/usr/share/matita/matitaclean \
 		| gzip -9 > debian/tmp/usr/share/man/man1/matitaclean.1.gz
	if [ -e  debian/tmp/usr/share/matita/matitac.opt ]; then\
 		ln -s /usr/share/man/man1/matitac.1.gz \
 			debian/tmp/usr/share/man/man1/matitac.opt.1.gz;\
 	fi
	# install .opt .byte (symlinks are installed with .install
	mkdir -p debian/matita/usr/bin/
	# make depend on the interpreter if needed
	if [ ! -e matita/matitac.opt ]; then \
	        echo "interpreter:Depends=ocaml-base-nox-$(shell ocamlc -version)" \
 	                >> debian/matita.substvars; \
 	else \
 	        echo "interpreter:Depends=" \
 	                >> debian/matita.substvars; \
 	fi
