#!/bin/bash
set -ue

# Parse command line options
ha=YES
doc=YES
for arg in "$@"; do
	case "$arg" in
		--with-ha) ha=YES;;
		--without-ha) ha=NO;;
		--with-doc) doc=YES;;
		--without-doc) doc=NO;;
		*) echo "Unrecognized command line option '$arg'" >&2; exit 1;;
	esac
done

cd "$(dirname "$0")"
mkdir -p build-pack
cd build-pack
rm -f CMakeCache.txt
cmake .. \
	-DCMAKE_BUILD_TYPE=Release \
	-DENABLE_TESTS=NO \
	-DCMAKE_INSTALL_PREFIX=/ \
	-DENABLE_DEBIAN_PATHS=YES \
	-DENABLE_DOCS=$doc \
	-DENABLE_HA_CLUSTER=$ha

cat >../Makefile <<END
all:
	make --no-print-directory -C build-pack all

clean:
	make --no-print-directory -C build-pack clean

install:
	make --no-print-directory -C build-pack install

distclean:
	rm -rf build-pack
	rm -rf external/gtest*
	rm -f Makefile
END
