#!/usr/bin/make -f

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

DPKG_EXPORT_BUILDFLAGS := 1
DEB_BUILD_MAINT_OPTIONS := hardening=+all
DEB_ADAFLAGS_MAINT_APPEND := -gnatn
DEB_LDFLAGS_MAINT_APPEND := \
  -Wl,--no-allow-shlib-undefined \
  -Wl,--no-copy-dt-needed-entries \
  -Wl,--no-undefined
include /usr/share/dpkg/buildflags.mk
include $(wildcard /usr/share/ada/packaging.mk)
# wildcard means: not during -indep builds.

%:
	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-arch install-indep clean)

# A patch replaces gnatmake with gprbuild.
# Ignore the obsolete Makefile.

# Both kinds need SOVERSION set, allthough only shared uses its value.
common += -XSOVERSION=$(texttools_SO_VERSION)

# Select dependencies with pkg-config instead of hardcoding a version.
#   Author: Sven Joachim <svenjoac@gmx.de>
#   Bug-Debian: https://bugs.debian.org/851608
# Add -lm to the default value, see #717014.
# This is required even for static links, see Linker package.
common += -XLDLIBS='$(shell pkg-config --libs ncurses) -lm'

static := $(common) -XKIND=static
shared := $(common) -XKIND=dynamic

override_dh_auto_configure-arch:
	gprconfig --batch $(GPRCONFIG_FLAGS)
override_dh_auto_build-arch:
	gprbuild -Ptexttools.gpr $(GPRBUILDFLAGS) $(common) $(static)
	gprbuild -Ptexttools.gpr $(GPRBUILDFLAGS) $(common) $(shared)
override_dh_auto_test-arch:
	gprbuild -Pexamples/examples.gpr $(GPRBUILDFLAGS) $(common) $(static)
override_dh_auto_install-arch:
	gprinstall -Ptexttools.gpr $(common) $(static) \
	  $(static_GPRINSTALLFLAGS)
	gprinstall -Ptexttools.gpr $(common) $(shared) \
	  $(call shared_GPRINSTALLFLAGS,texttools)
