#!/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 ?= $(strip $(shell egrep '^Source: ' debian/control | cut -f 2 -d ':'))
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)

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

override_dh_usrlocal:
	dh $@

override_dh_auto_install:
	@echo "RULES.$@"
	mkdir -p $(TMP)
	cp distro/pmm-admin $(TMP)/pmm-admin
	cp -f distro/node_exporter $(TMP)/node_exporter
	cp -f distro/mysqld_exporter $(TMP)/mysqld_exporter
	cp -f distro/postgres_exporter $(TMP)/postgres_exporter
	cp -f distro/mongodb_exporter $(TMP)/mongodb_exporter
	cp -f distro/proxysql_exporter $(TMP)/proxysql_exporter
	cp -f distro/percona-qan-agent $(TMP)/percona-qan-agent
	cp -f distro/pt-summary $(TMP)/pt-summary
	cp -f distro/pt-mysql-summary $(TMP)/pt-mysql-summary
	cp -f distro/pt-mongodb-summary $(TMP)/pt-mongodb-summary
	cp -f distro/percona-qan-agent-installer $(TMP)/percona-qan-agent-installer
	install -m 0644 queries-mysqld.yml $(TMP)/queries-mysqld.yml
	install -m 0755 example.prom $(TMP)/example.prom
