#!/usr/bin/make -f

SOVERSION != \
  sed -n '/^Package: libaunit\([0-9.]\+\)$$/{s//\1/p;q}' debian/control

DPKG_EXPORT_BUILDFLAGS := 1
DEB_BUILD_MAINT_OPTIONS := hardening=+all
DEB_ADAFLAGS_MAINT_APPEND := -gnatfno -gnatwa -gnatVa
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 /usr/share/dpkg/buildopts.mk
include $(wildcard /usr/share/ada/debian_packaging.mk)
# wildcard in case only Build-Depends-Indep are installed.

%:
	dh $@

######################################################################
# Ignore upstream Makefile/configure.
.PHONY: $(addprefix override_dh_auto_,configure build-arch build-indep test install)
# clean target is OK.

override_dh_auto_build-arch:
# static library
	dh_auto_build -- GPRBUILD='gprbuild $(GPRBUILDFLAGS)'
# shared library
	SOVERSION=$(SOVERSION) \
	dh_auto_build -- GPRBUILD='gprbuild $(GPRBUILDFLAGS)'

######################################################################
INSTALLED_EXAMPLES := \
  debian/libaunit-doc/usr/share/doc/libaunit-doc/examples/*/

.PHONY: execute_after_dh_installexamples-indep
execute_after_dh_installexamples-indep:
  # Replace duplicate files with symlinks.
	rdfind -makeresultsfile false -makesymlinks true $(INSTALLED_EXAMPLES)
  # Make these symlinks relative.
	symlinks -r -s -c $(INSTALLED_EXAMPLES)

override_dh_auto_build-indep:
  ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
    # Replace sphinx.sty copy with with packaged one.
	ln -fs /usr/share/sphinx/texinputs/sphinx.sty doc/share/sphinx.sty
	dh_auto_build --sourcedirectory=doc -- aunit_cb.html aunit_cb.pdf aunit_cb.txt \
	  $(addprefix SPHINXOPTS=-j,$(DEB_BUILD_OPTION_PARALLEL))
  endif
