#!/usr/bin/make -f

export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS=hardening=+bindnow

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

# fclib is header-implemented: in non-header-only builds FCLIB_STATIC is
# empty, so dnrm2()/projectionOnCone() in src/fclib.h become plain C99
# "inline" definitions which do not emit symbols. Without an optimisation
# flag (-O0, CMAKE_BUILD_TYPE=None) GCC does not inline them, leaving
# undefined references in libfclib.so that break linking of fctest1 and
# fctest_merit. Ensure -O2 so these small inline functions are inlined,
# matching the default upstream build (dpkg-buildflags normally provides -O2).
export CFLAGS := $(CFLAGS) -O2

LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)

%:
	dh $@

# Notes: remove rpath due to Debian policy
override_dh_auto_configure:
	dh_auto_configure -- \
	  -DCMAKE_SKIP_BUILD_RPATH=TRUE \
	  -DFORCE_SKIP_RPATH=1 \
	  -DCMAKE_SKIP_INSTALL_RPATH=TRUE \
	  -DCMAKE_SKIP_RPATH=TRUE \
	  -DFCLIB_WITH_MERIT_FUNCTIONS=ON \
	  -DFCLIB_HEADER_ONLY=OFF \
	  -DHARDCODE_NOT_HEADER_ONLY=ON \
	  -DINSTALL_CMAKE_DIR=$(LIBDIR)/cmake/FCLIB
