#!/bin/bash export OLD_DIR="$(pwd)" cmd_err() { CUR_DIR="$(pwd)" code=$1 echo "Error: Command exited with non-zero status ($code)" >&2 echo "Directory: $CUR_DIR" echo "Command: $2" >&2 cd $OLD_DIR exit $code } on_err() { echo "Script error." cmd_err "$?" "$BASH_COMMAND" } run_command() { trap ERR echo "$@" >&2 "$@" code=$? if [ $code -ne 0 ]; then cmd_err "$code" "$*" fi trap on_err ERR } trap on_err ERR mkdir -p build cd build run_command cmake .. -DDISABLE_GTK_UI=ON -DCMAKE_BUILD_TYPE=Debug run_command cmake --build . "$@" cd ..