#!/usr/bin/make -f

%:
	dh $@ --sourcedirectory=c++

ifeq "" "$(filter noopt,$(DEB_BUILD_OPTIONS))"
  WITH_OPTIM=--with-optimization
endif

VDB_SUBTREES=os/$(DEB_HOST_ARCH_OS) os/unix cc/gcc/$(DEB_HOST_GNU_CPU) cc/gcc
VDB_INC=-I/usr/include/ncbi-vdb
VDB_INCLUDE=$(VDB_INC) $(VDB_SUBTREES:%=$(VDB_INC)/%)

override_dh_auto_configure:
	cd c++ && yes | \
        ./configure.orig --prefix=/usr \
	  --with-lmdb \
	  --with-mbedtls \
	  --with-openmp $(WITH_OPTIM) \
	  --with-vdb=/usr VDB_INCLUDE="$(VDB_INCLUDE)" \
	  --without-runpath \
	  --with-flat-makefile

#	  --with-vdb VDB_LIBS=-lncbi-vdb VDB_INCLUDE=-I/usr/include/ncbi-vdb \

override_dh_auto_build:
	cd c++/*/build && make -f Makefile.flat app/igblast/
	find . -name igblastn -o -name igblastp | xargs chrpath --delete

override_dh_auto_install:
	find . -name igblastn
	find . -name igblastp

override_dh_clean:
	# cleans *.orig files, which it should not
	dh_clean -X*.orig
	#Tricky - for each module directory there may be several module files
	#or there may be none but then there is still a module named after the
	#directory.  Clean everything!
	-for x in c++/src/objects/* ; do \
	    (test -d "$$x" && cd "$$x" && ( \
		mods="`echo *.module`" ; \
		[ "$${mods#*\*}" = "$$mods" ] || mods="`basename $$x`" ; \
		for mod in $$mods ; do \
	            ../../../GCC*/build/new_module.sh $$mod \
	                purge_sources ; \
		done ) ; \
	    ) ; \
	done
	rm -rf c++/compilers/dll c++/config.log c++/Makefile c++/GCC*
	rm -f c++/configure.lineno c++/src/objects/blastxml/blastxml.module
	rm -f c++/include/common/ncbi_revision.h
