@@ -4,30 +4,41 @@ set -euo pipefail
44
55SCRIPTPATH=" $( cd -- " $( dirname " $0 " ) " > /dev/null 2>&1 ; pwd -P ) "
66
7- LOG_FILE=build.log
8-
7+ export LOG_FILE=build.log
8+ # shellcheck source=./common.sh
99source " $SCRIPTPATH /common.sh"
1010
1111log_exec_params " $@ "
1212
1313# This cript builds all (or selected) targets in the hive repo
1414
1515print_help () {
16- echo " Usage: $0 [OPTION[=VALUE]]... [target]..."
17- echo
18- echo " Allows to build Hive sources "
19- echo " --source-dir=DIRECTORY_PATH"
20- echo " Specify a directory containing a Hived source tree."
21- echo " --binary-dir=DIRECTORY_PATH"
22- echo " Specify a directory to store a build output (hived binaries)."
23- echo " Usually it is a \` build\` subdirectory in the hive source tree."
24- echo " --cmake-arg=ARG Specify additional arguments to the CMake tool spawn."
25- echo " --help Display this help screen and exit."
26- echo
16+ cat << EOF
17+ Usage: $0 [OPTION[=VALUE]]... [target]...
18+
19+ Allows to build Hive sources
20+ --source-dir=DIRECTORY_PATH
21+ Specify a directory containing a Hived source tree.
22+ --binary-dir=DIRECTORY_PATH
23+ Specify a directory to store a build output (hived binaries).
24+ Usually it is a \` build\` subdirectory in the hive source tree.
25+ --flat-binary-directory=DIRECTORY_PATH
26+ Directory where all binaries are moved after build while flattening
27+ the directory structure, that is installation directory (optional, not set by default, must exist)
28+ --cmake-arg=ARG Specify additional arguments to the CMake tool spawn.
29+ --clean-after-build Remove compiled files after build
30+ --haf-build Set if build is called from HAF
31+ --help Display this help screen and exit.
32+
33+ EOF
2734}
2835
2936HIVED_BINARY_DIR=" ../build"
3037HIVED_SOURCE_DIR=" ."
38+ HIVED_INSTALLATION_DIR=" "
39+ CLEAN_AFTER_BUILD=" false"
40+ HAF_BUILD=" "
41+
3142CMAKE_ARGS=()
3243
3344JOBS=$( nproc)
@@ -50,6 +61,15 @@ while [ $# -gt 0 ]; do
5061 --source-dir=* )
5162 HIVED_SOURCE_DIR=" ${1#* =} "
5263 ;;
64+ --flat-binary-directory=* )
65+ HIVED_INSTALLATION_DIR=" ${1#* =} "
66+ ;;
67+ --clean-after-build)
68+ CLEAN_AFTER_BUILD=" true"
69+ ;;
70+ --haf-build)
71+ HAF_BUILD=" true"
72+ ;;
5373 --help)
5474 print_help
5575 exit 0
@@ -67,16 +87,69 @@ while [ $# -gt 0 ]; do
6787 shift
6888done
6989
70- abs_src_dir=` realpath -e --relative-base=" $SCRIPTPATH " " $HIVED_SOURCE_DIR " `
71- abs_build_dir=` realpath -m --relative-base=" $SCRIPTPATH " " $HIVED_BINARY_DIR " `
90+ abs_src_dir=$( realpath -e --relative-base=" $SCRIPTPATH " " $HIVED_SOURCE_DIR " )
91+ abs_build_dir=$( realpath -m --relative-base=" $SCRIPTPATH " " $HIVED_BINARY_DIR " )
7292
73- pwd
93+ # pwd
7494mkdir -vp " $abs_build_dir "
7595pushd " $abs_build_dir "
76- pwd
77- cmake -DCMAKE_BUILD_TYPE=Release -GNinja " ${CMAKE_ARGS[@]} " " $abs_src_dir "
96+ # pwd
97+
98+ echo " Building Hive!"
7899
100+ cmake -DCMAKE_BUILD_TYPE=Release -GNinja " ${CMAKE_ARGS[@]} " " $abs_src_dir "
79101ninja " $@ "
80102
103+ if [[ " $CLEAN_AFTER_BUILD " == " true" ]]; then
104+ echo " Cleaning up after build..."
105+ # Patterns for find must be quoted so they're not expanded by Bash
106+ find . -name " *.o" -type f -delete
107+ find . -name " *.a" -type f -delete
108+ fi
109+
110+ echo " Done!"
111+
81112popd
82113
114+ if [[ -d " $HIVED_INSTALLATION_DIR " ]]; then
115+
116+ # Move all the binaries to the $HIVED_INSTALLATION_DIR directory
117+ sudo mv " $abs_build_dir /${HAF_BUILD: +" hive/" } programs/hived/hived" \
118+ " $abs_build_dir /${HAF_BUILD: +" hive/" } programs/cli_wallet/cli_wallet" \
119+ " $abs_build_dir /${HAF_BUILD: +" hive/" } programs/util/" * \
120+ " $HIVED_INSTALLATION_DIR /"
121+
122+ sudo rm -rf " $HIVED_INSTALLATION_DIR /CMakeFiles"
123+
124+ if [[ -f " $abs_build_dir /${HAF_BUILD: +" hive/" } programs/beekeeper/beekeeper/beekeeper" ]]; then
125+ sudo mv " $abs_build_dir /${HAF_BUILD: +" hive/" } programs/beekeeper/beekeeper/beekeeper" \
126+ " $HIVED_INSTALLATION_DIR /"
127+ fi
128+
129+ if [[ -n " $( shopt -s nullglob; echo " $abs_build_dir /${HAF_BUILD: +" hive/" } programs/blockchain_converter/blockchain_converter" * ) " ]]; then
130+ sudo mv " $abs_build_dir /${HAF_BUILD: +" hive/" } programs/blockchain_converter/blockchain_converter" * \
131+ " $HIVED_INSTALLATION_DIR /"
132+ fi
133+
134+ if [[ -n " $( shopt -s nullglob; echo " $abs_build_dir /${HAF_BUILD: +" hive/" } bin/" * ) " ]]; then
135+ sudo mv " $abs_build_dir /${HAF_BUILD: +" hive/" } bin/" * \
136+ " $HIVED_INSTALLATION_DIR /"
137+ fi
138+
139+ if [[ -n " $( shopt -s nullglob; echo " $abs_build_dir /bin/" * ) " ]]; then
140+ sudo mv " $abs_build_dir /bin/" * \
141+ " $HIVED_INSTALLATION_DIR /"
142+ fi
143+
144+ if [[ -n " $( shopt -s nullglob; echo " $abs_build_dir /tests/unit/" * ) " ]]; then
145+ sudo mv " $abs_build_dir /tests/unit/" * " $HIVED_INSTALLATION_DIR /"
146+ fi
147+
148+ sudo rm -rf " $HIVED_INSTALLATION_DIR /CMakeFiles" " $HIVED_INSTALLATION_DIR /cmake_install.cmake"
149+
150+ if [[ -n " $( shopt -s nullglob; echo " $abs_build_dir /${HAF_BUILD: +" hive/" } libraries/vendor/rocksdb/tools/sst_dum" * ) " ]]; then
151+ sudo mv " $abs_build_dir /${HAF_BUILD: +" hive/" } libraries/vendor/rocksdb/tools/sst_dum" * \
152+ " $HIVED_INSTALLATION_DIR /"
153+ fi
154+
155+ fi
0 commit comments