2020-05-20 22:29:37 +08:00
|
|
|
#!/usr/bin/env bash
|
2018-11-16 15:31:08 +08:00
|
|
|
|
2019-03-06 15:57:05 +08:00
|
|
|
#build drogon
|
2018-11-16 15:31:08 +08:00
|
|
|
function build_drogon() {
|
|
|
|
|
2018-11-16 18:25:41 +08:00
|
|
|
#Update the submodule and initialize
|
2018-11-16 15:31:08 +08:00
|
|
|
git submodule update --init
|
|
|
|
|
2019-09-30 21:34:30 +08:00
|
|
|
#Remove the config.h generated by the old version of drogon.
|
|
|
|
rm -f lib/inc/drogon/config.h
|
|
|
|
|
2019-03-06 15:57:05 +08:00
|
|
|
#Save current directory
|
2018-11-16 15:31:08 +08:00
|
|
|
current_dir="${PWD}"
|
|
|
|
|
2019-03-06 15:57:05 +08:00
|
|
|
#The folder in which we will build drogon
|
2018-11-16 15:31:08 +08:00
|
|
|
build_dir='./build'
|
|
|
|
if [ -d $build_dir ]; then
|
|
|
|
echo "Deleted folder: ${build_dir}"
|
2018-11-16 17:26:35 +08:00
|
|
|
rm -rf $build_dir
|
2018-11-16 15:31:08 +08:00
|
|
|
fi
|
|
|
|
|
2019-03-06 15:57:05 +08:00
|
|
|
#Create building folder
|
2018-11-16 15:31:08 +08:00
|
|
|
echo "Created building folder: ${build_dir}"
|
2018-11-16 17:26:35 +08:00
|
|
|
mkdir $build_dir
|
2018-11-16 15:31:08 +08:00
|
|
|
|
|
|
|
echo "Entering folder: ${build_dir}"
|
|
|
|
cd $build_dir
|
|
|
|
|
|
|
|
echo "Start building drogon ..."
|
2019-08-16 23:41:03 +08:00
|
|
|
if [ $1 -eq 1 ]; then
|
2020-03-17 00:54:30 +08:00
|
|
|
cmake .. -DBUILD_TESTING=YES $cmake_gen
|
2019-08-16 23:41:03 +08:00
|
|
|
else
|
2020-07-30 16:27:35 +08:00
|
|
|
cmake .. -DCMAKE_BUILD_TYPE=release $cmake_gen
|
2019-08-16 23:41:03 +08:00
|
|
|
fi
|
|
|
|
|
2018-11-16 18:25:41 +08:00
|
|
|
#If errors then exit
|
2018-11-16 15:31:08 +08:00
|
|
|
if [ "$?" != "0" ]; then
|
2019-03-26 15:25:22 +08:00
|
|
|
exit -1
|
2018-11-16 15:31:08 +08:00
|
|
|
fi
|
|
|
|
|
2020-03-17 00:54:30 +08:00
|
|
|
$make_program $make_flags
|
2018-11-16 15:31:08 +08:00
|
|
|
|
2018-11-16 18:25:41 +08:00
|
|
|
#If errors then exit
|
2018-11-16 15:31:08 +08:00
|
|
|
if [ "$?" != "0" ]; then
|
2019-03-26 15:25:22 +08:00
|
|
|
exit -1
|
2018-11-16 15:31:08 +08:00
|
|
|
fi
|
|
|
|
|
2018-11-16 18:25:41 +08:00
|
|
|
echo "Installing ..."
|
2020-03-17 00:54:30 +08:00
|
|
|
sudo $make_program install
|
2018-11-16 15:31:08 +08:00
|
|
|
|
2019-03-06 15:57:05 +08:00
|
|
|
#Go back to the current directory
|
2018-11-16 15:31:08 +08:00
|
|
|
cd $current_dir
|
2018-11-16 18:25:41 +08:00
|
|
|
#Ok!
|
2018-11-16 15:31:08 +08:00
|
|
|
}
|
|
|
|
|
2020-03-17 00:54:30 +08:00
|
|
|
make_program=make
|
|
|
|
make_flags=''
|
|
|
|
cmake_gen=''
|
|
|
|
parallel=1
|
|
|
|
|
2021-03-13 18:56:16 +08:00
|
|
|
case $(uname) in
|
|
|
|
FreeBSD)
|
|
|
|
nproc=$(sysctl -n hw.ncpu)
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
nproc=$(sysctl -n hw.ncpu) # sysctl -n hw.ncpu is the equivalent to nproc on macOS.
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
nproc=$(nproc)
|
|
|
|
;;
|
|
|
|
esac
|
2020-05-20 22:29:37 +08:00
|
|
|
|
2020-03-17 00:54:30 +08:00
|
|
|
# simulate ninja's parallelism
|
2020-05-20 22:29:37 +08:00
|
|
|
case nproc in
|
2020-03-17 00:54:30 +08:00
|
|
|
1)
|
2020-05-20 22:29:37 +08:00
|
|
|
parallel=$(( nproc + 1 ))
|
2020-03-17 00:54:30 +08:00
|
|
|
;;
|
|
|
|
2)
|
2020-05-20 22:29:37 +08:00
|
|
|
parallel=$(( nproc + 1 ))
|
2020-03-17 00:54:30 +08:00
|
|
|
;;
|
|
|
|
*)
|
2020-05-20 22:29:37 +08:00
|
|
|
parallel=$(( nproc + 2 ))
|
2020-03-17 00:54:30 +08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -f /bin/ninja ]; then
|
|
|
|
make_program=ninja
|
|
|
|
cmake_gen='-G Ninja'
|
|
|
|
else
|
|
|
|
make_flags="$make_flags -j$parallel"
|
|
|
|
fi
|
|
|
|
|
2019-08-16 23:41:03 +08:00
|
|
|
if [ "$1" = "-t" ]; then
|
|
|
|
build_drogon 1
|
|
|
|
else
|
|
|
|
build_drogon 0
|
2021-03-13 18:56:16 +08:00
|
|
|
fi
|