#!/usr/bin/make -f

# +pie breaks the build
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

pkg := sra-toolkit

%:
	dh $@ --no-parallel

OUTDIR=$(CURDIR)/debian/tmp
MULTIARCH := $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

override_dh_auto_clean:

override_dh_clean:
	dh_clean
	rm -f build/OUTDIR.linux

override_dh_update_autotools_config:
	echo "do nothing"

override_dh_auto_configure:
	# output dir will be checked so create it before
	mkdir -p debian/tmp/usr/lib
	ln -s /usr/lib/$(MULTIARCH) debian/tmp/usr/lib
	#
        # that's no standard configure script lacking support of default options
	#
	# --with-debug sets some options that require header files like compiler.h which
	# is internal to ncbi-vcb and not installed into the package - so this option
	# should not be used.
	./configure --build=$(MULTIARCH) --prefix=$(CURDIR)/debian/tmp/usr --build-prefix=$(CURDIR)/debian/tmp/usr --with-ngs-sdk-prefix=/usr

override_dh_auto_build:
	export LD_LIBRARY_PATH="$$LD_LIBRARY_PATH:$(OUTDIR)/lib"; export OUTDIR=$(OUTDIR) ; make DEB_CFLAGS="$(CFLAGS)" DEB_LDFLAGS="$(LDFLAGS)"

override_dh_install:
	# upstream installs versioned *.a libs - we only want a single version
	for bin in debian/tmp/usr/bin/*[a-z] ; do \
	    mv debian/tmp/usr/bin/`readlink $$bin` $$bin ; \
	    mv debian/tmp/usr/bin/`readlink $$bin` $$bin ; \
	done
	dh_install
	# remove susipcious file which is not executable and conflicts with package magic
	rm -f debian/*/usr/bin/magic
	# rename kget which conflicts with kget download manager (see #851219)
	mv debian/$(pkg)/usr/bin/kget debian/$(pkg)/usr/bin/vdb-get

#override_dh_auto_test:
#	echo "FIXME: try activating tests!!!!!!!!!!!!!!!!!!!!!!!!"

override_dh_prep:
	dh_prep -X debian/tmp

