-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·209 lines (175 loc) · 4.75 KB
/
install
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env bash
trap exitfunc ERR
prefix=$HOME/local.rtaproto2
sourcedir=$PWD
build_type=Release
buildexe=true
platform=$(uname -s)
if [[ $platform == "Darwin" ]] ; then
nthreads=$(sysctl hw.ncpu | awk '{print $2}')
else
nthreads=$(cat /proc/cpuinfo | grep processor | wc -l)
fi
clean=$1
function exitfunc() {
if [[ $plaform == "Darwin" ]] ; then
tput seaf op
fi
exit -1
}
function echo_red() {
if [[ $platform == "Darwin" ]] ; then
tput setaf 1
echo $@
tput setaf op
else
echo -e "\e[00;31m$1\e[00m"
fi
}
function set_debug_flags() {
if [[ $build_type == "Debug" ]] ; then
export CFLAGS="$CFLAGS -O0 -g" ; export CXXFLAGS="$CXXFLAGS -O0 -g"
else
export CFLAGS="$CFLAGS -O2" ; export CXXFLAGS="$CXXFLAGS -O2"
fi
}
function reset_flags() {
unset CFLAGS ; unset CXXFLAGS ; unset LDFLAGS
}
function show_help {
echo "Usage: $0 [-hld] [-p PREFIX] [-n NUMTHREADS] [clean]"
echo " -h print this help"
echo " -p PREFIX set installation prefix, default is \$HOME/local.rtaproto2"
echo " -l install only the libRTAAlgorithms"
echo " -n NUMTHREADS default number of threads is equal to the number of cores"
echo " -d compile with debug"
exit
}
#################################################
# parse command options
while getopts "hp:ln:d" o;
do
case "${o}" in
h)
show_help
;;
p)
prefix=${OPTARG}
;;
l)
buildexe=false
;;
n)
nthreads=${OPTARG}
;;
d)
build_type=Debug
;;
*)
show_help
;;
esac
done
shift $((OPTIND-1))
#################################################
# check privileges and create prefix directories
trap - ERR
mkdir -p $prefix
if [ $? -ne 0 ] ; then
trap exitfunc ERR
echo_red "You have not the write permissions on $prefix."
echo_red "Maybe you want to run the script as root? Trying with sudo.."
sudo=sudo
$sudo mkdir -p $prefix
fi
trap exitfunc ERR
#################################################
# generate profile and load it
if [[ $clean != "clean" ]] ; then
echo_red "#### generating profile"
cat << EOF > profile_rtaproto2
#!/usr/bin/env bash
rtaproto2_prefix=$prefix
include_paths="\$rtaproto2_prefix/include"
lib_paths="\$rtaproto2_prefix/lib"
bin_paths="\$rtaproto2_prefix/bin"
if [[ -z \$C_INCLUDE_PATH || \$C_INCLUDE_PATH != *"\$include_paths"* ]] ; then
export C_INCLUDE_PATH="\$include_paths"\${C_INCLUDE_PATH:+:\$C_INCLUDE_PATH}
fi
if [[ -z \$CPLUS_INCLUDE_PATH || \$CPLUS_INCLUDE_PATH != *"\$include_paths"* ]] ; then
export CPLUS_INCLUDE_PATH="\$include_paths"\${CPLUS_INCLUDE_PATH:+:\$CPLUS_INCLUDE_PATH}
fi
if [[ -z \$PATH || \$PATH != *"\$bin_paths"* ]] ; then
export PATH="\$bin_paths"\${PATH:+:\$PATH}
fi
if [[ -z \$CMAKE_INCLUDE_PATH || \$CMAKE_INCLUDE_PATH != *"\$include_paths"* ]] ; then
export CMAKE_INCLUDE_PATH="\$include_paths"\${CMAKE_INCLUDE_PATH:+:\$CMAKE_INCLUDE_PATH}
fi
if [[ -z \$CMAKE_LIBRARY_PATH || \$CMAKE_LIBRARY_PATH != *"\$lib_paths"* ]] ; then
export CMAKE_LIBRARY_PATH="\$lib_paths"\${CMAKE_LIBRARY_PATH:+:\$CMAKE_LIBRARY_PATH}
fi
if [[ -z \$LIBRARY_PATH || \$LIBRARY_PATH != *"\$lib_paths"* ]] ; then
export LIBRARY_PATH="\$lib_paths"\${LIBRARY_PATH:+:\$LIBRARY_PATH}
fi
if [[ -z \$LD_LIBRARY_PATH || \$LD_LIBRARY_PATH != *"\$lib_paths"* ]] ; then
export LD_LIBRARY_PATH="\$lib_paths"\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}
fi
if [[ -z \$DYLD_LIBRARY_PATH || \$DYLD_LIBRARY_PATH != *"\$lib_paths"* ]] ; then
export DYLD_LIBRARY_PATH="\$lib_paths"\${DYLD_LIBRARY_PATH:+:\$DYLD_LIBRARY_PATH}
fi
if [[ -z \$PYTHONPATH || \$PYTHONPATH != *"\$lib_paths"* ]] ; then
export PYTHONPATH="\$lib_paths"\${PYTHONPATH:+:\$PYTHONPATH}
fi
export CTARTA=\$rtaproto2_prefix
EOF
echo_red "#### loading profile"
. profile_rtaproto2
fi
#################################################
# build packages
declare -a libs=("PacketLib" "CTAUtils" "CTAConfig" "CTAAlgorithms")
declare -a execs=("RTAAlgorithms" "RTAPrototype2")
for i in "${libs[@]}"
do
pushd $PWD
cd $sourcedir/$i
if [[ $clean == "clean" ]] ; then
echo_red "#### cleaning $i"
make clean
echo_red "#### clean complete."
else
echo_red "#### installing $i"
set_debug_flags
make -j$nthreads
$sudo make install prefix="$prefix"
reset_flags
echo_red "#### $i installation successful."
fi
popd
done
if ! $buildexe ; then
echo_red "#### Done."
exit
fi
for i in "${execs[@]}" ; do
pushd $PWD
cd $sourcedir/$i
if [[ $clean == "clean" ]] ; then
echo_red "#### cleaning $i"
make clean
echo_red "#### clean complete."
else
echo_red "#### installing $i"
set_debug_flags
make -j$nthreads
$sudo make install prefix="$prefix"
reset_flags
echo_red "#### $i installation successful."
fi
popd
done
if [[ $1 != "clean" ]] ; then
cd $sourcedir
$sudo cp -p profile_rtaproto2 $prefix/share
fi
echo_red "#### Done."