#!/usr/bin/make -f

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/packaging.mk)
# wildcard in case only Build-Depends-Indep are installed.

%:
	dh $@

######################################################################
# clean target is OK.

override_dh_auto_build-arch:
# static library
	gprbuild lib/gnat/aunit.gpr $(GPRBUILDFLAGS) -XSOVERSION=
# shared library
	gprbuild lib/gnat/aunit.gpr $(GPRBUILDFLAGS) \
	  -XSOVERSION=$(aunit_SO_VERSION)

override_dh_auto_install-arch:
	gprinstall lib/gnat/aunit.gpr $(static_GPRINSTALLFLAGS) -XSOVERSION=
	gprinstall lib/gnat/aunit.gpr $(call shared_GPRINSTALLFLAGS,aunit) \
	  -XSOVERSION=$(aunit_SO_VERSION)
######################################################################
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
    # Avoid dh_auto_build (make -jN would launch several sphinx).
	$(MAKE) -Cdoc aunit_cb.html aunit_cb.pdf aunit_cb.txt \
	  $(DEB_BUILD_OPTION_PARALLEL:%=SPHINXOPTS=-j%)
  endif

override_dh_auto_install-indep:
