-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.sh
executable file
·62 lines (56 loc) · 1.5 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /bin/bash
contract=""
did_init=false
RED='\033[0;31m'
NC='\033[0m'
CORES=`getconf _NPROCESSORS_ONLN`
usage_info() {
echo "Usage: build.sh [-c] contract_name"
}
find_out=$(find ./contracts/ -type d -mindepth 1 -maxdepth 1 -exec basename {} \; | tr "\n" " ")
IFS=' ' && read -ra contracts_array <<< "$find_out"
len=${#contracts_array[@]} && options=""
for (( i=0; i<$len; i++)); do
if [[ $i == $(($len-1)) ]]; then
options+="${contracts_array[$i]}"
else
options+="${contracts_array[$i]}, "
fi
done
if ! [[ -d "./build" ]]; then
printf "${RED}\tBuild folder not found, generating cmake files\n\n${NC}"
printf "\t=========== Building Telos Works ===========\n\n"
mkdir -p build
pushd build &> /dev/null
cmake ../
make -j${CORES}
popd &> /dev/null
did_init=true
fi
while getopts ":c:h" opt; do
case ${opt} in
c )
contract=$OPTARG
;;
h )
usage_info
exit 0
;;
esac
done
shift $((OPTIND -1))
if [[ $contract != "" ]]; then
if [[ " ${contracts_array[@]} " =~ " ${contract} " ]]; then
printf "\t=========== Building ${contract} Contract ===========\n\n"
pushd build/contracts/${contract} &> /dev/null
make -j${CORES}
popd &> /dev/null
else
echo "[-c] flag value must be the name of a contract compiled by this project. Options: [ ${options} ]"
exit 1
fi
elif [[ $did_init != true ]]; then
pushd build &> /dev/null
make -j${CORES}
popd &> /dev/null
fi