#!/usr/bin/make -f

DEB_BUILD_MAINT_OPTIONS=hardening=+all
export DEB_BUILD_MAINT_OPTIONS
include /usr/share/dpkg/architecture.mk

%:
	dh $@ --with bash-completion

## If system (i.e., external) sqlite has a high
## enough version, then disable internal sqlite.

## Here's how to find the minimal required version:
# $ egrep -i 'sqlite.*at least' src/main.c
#     fossil_panic("Unsuitable SQLite version %s, must be at least 3.34.0",

SQLITE_MIN_VERSION=3.34
FOSSIL_CONF_SQLITE_OPTIONS:=$(shell pkg-config sqlite3 --atleast-version=$(SQLITE_MIN_VERSION) && echo --disable-internal-sqlite)

## This is an alternative method for checking sqlite version. Seems
## less robust, as pkg-config is designed for this purpose.

# dpkg --compare-versions \
# 	$(shell dpkg --status libsqlite3-dev | egrep '^Version: ' | cut --field=2 --delimiter=' ') \
# 	ge $(SQLITE_MIN_VERSION)

override_dh_auto_configure:
	dh_auto_configure -- --disable-option-checking \
			     $(FOSSIL_CONF_SQLITE_OPTIONS) \
			     --json \
			     --with-th1-docs --with-th1-hooks \
			     --with-tcl=1 \
			     --with-tcl-stubs \
			     --with-tcl-private-stubs

# From src/main.mk:
#
# WARNING. DANGER. Running the test suite modifies the repository the
# build is done from, i.e. the checkout belongs to. Do not sync/push
# the repository after running the tests.

override_dh_auto_test:
	@echo skipping test due to scary warning in src/main.mk

# Currently, test fails for json.  Needs to be investigated.

override_dh_installdocs:
	dh_installdocs
	mv debian/fossil/usr/share/doc/fossil/changes.wiki \
	   debian/fossil/usr/share/doc/fossil/changelog
