#!/usr/bin/make -f
# Debian build script for log4Ada
# Copyright 2009-2016 Xavier Grave <xavier.grave@csnsm.in2p3.fr>
# Copyright 2016-2019 Nicolas Boulenguez <nicolas@debian.org>

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

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
ifneq (,$(wildcard /usr/bin/gnatgcc))
  # Only present if Build-Depends-Arch are installed.
  include /usr/share/ada/debian_packaging-$(shell gnatgcc -dumpversion).mk
endif

%:
	dh $@

# Ignore these targets from upstream GNUmakefile.
.PHONY: $(addprefix override_dh_auto_,build-arch build-indep install clean)

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

override_dh_auto_clean:
	rm -fr lib obj-relocatable obj-static
	$(MAKE) -C doc clean

gpr := log4ada.gpr

override_dh_auto_build-arch:
	gprbuild -p $(BUILDER_OPTIONS) $(gpr) \
	  -XLIBRARY_TYPE=static \
	  $(foreach v,ADAFLAGS,"-X$(v)=$($(v))")
	gprbuild -p $(BUILDER_OPTIONS) $(gpr) \
	  -XLIBRARY_TYPE=relocatable \
	  $(foreach v,ADAFLAGS LDFLAGS soname,"-X$(v)=$($(v))")

# The only effect should be to avoid a debhelper warning.
.PHONY: override_dh_installdocs override_dh_installexamples
override_dh_installdocs override_dh_installexamples: override_%:
	$* --package=liblog4ada-doc --doc-main-package=liblog4ada-doc
	$* --remaining-packages
