#!/usr/bin/make -f
# -*- makefile-gmake -*-
#
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# This has to be exported to make some magic below work.
export DH_OPTIONS
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_BUILD_HARDENING = 1
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh $@ --without=autoreconf

override_dh_auto_configure:
	if dpkg -l libarrow-dev > /dev/null 2>&1; then		\
	  GRN_WITH_APACHE_ARROW=ON;				\
	else							\
	  GRN_WITH_APACHE_ARROW=OFF;				\
	fi;							\
	dh_auto_configure					\
	  --buildsystem=cmake+ninja				\
	  --							\
	  -DCMAKE_BUILD_TYPE=RelWithDebInfo			\
	  -DFETCHCONTENT_FULLY_DISCONNECTED=OFF			\
	  -DGRN_WITH_APACHE_ARROW=$${GRN_WITH_APACHE_ARROW}	\
	  -DGRN_WITH_BLOSC=bundled				\
	  -DGRN_WITH_DOC=ON					\
	  -DGRN_WITH_EXAMPLES=ON				\
	  -DGRN_WITH_MRUBY=ON					\
	  -DGRN_WITH_MUNIN_PLUGINS=ON                           \
	  -DGRN_WITH_SIMDJSON=auto

# disable 'make check'.
override_dh_auto_test:

override_dh_auto_install:
	dh_auto_install				\
	  --buildsystem=cmake+ninja
	find $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/ -name *.la -delete
	install -d debian/tmp/etc/munin/plugin-conf.d/
	install -m 0644 debian/groonga-munin-plugins.conf \
	  debian/tmp/etc/munin/plugin-conf.d/groonga
	install -d debian/tmp/usr/share/groonga/faiss/
	mv debian/tmp/usr/share/doc/groonga/ \
	  debian/tmp/usr/share/doc/groonga-doc/
