#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

UPSTREAM_GIT    ?= http://lab.jerasure.org/jerasure/gf-complete.git

GIT_TAG         ?= $(shell echo '$(DEB_VERSION_UPSTREAM)' | sed -e 's/~/_/')

%:
	dh $@  --with autoreconf --parallel

ifeq ($(DEB_HOST_ARCH_BITS), 32)
override_dh_auto_configure:
	dh_auto_configure -- --disable-sse --disable-neon
endif

override_dh_install:
	dh_install
	# NOTE(jamespage): Don't ship example binaries, just the actual tools
	rm -rf $(CURDIR)/debian/gf-complete-tools/usr/bin/gf_example*

gen-orig-xz:
	git tag -v $(GIT_TAG) || true
	if [ ! -f ../$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.xz ] ; then \
		git archive --prefix=$(DEB_SOURCE)-$(DEB_VERSION_UPSTREAM)/ $(GIT_TAG) | xz >../$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.xz ; \
	fi
	[ ! -e ../build-area ] && mkdir ../build-area || true
	[ ! -e ../build-area/$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.xz ] && cp ../$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.xz ../build-area

fetch-upstream-remote:
	git remote add upstream $(UPSTREAM_GIT) || true
	git fetch upstream
