This repository has been archived by the owner on May 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 185
/
build_setup.sh
executable file
·144 lines (127 loc) · 3.32 KB
/
build_setup.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
#----------------------------------------
#
# Purpose: routines used by build.sh to set up the environment
# The log file $LOG should go in the build directory. This can be
# reassigned after the command line argumens have been parsed. Also
# that dir can be clean out if the -c option is given.
# Don't call this function until after the above is done.
function log
{
echo "$@" | tee -a $LOG
}
function run
{
log "============================================================"
log "$@"
if [ $verbose ]; then
"$@" 2>&1 | tee -a $LOG
else
"$@" 2>&1 >> $LOG
fi
rc=${PIPESTATUS[0]}
if [[ $rc != 0 && -z $ignore_failures ]]; then
log
log "Error $rc :-("
log "See $build_root/Testing/Temporary/LastTest.log for detailed test log"
log "See $LOG for detailed build log"
exit $rc
fi
return $rc
}
# helper function: Print True Or False
function ptof {
if [[ -z $1 ]]; then printf "False";
else printf "True";
fi
}
abspath()
{
if [ -d "$1" ]; then
(cd "$1"; pwd)
elif [ -f "$1" ]; then
if [[ $1 == */* ]]; then
echo "$(cd "${1%/*}"; pwd)/${1##*/}"
else
echo "$(pwd)/$1"
fi
else
# It doesn't exist...
if [[ ${1:0:1} == "/" ]]; then
printf "$1"
elif [[ ${1:0:2} == "./" ]]; then
printf "$(pwd)/"${1:2}
elif [[ ${1:0:2} == "~/" ]]; then
printf "$(HOME)/"${1:2}
elif [[ ${1:0:3} == "../" ]]; then
printf "$(cd ..;pwd)/"${1:3}
else
printf $(pwd)/${1}
fi
fi
}
#----------------------------------------
# Determine number of cores for compiling.
#----------------------------------------
case `uname` in
Linux)
last_core_index=`cat /proc/cpuinfo | grep "processor" | awk '{print $3}' | tail -1`
((num_cores=last_core_index+1))
hostname=$(hostname -s)
;;
Darwin)
num_cores=`sysctl -n hw.ncpu`
hostname=$(hostname -s)
;;
SunOS)
num_cores=`psrinfo | wc -l`
hostname=$(uname -n)
;;
MINGW32_NT-6.1)
hostname=$(uname -n)
;;
*)
num_cores=1
esac
if ((num_cores<8)); then
num_threads=$num_cores
elif ((num_cores<16)); then
num_threads=$((num_cores - 2))
else
num_threads=$((num_cores*3/4))
fi
repo=$(abspath $(dirname "$0"))
user_install_prefix=$HOME/.local
system_install_prefix=/usr/local
python_exe=`which python`
system_python_install="/usr/local"
user_python_install="$HOME/.local"
function hashit
{
case `uname` in
Linux)
echo $1 | shasum
;;
Darwin)
echo $1 | shasum
;;
SunOS)
echo $1 | shasum
;;
esac
}
function get_repo_state
{
git_hash=`cd $1; git rev-parse HEAD`
git_tag=`cd $1; git name-rev --tags --name-only $git_hash`
git_tag=${git_tag%^0}
git_branch=`cd $1;git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' | sed -e 's/(detached from \(.*\))/\1/'`
if [ "$git_tag" != "undefined" ]; then
printf $git_tag
elif [ -n "$git_branch" ]; then
printf $git_branch
else
printf ${git_hash:0:7}
fi
}
build_root=$repo/build/$hostname-$(get_repo_state $repo)