diff --git a/build.sh b/build.sh index 4166596e..07803961 100755 --- a/build.sh +++ b/build.sh @@ -28,9 +28,9 @@ function build_drogon() { echo "Start building drogon ..." if [ $1 -eq 1 ]; then - cmake .. -DBUILD_TESTING=YES + cmake .. -DBUILD_TESTING=YES $cmake_gen else - cmake .. + cmake .. $cmake_gen fi #If errors then exit @@ -38,7 +38,7 @@ function build_drogon() { exit -1 fi - make + $make_program $make_flags #If errors then exit if [ "$?" != "0" ]; then @@ -46,13 +46,38 @@ function build_drogon() { fi echo "Installing ..." - sudo make install + sudo $make_program install #Go back to the current directory cd $current_dir #Ok! } +make_program=make +make_flags='' +cmake_gen='' +parallel=1 + +# simulate ninja's parallelism +case $(nproc) in + 1) + parallel=$(( $(nproc) + 1 )) + ;; + 2) + parallel=$(( $(nproc) + 1 )) + ;; + *) + parallel=$(( $(nproc) + 2 )) + ;; +esac + +if [ -f /bin/ninja ]; then + make_program=ninja + cmake_gen='-G Ninja' +else + make_flags="$make_flags -j$parallel" +fi + if [ "$1" = "-t" ]; then build_drogon 1 else diff --git a/test.sh b/test.sh index 319f596b..343f624a 100755 --- a/test.sh +++ b/test.sh @@ -4,6 +4,31 @@ drogon_ctl_exec=`pwd`/build/drogon_ctl/drogon_ctl echo ${drogon_ctl_exec} cd build/examples/ +make_program=make +make_flags='' +cmake_gen='' +parallel=1 + +# simulate ninja's parallelism +case $(nproc) in + 1) + parallel=$(( $(nproc) + 1 )) + ;; + 2) + parallel=$(( $(nproc) + 1 )) + ;; + *) + parallel=$(( $(nproc) + 2 )) + ;; +esac + +if [ -f /bin/ninja ]; then + make_program=ninja + cmake_gen='-G Ninja' +else + make_flags="$make_flags -j$parallel" +fi + #Make webapp run as a daemon sed -i -e "s/\"run_as_daemon.*$/\"run_as_daemon\": true\,/" config.example.json sed -i -e "s/\"relaunch_on_error.*$/\"relaunch_on_error\": true\,/" config.example.json @@ -93,14 +118,14 @@ if [ ! -f "Test_TestPlugin.h" -o ! -f "Test_TestPlugin.cc" ]; then fi cd ../build -cmake .. +cmake .. $cmake_gen if [ $? -ne 0 ]; then echo "Error in testing" exit -1 fi -make +$make_program $make_flags if [ $? -ne 0 ]; then echo "Error in testing" @@ -119,7 +144,7 @@ if [ "$1" = "-t" ]; then #unit testing cd ../ echo "Unit testing" - make test + $make_program $make_flags test if [ $? -ne 0 ]; then echo "Error in unit testing" exit -1