-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·281 lines (254 loc) · 7.46 KB
/
build
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#! /bin/sh
fmt="SDF"
fullversion=`visit -version 2>&1 | sed 's,.* \([0-9\.]*\),\1,'`
version=${fullversion%%\.*}
tmpdir=.builddir
clean=0
build_type=0
build_visit_reader=1
build_utilities=0
DBG=""
DEBUG=""
PRIVATE="-private"
VERBOSE=""
OPTS=""
PLUGNDIR=""
err=0
stop=0
while getopts crdpnuvh123i: name
do
case $name in
c) clean=2 ; OPTS="$OPTS -c";;
r) clean=1 ; OPTS="$OPTS -r";;
d) DBG="-g -O0"; OPTS="$OPTS -d";
DEBUG="-DCMAKE_BUILD_TYPE=Debug" ;;
p) PRIVATE="-public"; OPTS="$OPTS -p" ;;
n) build_visit_reader=0 ;;
u) build_utilities=1 ;;
v) VERBOSE="VERBOSE=1" ;;
h) cat <<EOF
The VisIt build script attempts to automate the process of building the SDF
VisIt reader plugin on a variety of platforms. By default it will try three
approaches to building the plugin. First it tries the build environment
supplied by the VisIt installation. If this fails, it will attempt to build a
parallel version of the plugin using the mpi compiler in the current search
path. Finally, it will try just building the serial version of the plugin.
VisIt build script options:
-c: Clean up files. Do not build anything.
-r: Rebuild. Clean up files and then build.
-d: Build with debugging flags enabled.
-p: Do a "public" build. This passes the "-public" flag on to the VisIt build
system which copies the binaries into a publically accessible location.
-n: Don't build the VisIt reader plugin.
-u: Do build the additional SDF utilities.
-i VISITPLUGINDIR:
Install the reader plugin in the path VISITPLUGINDIR
-v: Build verbosely.
-1: Perform only the default VisIt build.
-2: Perform only a parallel VisIt build.
-3: Perform only a serial VisIt build.
EOF
exit ;;
1) build_type=1 ; stop=1 ;;
2) build_type=2 ; stop=1 ;;
3) build_type=3 ; stop=1 ;;
i) PLUGINDIR="$OPTARG"
esac
done
# Find directory containing the actual visit binary
cwd=`pwd`
cmd=`which visit`
if [ "$cmd"x = x ]; then
echo ERROR: The command 'visit' was not found in your search PATH
exit 1
fi
i=0
while [ $i -lt 100 ]; do
visitpath=`dirname $cmd`
cd "$visitpath"
[ "$visitpath"x = "."x ] && visitpath=`pwd`
cmd=`basename $cmd`
cmd=`readlink $cmd`
[ "$cmd"x = x ] && break
i=$((i+1))
done
cd "$cwd"
export PATH="$visitpath:$PATH"
export CXXFLAGS="-Wno-deprecated $DBG"
export CFLAGS="$DBG"
stdlib="$CXXFLAGS"
# Auto-detect C++ compiler
cpp=$CXX
[ "$cpp"x = x ] && cpp=$(which c++)
[ "$cpp"x = x ] && cpp=$(which cpp)
[ "$cpp"x = x ] && cpp=$(which g++)
$cpp --version | grep -i clang > /dev/null 2>&1
if [ $? -eq 0 ]; then
stdlib="-stdlib=libstdc++ $CXXFLAGS"
fi
buildit () {
err=0
purge=0
buildver="$build_type -- $fullversion"
oldbuildver=""
[ -r $tmpdir/buildver ] && oldbuildver=`cat $tmpdir/buildver`
if [ "$oldbuildver"x != "$buildver"x ]; then
purge=1
rm -rf $tmpdir
mkdir -p $tmpdir
echo "$buildver" > $tmpdir/buildver
rm -rf CMake* cmake* Makefile
else
echo "No need to purge"
fi
if [ "$version"x = x ]; then
echo "Unable to build. Please add visit to your \$PATH"
exit 1
fi
if [ $purge -ne 0 ]; then
xml2info -clobber $PRIVATE ${fmt}${version}.xml
if [ $version -eq 1 ]; then
xml2makefile -clobber $PRIVATE ${fmt}${version}.xml
if [ "`uname -m`"x = "x86_64x" ]; then
sed "s,\(^CXXFLAGS.*\),\1 -m32 $DBG\\
CFLAGS=\$(CFLAGSORIG) -m32 $DBG\\
PY_CXXFLAGS=-I\$(TOPDIR)/include/python,;s,\(^LDFLAGS.*\),\1 -m32 $DBG," \
Makefile > .Makefile.tmp
\mv -f .Makefile.tmp Makefile
fi
if [ $build_type -eq 2 ]; then
sed "s,\(^CXXFLAGS.*\),\1\\
CXX=mpic++\\
CC=mpicc," Makefile > .Makefile.tmp
\mv -f .Makefile.tmp Makefile
elif [ $build_type -eq 3 ]; then
grep -v "^EPARDSO" Makefile > .Makefile.tmp
\mv -f .Makefile.tmp Makefile
fi
else
xml2cmake -clobber $PRIVATE ${fmt}${version}.xml
if [ -n "$PLUGINDIR" ] ; then
sed -i '/VISIT_PLUGIN_DIR/ s;".*";"'$PLUGINDIR'";' CMakeLists.txt
fi
setup=$(grep -w PluginVsInstall.cmake CMakeLists.txt | cut -f2 -d\")
grep -w clang $setup > /dev/null
if [ $? -ne 0 ]; then
# If using clang when original was compiled with gcc, then we need
# to add a flag for stdlib
export CXXFLAGS="$stdlib"
fi
for f in `grep -w INCLUDE CMakeLists.txt | cut -f2 -d\( | \
cut -f1 -d\) | tr -d \"`; do
base=`basename $f`
com1=vtkCommonDataModel
com2=vtkCommonExecutionModel
sed 's/\([;"]'$com1'-\)\([^;]*\)/\1\2;'$com2'-\2/' \
$f > $tmpdir/$base
if [ $build_type -eq 2 ]; then
sed 's/\([;"]\)[^;]*libmpi[^;]*;/\1/g;
s/\([;"]\)[^;]*libopen-[^;]*;/\1/g;
s/\([;"]\)[^;]*general[^;]*;/\1/g' $f > $tmpdir/$base
grep -v 'CMAKE_CXX_COMPILER ' $tmpdir/$base | \
grep -v 'CMAKE_C_COMPILER ' | \
grep -v 'VISIT_PARALLEL_LIBS ' > $tmpdir/tmp
mv $tmpdir/tmp $tmpdir/$base
elif [ $build_type -eq 3 ]; then
sed 's/\([;"]\)[^;]*libmpi[^;]*;/\1/g;
s/\([;"]\)[^;]*libopen-[^;]*;/\1/g;
s/\([;"]\)[^;]*general[^;]*;/\1/g' $f > $tmpdir/$base
grep -v 'VISIT_PARALLEL ' $tmpdir/$base > $tmpdir/tmp
mv $tmpdir/tmp $tmpdir/$base
fi
sed 's,\(INCLUDE(["]*\)'$f'\(["]*\),\1'$tmpdir/$base'\2,' \
CMakeLists.txt > $tmpdir/tmp
mv $tmpdir/tmp CMakeLists.txt
done
fi
cmake $DEBUG .
# FIXME: This is to workaround incorrect cmake output
ofile=CMakeFiles/ESDFDatabase_par.dir/build.make
if [ -e $ofile ]; then
sed '/linux-x86_64\/lib\/librt\.so/ d;
/linux-x86_64\/lib\/libpthread\.so/ d' $ofile > $tmpdir/tmp
mv $tmpdir/tmp $ofile
fi
fi
if [ $clean -ge 1 ] ; then make clean ; fi
make $VERBOSE
err=$?
if [ $err -eq 0 ]; then
echo
echo "VisIt ${fmt} reader successfully built.${srl}"
fi
if [ $stop -ne 0 ] ; then exit ; fi
return $err
}
build_default () {
srl=""
build_type=1
buildit
err=$?
}
build_parallel () {
srl=""
build_type=2
# Execute in a subshell to stop CC being altered in the current shell.
(export CC=mpicc
export CXX=mpicxx
buildit)
err=$?
}
build_serial () {
srl=" (Serial version only)."
build_type=3
buildit
err=$?
}
get_old_build_type () {
type=1
[ -r $tmpdir/buildver ] && type=`cut -c1 $tmpdir/buildver`
return $type
}
if [ $clean -ge 2 ]; then
make clean > /dev/null 2>&1
rm -rf CMake* cmake* Makefile ${fmt}*Info.C ${fmt}*Info.h $tmpdir
elif [ $build_visit_reader -eq 1 ]; then
sh gen_commit_string.sh
echo "#define SDF_READER_BUILD_DATE \"`date`\"" > build_date.h
if [ $build_type -eq 1 ]; then
build_default
elif [ $build_type -eq 2 ]; then
build_parallel
elif [ $build_type -eq 3 ]; then
build_serial
else
get_old_build_type
tried=$?
if [ $tried -eq 1 ]; then
build_default
elif [ $tried -eq 2 ]; then
build_parallel
elif [ $tried -eq 3 ]; then
build_serial
fi
if [ $err -ne 0 -a $tried -ne 1 ]; then
echo
echo "Trying again with default"
build_default
fi
if [ $err -ne 0 -a $tried -ne 2 ]; then
echo
echo "Trying again with mpicc"
build_parallel
fi
if [ $err -ne 0 -a $tried -ne 3 ]; then
echo
echo "Trying again without parallel reader."
build_serial
fi
fi
if [ $err -ne 0 ]; then
echo "ERROR: Failed to build VisIt reader."
exit 1
fi
fi