#!/usr/bin/make -f

# Extract useful information from debian/control.
$(foreach line,$(shell sed -nr '\
  s/^Package: libalog([0-9.]+)$$/ soversion:=\1    /p;\
  s/^ gnat-([0-9]+).*/            gnat_version:=\1 /p;\
 ' debian/control),$(eval $(line)))

DPKG_EXPORT_BUILDFLAGS  = 1
DEB_BUILD_MAINT_OPTIONS = hardening=+all
DEB_LDFLAGS_MAINT_APPEND := -Wl,--no-undefined \
  -Wl,--no-copy-dt-needed-entries -Wl,--no-allow-shlib-undefined
include /usr/share/dpkg/buildflags.mk

# wildcard means: not during -indep builds.
include $(wildcard /usr/share/ada/debian_packaging-$(gnat_version).mk)

export GNAT_BUILDER_FLAGS = $(BUILDER_OPTIONS)

%:
	dh $@

override_dh_auto_build-arch:
ifeq ($(DEB_HOST_ARCH),kfreebsd-i386)
	patch -p1 < debian/Don-t-store-tracebacks-in-exception-occurrences.patch
endif
	dh_auto_build -- VERSION=$(soversion)
	dh_auto_build -- LIBRARY_KIND=static

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

override_dh_auto_install:

override_dh_auto_test-indep:
override_dh_auto_test-arch:
	dh_auto_build -- tests

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