-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·214 lines (212 loc) · 6.43 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
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
#!/usr/bin/env bash
version=dbg
clean=1
relink=
out=
compiler=
silent="-s"
tests=1
build_dir=
noopt=
nodbg=
noTangoUser=1
installLibs=
BLIP_HOME=$PWD
mpi=
die() {
echo "$1"
exit $2
}
if [ -z "$D_HOME" ] ; then
D_HOME=$HOME
fi
if [ -n "`which gmake >& /dev/null`" ] ; then
make="gmake"
elif [ -n "`which gnumake >& /dev/null`" ] ; then
make="gnumake"
else
make="make"
fi
while [ $# -gt 0 ]
do
case $1 in
--help)
echo "usage: build [options]"
echo ""
echo " builds the blip library and its tests and possibly installs it"
echo " --version x builds version x (typically opt or dbg)"
echo " --quick no clean before rebuilding"
echo " --verbose verbose building"
echo " --d-home x uses x as d home (default $D_HOME )"
echo " --blip-home x uses x as blip home (defaults to $PWD )"
echo " --mpi compiles the mpi version"
echo " --tango-user does link the tango-user library"
echo " --no-tests does not compile the tests"
echo " --no-opt does not compile the opt version"
echo " --no-dbg does not compile the dbg version"
echo " --build-dir X uses X as build dir (you *really* want to use a local"
echo " filesystem like /tmp/$USER/build for building if possible"
echo " --install installs the libraries (in the lib dir close to the compiler)"
if [ -n "$D_BUILD_DIR" ] ; then
echo " defaults to $D_BUILD_DIR )"
else
echo " defaults to $D_HOME/build )"
fi
echo ""
echo "The script uses '$'DC as compiler if set"
echo "or the first compiler found if not set."
echo "important environment variables are:"
echo " D_HOME: the default --d-home value"
echo " D_BUILD_DIR: the default build dir (you should use a local filesystem)"
echo " DFLAGS_ADD: adds the given D flags"
echo " CFLAGS_ADD: adds the given C flags"
echo " DFLAGS: as environment variable is not changed"
echo " CFLAGS: adds the given C flags"
echo " EXTRA_LIBS: add the given link flags (to link lapack for example)"
echo " MKLROOT: if sets links the mkl library on linux x86_64"
exit 0
;;
--version)
shift
version=$1
;;
--quick)
clean=
;;
--verbose)
silent=
;;
--d-home)
shift
D_HOME=$1
;;
--make)
shift
make="$1"
;;
--build-dir)
shift
build_dir="OBJDIRBASE=$1"
;;
--blip-home)
shift
BLIP_HOME=$1
;;
--install)
installLibs=1
;;
--mpi)
mpi=1
;;
--tango-user)
noTangoUser=
;;
--no-tests)
tests=0
;;
--no-dbg)
nodbg=1
;;
--no-opt)
noopt=1
;;
*)
die "unexpected argument $1"
break
;;
esac
shift
done
if [ -z "$build_dir" ] ; then
if [ -n "$D_BUILD_DIR" ] ; then
build_dir=OBJDIRBASE="$D_BUILD_DIR"
fi
fi
if [ -z "$compiler" ]; then
compiler=`$BLIP_HOME/build/tools/guessCompiler.sh --path $DC`
fi
compShort=`$BLIP_HOME/build/tools/guessCompiler.sh $compiler`
if [ "$version" == "opt" ]; then
libExt=
else
libExt="-$version"
fi
case $compShort in
dmd)
linkFlag="-L"
versionFlag="-version="
extra_libs_comp=""
;;
ldc)
linkFlag="-L="
versionFlag="-d-version="
extra_libs_comp=
;;
*)
die "unsupported compiler"
esac
mpiVersion=
mpiFlags=
if [ -n "$mpi" ] ; then
mpiFlags=
for f in `mpicc --showme:link` ; do
mpiFlags="$mpiFlags ${linkFlag}$f"
done
mpiFlags="$mpiFlags ${versionFlag}mpi"
mpiVersion="_mpi"
fi
case `uname` in
Darwin)
extra_libs_os="${linkFlag}-lhwloc ${linkFlag}-lev ${linkFlag}-framework ${linkFlag}Accelerate ${linkFlag}-lz ${linkFlag}-lbz2"
;;
Linux)
if [ -n "$MKLROOT" ] ; then
DFLAGS_ADD="$DFLAGS_ADD ${versionFlag}CBlasDot"
extra_libs_os="${linkFlag}-lhwloc ${linkFlag}-lxml2 ${linkFlag}-lev ${linkFlag}-L$MKLROOT/lib/em64t ${linkFlag}-lmkl_lapack ${linkFlag}--start-group ${linkFlag}-lmkl_intel_lp64 ${linkFlag}-lmkl_core ${linkFlag}-lmkl_sequential ${linkFlag}--end-group ${linkFlag}-ldl ${linkFlag}-lz ${linkFlag}-lbz2"
else
extra_libs_os="${linkFlag}-lhwloc ${linkFlag}-lev ${linkFlag}-llapack ${linkFlag}-lblas ${linkFlag}-lgfortran ${linkFlag}-ldl ${linkFlag}-lz ${linkFlag}-lbz2"
fi
;;
*)
die "unknown platform, you need to set extra_libs_os"
esac
if [ -z "$noTangoUser" ]; then
tangoUserOpt="${linkFlag}-ltango-user-${compShort}"
tangoUserDbg="${linkFlag}-ltango-user-${compShort}-dbg"
fi
extra_libs_opt="${linkFlag}-L${D_HOME}/lib $tangoUserOpt $extra_libs_os $extra_libs_comp $mpiFlags"
extra_libs_dbg="${linkFlag}-L${D_HOME}/lib $tangoUserDbg $extra_libs_os $extra_libs_comp $mpiFlags"
case $version in
opt)
extra_libs="$extra_libs_opt"
;;
dbg)
extra_libs="$extra_libs_dbg"
;;
*)
echo "unknown version, guessing extra_libs"
extra_libs="${linkFlag}-L${D_HOME}/lib $tangoUserDbg $extra_libs_os $extra_libs_comp $mpiFlags"
esac
makeFlags="$silent $build_dir"
if [ -n "$clean" ]; then
$make $makeFlags distclean
rm -f libs/libblip-*
fi
if [ -z "$noopt" ]; then
$make $makeFlags DFLAGS_ADD="$DFLAGS_ADD" EXTRA_LIBS="$EXTRA_LIBS $extra_libs_opt" VERSION=opt${mpiVersion} lib || die "error building the opt version"
fi
if [ -z "$nodbg" ]; then
$make $makeFlags DFLAGS_ADD="$DFLAGS_ADD" EXTRA_LIBS="$EXTRA_LIBS $extra_libs_dbg" VERSION=dbg${mpiVersion} lib || die "error building the dbg version"
fi
if [ -n "$tests" ] ; then
$make $makeFlags DFLAGS_ADD="$DFLAGS_ADD" EXTRA_LIBS="$EXTRA_LIBS $extra_libs" VERSION=$version${mpiVersion} || die "error building the tests"
fi
if [ -n "$installLibs" ]; then
installDir=`dirname $compiler`/../lib
for l in libs/libblip-* ; do
if [ -e "$l" ] ; then
echo "$l -> $installDir"
cp $l $installDir
fi
done
fi