#!/usr/bin/make -f

%:
	dh $@

# Upstream ships lib/preamble.min.js and lib/preamble.dart as the output of
# tool/minify.js, and only that tool's input, lib/preamble.js, is a source
# file.  Regenerate both from it with Debian's terser, into build/, so that
# what we install is built here rather than copied from upstream's tarball.
override_dh_auto_build:
	node debian/minify-preamble.cjs build

override_dh_auto_clean:
	rm -rf build
	dh_auto_clean

# Upstream's pub.dev archives record every directory entry with an epoch (0)
# timestamp.  dh_install preserves the mtime of the directories it copies, so
# the binary package would ship lib/ dated 1970-01-01 and lintian reports it as
# package-contains-ancient-file.  Stamp the installed directories with the
# source date instead (dh exports SOURCE_DATE_EPOCH from debian/changelog, so
# builds stay reproducible); no file content is affected.
override_dh_install:
	dh_install
	cp -f build/preamble.min.js build/preamble.dart \
	    debian/dart-node-preamble/usr/share/dart/packages/node_preamble/lib/
	find debian/dart-node-preamble -type d -exec touch -d "@$${SOURCE_DATE_EPOCH}" {} +
