#!/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 (external) sqlite has high enough version, disable internal sqlite.

## Only use internal (vendored) sqlite for now.
##
##  Checking for sqlite3_open in sqlite3...-lsqlite3
##  Error: system SQLite library omits required build option -DSQLITE_ENABLE_JSON1
##
## Also removed corresponding dependencies from debian/control:
##               libsqlite3-dev (>= 3.38),
##               sqlite3,

SQLITE_MIN_VERSION=$(shell ./configure --print-minimum-sqlite-version | tail -1)
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

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