#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Use clang-20 which matches the LLVM version Zig links against.
export CC = clang-20
export CXX = clang++-20

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- \
		-DCMAKE_BUILD_TYPE=Release \
		-DZIG_SHARED_LLVM=ON \
		-DZIG_VERSION="0.15.2" \
		-DCMAKE_INSTALL_PREFIX=/usr

# Zig's cmake install script re-runs the stage3 build with the install prefix.
# dh_auto_install passes DESTDIR but zig's custom install.cmake ignores it.
# Instead, copy the already-built stage3 output to the right location.
override_dh_auto_install:
	mkdir -p debian/tmp/usr/bin debian/tmp/usr/lib debian/tmp/usr/share/man/man1
	cp obj-*/stage3/bin/zig debian/tmp/usr/bin/
	cp -r obj-*/stage3/lib/zig debian/tmp/usr/lib/
	chrpath -d debian/tmp/usr/bin/zig
	LD_LIBRARY_PATH=/usr/lib/llvm-20/lib help2man --no-info --no-discard-stderr \
		--name="Zig programming language compiler and toolchain" \
		--version-string="zig 0.15.2" \
		debian/tmp/usr/bin/zig > debian/tmp/usr/share/man/man1/zig.1

override_dh_auto_test:
	# Tests require a full compiler bootstrap and significant resources.
	echo "Skipping full test suite during build"

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
