#!/usr/bin/make -f

%:
	dh $@

# dh_auto_build attempts to build using the upstream Makefile - which doesn't
# actually build anything. Disable it.
override_dh_auto_build:
	:

# dh_auto_install attempts to install files using pyproject.toml metadata - which
# again doesn't actually install anything. Instead we install the scripts using
# dh_install below.
override_dh_auto_install:
	:

override_dh_install:
	dh_install

	# Remove VCS control files & docs from installed directory tree.
	find debian/kicad-library-utils/usr/share/kicad-library-utils -type f -name '.gitignore' -delete
	find debian/kicad-library-utils/usr/share/kicad-library-utils -type f -name '*.md' -delete
	find debian/kicad-library-utils/usr/share/kicad-library-utils -type f -name '*.txt' -delete

	# step_diff.py imports cadquery which is not yet packaged in Debian. Remove
	# the script until we have the dependency packaged.
	rm -f debian/kicad-library-utils/usr/share/kicad-library-utils/tools/step_diff.py

	# empty.kicad_sym is an unused file and is not referenced by any shipped
	# script. Remove it.
	rm -f debian/kicad-library-utils/usr/share/kicad-library-utils/common/empty.kicad_sym

	# Use the packaged version of Roboto font instead of the bundled one.
	mkdir -p debian/kicad-library-utils/usr/share/kicad-library-utils/tools/fonts/Roboto
	ln -s /usr/share/fonts/truetype/roboto/unhinted/RobotoCondensed-Regular.ttf \
		debian/kicad-library-utils/usr/share/kicad-library-utils/tools/fonts/Roboto/RobotoCondensed-Regular.ttf

# The upstream Makefile test target does all kinds of stuff we don't care about
# (e.g. spellchecking and formatting the code) so only run the test targets we
# really want to call.
override_dh_auto_test:
	$(MAKE) \
		test-klc-footprints \
		test-klc-symbols \
		test-comparelibs-symbols
