#!/usr/bin/make -f

# Copyright (c) 2003-2009 Ludovic Brenta <lbrenta@debian.org>
# Copyright (c) 2009-2019 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.

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

$(foreach line,$(shell sed -n '\
  s/^ gnat, gnat-\([0-9.]\+\),$$/ \
    GNAT_VERSION:=\1 \
  /p;\
  s/^Package: libtexttools\([0-9.]\+\)$$/ \
    SOVERSION:=\1 \
  /p;\
  ' debian/control),$(eval $(line)))

DEB_BUILD_MAINT_OPTIONS := hardening=+all
DEB_ADAFLAGS_MAINT_APPEND := -gnatn
DEB_LDFLAGS_MAINT_APPEND := -Wl,--no-undefined \
  -Wl,--no-copy-dt-needed-entries -Wl,--no-allow-shlib-undefined
include /usr/share/dpkg/buildflags.mk
ifneq (,$(wildcard /usr/share/ada/debian_packaging-$(GNAT_VERSION).mk))
# The file may not be available during -indep builds.
include /usr/share/ada/debian_packaging-$(GNAT_VERSION).mk
endif

%:
	dh $@

# All these targets are redefined or empty. No implicit default behaviour.
.PHONY: $(addprefix override_dh_auto_, \
  configure build-arch build-indep test-arch test-indep install clean)

OPTS := $(foreach var, \
          ADAFLAGS CC CFLAGS CPPFLAGS LDFLAGS SOVERSION,$(var)="$($(var))") \
          GNATMAKE_OPTIONS="$(BUILDER_OPTIONS)"
override_dh_auto_clean:
	dh_auto_clean -- $(OPTS)
override_dh_auto_build-arch:
	dh_auto_build -a -- $(OPTS)
override_dh_auto_test-arch:
	dh_auto_test -a -- $(OPTS)

# Prevent a warning about autodetection of doc-main-package.
.PHONY: override_dh_installdocs override_dh_installexamples
override_dh_installdocs override_dh_installexamples: override_%:
	$* --package=libtexttools-doc --doc-main-package=libtexttools-doc
	$* --remaining-packages
