#!/usr/bin/make -f

MANTEMPLATE="${CURDIR}/doc/output/man/pgbackrest.1.txt"

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

#export DH_VERBOSE = 1

%:
	dh $@

override_dh_builddeb:
	dh_builddeb -- -Zgzip

override_dh_auto_configure:
	# src contains a seperate configure script.
	cd $(CURDIR)/src && ./configure --prefix=/usr --bindir=/usr/bin
	dh_auto_configure

override_dh_auto_build:
	# Replace user name in doc cache with the current user
	[ $$(whoami) = root ] || sed -i "s/vagrant/$$(whoami)/g" $(CURDIR)/doc/resource/exe.cache

	perl $(CURDIR)/doc/doc.pl --out=man --out=html --cache-only \
	  --var=project-url-root=index.html --exclude=backlog \
	  --var=release-date-static=y
	txt2man \
	  -v "pgBackRest Command Reference" \
	  -t pgbackrest \
	  -s 1 \
	  ${MANTEMPLATE} > ${CURDIR}/doc/output/man/pgbackrest.1
	make -C $(CURDIR)/src/
	dh_auto_build

override_dh_auto_clean:
	rm -rf $(CURDIR)/doc/output
	dh_auto_clean

override_dh_auto_install:
	make -C src install DESTDIR=$(CURDIR)/debian/percona-pgbackrest
	dh_auto_install

.PHONY: build

build:
	dh build
