#!/usr/bin/make -f
# output every command that modifies files on the build system.
#DH_VERBOSE = 1

# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk
include /usr/share/dpkg/buildflags.mk

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all reproducible=+all future=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
source_directory=$(CURDIR)
build_directory=build
prefix = $(CURDIR)/debian/tmp

system_description := $(shell lsb_release --description --short)
source_version := $(shell git -C ${source_directory}/exec-helper describe --long --dirty)
version := (${system_description}) ${source_version}
copyright := Copyright (c) $(shell date +'%Y') Bart Verhagen

# main packaging script based on dh7 syntax
%:
	dh $@ '--sourcedirectory=${source_directory}' '--builddirectory=${build_directory}'

override_dh_auto_configure:
	dh_auto_configure -- --unity on -D "usage-documentation=true" -D "api-documentation=false" -D "plugins-prefix=/usr/share/exec-helper/plugins" -D "test=false" -D "version=${version}" -D "copyright=${copyright}" -D "use-system-yaml-cpp=enabled" -D "use-system-lua=enabled"

override_dh_auto_test:
	$(build_directory)/src/applications/exec-helper --help 2>/dev/null | grep --silent 'Usage'
	$(build_directory)/src/applications/exec-helper --version 2>/dev/null | grep --silent 'exec-helper'
	$(build_directory)/src/applications/exec-helper --list-plugins "--additional-search-path=${source_directory}/src/plugins/src/scripts" 2>/dev/null | grep --silent 'make.lua'
