-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·231 lines (208 loc) · 5.18 KB
/
configure
File metadata and controls
executable file
·231 lines (208 loc) · 5.18 KB
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
#!/bin/bash
# Configure script for CreateRemdDirs
Usage() {
echo "Usage: ./configure <OPTIONS> [gnu | intel | pgi | clang | cray]"
echo " OPTIONS:"
echo " --help : Display this message."
echo " -cray : Use cray compiler wrappers (cc/CC/ftn)."
echo " --with-netcdf=<DIR>: Use NetCDF in <DIR>"
echo " -nonetcdf : Disable NetCDF (disables check functionality)."
echo " -nolfs : Disable large file support."
echo ""
}
# ------------------------------------------------------------------------------
# If arg is Key=Value, separate into Key and Value
ParseArg() {
KEY=`echo "$1" | awk 'BEGIN{FS = "=";}{print $1;}'`
VALUE=`echo "$1" | awk 'BEGIN{FS = "=";}{print $2;}'`
eval VALUE=$VALUE
if [[ $VALUE = $KEY ]] ; then
VALUE=""
fi
}
CompileError() {
echo "Compile error: $1" > /dev/stderr
if [[ -f "compile.err" ]] ; then
cat compile.err > /dev/stderr
rm compile.err
fi
exit 1
}
# TestCxxProgram {required|optional} <TestName> [<Lib>]
# Test compile test program testp.cpp
TestCxxProgram() {
echo "$2"
COMPILELINE="$CXX $CXXFLAGS -o testp testp.cpp $3"
$COMPILELINE > /dev/null 2> compile.err
if [[ $? -ne 0 ]] ; then
if [ "$1" = 'required' ] ; then
CompileError "$COMPILELINE"
fi
return 1
fi
./testp | grep "Testing" > /dev/null
if [[ $? -ne 0 ]] ; then
if [ "$1" = 'required' ] ; then
CompileError "$COMPILELINE"
fi
return 1
fi
/bin/rm -f testp.cpp testp compile.err
echo " OK"
return 0
}
TestNetcdf() {
if [[ ! -z $NETCDFLIB ]] ; then
compile_stat=''
if [ $NETCDF_SPECIFIED -eq 1 ] ; then
compile_stat='required'
else
compile_stat='optional'
fi
cat > testp.cpp <<EOF
#include <cstdio>
#include "netcdf.h"
int main() { printf("Testing\n"); printf("%s\n",nc_strerror(0)); return 0; }
EOF
TestCxxProgram "$compile_stat" "Checking NetCDF" "$NETCDFLIB"
if [ $? -ne 0 ] ; then
# If we are here netcdf is optional and failed. Disabled it.
echo " NetCDF not found. Disabling."
NETCDFLIB=""
fi
fi
}
TestCompile() {
cat > testp.cpp <<EOF
#include <cstdio>
int main() { printf("Testing\n"); return 0; }
EOF
TestCxxProgram 'required' "Testing C++ compiler"
}
# ------------------------------------------------------------------------------
if [[ $1 = "--help" || $1 = "-h" ]] ; then
Usage
exit 0
fi
CONFIGURECMD="./configure $*"
KEY=""
VALUE=""
echo ""
# Process options
if [[ ! -z $CXX ]] ; then
COMPILER=$CXX
else
COMPILER=g++
fi
NETCDFLIB=-lnetcdf
NETCDF_HOME=""
NETCDF_SPECIFIED=0
DIRECTIVES=""
INCLUDE=""
LFS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
NO_OPT=0
DBG_FLAG=""
while [[ ! -z $1 ]] ; do
ParseArg $1
case "$KEY" in
"gnu" ) COMPILER=g++ ;;
"clang" ) COMPILER=clang++ ;;
"intel" ) COMPILER=icpc ;;
"pgi" ) COMPILER=pgc++ ;;
"cray" ) COMPILER=CC ;;
"-cray" ) echo "Using cray compiler wrapper (CC)." ; USECRAY=1 ;;
"-nonetcdf" ) echo "Not using netcdf." ; NETCDFLIB="" ;;
"-nolfs" ) echo "Disabling large file support." ; LFS="" ;;
"-noopt" ) echo "Disabling optimization." ; NO_OPT=1 ;;
"-debug" ) echo "Enabling compile debug." ; DBG_FLAG=-g ;;
"-d" )
echo "Disabling optimization and enabling compile debug."
NO_OPT=1
DBG_FLAG=-g
;;
"--with-netcdf" )
NETCDF_SPECIFIED=1
INCLUDE="$INCLUDE -I$VALUE/include"
NETCDF_HOME="$VALUE"
echo "Using NETCDF in $NETCDF_HOME"
;;
* ) echo "Error: Unrecognized option $KEY" > /dev/stderr ; exit 1 ;;
esac
shift
done
# Determine compile flags
case "$COMPILER" in
"g++" )
echo "Using gnu compilers"
CXX=g++
OPTFLAGS="-O3 -Wall"
PICFLAG="-fPIC"
;;
"clang++" )
echo "Using clang compilers"
CXX=clang++
OPTFLAGS="-O3 -Weverything"
PICFLAG="-fPIC"
;;
"icpc" )
echo "Using intel compilers"
CXX=icpc
OPTFLAGS="-O3 -Wall"
PICFLAG="-fpic"
;;
"pgc++" )
echo "Using PGI compilers"
CXX=pgc++
OPTFLAGS="-O2"
PICFLAG="-fpic"
;;
"CC" )
echo "Using Cray compilers"
CXX=CC
OPTFLAGS=""
PICFLAG="-fpic"
;;
* ) echo "Error: No compiler." > /dev/stderr ; exit 1 ;;
esac
# Use cray wrappers
if [[ $USECRAY -eq 1 ]] ; then
CXX=CC
fi
# Remove optimizations
if [[ $NO_OPT -eq 1 ]] ; then
OPTFLAGS=""
fi
# Set up NETCDF linking
if [[ ! -z $NETCDF_HOME && ! -z $NETCDFLIB ]] ; then
# Try to link statically if possible
if [ -f "$NETCDF_HOME/lib/libnetcdf.a" ] ; then
NETCDFLIB="$NETCDF_HOME/lib/libnetcdf.a"
else
NETCDFLIB="-L$NETCDF_HOME/lib $NETCDFLIB"
fi
fi
# Set up compiler flags
CXXFLAGS="$DBG_FLAG $OPTFLAGS $LFS $INCLUDE"
# Test compilers
TestCompile
TestNetcdf
# Set up directives
if [[ ! -z $NETCDFLIB ]] ; then
DIRECTIVES="$DIRECTIVES -DHAS_NETCDF"
fi
# Set up linking flags
LDFLAGS="$NETCDFLIB"
# Write config.h
cat > config.h <<EOF
# config.h for CreateRemdDirs
# configured using: $CONFIGURECMD
CXX=$CXX
CXXFLAGS=$CXXFLAGS
DIRECTIVES=$DIRECTIVES
LDFLAGS=$LDFLAGS
EOF
echo "Cleaning source directories."
cd src && make clean > make.log 2>&1
rm make.log
echo ""
exit 0