#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.

# Detect the current build architecture (e.g., x86_64-linux-gnu, aarch64-linux-gnu, etc.)
include /usr/share/dpkg/architecture.mk
BUILD_DIR = obj-$(DEB_HOST_GNU_TYPE)

#export DH_VERBOSE = 1


# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@ --parallel --buildsystem=cmake


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

# Override the default configure step to manage the build directory dynamically
override_dh_auto_configure:
	mkdir -p $(CURDIR)/$(BUILD_DIR)
	cd $(CURDIR)/$(BUILD_DIR) && cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DCMAKE_INSTALL_LIBDIR=lib/$(DEB_HOST_MULTIARCH) \
		-DCMAKE_INSTALL_SYSCONFDIR=/usr/etc \
		$(CURDIR)

# Override the default build step to use architecture-neutral directory
override_dh_auto_build:
	cd $(CURDIR)/$(BUILD_DIR) && $(MAKE) -j$(shell nproc)

# Override the default install step to ensure files are installed correctly
# We use dh_auto_install usually, but keeping your manual logic updated:
override_dh_auto_install:
	cd $(CURDIR)/$(BUILD_DIR) && $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp