#!/usr/bin/make -f
# debian/rules for adacontrol.
# Copyright (c) 2006-2012 Ludovic Brenta <lbrenta@debian.org>
# Copyright (c) 2014-2017 Nicolas Boulenguez <nicolas@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# The full text of the GNU General Public License is in the file
# /usr/share/common-licenses/GPL on Debian systems.

gnatgcc_base_version := $(shell gnatgcc -dumpversion)
DEB_BUILD_MAINT_OPTIONS := hardening=+all
include /usr/share/dpkg/default.mk
include /usr/share/ada/debian_packaging-$(gnatgcc_base_version).mk
ADAFLAGS += -gnatwa

%:
	dh $@

.PHONY: $(addprefix override_dh_auto_, \
  configure build-arch build-indep test-arch test-indep install clean)

override_dh_auto_build-arch:
	$(MAKE) build 'CARGS=$(ADAFLAGS)' \
	  'GARGS=$(BUILDER_OPTIONS) "-XLDFLAGS=$(LDFLAGS)"'
override_dh_auto_clean::
	$(MAKE) veryclean

override_dh_auto_build-indep:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	$(MAKE) -C doc
endif
override_dh_auto_clean::
	rm -f \
	  doc/adacontrol_??.html \
	  doc/adacontrol_??.info \
	  doc/adacontrol_??.txt \
	  doc/adacontrol_??.pdf

override_dh_auto_test-arch:
	cd test && sh -e run.sh
override_dh_auto_clean::
	rm -fr test/res
	rm -f $(addprefix test/,*.ali *.adt)

GNAT_VERSION := $(shell gnat --version | head -n1)
override_dh_auto_test-arch: test/ref/tfw_help.txt~
test/ref/tfw_help.txt~:
	sed -i~ \
	  's/^\(ADACTL v\. \).*\( with ASIS .* for \)GNAT .*/\1$(DEB_VERSION_UPSTREAM)\2$(GNAT_VERSION)/' \
	  test/ref/tfw_help.txt
override_dh_auto_clean::
	if test -f test/ref/tfw_help.txt~; then \
	  mv test/ref/tfw_help.txt~ test/ref/tfw_help.txt; \
	fi

# Adactl cannot open compressed rules.
# PDF files are already internally compressed.
.PHONY: override_dh_compress
override_dh_compress:
	dh_compress --package=adacontrol --exclude=.aru
	dh_compress --package=adacontrol-doc --exclude=.pdf
	dh_compress --remaining-packages
