#!/usr/bin/make -f

VERSION=0.14

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	pwd
	ln -s /usr/lib/llvm-19/lib/clang/19/include/ lib/include
	# without specifying MCPU, it targets native
	#	we want to specify -DZIG_TARGET_TRIPLE=$(DEB_HOST_MULTIARCH), but it breaks PIE
	dh_auto_configure -- \
		-DZIG_PIE=ON \
		-DZIG_SHARED_LLVM=ON \
		-DZIG_TARGET_MCPU=$(DEB_HOST_GNU_CPU)

# output of build is stage3/bin and stage3/lib
export BBASE:=obj-$(DEB_HOST_MULTIARCH)/stage3

# make a man page and move the docs to usr/share/doc
override_dh_auto_install:
	help2man -s 1 -N -n "zig compiler and build tool" -v version $(BBASE)/bin/zig -o zig$(VERSION).1
	mkdir -p debian/tmp/usr/share/doc/zig$(VERSION)
	mv $(BBASE)/lib/zig/docs/* debian/tmp/usr/share/doc/zig$(VERSION)/
	rmdir $(BBASE)/lib/zig/docs
	dh_auto_install
	chrpath -d debian/tmp/usr/bin/zig

override_dh_auto_test:
	$(BBASE)/bin/zig test test/behavior.zig
	dh_auto_test
