Setting to standard shell
[WPS.git] / arch / Config.pl
blob2faef0a8c91176f77f28778f3a865f61c1659ccd
1 #!/usr/bin/perl
3 # Configuration script for WPS code
4 #
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!
9 $sw_perl_path = perl;
10 $sw_wrf_path = "<SET ME>";
11 $sw_netcdf_path = "";
12 $sw_netcdff_lib = "";
13 $sw_phdf5_path = "";
14 $sw_grib2_path = "";
15 $sw_jasperlib_path = "";
16 $sw_jasperinc_path = "";
17 $sw_ldflags = "";
18 $sw_compileflags = "";
19 $sw_os = "ARCH" ; # ARCH will match any
20 $sw_mach = "ARCH" ; # ARCH will match any
21 #$sw_compL = "";
22 #$sw_compI = "";
23 #$sw_fdefs = "";
24 #$sw_fc = "";
25 #$sw_cc = "";
26 #$sw_mpi = "";
28 while(substr( $ARGV[0], 0, 1 ) eq "-")
30 if(substr( $ARGV[0], 1, 5 ) eq "perl=")
32 $sw_perl_path = substr( $ARGV[0], 6);
34 if(substr( $ARGV[0], 1, 7 ) eq "wrfdir=")
36 $sw_wrf_path = substr( $ARGV[0], 8);
38 if(substr( $ARGV[0], 1, 7 ) eq "netcdf=")
40 $sw_netcdf_path = substr( $ARGV[0], 8);
42 if(substr( $ARGV[0], 1, 8 ) eq "netcdff=")
44 $sw_netcdff_lib = substr( $ARGV[0], 9);
46 if(substr( $ARGV[0], 1, 6 ) eq "phdf5=")
48 $sw_phdf5_path = substr( $ARGV[0], 7);
50 if(substr( $ARGV[0], 1, 3 ) eq "os=")
52 $sw_os = substr( $ARGV[0], 4 );
54 if(substr( $ARGV[0], 1, 5 ) eq "mach=")
56 $sw_mach = substr( $ARGV[0], 6 );
58 if(substr( $ARGV[0], 1, 8 ) eq "ldflags=")
60 $sw_ldflags = substr( $ARGV[0], 9 );
61 # multiple options separated by spaces are passed in from sh script
62 # separated by ! instead. Replace with spaces here.
63 $sw_ldflags =~ s/!/ /g ;
65 if(substr( $ARGV[0], 1, 9 ) eq "grib2dir=")
67 $sw_grib2_path = substr( $ARGV[0], 10 );
69 shift @ARGV;
70 } # end while
72 if ($sw_grib2_path eq "")
74 # The jasper library is required to build Grib2 I/O. User must set
75 # environment variables JASPERLIB and JASPERINC to paths to library and
76 # include files to enable this feature prior to running configure.
77 if($ENV{JASPERLIB} && $ENV{JASPERINC})
79 printf "Found Jasper environment variables for GRIB2 support...\n";
80 printf(" \$JASPERLIB = %s\n",$ENV{JASPERLIB});
81 printf(" \$JASPERINC = %s\n",$ENV{JASPERINC});
82 $sw_jasperlib_path = "-L$ENV{JASPERLIB} -ljasper -lpng -lz";
83 $sw_jasperinc_path = "-I$ENV{JASPERINC}";
85 else
88 $tmp1 = '/usr/local/jasper';
89 if (-e $tmp1) {
90 $sw_jasperlib_path = '-L/usr/local/jasper/lib -ljasper -L/usr/local/libpng -lpng12 -lpng -L/usr/local/zlib/lib -lz' ;
91 $sw_jasperinc_path = '-I/usr/local/zlib/include -I/usr/local/jasper/include -I/usr/local/libpng/' ;
92 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using /usr/local for library paths...\n";
94 else {
95 $tmp1 = '/opt/local/lib';
96 if (-e $tmp1) {
97 $sw_jasperlib_path = '-L/opt/local/lib -ljasper -lpng -lz';
98 $sw_jasperinc_path = '-I/opt/local/include';
99 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using /opt/local for library paths...\n";
101 else {
102 $sw_jasperlib_path = '-L/glade/u/home/wrfhelp/UNGRIB_LIBRARIES/lib -ljasper -lpng -lz';
103 $sw_jasperinc_path = '-I/glade/u/home/wrfhelp/UNGRIB_LIBRARIES/include';
104 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using default values for library paths...\n";
108 @platforms = ('serial', 'serial_NO_GRIB2', 'dmpar', 'dmpar_NO_GRIB2');
110 else
112 $sw_jasperlib_path = '-L$(INTERNAL_GRIB2_PATH)/lib -ljasper -lpng -lz';
113 $sw_jasperinc_path = '-I$(INTERNAL_GRIB2_PATH)/include';
114 @platforms = ('serial', 'dmpar');
117 $validresponse = 0 ;
118 # Display the choices to the user and get selection
119 until ($validresponse)
121 printf "------------------------------------------------------------------------\n";
122 printf "Please select from among the following supported platforms.\n\n";
124 $opt = 1;
125 # Read configure.defaults
126 open CONFIGURE_DEFAULTS, "< ./arch/configure.defaults"
127 || die "Cannot open ./arch/configure.defaults for reading";
128 # first read through the .defaults, user select and a read of all appropriate parms is not done here
129 while(<CONFIGURE_DEFAULTS>)
131 for $paropt (@platforms)
133 # read all the System/OS/Compiler appropriate selections and present same to user
134 if(substr($_, 0, 5) eq "#ARCH" && (index($_, $sw_os) >= 0) && (index($_, $sw_mach) >= 0) && (index($_, $paropt) >= 0))
136 $optstr[$opt] = substr($_,6);
137 $optstr[$opt] =~ s/^[ ]*//;
138 $optstr[$opt] =~ s/#.*$//g;
139 chomp($optstr[$opt]);
140 $optstr[$opt] = $optstr[$opt]." (".$paropt.")";
141 if(substr($optstr[$opt], 0, 4) ne "NULL")
143 printf " %2d. %s\n", $opt, $optstr[$opt];
144 $opt++;
149 close CONFIGURE_DEFAULTS;
151 $opt --;
153 printf "\nEnter selection [%d-%d] : ", 1, $opt;
154 $response = <STDIN>;
155 if($response == -1) {exit;}
156 if($response >= 1 && $response <= $opt)
158 $validresponse = 1;
160 else
162 printf("\nInvalid response (%d)\n",$response);
166 printf "------------------------------------------------------------------------\n";
167 # save user input
168 $optchoice = $response;
170 # this HAS to be opened in 'cat' mode... why?
171 open CONFIGURE_DEFAULTS, "< ./arch/configure.defaults" || die "cannot Open for writing... configure.defaults: \n";
172 $latchon = 0;
173 while(<CONFIGURE_DEFAULTS>)
175 if(substr($_, 0, 5) eq "#ARCH" && $latchon == 1)
177 $latchon = 0;
179 if($latchon == 1)
181 $_ =~ s/CONFIGURE_PERL_PATH/$sw_perl_path/g;
182 $_ =~ s/CONFIGURE_NETCDF_PATH/$sw_netcdf_path/g;
183 $_ =~ s/CONFIGURE_LDFLAGS/$sw_ldflags/g;
184 $_ =~ s/CONFIGURE_COMPILEFLAGS/$sw_compileflags/g;
185 $_ =~ s/CONFIGURE_COMP_L/$sw_compL/g;
186 $_ =~ s/CONFIGURE_COMP_I/$sw_compI/g;
187 $_ =~ s/CONFIGURE_FDEFS/$sw_fdefs/g;
188 $_ =~ s/CONFIGURE_FC/$sw_fc/g;
189 $_ =~ s/CONFIGURE_CC/$sw_cc/g;
190 $_ =~ s/CONFIGURE_MPI/$sw_mpi/g;
192 # Load the read in parameters from the configure.defaults file
193 if(!(substr($_, 0, 5) eq "#ARCH"))
195 @machopts = (@machopts, $_);
197 } # end if latchon == 1
199 #-----------------------------------------------------------------------------------------------
200 # added for the unified WPS build
201 # init the following for the configure.wps write
204 # now loop through the .defaults again and read the parameters to be written into the configure.wps
205 for $paropt (@platforms)
207 if(substr($_, 0, 5) eq "#ARCH" && $latchon == 0 && (index( $_, $sw_os) >= 0) && (index( $_, $sw_mach) >= 0) && (index($_, $paropt) >= 0))
209 # after #ARCH the following reads the rest of the line in the configure.defaults
210 $x=substr($_,6);
211 $x=~s/^[ ]*//;
212 $x =~ s/#.*$//g;
213 chomp($x);
214 $x = $x." (".$paropt.")" ;
216 if($x eq $optstr[$optchoice])
218 $latchon = 1;
220 if($latchon == 1)
222 if($paropt eq 'serial')
224 if(($ENV{JASPERLIB} && $ENV{JASPERINC}) || $sw_grib2_path ne "")
226 $sw_compL = $sw_jasperlib_path;
227 $sw_compI = $sw_jasperinc_path;
229 else
231 $sw_compL = $sw_jasperlib_path;
232 $sw_compI = $sw_jasperinc_path;
233 # $sw_compL = "-L/contrib/jasper/lib -L/opt/freeware/lib -ljasper -lpng -lz";
234 # $sw_compI = "-I/contrib/libpng/include -I/contrib/zlib/include -I/contrib/jasper/include";
236 $sw_fdefs = "-DUSE_JPEG2000 -DUSE_PNG";
237 $sw_fc = "\$(SFC)";
238 $sw_cc = "\$(SCC)";
239 $sw_mpi = "";
241 if($paropt eq 'serial_NO_GRIB2')
243 $sw_compL = "";
244 $sw_compI = "";
245 $sw_fdefs = "";
246 $sw_fc = "\$(SFC)";
247 $sw_cc = "\$(SCC)";
248 $sw_mpi = "";
250 if($paropt eq 'dmpar')
252 if(($ENV{JASPERLIB} && $ENV{JASPERINC}) || $sw_grib2_path ne "")
254 $sw_compL = $sw_jasperlib_path;
255 $sw_compI = $sw_jasperinc_path;
257 else
259 $sw_compL = $sw_jasperlib_path;
260 $sw_compI = $sw_jasperinc_path;
261 # $sw_compL = "-L/contrib/jasper/lib -L/opt/freeware/lib -ljasper -lpng -lz";
262 # $sw_compI = "-I/contrib/libpng/include -I/contrib/zlib/include -I/contrib/jasper/include";
264 $sw_fdefs = "-DUSE_JPEG2000 -DUSE_PNG";
265 $sw_fc = "\$(DM_FC)";
266 $sw_cc = "\$(DM_CC)";
267 $sw_mpi = "-D_MPI";
269 if($paropt eq 'dmpar_NO_GRIB2')
271 $sw_compL = "";
272 $sw_compI = "";
273 $sw_fdefs = "";
274 $sw_fc = "\$(DM_FC)";
275 $sw_cc = "\$(DM_CC)";
276 $sw_mpi = "-D_MPI";
279 #####################################################################################
280 } # end if latchon == 1
281 } # end if
282 } # end for
284 close CONFIGURE_DEFAULTS ;
286 #printf "\n------------------------------------------------------------------------\n";
287 #foreach $f (@machopts)
289 # if(substr($f , 0 , 8) eq "external")
290 # {
291 # last ;
293 # print $f;
295 #printf "--------------------------------------------------------------------------\n";
296 #printf "\nYou have chosen: %s\n",$optstr[$optchoice];
297 #printf "Listed above are the default options for this platform.\n";
298 #printf "Settings are written to the file configure.wps here in the top-level\n";
299 #printf "directory. If you wish to change settings, please edit that file.\n";
300 #printf "If you wish to change the default options, edit the file:\n\n";
301 #printf " arch/configure.defaults\n";
302 #printf "\n";
303 #printf "------------------------------------------------------------------------\n";
305 open CONFIGURE_WRF, "> configure.wps" || die "cannot Open for writing... configure.wps: \n";
306 open ARCH_PREAMBLE, "< arch/preamble" || die "cannot Open for reading... arch/preamble: \n";
307 my @preamble;
308 # apply substitutions to the preamble...
309 while (<ARCH_PREAMBLE>)
311 if($sw_os eq "CYGWIN_NT")
313 $_ =~ s/^WRF_DIR.*$/COMPILING_ON_CYGWIN_NT = yes/; # will get from environment
316 $_ =~ s:CONFIGURE_NETCDFF_LIB:$sw_netcdff_lib:g;
317 $_ =~ s:CONFIGURE_WRF_PATH:$sw_wrf_path:g;
318 $_ =~ s:CONFIGURE_GRIB2_PATH:$sw_grib2_path:g;
319 @preamble = ( @preamble, $_ ) ;
321 close ARCH_PREAMBLE;
324 print CONFIGURE_WRF @preamble;
325 close ARCH_PREAMBLE;
326 printf CONFIGURE_WRF "#\n";
327 printf CONFIGURE_WRF "# Settings for %s \n", $optstr[$optchoice];
328 printf CONFIGURE_WRF "#\n";
329 print CONFIGURE_WRF @machopts;
331 open ARCH_POSTAMBLE, "< arch/postamble" || die "cannot open arch/postamble: \n";
332 while(<ARCH_POSTAMBLE>)
334 $_ =~ s:CONFIGURE_NETCDFF_LIB:$sw_netcdff_lib:g;
335 print CONFIGURE_WRF;
338 close ARCH_POSTAMBLE;
339 close CONFIGURE_WPS;
341 printf "Configuration successful. To build the WPS, type: compile\n";
342 printf "------------------------------------------------------------------------\n";