#!/usr/bin/make -f

# Regenerate the baked data from the CLDR JSON sources instead of shipping
# the pre-generated files from the crate (#1143092). The marker list is
# derived from the data files shipped upstream; the options match upstream's
# tools/make/bakeddata. Upstream's copy is kept aside and restored on clean.
CLDR_ROOT = /usr/share/unicode/cldr-json

execute_before_dh_auto_configure:
	[ -d data.upstream ] || mv data data.upstream
	rm -rf data
	markers=$$(cd data.upstream && ls *.rs.data | sed 's/\.rs\.data$$//; s/\(^\|_\)\([a-z0-9]\)/\U\2/g'); \
	icu4x-datagen --format baked --pretty --overwrite \
		--cldr-root $(CLDR_ROOT) \
		--locales recommended --deduplication maximal \
		--markers $$markers \
		--out data
	diff -ru data.upstream data || echo "W: regenerated data differs from upstream's"

execute_after_dh_auto_clean:
	if [ -d data.upstream ]; then rm -rf data && mv data.upstream data; fi

%:
	dh $@ --buildsystem cargo
