#!/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.
OPTS := \
  SOVERSION=$(texttools_SO_VERSION) \
  GNATMAKE_OPTIONS='$(GPRBUILDFLAGS)' \
  SRC_DIR=$(DEB_ADA_SOURCE_DIR) \
  GPR_DIR=$(DEB_GNAT_PROJECT_DIR) \
  ALI_DIR=$(DEB_ADA_LIB_INFO_DIR) \
  LIB_DIR=$(DEB_LIB_DIR) \
  # EOL

# Add -lm to the default value, see #717014.
OPTS += "LDLIBS=`pkg-config --libs ncurses` -lm"

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)
override_dh_auto_install-arch:
	dh_auto_install -a -- $(OPTS)

# Prevent a warning about autodetection of doc-main-package.
doc_pkg := libtexttools-doc
execute_before_dh_installdocs:
	dh_installdocs --package=$(doc_pkg) --doc-main-package=$(doc_pkg)
execute_before_dh_installexamples:
	dh_installexamples --package=$(doc_pkg) --doc-main-package=$(doc_pkg)
