#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/cmake.mk

DEB_SRCDIR              := cmake
DEB_MAKE_INSTALL_TARGET :=

DEB_DH_BUILDDEB_ARGS = -- -Zxz

## dh does not seem to propagate the correct options to cmake configure step
#%:
#	dh $@ --parallel --buildsystem=cmake

#override_dh_auto_build:
makebuilddir::
	# create backups of original *generated_forwards.h files to build twice in a row
	for header in `find seqan -name "*generated_forwards.h"` ; do \
	  mkdir -p orig/`dirname $$header` ; \
	  cp -a $$header orig/$${header} ; \
	done
#	dh_auto_build

#override_dh_auto_install:
#	dh_auto_install
install/seqan-apps:: debian/stamp-install-seqan-apps
debian/stamp-install-seqan-apps:
	#install binaries
	for APP in `find $(CURDIR)/obj*/apps -mindepth 1 -maxdepth 1 -executable -type f` ; do \
	  cp -a $$APP $(CURDIR)/debian/seqan-apps/usr/lib/sequan/bin/ ; done
	#install readmes
	for APP in `find apps -name README` ; do \
	  app=`echo $$APP | sed 's?.*apps/\(.\+\)/README?\1?'` ; \
	  echo $$app ; \
	  cp -a $$APP $(CURDIR)/debian/seqan-apps/usr/share/doc/seqan-apps/README.$$app ; \
	done

# Delete extra license files
install/seqan-dev::
	@echo "This should be post-install action after installing files for seqan-dev ... but the doc is lying :-("
	find debian -type f -name LICENSE -delete
	# FIXME: Anybody able to convince cdbs to do what the doc is promising and remove the unneeded LICENSE files?

#override_dh_auto_clean:
#	dh_auto_clean
clean::
	if [ -d orig ] ; then \
	  for header in `find orig -name "*generated_forwards.h"` ; do \
	    mv $${header} `echo $$header | sed 's?orig/??'` ; \
	  done ; \
	fi
	rm -rf orig

get-orig-source:
	uscan --force-download
	@echo successfully retrieved upstream tarball


