#!/usr/bin/perl -w # cycle through fortran files, determine which headers are included; # the "used" array eliminates duplicate enties # for LES, PUPIL and APBS programs, add these dependencies as well # to the list # Be sure do to a "make clean" before running this script! # (probably not really needed, but better safe than sorry) printf < ){ next if $file =~ /^_/; next if $file =~ /xray/; ($fileroot) = $file =~ /(.+)\.F90$/; $optimized{$fileroot} = 0; open( F, "$file" ) || die "unable to open $file\n"; while( ){ if( /^ *module /i ){ ($head,$modulename) = /( *[Mm][Oo][Dd][Uu][Ll][Ee]) +(\w*)/; $modulefile{$modulename} = $fileroot; # printf STDERR "modulefile: $modulename $fileroot\n"; } if( /compile=optimized/ ){ $optimized{$fileroot} = 1; } } close( F ); } # Now, cycle over all source files to create the compilation rules and # dependencies. Check for "compile=optimized" comments and do the right # thing: foreach $file ( <*.F90> ){ next if $file =~ /^_/; next if $file =~ /xray/; $deps = $depsLES = $depsPUPIL = $depsAPBS = ""; ($fileroot) = $file =~ /(.+)\.F90$/; # construct the header and module dependency rules: open( F, "$file" ) || die "unable to open $file\n"; while( ){ if( /^ *use / ){ ($head,$usee) = /( *use) +(\w*)/; # printf STDERR " usee: $usee; modulefile is $modulefile{$usee}\n"; next if $usee =~ /xray/; if( !defined $modulefile{$usee} ){ printf STDERR "No file name associated with module $usee\n"; exit(1); } if( !defined $used{ $fileroot,$modulefile{$usee} } ){ # remove any circular references: next if $fileroot eq $modulefile{$usee}; $deps .= "\\\n " . $modulefile{$usee} . ".o" ; if( defined $LES{$modulefile{$usee}} ){ $depsLES .= "\\\n " . $modulefile{$usee} . ".LES.o" ; } else { $depsLES .= "\\\n " . $modulefile{$usee} . ".o" ; } if( defined $PUPIL{$modulefile{$usee}} ){ $depsPUPIL .= "\\\n " . $modulefile{$usee} . ".PUPIL.o" ; } else { $depsPUPIL .= "\\\n " . $modulefile{$usee} . ".o" ; } if( defined $APBS{$modulefile{$usee}} ){ $depsAPBS .= "\\\n " . $modulefile{$usee} . ".APBS.o" ; } else { $depsAPBS .= "\\\n " . $modulefile{$usee} . ".o" ; } $used{ $fileroot,$modulefile{$usee} } = 1; } } if (/^# *include/) { ($head,$included) = /(# *include) +"(.*)"/; next if $included eq "mpif.h"; next if $included eq "timer.h"; if( !defined $used{ $fileroot,$included } ){ $deps .= "\\\n " . $included ; $depsLES .= "\\\n " . $included ; $depsPUPIL .= "\\\n " . $included ; $depsAPBS .= "\\\n " . $included ; $used{ $fileroot,$included } = 1; } } } printf "$fileroot.o: $deps\n\n" unless $deps eq ""; # construct the compilation rules: printf "\n$fileroot.o: $fileroot.F90\n"; if( $optimized{$fileroot} ){ printf "\t\$(FC) \$(FPPFLAGS) -c \$(FOPTFLAGS) \$(FFLAGS) \$(AMBERFFLAGS) \$(RISMSANDER) -o \$@ $fileroot.F90\n\n"; } else { printf "\t\$(FC) \$(FPPFLAGS) -c \$(FNOOPTFLAGS) \$(FFLAGS) \$(AMBERFFLAGS) \$(RISMSANDER) -o \$@ $fileroot.F90\n\n"; } if( defined $LES{$fileroot} ){ printf "$fileroot.LES.o: $depsLES\n" unless $depsLES eq ""; printf "\n$fileroot.LES.o: $fileroot.F90\n"; if( $optimized{$fileroot} ){ printf "\t\$(FC) \$(FPPFLAGS) -DLES -c \$(FOPTFLAGS) \$(FFLAGS) \$(AMBERFFLAGS) \$(RISMSANDER) -o \$@ $fileroot.F90\n\n"; } else { printf "\t\$(FC) \$(FPPFLAGS) -DLES -c \$(FNOOPTFLAGS) \$(FFLAGS) \$(AMBERFFLAGS) \$(RISMSANDER) -o \$@ $fileroot.F90\n\n"; } } if( defined $PUPIL{$fileroot} ){ printf "$fileroot.PUPIL.o: $depsPUPIL\n" unless $depsPUPIL eq ""; printf "\n$fileroot.PUPIL.o: $fileroot.F90\n"; if( $optimized{$fileroot} ){ printf "\t\$(FC) \$(FPPFLAGS) -DPUPIL_SUPPORT -c \$(FOPTFLAGS) \$(FFLAGS) \$(AMBERFFLAGS) \$(RISMSANDER) -o \$@ $fileroot.F90\n\n"; } else { printf "\t\$(FC) \$(FPPFLAGS) -DPUPIL_SUPPORT -c \$(FNOOPTFLAGS) \$(FFLAGS) \$(AMBERFFLAGS) \$(RISMSANDER) -o \$@ $fileroot.F90\n\n"; } } if( defined $APBS{$fileroot} ){ printf "$fileroot.APBS.o: $depsAPBS\n" unless $depsAPBS eq ""; printf "\n$fileroot.APBS.o: $fileroot.F90\n"; if( $optimized{$fileroot} ){ printf "\t\$(FC) \$(FPPFLAGS) -DAPBS -c \$(FOPTFLAGS) \$(FFLAGS) \$(AMBERFFLAGS) \$(RISMSANDER) -o \$@ $fileroot.F90\n\n"; } else { printf "\t\$(FC) \$(FPPFLAGS) -DAPBS -c \$(FNOOPTFLAGS) \$(FFLAGS) \$(AMBERFFLAGS) \$(RISMSANDER) -o \$@ $fileroot.F90\n\n"; } } } # special "compilation rule" for netcdf.o printf "netcdf.o: \$(NETCDF)\n\ttest -e \$\@ || touch netcdf.o\n\n"; # special compilation rule for AmberNetcdf.o printf "AmberNetcdf.o: ../lib/AmberNetcdf.F90\n"; printf "\t\$(FC) \$(FPPFLAGS) -c \$(FREEFORMAT_FLAG) \$(FOPTFLAGS) \$(FFLAGS) -o AmberNetcdf.o ../lib/AmberNetcdf.F90\n\n"; # special compilation rule for amber_rism_interface print "../rism/amber_rism_interface.SANDER.o: ../rism/amber_rism_interface.F90\n" ."\tcd ../rism && \\\n" ."\tif [ -n \"\$(RISMSANDER)\" ]; then \\\n" ."\t\t\$(MAKE) amber_rism_interface.SANDER.o; \\\n" ."\telse \\\n" ."\t\ttest -e amber_rism_interface.SANDER.o || touch amber_rism_interface.SANDER.o; \\\n" ."\tfi\n\n" ; print "poisson_boltzmann.o: libpbsa file_io_dat.o \n\ttest -e \$\@ || touch \$\@\n\n"; print "dispersion_cavity.o: libpbsa\n\ttest -e \$\@ || touch \$\@\n\n"; print "pbtimer_module.o: libpbsa\n\ttest -e \$\@ || touch \$\@\n\n"; # special "compilation" rule for module object files in ../sqm print "qmmm_module.o: libsqm \n\ttest -e \$\@ || touch \$\@\n\n"; print "qmmm_nml_module.o: libsqm \n\ttest -e \$\@ || touch \$\@\n\n"; print "qmmm_qmtheorymodule.o: libsqm \n\ttest -e \$\@ || touch \$\@\n\n"; print "qmmm_struct_module.o: libsqm \n\ttest -e \$\@ || touch \$\@\n\n"; print "qmmm_vsolv_module.o: libsqm \n\ttest -e \$\@ || touch \$\@\n\n"; print "elementOrbitalIndex.o: libsqm \n\ttest -e \$\@ || touch \$\@\n\n"; print "utilitiesmodule.o: libsqm \n\ttest -e \$\@ || touch \$\@\n\n";