3 # Configuration script for WPS code
5 # Be sure to run as ./configure (to avoid getting a system configure command by mistake)
6 # There are two (2) reads of the configure.defaults one to present the user with
7 # the appropriate options for the type of machine, and the OS, and the compiler!
13 $sw_jasperlib_path = "";
14 $sw_jasperinc_path = "";
16 $sw_compileflags = "";
17 $sw_os = "ARCH" ; # ARCH will match any
18 $sw_mach = "ARCH" ; # ARCH will match any
26 while(substr( $ARGV[0], 0, 1 ) eq "-")
28 if(substr( $ARGV[0], 1, 5 ) eq "perl=")
30 $sw_perl_path = substr( $ARGV[0], 6);
32 if(substr( $ARGV[0], 1, 7 ) eq "netcdf=")
34 $sw_netcdf_path = substr( $ARGV[0], 8);
36 if(substr( $ARGV[0], 1, 8 ) eq "netcdff=")
38 $sw_netcdff_lib = substr( $ARGV[0], 9);
40 if(substr( $ARGV[0], 1, 6 ) eq "phdf5=")
42 $sw_phdf5_path = substr( $ARGV[0], 7);
44 if(substr( $ARGV[0], 1, 3 ) eq "os=")
46 $sw_os = substr( $ARGV[0], 4 );
48 if(substr( $ARGV[0], 1, 5 ) eq "mach=")
50 $sw_mach = substr( $ARGV[0], 6 );
52 if(substr( $ARGV[0], 1, 8 ) eq "ldflags=")
54 $sw_ldflags = substr( $ARGV[0], 9 );
55 # multiple options separated by spaces are passed in from sh script
56 # separated by ! instead. Replace with spaces here.
57 $sw_ldflags =~ s/!/ /g ;
62 # The jasper library is required to build Grib2 I/O. User must set
63 # environment variables JASPERLIB and JASPERINC to paths to library and
64 # include files to enable this feature prior to running configure.
65 if($ENV{JASPERLIB
} && $ENV{JASPERINC
})
67 printf "Found Jasper environment variables for GRIB2 support...\n";
68 printf(" \$JASPERLIB = %s\n",$ENV{JASPERLIB
});
69 printf(" \$JASPERINC = %s\n",$ENV{JASPERINC
});
70 $sw_jasperlib_path = "-L$ENV{JASPERLIB} -ljasper -lpng -lz";
71 $sw_jasperinc_path = "-I$ENV{JASPERINC}";
76 $tmp1 = '/usr/local/jasper';
78 $sw_jasperlib_path = '-L/usr/local/jasper/lib -ljasper -L/usr/local/libpng -lpng12 -lpng -L/usr/local/zlib/lib -lz' ;
79 $sw_jasperinc_path = '-I/usr/local/zlib/include -I/usr/local/jasper/include -I/usr/local/libpng/' ;
80 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using /usr/local for library paths...\n";
83 $tmp1 = '/opt/local/lib';
85 $sw_jasperlib_path = '-L/opt/local/lib -ljasper -lpng -lz';
86 $sw_jasperinc_path = '-I/opt/local/include';
87 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using /opt/local for library paths...\n";
90 $sw_jasperlib_path = '-L/glade/u/home/wrfhelp/UNGRIB_LIBRARIES/lib -ljasper -lpng -lz';
91 $sw_jasperinc_path = '-I/glade/u/home/wrfhelp/UNGRIB_LIBRARIES/include';
92 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using default values for library paths...\n";
98 # added this from the WRF Config.pl by John M.
99 @platforms = ('serial', 'serial_NO_GRIB2', 'dmpar', 'dmpar_NO_GRIB2');
100 # Display the choices to the user and get selection
101 until ($validresponse)
103 printf "------------------------------------------------------------------------\n";
104 printf "Please select from among the following supported platforms.\n\n";
107 # Read configure.defaults
108 open CONFIGURE_DEFAULTS
, "< ./arch/configure.defaults"
109 || die "Cannot open ./arch/configure.defaults for reading";
110 # first read through the .defaults, user select and a read of all appropriate parms is not done here
111 while(<CONFIGURE_DEFAULTS
>)
113 for $paropt (@platforms)
115 # read all the System/OS/Compiler appropriate selections and present same to user
116 if(substr($_, 0, 5) eq "#ARCH" && (index($_, $sw_os) >= 0) && (index($_, $sw_mach) >= 0) && (index($_, $paropt) >= 0))
118 $optstr[$opt] = substr($_,6);
119 $optstr[$opt] =~ s/^[ ]*//;
120 $optstr[$opt] =~ s/#.*$//g;
121 chomp($optstr[$opt]);
122 $optstr[$opt] = $optstr[$opt]." (".$paropt.")";
123 if(substr($optstr[$opt], 0, 4) ne "NULL")
125 printf " %2d. %s\n", $opt, $optstr[$opt];
131 close CONFIGURE_DEFAULTS
;
135 printf "\nEnter selection [%d-%d] : ", 1, $opt;
137 if($response == -1) {exit;}
138 if($response >= 1 && $response <= $opt)
144 printf("\nInvalid response (%d)\n",$response);
148 printf "------------------------------------------------------------------------\n";
150 $optchoice = $response;
152 # this HAS to be opened in 'cat' mode... why?
153 open CONFIGURE_DEFAULTS
, "< ./arch/configure.defaults" || die "cannot Open for writing... configure.defaults: \n";
155 while(<CONFIGURE_DEFAULTS
>)
157 if(substr($_, 0, 5) eq "#ARCH" && $latchon == 1)
163 $_ =~ s/CONFIGURE_PERL_PATH/$sw_perl_path/g;
164 $_ =~ s/CONFIGURE_NETCDF_PATH/$sw_netcdf_path/g;
165 $_ =~ s/CONFIGURE_LDFLAGS/$sw_ldflags/g;
166 $_ =~ s/CONFIGURE_COMPILEFLAGS/$sw_compileflags/g;
167 $_ =~ s/CONFIGURE_COMP_L/$sw_compL/g;
168 $_ =~ s/CONFIGURE_COMP_I/$sw_compI/g;
169 $_ =~ s/CONFIGURE_FDEFS/$sw_fdefs/g;
170 $_ =~ s/CONFIGURE_FC/$sw_fc/g;
171 $_ =~ s/CONFIGURE_CC/$sw_cc/g;
172 $_ =~ s/CONFIGURE_MPI/$sw_mpi/g;
174 # Load the read in parameters from the configure.defaults file
175 if(!(substr($_, 0, 5) eq "#ARCH"))
177 @machopts = (@machopts, $_);
179 } # end if latchon == 1
181 #-----------------------------------------------------------------------------------------------
182 # added for the unified WPS build
183 # init the following for the configure.wps write
186 # now loop through the .defaults again and read the parameters to be written into the configure.wps
187 for $paropt (@platforms)
189 if(substr($_, 0, 5) eq "#ARCH" && $latchon == 0 && (index( $_, $sw_os) >= 0) && (index( $_, $sw_mach) >= 0) && (index($_, $paropt) >= 0))
191 # after #ARCH the following reads the rest of the line in the configure.defaults
196 $x = $x." (".$paropt.")" ;
198 if($x eq $optstr[$optchoice])
204 if($paropt eq 'serial')
206 if($ENV{JASPERLIB
} && $ENV{JASPERINC
})
208 $sw_compL = $sw_jasperlib_path;
209 $sw_compI = $sw_jasperinc_path;
213 $sw_compL = $sw_jasperlib_path;
214 $sw_compI = $sw_jasperinc_path;
215 # $sw_compL = "-L/contrib/jasper/lib -L/opt/freeware/lib -ljasper -lpng -lz";
216 # $sw_compI = "-I/contrib/libpng/include -I/contrib/zlib/include -I/contrib/jasper/include";
218 $sw_fdefs = "-DUSE_JPEG2000 -DUSE_PNG";
223 if($paropt eq 'serial_NO_GRIB2')
232 if($paropt eq 'dmpar')
234 if($ENV{JASPERLIB
} && $ENV{JASPERINC
})
236 $sw_compL = $sw_jasperlib_path;
237 $sw_compI = $sw_jasperinc_path;
241 $sw_compL = $sw_jasperlib_path;
242 $sw_compI = $sw_jasperinc_path;
243 # $sw_compL = "-L/contrib/jasper/lib -L/opt/freeware/lib -ljasper -lpng -lz";
244 # $sw_compI = "-I/contrib/libpng/include -I/contrib/zlib/include -I/contrib/jasper/include";
246 $sw_fdefs = "-DUSE_JPEG2000 -DUSE_PNG";
247 $sw_fc = "\$(DM_FC)";
248 $sw_cc = "\$(DM_CC)";
251 if($paropt eq 'dmpar_NO_GRIB2')
256 $sw_fc = "\$(DM_FC)";
257 $sw_cc = "\$(DM_CC)";
261 #####################################################################################
262 } # end if latchon == 1
266 close CONFIGURE_DEFAULTS
;
268 #printf "\n------------------------------------------------------------------------\n";
269 #foreach $f (@machopts)
271 # if(substr($f , 0 , 8) eq "external")
277 #printf "--------------------------------------------------------------------------\n";
278 #printf "\nYou have chosen: %s\n",$optstr[$optchoice];
279 #printf "Listed above are the default options for this platform.\n";
280 #printf "Settings are written to the file configure.wps here in the top-level\n";
281 #printf "directory. If you wish to change settings, please edit that file.\n";
282 #printf "If you wish to change the default options, edit the file:\n\n";
283 #printf " arch/configure.defaults\n";
285 #printf "------------------------------------------------------------------------\n";
287 open CONFIGURE_WRF
, "> configure.wps" || die "cannot Open for writing... configure.wps: \n";
288 open ARCH_PREAMBLE
, "< arch/preamble" || die "cannot Open for reading... arch/preamble: \n";
290 # apply substitutions to the preamble...
291 while (<ARCH_PREAMBLE
>)
293 if($sw_os eq "CYGWIN_NT")
295 $_ =~ s/^WRF_DIR.*$/COMPILING_ON_CYGWIN_NT = yes/; # will get from environment
298 $_ =~ s
:CONFIGURE_NETCDFF_LIB
:$sw_netcdff_lib:g
;
299 @preamble = ( @preamble, $_ ) ;
304 print CONFIGURE_WRF
@preamble;
306 printf CONFIGURE_WRF
"#\n";
307 printf CONFIGURE_WRF
"# Settings for %s \n", $optstr[$optchoice];
308 printf CONFIGURE_WRF
"#\n";
309 print CONFIGURE_WRF
@machopts;
311 open ARCH_POSTAMBLE
, "< arch/postamble" || die "cannot open arch/postamble: \n";
312 while(<ARCH_POSTAMBLE
>)
314 $_ =~ s
:CONFIGURE_NETCDFF_LIB
:$sw_netcdff_lib:g
;
318 close ARCH_POSTAMBLE
;
321 printf "Configuration successful. To build the WPS, type: compile\n";
322 printf "------------------------------------------------------------------------\n";