/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Diff of /MITgcm/tools/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.29 by edhill, Tue Nov 11 20:38:27 2003 UTC revision 1.38 by edhill, Fri Nov 14 12:52:56 2003 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/sh
2  #  #
3  # $Header$  # $Header$
4  #  #
# Line 104  find_possible_configs()  { Line 104  find_possible_configs()  {
104          CPP="cpp -traditional -P"          CPP="cpp -traditional -P"
105      fi      fi
106    
107        # makedepend is not always available
108        if test "x${MAKEDEPEND}" = x ; then
109          which makedepend >& /dev/null
110          RETVAL=$?
111          if test "x${RETVAL}" = x1 ; then
112             echo "    makedepend was not found. Using xmakedpend instead."
113             MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
114          fi
115        fi
116    
117      # look for possible fortran compilers      # look for possible fortran compilers
118      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
119      p_FC=      p_FC=
# Line 206  get_pdepend_list()  { Line 216  get_pdepend_list()  {
216      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
217          | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \          | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
218          > ./.pd_tmp          > ./.pd_tmp
219      source ./.pd_tmp      . ./.pd_tmp
220      rm -f ./.pd_tmp      rm -f ./.pd_tmp
221    
222      echo -n "PNAME = "${}      echo -n "PNAME = "${}
# Line 264  usage()  { Line 274  usage()  {
274      exit 1      exit 1
275  }  }
276    
277  #eh3 # This is the generic configuration.  #  Build a CPP macro to automate calling C routines from FORTRAN
278  #eh3 set LN         = ( 'ln -s' )  get_fortran_c_namemangling()  {
279  #eh3 set CPP        = ( '/lib/cpp -P' )      default_nm="#define FC_NAMEMANGLE(X) X ## _"
280  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )      
281  #eh3 set KPP        = (  )      cat > genmake_test.c <<EOF
282  #eh3 set FC         = ( 'f77' )  void tcall( char * string ) { tsub( string ); }
283  #eh3 set LINK       = $FC  EOF
284  #eh3 set MAKEDEPEND = ( 'makedepend' )      $MAKE genmake_test.o > genmake_test.log 2>&1
285  #eh3 set INCLUDES   = ( -I. )      RETVAL=$?
286  #eh3 set FFLAGS     = (  )      if test "x$RETVAL" != x0 ; then
287  #eh3 set FOPTIM     = (  )          cat genmake_test.log >> genmake_errors
288  #eh3 set CFLAGS     = (  )          FC_NAMEMANGLE=$default_nm
289  #eh3 set KFLAGS1    = (  )          echo
290  #eh3 set KFLAGS2    = (  )          echo "WARNING: C test compile fails -- please see \"genmake_errors\""
291  #eh3 set LIBS       = (  )          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
292  #eh3 set KPPFILES   = (  )          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
293  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )          rm -f genmake_tcomp.* genmake_test.*
294  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )          return 1
295        fi
296        c_tcall=`nm genmake_test.o | grep tcall | cut -d ' ' -f 3`
297        RETVAL=$?
298        if test "x$RETVAL" != x0 ; then
299            FC_NAMEMANGLE=$default_nm
300            echo
301            echo "WARNING: The \"nm\" command failed."
302            echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
303            echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
304            rm -f genmake_tcomp.* genmake_test.*
305            return 1
306        fi
307        cat > genmake_tcomp.f <<EOF
308          subroutine tcall( string )
309          character*(*) string
310          call tsub( string )
311          end
312    EOF
313        $FC $FFLAGS $DEFINES -c genmake_tcomp.f > genmake_tcomp.log 2>&1
314        RETVAL=$?
315        if test "x$RETVAL" != x0 ; then
316            cat genmake_tcomp.log >> genmake_errors
317            FC_NAMEMANGLE=$default_nm
318            echo
319            echo "WARNING: FORTRAN test compile fails -- please see \"genmake_errors\""
320            echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
321            echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
322            rm -f genmake_tcomp.* genmake_test.*
323            return 1
324        fi
325        f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3`
326        RETVAL=$?
327        if test "x$RETVAL" != x0 ; then
328            FC_NAMEMANGLE=$default_nm
329            echo
330            echo "WARNING: The \"nm\" command failed."
331            echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
332            echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
333            rm -f genmake_tcomp.* genmake_test.*
334            return 1
335        fi
336    
337        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
338        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
339        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
340        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
341    
342        nmangle="X"
343        if test "x$c_a" != "x$f_a" ; then
344            comm="echo x$f_a | sed -e 's|x$c_a||'"
345            a=`eval $comm`
346            nmangle="$a ## $nmangle"
347        fi
348        if test "x$c_b" != "x$f_b" ; then
349            comm="echo x$f_b | sed -e 's|x$c_b||'"
350            b=`eval $comm`
351            nmangle="$nmangle ## $b"
352        fi
353    
354        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
355    
356        #  cleanup the testing files
357        rm -f genmake_tcomp.* genmake_test.*
358    }
359    
360  #  Set defaults here  #  Set defaults here
361  COMMANDL="$0 $@"  COMMANDL="$0 $@"
# Line 292  S64= Line 366  S64=
366  KPP=  KPP=
367  FC=  FC=
368  LINK=  LINK=
369  DEFINES="-DWORDLENGTH=4"  # DEFINES="-DWORDLENGTH=4"
370    DEFINES=
371  PACKAGES=  PACKAGES=
372  ENABLE=  ENABLE=
373  DISABLE=  DISABLE=
# Line 379  echo "===  Processing options files and Line 454  echo "===  Processing options files and
454  gm_local="genmake_local"  gm_local="genmake_local"
455  for i in . $MODS ; do  for i in . $MODS ; do
456      if test -r $i/$gm_local ; then      if test -r $i/$gm_local ; then
457          source $i/$gm_local          . $i/$gm_local
458          break          break
459      fi      fi
460  done  done
461  echo -n "  getting local config information:  "  echo -n "  getting local config information:  "
462  if test -e $gm_local ; then  if test -e $gm_local ; then
463      echo "using $gm_local"      echo "using $gm_local"
464      source $gm_local      . $gm_local
465      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
466      # echo "ENABLE=$ENABLE"      # echo "ENABLE=$ENABLE"
467  else  else
# Line 590  fi Line 665  fi
665  if test "x$OPTFILE" != xNONE ; then  if test "x$OPTFILE" != xNONE ; then
666      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
667          echo "    using OPTFILE=\"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
668          source "$OPTFILE"          . "$OPTFILE"
669          RETVAL=$?          RETVAL=$?
670          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
671              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
# Line 617  fi Line 692  fi
692  if test "x${AD_OPTFILE}" != xNONE ; then  if test "x${AD_OPTFILE}" != xNONE ; then
693      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
694          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
695          source "$AD_OPTFILE"          . "$AD_OPTFILE"
696          RETVAL=$?          RETVAL=$?
697          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
698              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
# Line 633  if test "x${AD_OPTFILE}" != xNONE ; then Line 708  if test "x${AD_OPTFILE}" != xNONE ; then
708      fi      fi
709  fi  fi
710    
711  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain  #  Check that FC, LINK, CPP, S64, and LN are defined.  If not,
712  #  and abort!  #  complain and abort!
713  if test "x$FC" = x ; then  if test "x$FC" = x ; then
714      cat <<EOF 1>&2      cat <<EOF 1>&2
715    
# Line 660  Error: C pre-processor "$CPP" failed the Line 735  Error: C pre-processor "$CPP" failed the
735    
736    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
737    2) the "./genmake_local" file    2) the "./genmake_local" file
738      3) with the CPP environment variable
739    
740  EOF  EOF
741      exit 1      exit 1
# Line 669  fi Line 745  fi
745  if test "x$MAKEDEPEND" = x ; then  if test "x$MAKEDEPEND" = x ; then
746      MAKEDEPEND=makedepend      MAKEDEPEND=makedepend
747  fi  fi
748    if test "x$LN" = x ; then
749        LN="ln -s"
750    fi
751    echo "test" > genmake_test_ln
752    $LN genmake_test_ln genmake_tlink
753    RETVAL=$?
754    if test "x$RETVAL" != x0 ; then
755        cat <<EOF 1>&2
756    
757    Error: The command "ln -s" failed -- please specify a working soft-link
758      command in the optfile.
759    
760    EOF
761        exit 1
762    fi
763    rm -f genmake_test_ln genmake_tlink
764    
765  printf "\n===  Checking system libraries  ===\n"  printf "\n===  Checking system libraries  ===\n"
766  echo -n "  Do we have the system() command using $FC...  "  echo -n "  Do we have the system() command using $FC...  "
# Line 711  else Line 802  else
802  fi  fi
803  rm -f genmake_tcomp*  rm -f genmake_tcomp*
804    
805  echo -n "  The name mangling convention for $FC is...  "  echo "  The name mangling convention for $FC is...  "
806    #FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _"
807  if test "x$FC_NAMEMANGLE" = x ; then  if test "x$FC_NAMEMANGLE" = x ; then
808      FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _"      get_fortran_c_namemangling
 fi  
 cat > genmake_tcomp.f <<EOF  
       subroutine tcall( string )  
       character*(*) string  
       call tsub( string )  
       end  
 EOF  
 $FC $FFLAGS $DEFINES -c genmake_tcomp.f > genmake_tcomp.log 2>&1  
 RETVAL=$?  
 if test "x$RETVAL" != x0 ; then  
     cat genmake_tcomp.log >> genmake_errors  
     echo  
     echo "WARNING: test compile fails -- please see \"genmake_errors\""  
     echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  
     echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  
 else  
     tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3`  
     RETVAL=$?  
     if test "x$RETVAL" != x0 ; then  
         echo  
         echo "WARNING: The \"nm\" command failed."  
         echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  
         echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  
     else  
         t0=`echo $tcall | sed -e 's|_tcall|_ ## X|g'`  
         nmres=`echo $t0 | sed -e 's|tcall_|X ## _|g'`  
         FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmres"  
         echo "'$FC_NAMEMANGLE'"  
     fi  
809  fi  fi
810    echo "    '$FC_NAMEMANGLE'"
811  echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template  echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template
812  cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1  cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1
813  RETVAL=$?  RETVAL=$?
814  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
815      mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h      mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h
816  fi  fi
 rm -f genmake_tcomp*  
817    
818    
819  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
# Line 805  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 868  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
868  #  they appear as regular source code  #  they appear as regular source code
869  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
870      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
871      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
872      RETVAL=$?      RETVAL=$?
873      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
874          rm -f make_eesupp.errors          rm -f make_eesupp.errors
# Line 842  if test ! "x${RETVAL}" = x0 ; then Line 905  if test ! "x${RETVAL}" = x0 ; then
905      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
906      exit 1      exit 1
907  fi  fi
908  source ./.pd_tmp  . ./.pd_tmp
909  rm -f ./.pd_tmp  rm -f ./.pd_tmp
910    
911  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
# Line 1436  ad_taf_output.f: ad_input_code.f Line 1499  ad_taf_output.f: ad_input_code.f
1499          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1500          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1501    
1502    adtafonly:
1503            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1504            cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1505    
1506  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_taf: ad_taf_output.o \$(OBJFILES)
1507          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1508    

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.38

  ViewVC Help
Powered by ViewVC 1.1.22