/
rose-build.sh
executable file
·212 lines (197 loc) · 4.98 KB
/
rose-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
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
210
211
212
#!/usr/bin/env bash
#
# Detects options and path settings and runs configure and make.
#
# Usage:
# rose-build.sh -r <src-path> -p <install-path>:
# - src-path: unpacked ROSE source directory
# - install-path: installation path (should be an absolute path)
#
# After options are determined, each of the following commands can be selected.
# - configure
# - make
# - make install
#set -u
set -e
ROSE_SRC=""
INSTALL_PREFIX=""
function download_latest_tarball()
{
local site='https://outreach.scidac.gov'
echo "Trying to detect the latest ROSE source package..."
local path=$(wget --quiet -O- "$site/frs/?group_id=24" | egrep -o -m1 '/frs/download.php/[0-9]+/rose-0.9.5a-without-EDG-[0-9]+\.tar\.gz')
echo "Downloading $site$path..."
wget $site$path
echo "Download finished."
tar zxf $(basename $path)
local dname=$(basename $path .tar.gz| sed 's/-without-EDG//')
mv $dname src
mkdir $dname
mv src $dname
mkdir $dname/build $dname/install
ROSE_SRC=$(pwd)/$dname/src
INSTALL_PREFIX=$(pwd)/$dname/install
cd $dname/build
}
function detect_boost()
{
local BOOST_CANDIDATES=($HOME/homebrew /usr
$HOME/tools/boost /work0/GSIC/apps/boost/1_45_0/gcc)
if [ -z "$BOOST" ]; then
for c in ${BOOST_CANDIDATES[*]}; do
if [ -d $c/include/boost ]; then
BOOST=$c
break
fi
done
fi
echo Using Boost found at $BOOST
if [ -e "$BOOST/lib64/libboost_program_options.so" ]; then
BOOSTLIB=$BOOST/lib64
elif [ -e "$BOOST/lib/libboost_program_options.so" ]; then
BOOSTLIB=$BOOST/lib
else
echo "ERROR! Boost library not found."
exit 1
fi
}
function set_java_home()
{
if [ -z "$JAVA_HOME" ]; then
case $OSTYPE in
linux*)
for i in $(locate libjvm.so); do
if echo $i | grep --silent -e gcc -e gcj -e openjdk; then continue; fi
echo -n "Using $i? [Y/n] "
read yn
if [ "$yn" != "n" ]; then
export JAVA_HOME=${i%/jre*}
break
fi
done
if [ -z "$JAVA_HOME" ]; then
echo "Error: no Java found"
exit 1
fi
;;
darwin*)
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
;;
esac
fi
echo JAVA_HOME is set to $JAVA_HOME
}
function detect_java_libraries()
{
local JVM_DIR=$(dirname $(find ${JAVA_HOME}/ -name "libjvm\.*" | head -1))
case $OSTYPE in
linux*)
JAVA_LIBRARIES=${JAVA_HOME}/jre/lib:$JVM_DIR
;;
darwin*)
JAVA_LIBRARIES=$JVM_DIR
;;
esac
}
function exec_configure()
{
if [ -z "$ROSE_SRC" ]; then echo "ERROR! ROSE src path not set"; exit 1; fi
if [ -z "$INSTALL_PREFIX" ]; then echo "ERROR! install prefix not set"; exit 1; fi
echo Building ROSE at $ROSE_SRC and installing it to $INSTALL_PREFIX
echo $ROSE_SRC/configure --prefix=$INSTALL_PREFIX --with-CXX_DEBUG=-g --with-CXX_WARNINGS="-Wall -Wno-deprecated" --with-boost=$BOOST --with-boost-libdir=$BOOSTLIB --enable-languages=c,c++,fortran,cuda,opencl --disable-binary-analysis-tests -with-haskell=no
echo -n "Type Enter to proceed: "
read x
$ROSE_SRC/configure --prefix=$INSTALL_PREFIX --with-CXX_DEBUG=-g --with-CXX_WARNINGS="-Wall -Wno-deprecated" --with-boost=$BOOST --with-boost-libdir=$BOOSTLIB --enable-languages=c,c++,fortran,cuda,opencl --enable-binary-analysis-tests=no --disable-projects-directory --disable-tutorial-directory -with-haskell=no
if [ $? == 0 ]; then
echo "Rerun again and select make for building ROSE"
fi
}
function detect_num_cores()
{
NUM_PROCESSORS=1 # default
echo "Detecting number of cores..."
case $OSTYPE in
linux*)
NUM_PROCESSORS=$(grep processor /proc/cpuinfo|wc -l)
;;
darwin*)
NUM_PROCESSORS=$(system_profiler |grep 'Total Number Of Cores' | awk '{print $5}')
;;
esac
}
function exec_make()
{
detect_num_cores
echo building ROSE by make -j$NUM_PROCESSORS
make -j$((NUM_PROCESSORS / 2))
if [ $? == 0 ]; then
echo "Rerun again and select make install to install ROSE"
fi
}
function exec_install()
{
echo installing ROSE
make install
echo "ROSE is installed at $INSTALL_PREFIX"
}
while getopts ":r:p:b:" opt; do
case $opt in
r)
ROSE_SRC=$OPTARG
;;
p)
INSTALL_PREFIX=$OPTARG
;;
b)
BOOST=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
detect_boost
set_java_home
detect_java_libraries
case $OSTYPE in
linux*)
echo export LD_LIBRARY_PATH=${JAVA_LIBRARIES}:${BOOST}/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${JAVA_LIBRARIES}:${BOOST}/lib:$LD_LIBRARY_PATH
;;
darwin*)
echo export DYLD_LIBRARY_PATH=${JAVA_LIBRARIES}:${BOOST}/lib:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=${JAVA_LIBRARIES}:${BOOST}/lib:$DYLD_LIBRARY_PATH
;;
esac
echo "Commands"
echo "1: download"
echo "2: configure"
echo "3: make"
echo "4: make install"
echo "5: do all"
echo -n "What to do? [1-5] (default: 5): "
read command
if [ "x$command" = "x" ]; then command="5"; fi
case $command in
1)
download_latest_tarball
;;
2)
exec_configure
;;
3)
exec_make
;;
4)
exec_install
;;
5)
download_latest_tarball
exec_configure
exec_make
exec_install
;;
*)
echo Invalid input \"$command\"
;;
esac