#!/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=reproducible=-timeless

BUILD_TYPE=release

%:
	dh $@ --with gir,autoreconf

override_dh_autoreconf:
	dh_autoreconf \
	  --sourcedirectory=c_glib \
	  ./autogen.sh

override_dh_auto_configure:
	if dpkg -l nvidia-cuda-toolkit > /dev/null 2>&1; then	\
	  ARROW_CUDA=ON;					\
	  ARROW_PLASMA=ON;					\
	else							\
	  ARROW_CUDA=OFF;					\
	  ARROW_PLASMA=OFF;					\
	fi;							\
	if dpkg -l | grep -q clang-; then			\
	  ARROW_GANDIVA=ON;					\
	else							\
	  ARROW_GANDIVA=OFF;					\
	fi;							\
	dh_auto_configure					\
	  --sourcedirectory=cpp					\
	  --builddirectory=cpp_build				\
	  --							\
	  -DARROW_CUDA=$${ARROW_CUDA}				\
	  -DARROW_GANDIVA=$${ARROW_GANDIVA}			\
	  -DARROW_GANDIVA_JAVA=OFF				\
	  -DARROW_MIMALLOC=ON					\
	  -DARROW_ORC=ON					\
	  -DARROW_PARQUET=ON					\
	  -DARROW_PLASMA=$${ARROW_PLASMA}			\
	  -DARROW_PYTHON=ON					\
	  -DARROW_S3=ON						\
	  -DARROW_WITH_BROTLI=ON				\
	  -DARROW_WITH_BZ2=ON					\
	  -DARROW_WITH_LZ4=ON					\
	  -DARROW_WITH_SNAPPY=ON				\
	  -DARROW_WITH_ZLIB=ON					\
	  -DARROW_WITH_ZSTD=ON					\
	  -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)			\
	  -DCMAKE_UNITY_BUILD=ON				\
	  -DPARQUET_REQUIRE_ENCRYPTION=ON			\
	  -DPythonInterp_FIND_VERSION=ON			\
	  -DPythonInterp_FIND_VERSION_MAJOR=3
	dh_auto_configure						\
	  --sourcedirectory=c_glib					\
	  --builddirectory=c_glib_build					\
	  --								\
	  --with-arrow-cpp-build-dir=$(CURDIR)/cpp_build		\
	  --with-arrow-cpp-build-type=$(BUILD_TYPE)			\
	  --enable-gtk-doc						\
	  --with-html-dir=\$${prefix}/share/doc/libarrow-glib-doc

override_dh_auto_build:
	dh_auto_build				\
	  --sourcedirectory=cpp			\
	  --builddirectory=cpp_build
	env							\
	  LD_LIBRARY_PATH=$(CURDIR)/cpp_build/$(BUILD_TYPE)	\
	    dh_auto_build					\
	      --sourcedirectory=c_glib				\
	      --builddirectory=c_glib_build

override_dh_auto_install:
	dh_auto_install				\
	  --sourcedirectory=cpp			\
	  --builddirectory=cpp_build
	dh_auto_install				\
	  --sourcedirectory=c_glib		\
	  --builddirectory=c_glib_build
	# Remove built files to reduce disk usage
	dh_auto_clean				\
	  --sourcedirectory=cpp			\
	  --builddirectory=cpp_build
	dh_auto_clean				\
	  --sourcedirectory=c_glib		\
	  --builddirectory=c_glib_build

# disable 'make check'.
override_dh_auto_test:
