#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE=1

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
CROSS= --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
else
CROSS= --build $(DEB_BUILD_GNU_TYPE)
endif

DEB_VERSION := $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')
DEB_NOEPOCH_VERSION := $(shell echo $(DEB_VERSION) | cut -d: -f2-)
DEB_UPSTREAM_VERSION := $(shell echo $(DEB_NOEPOCH_VERSION) | sed 's/-[^-]*$$//')

override_dh_auto_configure:

ifeq "$(DEB_DUMMY)" ""
	cmake -DBUILD_CONFIG=xtrabackup_release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
		-DWITH_SSL=system \
		-DINSTALL_MYSQLTESTDIR=/usr/share/percona-xtrabackup-test \
		-DINSTALL_MANDIR=/usr/share/man . \
		-DDOWNLOAD_BOOST=0 \
		-DWITH_BOOST=boost
else
	# Dummy binaries that avoid compilation
	echo 'main() { return 300; }' | gcc -x c - -o xtrabackup
	echo 'main() { return 300; }' | gcc -x c - -o xtrabackup_55
	echo 'main() { return 300; }' | gcc -x c - -o xtrabackup_56
	echo 'main() { return 300; }' | gcc -x c - -o xbstream
	echo 'main() { return 300; }' | gcc -x c - -o xbcrypt
	echo 'main() { return 300; }' | gcc -x c - -o xbcloud
endif

	#docbook-to-man debian/xtrabackup.sgml > xtrabackup.1

override_dh_strip:
	dh_strip --dbg-package=percona-xtrabackup-dbg

refresh-boost:
	bash debian/bundle-boost.sh $(DEB_UPSTREAM_VERSION)

%:
	dh $@
