#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# GCC 15 默认 C23：'bool' 成为关键字、旧式空括号函数声明 () 等价于 (void)，
# 造成 utils/magic.h 的 typedef unsigned char bool 报错，以及 bpDump.c 对
# CIFGetOutputScale(1000) 的调用报"参数过多"。
# 顶层 configure 脚本会强制 CFLAGS="-g" 并丢弃 dpkg-buildflags 传入的 CFLAGS，
# 因此 DEB_CFLAGS_MAINT_APPEND 无效；须在 dh_auto_configure 阶段显式向
# configure 传 CFLAGS 才能到达编译器。
# 选用 -std=gnu89（而非 gnu17）：该代码库为 K&R C89 风格，除上述两类外还
# 存在隐式函数声明，GCC 14+ 在 c99 及之后标准下将其默认视为错误，gnu89 下
# 均为警告，兼容度最高。
override_dh_auto_configure:
	dh_auto_configure -- CFLAGS="-g -std=gnu89"

%:
	dh $@ --no-parallel


override_dh_auto_install:
	dh_auto_install
	sed -i -e "s,/usr/bin/wish,$(shell readlink -f /usr/bin/wish)," debian/magic/usr/bin/magic

override_dh_auto_clean:
	dh_auto_clean
	-rm -f scripts/config.cache
