176 lines
4.2 KiB
Bash
Executable File
176 lines
4.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
function print_help_and_exit() {
|
|
cat <<EOF
|
|
Usage: setup_builds.sh [OPTIONS] compiler build-type
|
|
|
|
Positionals:
|
|
gcc Compile with gcc
|
|
clang Compile with clang
|
|
debug Build debug
|
|
release Build release
|
|
|
|
Options:
|
|
--compiler <clang|gcc> Specify the compiler
|
|
--type <debug|release> Specify the type of build
|
|
-f,--force Overwrite existing build directories
|
|
-h,--help Print this help message and exit
|
|
|
|
EOF
|
|
exit $1
|
|
}
|
|
|
|
function assert_dir() {
|
|
if [[ ! -d "$1" ]]; then
|
|
if [[ -n "$2" ]]; then
|
|
echo "Invalid variable $2: '$1' is not a directory"
|
|
else
|
|
echo "'$1' is not a directory"
|
|
fi
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# common variables
|
|
|
|
tools_path=$(dirname $(readlink -f $0))
|
|
sparkd_path_cmd=$tools_path/sparkd_path.sh
|
|
repot_root="$(eval $sparkd_path_cmd repot-root)"
|
|
externals_root=$repot_root/externals
|
|
build_root=$(readlink -f $repot_root/build)
|
|
mkdir -p $repot_root/build/
|
|
externals_linked=""
|
|
|
|
# Link sub dirs in externals to spark repot
|
|
function ensure_externals_linked() {
|
|
if [[ -z "$externals_linked" ]]; then
|
|
assert_dir $repot_root
|
|
assert_dir $externals_root
|
|
echo "Initialize sym links to dirs in externals"
|
|
set -x
|
|
rm -f $repot_root/src/web/ui/node_modules
|
|
rm -f $repot_root/src/web/api/node_modules
|
|
ln -s $externals_root/npm/web/ui/node_modules $repot_root/src/web/ui/node_modules
|
|
ln -s $externals_root/npm/web/api/node_modules $repot_root/src/web/api/node_modules
|
|
set +x
|
|
externals_linked=1
|
|
fi
|
|
}
|
|
|
|
# Initialize the build directory. Expected arguments: <compiler>, <build_type>
|
|
# Note: this method assumes the variables 'repot_root' and 'build_root' have
|
|
# already been properly initialized
|
|
function setup_build() {
|
|
assert_dir $repot_root
|
|
assert_dir $build_root
|
|
compiler=$1
|
|
build_type=$2
|
|
declare -A build_type_args=([debug]="Debug" [release]="Release")
|
|
|
|
if [[ (-z "$build_type" || ! ${build_type_args[${build_type}]+1}) ]]; then
|
|
print_help_and_exit 1
|
|
fi
|
|
|
|
declare -A compiler_args
|
|
|
|
if [[ "$build_type" == "debug" ]]; then
|
|
compiler_args["gcc"]="/usr/lib/ccache/g++"
|
|
# compiler_args["clang"]="/usr/lib/ccache/clang++"
|
|
compiler_args["clang"]="clang++-10"
|
|
elif [[ "$build_type" == "release" ]]; then
|
|
compiler_args["gcc"]="g++"
|
|
compiler_args["clang"]="clang++-10"
|
|
fi
|
|
|
|
if [[ (-z "$compiler" || ! ${compiler_args[$compiler]+1}) ]]; then
|
|
print_help_and_exit 1
|
|
fi
|
|
|
|
build_dest="$build_root/$compiler/$build_type"
|
|
|
|
echo "Set up build: ${compiler} ${build_type}"
|
|
|
|
if [[ -z ${force+1} && -d ${build_dest} ]]; then
|
|
echo "The build directory '${build_dest}' already exists (use -f to overwrite)"
|
|
return 1
|
|
fi
|
|
|
|
ensure_externals_linked
|
|
|
|
rm -rf $build_dest
|
|
mkdir -p $build_dest
|
|
cd $build_dest
|
|
cmake -G Ninja -DCMAKE_BUILD_TYPE=${build_type_args[$build_type]} -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_COMPILER=${compiler_args[$compiler]} $repot_root
|
|
}
|
|
|
|
# The while loop below removes arguments (via shift) as it parses them.
|
|
# Additional information that needs to be extracted from the arguments must be
|
|
# done so before the loop is executed.
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
declare -l arg="$1"
|
|
case "$arg" 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_help_and_exit 0
|
|
;;
|
|
--help)
|
|
print_help_and_exit 0
|
|
;;
|
|
*)
|
|
print_help_and_exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -n "$compiler" ]]; then
|
|
if [[ -n "$build_type" ]]; then
|
|
setup_build $compiler $build_type
|
|
else
|
|
# all builds for the specified compiler
|
|
setup_build $compiler "debug"
|
|
setup_build $compiler "release"
|
|
fi
|
|
elif [[ -n "$build_type" ]]; then
|
|
# all builds for the specified build type
|
|
setup_build "gcc" $build_type
|
|
setup_build "clang" $build_type
|
|
else
|
|
# all builds
|
|
setup_build "gcc" "debug"
|
|
setup_build "gcc" "release"
|
|
setup_build "clang" "debug"
|
|
setup_build "clang" "release"
|
|
fi
|