#!/usr/bin/make -f

##############
# Legal stuff
##############

# Copyright (c) 2003-2009 Ludovic Brenta <lbrenta@debian.org>
# Copyright (c) 2009-2017 Nicolas Boulenguez <nicolas@debian.org>

# This build script 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 3 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.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# On Debian systems, the full text of the GPL is in the file
# /usr/share/common-licenses/GPL-3.

######################
# Set some variables #
######################

define new_line :=


endef
$(eval $(addsuffix $(new_line),$(shell sed -n '\
  s/^ gnat, gnat-\([0-9.]\+\),$$/ \
    GNAT_VERSION:=\1 \
  /p;\
  s/^Package: lib[a-z-]\+\([0-9.]\+\)$$/ \
    SOVERSION:=\1 \
  /p;\
  ' debian/control)))

DEB_BUILD_MAINT_OPTIONS := hardening=+all
include /usr/share/dpkg/default.mk
include /usr/share/ada/debian_packaging-$(GNAT_VERSION).mk

ADAFLAGS += -gnatn
# This is very useful for the thin binding.

######################
# debhelper overrides
######################

%:
	dh $@ --with ada-library

OPTIONS_FOR_UPSTREAM_MAKE = $(foreach var,\
 ADAFLAGS CFLAGS CPPFLAGS LDFLAGS SOVERSION,$(var)="$($(var))") \
 GNATMAKE_OPTIONS="$(BUILDER_OPTIONS)"

.PHONY: override_dh_auto_build override_dh_auto_test
override_dh_auto_build override_dh_auto_test: override_%:
	$* -- $(OPTIONS_FOR_UPSTREAM_MAKE)
override_dh_auto_test: ADAFLAGS += -gnata

# Ignore this target from upstream Makefile.
.PHONY: override_dh_auto_install

.PHONY: override_dh_compress
override_dh_compress:
	dh_compress --all $(addprefix --exclude=,.ads .adb Makefile .c .h)
