From 69b0003e3fd355aeecdb36ab11310c460cbe61ed Mon Sep 17 00:00:00 2001 From: s1lentq Date: Tue, 13 Apr 2021 05:38:00 +0700 Subject: [PATCH] build.sh add help [skip ci] --- build.sh | 89 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/build.sh b/build.sh index 9b49a8da..876b458d 100755 --- a/build.sh +++ b/build.sh @@ -1,39 +1,60 @@ #!/bin/bash -CC=gcc -CXX=g++ +main() +{ + CC=gcc + CXX=g++ -n=0 -args=() -for i in "$@" -do -case $i in - -j=*|--jobs=*) - jobs="-j${i#*=}" - shift - ;; - -c=*|--compiler=*) - C="${i#*=}" - shift - ;; - *) - args[$n]="$i" - ((++n)) - ;; -esac -done + if [[ "$*" =~ "--help" ]]; then + help + exit 0; + fi -case "$C" in - ("intel"|"icc") CC=icc CXX=icpc ;; - ("gcc"|"g++") CC=gcc CXX=g++ ;; - ("clang|llvm") CC=clang CXX=clang++ ;; - *) - ;; -esac + n=0 + args=() + for i in "$@" + do + case $i in + -j=*|--jobs=*) + jobs="-j${i#*=}" + shift + ;; + -c=*|--compiler=*) + C="${i#*=}" + shift + ;; + *) + args[$n]="$i" + ((++n)) + ;; + esac + done -rm -rf build -mkdir build -pushd build &> /dev/null -CC=$CC CXX=$CXX cmake ${args[@]} .. -make ${jobs} -popd > /dev/null + case "$C" in + ("intel"|"icc") CC=icc CXX=icpc ;; + ("gcc"|"g++") CC=gcc CXX=g++ ;; + ("clang|llvm") CC=clang CXX=clang++ ;; + *) + ;; + esac + + rm -rf build + mkdir build + pushd build &> /dev/null + CC=$CC CXX=$CXX cmake ${args[@]} .. + make ${jobs} + popd > /dev/null +} + +help() +{ + printf "Usage: ./build.sh \n\n" + printf " -c= | --compiler= - Select preferred C/C++ compiler to build\n" + printf " -j= | --jobs= - Specifies the number of jobs (commands) to run simultaneously (For faster building)\n\n" +} + +# Initialize +main $* + +# Exit normally +exit 0