124 lines
2.2 KiB
Bash
Executable File
124 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
function print_help_and_exit() {
|
|
cat <<EOF
|
|
Print paths to core parts of the repository
|
|
Usage: sparkd_path.sh SUBCOMMAND
|
|
|
|
Subcommands:
|
|
build Print build path
|
|
repo-root Print repo root path
|
|
|
|
EOF
|
|
exit $1
|
|
}
|
|
|
|
function print_build_help_and_exit() {
|
|
cat <<EOF
|
|
Print build path
|
|
Usage: sparkd_path.sh build [OPTIONS] compiler build-type
|
|
|
|
Positionals:
|
|
gcc Print gcc build path
|
|
clang Print clang build path
|
|
debug Print debug build path
|
|
release Print release build path
|
|
|
|
Options:
|
|
--compiler <clang|gcc> Specify the compiler
|
|
--type <debug|release> Specify the type of build
|
|
-h,--help Print this help message and exit
|
|
|
|
EOF
|
|
exit $1
|
|
}
|
|
|
|
function print_repo_root() {
|
|
echo "$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd)"
|
|
}
|
|
|
|
function run_repo_root() {
|
|
print_repo_root
|
|
}
|
|
|
|
function run_build() {
|
|
compiler="gcc"
|
|
build_type="release"
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--compiler)
|
|
compiler=$2
|
|
shift 2
|
|
;;
|
|
--type)
|
|
build_type=$2
|
|
shift 2
|
|
;;
|
|
clang)
|
|
compiler="clang"
|
|
shift
|
|
;;
|
|
gcc)
|
|
compiler="gcc"
|
|
shift
|
|
;;
|
|
debug)
|
|
build_type="debug"
|
|
shift
|
|
;;
|
|
release)
|
|
build_type="release"
|
|
shift
|
|
;;
|
|
-f)
|
|
force=1
|
|
shift
|
|
;;
|
|
--force)
|
|
force=1
|
|
shift
|
|
;;
|
|
-h)
|
|
print_build_help_and_exit 0
|
|
;;
|
|
--help)
|
|
print_build_help_and_exit 0
|
|
;;
|
|
*)
|
|
print_build_help_and_exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
declare -A compilers=([gcc]="$(which gcc)" [clang]="$(which clang)")
|
|
declare -A build_types=([debug]="debug" [release]="release")
|
|
|
|
if [[ ${compilers[$compiler]+1} ]]; then
|
|
comp_path=${compilers[$compiler]}
|
|
else
|
|
print_build_help_and_exit 1
|
|
fi
|
|
|
|
if [[ ${build_types[$build_type]+1} ]]; then
|
|
build_type=${build_types[$build_type]}
|
|
else
|
|
print_build_help_and_exit 1
|
|
fi
|
|
|
|
src_root="$(print_repo_root)"
|
|
build_root=$(readlink -f $src_root/build)
|
|
build_dest="$build_root/$compiler/$build_type"
|
|
|
|
echo $build_dest
|
|
}
|
|
|
|
if [[ $1 == "repot-root" ]]; then
|
|
shift
|
|
print_repo_root $@
|
|
elif [[ $1 == "build" ]]; then
|
|
shift
|
|
run_build $@
|
|
else
|
|
print_help_and_exit 1
|
|
fi
|