#!/usr/bin/make -f
# debian/rules for adacontrol.
# Copyright (c) 2006-2012 Ludovic Brenta <lbrenta@debian.org>
# Copyright (c) 2014-2020 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.

DPKG_EXPORT_BUILDFLAGS := 1
DEB_BUILD_MAINT_OPTIONS := hardening=+all
DEB_ADAFLAGS_MAINT_APPEND := -gnatwa
DEB_LDFLAGS_MAINT_APPEND := \
  -Wl,--no-allow-shlib-undefined \
  -Wl,--no-copy-dt-needed-entries \
  -Wl,--no-undefined

ifneq (,$(wildcard /usr/bin/gnatgcc)) # Build-Depends-Arch are installed.
  include /usr/share/dpkg/buildflags.mk
  gnat_version := $(shell /usr/bin/gnatgcc -dumpversion)
  include /usr/share/ada/debian_packaging-$(gnat_version).mk
endif

%:
	dh $@

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

override_dh_auto_build-arch:
	dh_auto_build -- build 'GARGS=$(BUILDER_OPTIONS)'

override_dh_auto_build-indep:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	dh_auto_build --sourcedir=doc
endif

# If .adt files are generated with SOURCE_DATE_EPOCH, ASIS detects
# some tree files as inconsistent, see https://bugs.debian.org/959605.
override_dh_auto_test-arch:
	cd test && GCC=gnatgcc SOURCE_DATE_EPOCH= sh run.sh

# 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
