3 # Jonathan Beezley (jon.beezley@gmail.com)
5 # Addon script for automated building of WRF. See ./configure_auto -h for documentation.
17 : ${NETCDF:=/usr/local}
23 echo "usage: $0 [-c CC] [-f FC] [-r regex] [-s] [-d] [-g] [-n netcdf] [-1] [-v] [-e #] [-h]" >&2
27 if [ $1 -eq $TRUE ] ; then
35 if [ $VERBOSE -eq $TRUE ] ; then
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
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
69 # parse commandline options
70 while getopts ":c:f:r:sdgn:ve:h" opt
; do
108 # check that nesting is valid
109 if [[ $NESTING != [1-3] ||
( $NESTING == 0 && $MPI == $TRUE ) ]] ; then
110 echo "Invalid nesting option $NESTING." >&2
115 p_verbose
"Options parsed:"
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)"
128 # make sure we are in the right place
129 if [ ! -x configure
] ; then
130 echo "Could not find configure script in $PWD" >&2
134 # get output of ./configure for base options on this machine
138 .
/configure
2> /dev
/null | \
139 grep '^ *[0-9]\+.' > $tmp
148 p_verbose
"Options available:"
149 for (( i
=0 ; i
<${#opts[@]} ; i
++ )) ; do
150 p_verbose
"${opts[$i]}"
154 # construct parallelism string
155 if [ $OPENMP -eq $TRUE ] ; then
156 if [ $MPI -eq $TRUE ] ; then
162 if [ $MPI -eq $TRUE ] ; then
169 p_verbose
"Parallel option: $pstring"
172 # search for option in option array
174 for (( i
=0 ; i
<${#opts[@]} ; i
++ )) ; do
177 echo $o |
grep -E "$CC" >& /dev
/null
178 if [ $?
-ne 0 ] ; then
182 echo $o |
grep -E "$FC" >& /dev
/null
183 if [ $?
-ne 0 ] ; then
187 echo $o |
grep -E "$RE" >& /dev
/null
188 if [ $?
-ne 0 ] ; then
192 echo $o |
grep -E "$pstring" >& /dev
/null
193 if [ $?
-ne 0 ] ; then
197 if [ $optnum -ne -1 ] ; then
198 echo "More than one option matched. Use -1 flag to default to the first." >&2
203 if [ $ONE -eq $TRUE ] ; then
209 if [ $optnum -eq -1 ] ; then
210 echo "No options matched. Use -v flag to see details." >&2
214 p_verbose
"Selected option:"
215 p_verbose
"${opts[$((optnum-1))]}"
218 if [ $DEBUG -eq $TRUE ] ; then
224 # Remove old configure.wrf if it exists
227 runstring
="echo '$optnum\n$NESTING\n' | ./configure $d"
229 p_verbose
"$runstring"
232 eval $runstring >& configure.log
234 if [ ! -f configure.wrf
] ; then
235 echo "configure.wrf was not generated. Something has gone wrong!" >&2