#!/bin/bash base_path=$(pwd) if [[ $base_path == /home/* || $base_path == /root/* ]]; then build_path=${base_path}/build else build_path=/tmp/build fi echo "build directory: $build_path" function cmake_scan() { if [ ! -d ${build_path} ]; then mkdir ${build_path} fi cmake \ -G Ninja \ -S ${base_path} \ -B ${build_path} \ -DCMAKE_TOOLCHAIN_FILE=resources/toolchain.cmake \ -DCMAKE_BUILD_TYPE=Debug } function build() { if [ ! -f "${build_path}/CMakeCache.txt" ]; then cmake_scan fi if [ $? -ne 0 ]; then exit 1 fi cmake \ --build ${build_path} \ --target all if [ $? -ne 0 ]; then exit 1 fi } function clean() { if [ -d ${build_path} ]; then rm -fr ${build_path} fi } function main() { local cmd=$1 shift 1 case $cmd in build) build $@ ;; scan) cmake_scan ;; clean) clean ;; *) build ;; esac } main $@