#!/bin/sh
if [ ! -e /.dockerenv ]; then
	echo "This script should only be run in the Docker VM environment."
	exit 1
fi

cd

cp icinga2/tools/debug/gdb/gdbinit .gdbinit
sed -i 's/home\/gbeutner/home\/icinga/' .gdbinit

cd icinga2-build || exit 1

CCACHE_SLOPPINESS="include_file_mtime"
export CCACHE_SLOPPINESS

if [ ! -e Makefile ]; then
	CC="ccache clang" CXX="ccache clang++" cmake ../icinga2 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$HOME/icinga2-install -DCMAKE_INSTALL_SYSCONFDIR=$HOME/icinga2-config
fi

make -j 4 && make install && cgdb -ex set scheduler-locking step -ex r --args ../icinga2-install/sbin/icinga2 -c ../icinga2-config/icinga2/icinga2.conf -DUseVfork=0
