#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS  = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

%:
	dh $@

MODES = address citmatch contact filter link notify post proxy search spell
STD_WRAPPERS = $(MODES:%=bin/e%)
WRAPPERS = $(STD_WRAPPERS) bin/esummary
AS_IS_SCRIPTS = amino-acid-composition between-two-genes edirutil \
	        entrez-phrase-search filter-stop-words ftp-* \
	        join-into-groups-of nquire reorder-columns sort-uniq-count* \
	        word-at-a-time xy-plot

bin/edirect: edirect.pl
	mkdir -p bin
	install $< $@

$(STD_WRAPPERS): bin/e%: bin/edirect
	echo '#!/bin/sh' > $@
	echo 'exec /usr/bin/edirect -$* "$$@"' >> $@
	chmod +x $@

bin/esummary: bin/edirect
	echo '#!/bin/sh' > $@
	echo 'exec /usr/bin/edirect -fetch -format docsum "$$@"' >> $@
	chmod +x $@

override_dh_auto_build: $(WRAPPERS)
	dh_auto_build
	install $(AS_IS_SCRIPTS) debian/efetch debian/einfo bin/
# Always use gccgo?  The resulting binary would be much smaller, but
# pull in a large shared library with few other reverse dependencies.
	go build -gccgoflags '$(CFLAGS) $(LDFLAGS)' -o bin/xtract xtract.go || \
	    install xtract.pl bin/xtract

override_dh_auto_clean:
	dh_auto_clean
	rm -rf bin
