#!/usr/bin/make -f

FREEDICT_TOOLS = /usr/share/freedict
FREEDICT_FILTER_CRITERIA := $(strip sourceURL!wikdict)
.DEFAULT_GOAL := override_dh_auto_build
PKG_HELPERS := $(FREEDICT_TOOLS)/packaging/packaging.mk

ifneq ($(wildcard $(PKG_HELPERS)),)
include $(PKG_HELPERS)
else
# pdebuild cleans the source on the host before entering the build chroot.
DICTS ?= $(patsubst %/,%,$(wildcard ???-???/))

.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	dh_testdir
	rm -f build-stamp timestamp configure-stamp
	rm -rf config.txt
	set -e; for DICT in $(DICTS); do \
		rm -rf $$DICT/build; \
		rm -f debian/dict-freedict-$$DICT.dirs \
			debian/dict-freedict-$$DICT.docs \
			debian/dict-freedict-$$DICT.postinst \
			debian/dict-freedict-$$DICT.postrm; \
	done
	dh_clean
endif

%:
ifeq ($(wildcard $(PKG_HELPERS)),)
	$(if $(filter clean,$@),,$(error Install freedict-tools: $(PKG_HELPERS)))
endif
	dh $@ $(if $(filter dummy,$(BUILD_MODE)),,--max-parallel=2)
