#!/usr/bin/make -f

# DH_VERBOSE := 1
export LC_ALL=C.UTF-8

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

%:
	dh $@

override_dh_auto_build:
	dh_auto_build

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Run the C test suite, which covers the shipped library.  The
	# upstream Python test suite (allTests.py) exercises Python modules
	# that are not shipped in libsonlib-dev and currently fails on
	# Python 3.13, so it is deliberately not run here.
	./bin/sonLibTests CRITICAL
endif

override_dh_install:
	dh_install
	# Install the public headers under /usr/include/sonLib (vg includes
	# <sonLib/sonLib.h>); the bundled CuTest test harness is not shipped.
	mkdir -p debian/libsonlib-dev/usr/include/sonLib
	for header in lib/*.h; do \
		[ "$$header" = "lib/CuTest.h" ] || install -m 0644 "$$header" debian/libsonlib-dev/usr/include/sonLib/; \
	done
	# Name the static archive so that it can be linked with -lsonlib (as
	# vg's Makefile does), not only with its upstream name sonLib.a.
	mv debian/libsonlib-dev/usr/lib/$(DEB_HOST_MULTIARCH)/sonLib.a \
	   debian/libsonlib-dev/usr/lib/$(DEB_HOST_MULTIARCH)/libsonlib.a
