#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

%:
	dh $@

export DH_VERBOSE=1
export CFLAGS=
export CXXFLAGS=

TMP=$(CURDIR)/debian/tmp/
TMPD=$(CURDIR)/debian/tmp-debug/
prefix=/usr
ARCH = $(shell dpkg-architecture -qDEB_BUILD_ARCH)
ARCH_OS = $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS)
NCPU = $(shell grep -c processor /proc/cpuinfo)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

DEB_SOURCE_PACKAGE ?= proxysql2
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/-[^-]*$$//')
DEB_UPSTREAM_VERSION_MAJOR_MINOR := $(shell echo $(DEB_UPSTREAM_VERSION) | sed -r -n 's/^([0-9]+\.[0-9]+).*/\1/p')
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

EXPORTED_SOURCE_TARBALL = debian/percona-xtradb-cluster-source-5.7.tar.gz

DISTRIBUTION = $(shell lsb_release -i -s)
DISTRELEASE = $(shell lsb_release -c -s)

proxysqldir = proxysql

override_dh_auto_configure:
	@echo "RULES.$@"

	make clean && make
	touch $@ 

override_dh_auto_build:
	@echo "RULES.$@"
	make clean && make
	touch $@ 

override_dh_auto_install:
	@echo "RULES.$@"
	mkdir -p $(TMP)/etc
	mkdir -p $(TMP)/etc/logrotate.d
	mkdir -p $(TMP)/var/lib/proxysql
	mkdir -p $(TMP)/var/run/proxysql
	mkdir -p $(TMP)/etc/init.d
	mkdir -p $(TMP)/var/lib/proxysql
	cp src/proxysql $(TMP)/
	cp etc/proxysql.cnf $(TMP)/etc/
	cp etc/proxysql-admin.cnf $(TMP)/etc/
	cp etc/init.d/proxysql $(TMP)/etc/init.d
	cp tools/proxysql_galera_checker.sh $(TMP)/proxysql_galera_checker
	cp tools/proxysql_galera_writer.pl $(TMP)/proxysql_galera_writer
	cp tools/proxysql-admin $(TMP)/proxysql-admin
	cp tools/proxysql-logrotate $(TMP)/proxysql-logrotate
	cp tools/proxysql-status $(TMP)/proxysql-status

