#!/usr/bin/perl -w use strict; use Cwd qw(abs_path); use Getopt::Long; # Make sure there's a Makefile file. die "Makefile is missing in the current directory!\n" unless -e 'Makefile'; # Default values for command-line options. my %opt = ( hdflib => '/usr/local/hdf/lib', hdfinc => '/usr/local/hdf/include', 'with-lores-elev' => 0, help => 0, ); #my %opt = ( # hdflib => '/usr/local/hdf/lib', # hdfinc => '/usr/local/hdf/include', # hdf5root => '/usr/local/hdf5/', # 'with-lores-elev' => 0, # help => 0, # ); # Parse the command line. my @sargv = @ARGV; GetOptions( \%opt, 'hdflib=s', 'hdf5root=s', 'with-xlf90:s', 'with-ifort:s', 'with-gfortran:s', 'with-ifort_debug:s', 'with-szip:s', 'static', 'help' ) or die "Error parsing command-line options!\n"; my $STATIC = ""; if (exists($opt{'static'})) { $STATIC = "-static"; } # Compiler/linker settings. my %fc = ( xlf90 => { fc => 'xlf90', fflags => '-O2 -qmaxmem=20000 -bmaxdata:0x80000000 -qfree=f90 -qsuffix=f=f90', }, gfortran => { fc => "gfortran", fflags => "-O2 $STATIC -ffast-math -funroll-loops -fno-range-check -ffree-line-length-200", }, ifort => { fc => 'ifort', fflags => '-O2 -assume byterecl', }, ifort_debug => { fc => 'ifort', fflags => '-g -O0 -assume byterecl', } ); # Help. usage() if $opt{help}; # Make sure the user has selected only one compiler. my $fcs = exists($opt{'with-xlf90'}) + exists($opt{'with-gfortran'}) + exists($opt{'with-ifort'}) + exists($opt{'with-ifort_debug'}); if ($fcs == 0) { die "No compiler specified.\n"; } elsif ($fcs != 1) { die "More than one compiler specified.\n"; } # Check the HDF directory. $opt{hdflib} = abs_path($opt{hdflib}) if $opt{hdflib} =~ /^\./; $opt{hdflib} =~ s/^~/$ENV{HOME}/; -d $opt{hdflib} or die "Doesn't exist or not a directory: $opt{hdflib}\n"; # Check the HDF5 directory. if (exists($opt{'hdf5root'})) { $opt{hdf5root} = abs_path($opt{hdf5root}) if $opt{hdf5root} =~ /^\./; $opt{hdf5root} =~ s/^~/$ENV{HOME}/; -d $opt{hdf5root} or die "Doesn't exist or not a directory: $opt{hdf5root}\n"; } # Check the SZIP directory. if (exists($opt{'with-szip'}) and length($opt{'with-szip'})) { -d $opt{'with-szip'} or die "Doesn't exist or not a directory: $opt{'with-szip'}\n"; } # Generate linker options for the HDF lib. my $hdflibs = "-L$opt{hdflib}" . (exists($opt{'with-szip'}) and length($opt{'with-szip'}) ? " -L$opt{'with-szip'}" : '') . " -lmfhdf -ldf -ljpeg" . (exists($opt{'with-szip'}) ? ' -lsz' : '') . " -lz"; # Write configuration vars to a file. open CONFIG, '> config.mk' or die "open(config.mk) error: $!)\n"; print CONFIG '# This file was generated on ' . localtime() . " by $ENV{USER}", " with the following command-line arguments: @sargv.\n# System info: ", `uname -a`; if (exists($opt{'with-ifort'})) { if (length($opt{'with-ifort'})) { print CONFIG "fc = $opt{'with-ifort'}\n"; } else { print CONFIG "fc = $fc{ifort}->{fc}\n"; } print CONFIG "fflags = $fc{ifort}->{fflags}\n"; } elsif (exists($opt{'with-ifort_debug'})) { if (length($opt{'with-ifort_debug'})) { print CONFIG "fc = $opt{'with-ifort_debug'}\n"; } else { print CONFIG "fc = $fc{ifort_debug}->{fc}\n"; } print CONFIG "fflags = $fc{ifort_debug}->{fflags}\n"; } elsif (exists($opt{'with-gfortran'})) { if (length($opt{'with-gfortran'})) { print CONFIG "fc = $opt{'with-gfortran'}\n"; } else { print CONFIG "fc = $fc{gfortran}->{fc}\n"; } print CONFIG "fflags = $fc{gfortran}->{fflags}\n"; } else { die "Not an AIX computer." unless $^O =~ /aix/i; print CONFIG "xlf90 = 1\n"; if (length($opt{'with-xlf90'})) { print CONFIG "fc = $opt{'with-xlf90'}\n"; } else { print CONFIG "fc = $fc{xlf90}->{fc}\n"; } print CONFIG "fflags = $fc{xlf90}->{fflags}\n"; } print CONFIG "hdflibs = $hdflibs\n"; if (exists($opt{'hdf5root'})) { print CONFIG "hdf5libs = -I$opt{hdf5root}include/ -L$opt{hdf5root}lib/\n"; print CONFIG "hdf5links = -lhdf5_fortran -lhdf5 -lz\n"; } if (exists($opt{'hdf5-default'})) { print CONFIG "hdf5libs = -I/usr/local/hdf5/include/ -L/usr/local/hdf5/lib/\n"; print CONFIG "hdf5links = -lhdf5_fortran -lhdf5 -lz\n"; } close CONFIG; print "The CLAVR-x source code is configured for build on this system.\n"; exit; sub usage { print <] Intel FORTRAN compiler will be used. A path to the executable is optional. --with-ifort_debug[=] Intel FORTRAN compiler in debug mode will be used. A path to the executable is optional. --with-gfortran[=] GNU FORTRAN 95 compiler will be used. A path to the executable is optional. --static Adds compilation flags for creating static binaries. Only supports gfortran currently. --with-xlf90[=] IBM AIX FORTRAN compiler will be used. A path to the executable is optional. --hdflib= Path to the directory where HDF library files are stored. Default is /usr/local/hdf/lib. --hdf5root= Path to the directory where HDF5 lib and include directories are. Default is /usr/local/hdf5/. --with-szip[=] Path to the SZIP library, if required by the HDF library. If directory not given, the argument of '--hdflib' option used. --help Display this help message. HELP exit; }