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

NCPU=$(shell grep -c processor /proc/cpuinfo)

# 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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

override_dh_auto_configure:
	tar -zxpf /usr/src/mysql/mysql-source-8.0.tar.gz -C ..
	mkdir release && cd release && \
	  cmake .. -DBUILD_CONFIG=xtrabackup_release \
	  -DINSTALL_PLUGINDIR=lib/xtrabackup/plugin -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
	  -DDOWNLOAD_BOOST=0 -DWITH_BOOST=../../mysql-8.0/boost/boost_1_77_0 \
	  -DWITH_SSL=system -DWITH_PROTOBUF=system -DWITH_ZLIB=system -DWITH_ZSTD=system

override_dh_auto_build:
	cd release && make -j$(NCPU)

# xbcloud currently does not have a man page, use its help output instead
override_dh_auto_install:
	cd release && help2man -N \
	-n "Manage backups on cloud services" \
	-o ./storage/innobase/xtrabackup/doc/source/build/man/xbcloud.1 ./bin/xbcloud
	dh_auto_install

override_dh_strip:
	dh_strip -Xlibprotobuf-lite

%:
	dh $@
