fixed spurious error message inconsistent tign lfn in replay
[wrffire.git] / wrfv2_fire / configure_auto
blob5cfec1b2e7b5df7a004c9df5035103277a015596
1 #!/bin/bash
3 # Jonathan Beezley (jon.beezley@gmail.com)
4 # Feb 29, 2012
5 # Addon script for automated building of WRF. See ./configure_auto -h for documentation.
7 # set defaults
8 TRUE=0
9 FALSE=1
10 : ${CC:='gcc'}
11 : ${FC:='gfortran'}
12 : ${RE:='.*'}
13 : ${DEBUG:=$FALSE}
14 : ${OPENMP:=$FALSE}
15 : ${MPI:=$FALSE}
16 : ${ONE:=$FALSE}
17 : ${NETCDF:=/usr/local}
18 : ${VERBOSE:=$FALSE}
19 : ${NESTING:=1}
20 export NETCDF
22 function p_usage {
23 echo "usage: $0 [-c CC] [-f FC] [-r regex] [-s] [-d] [-g] [-n netcdf] [-1] [-v] [-e #] [-h]" >&2
26 function torf {
27 if [ $1 -eq $TRUE ] ; then
28 echo "yes"
29 else
30 echo "no"
34 function p_verbose {
35 if [ $VERBOSE -eq $TRUE ] ; then
36 echo "${@}"
40 function p_help {
41 p_usage
42 echo "-c CC : C compiler default : $CC" >&2
43 echo "-f FC : Fortran compiler default : $FC" >&2
44 echo "-r regex : Extra regex to pick configure option default : $RE" >&2
45 echo "-s : Use openmp default : $(torf $OPENMP)" >&2
46 echo "-d : Use mpi default : $(torf $MPI)" >&2
47 echo "-g : Debug (-g -O0) default : $(torf $DEBUG)" >&2
48 echo "-n netcdf : NetCDF install prefix default : $NETCDF" >&2
49 echo "-1 : Use the first option match default : $(torf $ONE)" >&2
50 echo "-e # : Select nesting option default : $NESTING" >&2
51 echo "-v : Verbose output default : $(torf $VERBOSE)" >&2
52 echo "-h : Print help and exit" >&2
53 echo "" >&2
54 echo "This is an addon script useful for compiling WRF in automated environments.
55 The build configuration is determined by named arguments and CC/FC
56 environment variables. The script chooses matching build options from
57 the list of available options displayed by the default configure script,
58 so compatible builds can be started that don't depend on the numbering
59 provided by a particular version of WRF. The CC/FC variables should
60 be in the option list title in arch/configure_new.defaults. This means
61 FC=PGI will work but not FC=pgf90. Future versions of this script may
62 allow for better selection of compilers and path substitution. By default,
63 the script will succeed only if exactly one option matches. You can refine
64 the selection by providing a regex with the -r option. The -1 option will
65 use the first match it encounters and not error out if there are more." >&2
66 exit 1
69 # parse commandline options
70 while getopts ":c:f:r:sdgn:ve:h" opt; do
71 case $opt in
73 CC=$OPTARG
76 FC=$OPTARG
79 RE=$OPTARG
82 export NETCDF=$OPTARG
85 OPENMP=$TRUE
88 MPI=$TRUE
91 DEBUG=$TRUE
94 ONE=$TRUE
97 VERBOSE=$TRUE
100 NESTING=$OPTARG
102 h|\?)
103 p_help
105 esac
106 done
108 # check that nesting is valid
109 if [[ $NESTING != [1-3] || ( $NESTING == 0 && $MPI == $TRUE ) ]] ; then
110 echo "Invalid nesting option $NESTING." >&2
111 exit 4
114 p_verbose ""
115 p_verbose "Options parsed:"
116 p_verbose "CC=$CC"
117 p_verbose "FC=$FC"
118 p_verbose "RE=$RE"
119 p_verbose "OPENMP=$(torf $OPENMP)"
120 p_verbose "MPI=$(torf $MPI)"
121 p_verbose "DEBUG=$(torf $DEBUG)"
122 p_verbose "NETCDF=$NETCDF"
123 p_verbose "NESTING=$NESTING"
124 p_verbose "ONE=$(torf $ONE)"
125 p_verbose "VERBOSE=$(torf $VERBOSE)"
126 p_verbose ""
128 # make sure we are in the right place
129 if [ ! -x configure ] ; then
130 echo "Could not find configure script in $PWD" >&2
131 exit 99
134 # get output of ./configure for base options on this machine
136 tmp=.$$.tmp
137 echo '1\n1\n' | \
138 ./configure 2> /dev/null | \
139 grep '^ *[0-9]\+.' > $tmp
141 while read line
143 opts[$i]="$line"
144 i=$(($i + 1))
145 done < $tmp
146 rm -f $tmp
148 p_verbose "Options available:"
149 for (( i=0 ; i<${#opts[@]} ; i++ )) ; do
150 p_verbose "${opts[$i]}"
151 done
152 p_verbose ""
154 # construct parallelism string
155 if [ $OPENMP -eq $TRUE ] ; then
156 if [ $MPI -eq $TRUE ] ; then
157 pstring='dm[+]sm'
158 else
159 pstring='smpar'
161 else
162 if [ $MPI -eq $TRUE ] ; then
163 pstring='dmpar'
164 else
165 pstring='serial'
169 p_verbose "Parallel option: $pstring"
170 p_verbose ""
172 # search for option in option array
173 optnum=-1
174 for (( i=0 ; i<${#opts[@]} ; i++ )) ; do
175 o="${opts[$i]}"
177 echo $o | grep -E "$CC" >& /dev/null
178 if [ $? -ne 0 ] ; then
179 continue
182 echo $o | grep -E "$FC" >& /dev/null
183 if [ $? -ne 0 ] ; then
184 continue
187 echo $o | grep -E "$RE" >& /dev/null
188 if [ $? -ne 0 ] ; then
189 continue
192 echo $o | grep -E "$pstring" >& /dev/null
193 if [ $? -ne 0 ] ; then
194 continue
197 if [ $optnum -ne -1 ] ; then
198 echo "More than one option matched. Use -1 flag to default to the first." >&2
199 exit 2
201 optnum=$((i+1))
203 if [ $ONE -eq $TRUE ] ; then
204 break
207 done
209 if [ $optnum -eq -1 ] ; then
210 echo "No options matched. Use -v flag to see details." >&2
211 exit 3
214 p_verbose "Selected option:"
215 p_verbose "${opts[$((optnum-1))]}"
216 p_verbose ""
218 if [ $DEBUG -eq $TRUE ] ; then
219 d="-d"
220 else
221 d=""
224 # Remove old configure.wrf if it exists
225 rm -f configure.wrf
227 runstring="echo '$optnum\n$NESTING\n' | ./configure $d"
228 p_verbose "Running:"
229 p_verbose "$runstring"
230 p_verbose
232 eval $runstring >& configure.log
234 if [ ! -f configure.wrf ] ; then
235 echo "configure.wrf was not generated. Something has gone wrong!" >&2
236 exit 98
238 exit 0