#!/usr/bin/make -f
# 禁用 dbgsym 调试符号包生成（避免用户误装缺依赖）
export DEB_BUILD_OPTIONS := noddebs
%:
	dh $@

override_dh_auto_configure:
override_dh_auto_build:
	# 动态更新版本日期为当天（YYYYMMDD），功能版本号保持不变
	python3 -c "import json,datetime,re; p='src/metadata.json'; d=json.load(open(p)); t=datetime.date.today().strftime('%Y%m%d'); d['Plugin']['Version']=re.sub(r'\(\d{8}\)', '('+t+')', d['Plugin']['Version']); json.dump(d,open(p,'w'),ensure_ascii=False,indent=2)"
	# 动态更新 changelog 首行版本日期为当天（保证 deb 版本与插件版本日期一致）
	python3 -c "import datetime,re; t=datetime.date.today().strftime('%Y%m%d'); p='debian/changelog'; s=open(p).read(); s=re.sub(r'(dde-shell-personal-calendar-plugin \([0-9.]+)-(\d{8}\))', r'\1-'+t+')', s, count=1); open(p,'w').write(s)"
	# 可复现构建原生插件 .so（与开发环境 build-native.sh 同一入口）
	./build-native.sh
	# 生成注入实际版本号的 main.qml（替换 @PACKAGE_VERSION@ 占位符，日期已动态更新）
	mkdir -p debian/pkg-mainqml
	python3 -c "import json; v=json.load(open('src/metadata.json'))['Plugin']['Version']; open('debian/pkg-mainqml/main.qml','w').write(open('src/main.qml').read().replace('@PACKAGE_VERSION@', v))"

override_dh_auto_test:
override_dh_auto_install:
	dh_install
