#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/pkg-info.mk

# The build embeds and the tests read data files outside testdata
# (core/english/alnum.tsv, data/english, models, platforms/*).
export DH_GOLANG_INSTALL_EXTRA := core/english/alnum.tsv data internal models platforms scripts

# Upstream's system install (platforms/linux-system) builds lib0c.so and lays
# out the data, icons and shell definitions; it takes the Go binaries from
# SYSBUILD, which is where dh-go puts them.
# The programs report upstream's release, without the +ds part of the package
# version.
UPSTREAM_VERSION := $(firstword $(subst +, ,$(DEB_VERSION_UPSTREAM)))
MAKE_ARGS := PREFIX=/usr VERSION=$(UPSTREAM_VERSION) SYSBUILD=_build/bin SETTINGS=0

# The SHA-256 of /usr/share/0c/data/manifest.json in 0c-ime-data.  The Depends
# of 0c-ime in debian/control names the versions that have this dictionary;
# change both together (see README.source).
DICTIONARY_MANIFEST := 3e93ed1ef3d2fc7443f64a0b5203294298181b84bed2cd6a144c48a4852aefee

%:
	dh $@ --buildsystem=golang --with=golang

override_dh_auto_build:
	$(DH_OVERRIDDEN_COMMAND) -- -ldflags '-X main.buildVersion=$(UPSTREAM_VERSION)'
	dh_auto_build --buildsystem=makefile -- build-fcitx5 $(MAKE_ARGS)

# The dictionary is in the 0c-ime-data source package.  Upstream's install
# stops without a manifest, so give it an empty one and do not ship it
# (debian/not-installed).  The pairing lock follows models/models.lock.json,
# which changes with the engine, so it is made here for that dictionary.
override_dh_auto_install:
	debian/pairing-lock $(DICTIONARY_MANIFEST) debian/pairing.lock.json
	dh_auto_install --buildsystem=makefile -- $(MAKE_ARGS) DATA=debian/no-dictionary PAIRING_LOCK=debian/pairing.lock.json
