#!/usr/bin/make -f

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

# This ensures we use the correct library path for Debian (e.g., /usr/lib/x86_64-linux-gnu)
include /usr/share/dpkg/architecture.mk

#export DH_VERBOSE = 1

# Standard way to skip the test stage and prevent Nouveau freezes
export DEB_BUILD_OPTIONS = nocheck
export FETCHCONTENT_FULLY_DISCONNECTED=FALSE

# See FEATURE AREAS in dpkg-buildflags(1).
#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 $@


# 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_dh_auto_configure:
	dh_auto_configure -- \
		-DCMAKE_BUILD_TYPE=Release \
		-DMANIFOLD_CROSS_SECTION=OFF \
		-DMANIFOLD_USE_BUILTIN_CLIPPER2=OFF \
		-DMANIFOLD_DOWNLOADS=OFF \
		-DMANIFOLD_PAR=ON \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_INSTALL_LIBDIR=lib/$(DEB_HOST_MULTIARCH) \
		-DMANIFOLD_TEST=OFF

override_dh_auto_install:
	# 1. Run standard CMake install (headers and libs)
	dh_auto_install --destdir=debian/tmp

	# 2. CREATE the doc folder inside debian/tmp manually
	install -d debian/tmp/usr/share/doc/manifold
	
	# 3. COPY the 5 files from your source into that folder
	# This makes them visible in debian/tmp/usr/share/doc/manifold/
	install -m 644 AUTHORS debian/tmp/usr/share/doc/manifold/
	install -m 644 CONTRIBUTING.md debian/tmp/usr/share/doc/manifold/
	install -m 644 LICENSE debian/tmp/usr/share/doc/manifold/
	install -m 644 README.md debian/tmp/usr/share/doc/manifold/
	install -m 644 RELEASE_CHECKLIST.md debian/tmp/usr/share/doc/manifold/

	# 4. Generate the doc-base file so it exists in debian/tmp too
	install -d debian/tmp/usr/share/doc-base
	printf "Document: manifold\nTitle: Manifold\nSection: Science/Math\n\nFormat: HTML\nIndex: /usr/share/doc/manifold/README.md\nFiles: /usr/share/doc/manifold/*\n" > debian/tmp/usr/share/doc-base/manifold.manifold