#!/bin/bash function print_help_and_exit() { cat < Specify the compiler --type 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