#!/usr/bin/perl -w # $Id: build,v 1.1 2009/06/09 21:51:53 daven Exp $ =head1 NAME BUILD =head1 SYNOPSIS BUILD is a Perl script which compiles the GEOS-CHEM code for a given combination of platform and compiler. =head1 REQUIRES Perl 5.003 =head1 EXPORTS none =head1 DESCRIPTION build Methods are provided for compiling the GEOS-CHEM model =head1 METHODS getMakeFile : Prints a separator line to stdout main : Driver program =head1 MODIFICATION HISTORY bmy, 04 Dec 2002 - INITIAL VERSION bmy, 03 Nov 2005 - Modified for Intel "ifort" compiler bmy, 29 Nov 2005 - Now use "and" instead of double ampersands =head1 AUTHOR Bob Yantosca (bmy@io.harvard.edu) =head1 SEE ALSO trun, bmrun =head1 COPYRIGHT Copyright 2002-2005, Bob Yantosca. All rights reserved. =cut require 5.003; # need this version of Perl or newer use English; # English language module use Carp; # detailed error msgs use strict; # forces implicit variable declarations #------------------------------------------------------------------------------ sub getMakeFile() { #========================================================================= # Subroutine getMakeFile examines the "define.h" file in order to # determine the name of the makefile which will be used to compile # GEOS-CHEM for the given platform and compiler. (bmy, 12/4/03, 11/3/05) # # Calling Sequence: # ------------------------------------------------------------------------ # $makeFile = getMakeFile(); # # NOTES: # (1 ) Now searches for Intel "ifort" compiler makefile "Makefile.ifort # if LINUX_IFORT switch is #defined. (bmy, 11/3/05) #========================================================================= # Local variables my $line = ""; my @lines = ""; # Read "define.h" into a string array open( INPUT, "define.h" ) or croak "getDefaults: Can't open define.h"; chomp( @lines = ); close( INPUT ); # Process each line individually foreach $line ( @lines ) { # Determine makefile name from the defined C-preprocessor switch if ( $line =~ "#define" and !( $line =~ "!#define" ) ) { if ( $line =~ "COMPAQ" ) { return( "Makefile.compaq" ); } elsif ( $line =~ "IBM" ) { return( "Makefile.ibm" ); } elsif ( $line =~ "LINUX_PGI" ) { return( "Makefile.pgi" ); } elsif ( $line =~ "LINUX_IFC" ) { return( "Makefile.ifc" ); } elsif ( $line =~ "LINUX_EFC" ) { return( "Makefile.efc" ); } elsif ( $line =~ "LINUX_IFORT" ) { return( "Makefile.ifort" ); } elsif ( $line =~ "LINUX" ) { return( "Makefile.linux" ); } elsif ( $line =~ 'SGI' ) { return( "Makefile.sgi" ); } elsif ( $line =~ 'SPARC' ) { return( "Makefile.sparc" ); } } } # Otherwise return failure return( '' ); } #------------------------------------------------------------------------------ sub main() { #========================================================================= # Perl script "build" compiles GEOS-CHEM with the correct makefile for # a given operating system and compiler. Examines the "define.h" file # in order to determine the makefile name. (bmy, 12/4/03) # # Arguments as Input: # ------------------------------------------------------------------------ # (1 ) $target : Name of the makefile target to build (default is "geos") # # NOTES: # (1 ) Need to set system variables for Intel IFORT compiler (bmy, 11/3/05) # (2 ) Now use "and" to avoid conflict w/ the sub mit command (bmy, 11/18/05) #========================================================================== # Local variables my $makeFile = ""; my $target = "geos"; # If an argument has been passed, then redefine $target if ( scalar( @ARGV ) > 0 ) { $target = $ARGV[0]; } # Get the makefile name by examining "define.h" $makeFile = getMakeFile(); # Compile GEOS-CHEM w/ the right makefile if ( length( $makeFile ) > 0 ) { print "Compiling $target in $makeFile\n"; # Need to set system variables for Intel IFORT compiler (bmy, 11/3/05) #if ( $makeFile =~ "ifort" and !( $target =~ "clean" ) ) # { qx( source /usr/local/bin/ifortvars.sh; make $target -f $makeFile ); } #else # { qx( make $target -f $makeFile ); } qx( make $target -f $makeFile ); } else { die "Could not find makefile name!\n" } } #------------------------------------------------------------------------------ # Execute MAIN program main(); # Exit normally exit(0);