#!/usr/bin/make -f

export PYBUILD_DISABLE=1
jobs := $(shell echo $$DEB_BUILD_OPTIONS | sed -r "s/.*parallel=([0-9]+).*/-j\1/")

override_dh_auto_configure:
	./configure.py --with=scylla --with=iotune --enable-dpdk --mode=release --static-thrift --static-boost --static-yaml-cpp --compiler=/opt/scylladb/bin/g++-7 --c-compiler=/opt/scylladb/bin/gcc-7 --cflags="-I/opt/scylladb/include -L/opt/scylladb/lib/x86-linux-gnu/" --ldflags="-Wl,-rpath=/opt/scylladb/lib"

override_dh_auto_build:
	PATH="/opt/scylladb/bin:$$PATH" ninja $(jobs)

override_dh_auto_clean:
	rm -rf build/release seastar/build
	rm -rf Cql.tokens
	rm -rf build.ninja seastar/build.ninja

override_dh_installinit:
{{#trusty}}
{{#scylla}}
	dh_installinit --no-start --upstart-only
{{/scylla}}
{{^scylla}}
	dh_installinit --no-start --name scylla-server --upstart-only
{{/scylla}}
	dh_installinit --no-start --name scylla-housekeeping --upstart-only
{{/trusty}}
{{^trusty}}
{{#scylla}}
	dh_installinit --no-start
{{/scylla}}
{{^scylla}}
	dh_installinit --no-start --name scylla-server
{{/scylla}}
	dh_installinit --no-start --name scylla-housekeeping-daily
	dh_installinit --no-start --name scylla-housekeeping-restart
	dh_installinit --no-start --name scylla-fstrim
	dh_installinit --no-start --name node-exporter
{{/trusty}}
{{#trusty}}
override_dh_installcron:
	dh_installcron
{{/trusty}}

override_dh_strip:
	dh_strip --dbg-package={{product}}-server-dbg
%:
	dh $@ --with-python3 --buildsystem=pybuild
