/[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.95 by edhill, Thu Aug 5 16:04:32 2004 UTC revision 1.108 by edhill, Thu Oct 21 13:38:46 2004 UTC
# Line 124  EOF Line 124  EOF
124  EOF  EOF
125      test -f Makefile  &&  mv -f Makefile Makefile.bak      test -f Makefile  &&  mv -f Makefile Makefile.bak
126      cat <<EOF >> Makefile      cat <<EOF >> Makefile
 %.$tfs : %.F  
127  .SUFFIXES:  .SUFFIXES:
128  genmake_hello.$tfs: genmake_hello.F  .SUFFIXES: .$tfs .F
129          $LN genmake_hello.F genmake_hello.$tfs  .F.$tfs:
130            $LN \$< \$@
131  EOF  EOF
132      $MAKE "genmake_hello."$tfs > /dev/null 2>&1      $MAKE "genmake_hello."$tfs > /dev/null 2>&1
133      RETVAL=$?      RETVAL=$?
# Line 675  EOF Line 675  EOF
675  }  }
676    
677    
678    check_HAVE_STAT()  {
679        get_fortran_c_namemangling
680        cat <<EOF > genmake_tc_1.c
681    $FC_NAMEMANGLE
682    #include <stdio.h>
683    #include <stdlib.h>
684    #include <unistd.h>
685    #include <sys/stat.h>
686    #include <sys/types.h>
687    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
688    {
689        char name[512];
690        struct stat astat;
691    
692        name[0] = 'a'; name[1] = '\0';
693        if (! stat(name, &astat))
694            *nbyte = (int)(astat.st_size);
695        else
696            *nbyte = -1;
697    }
698    EOF
699        make genmake_tc_1.o >> genmake_tc.log 2>&1
700        RET_C=$?
701        cat <<EOF > genmake_tc_2.f
702          program hello
703          integer nbyte
704          call tfsize(nbyte)
705          print *," HELLO WORLD", nbyte
706          end program hello
707    EOF
708        $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1
709        RET_F=$?
710        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1
711        RETVAL=$?
712        if test "x$RETVAL" = x0 ; then
713            HAVE_STAT=t
714            DEFINES="$DEFINES -DHAVE_STAT"
715        fi
716        rm -f genmake_tc*
717    }
718    
719    
720  check_netcdf_libs()  {  check_netcdf_libs()  {
721      echo "" > genmake_tnc.log      echo "" > genmake_tnc.log
722      cat <<EOF > genmake_tnc.for      cat <<EOF > genmake_tnc.for
# Line 689  check_netcdf_libs()  { Line 731  check_netcdf_libs()  {
731        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
732        end        end
733  EOF  EOF
734      #echo "$CPP $DEFINES $INCLUDES"      #echo "$CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f"
735        #echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.f"
736        #echo "$LINK -o genmake_tnc.o $LIBS"
737      $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null  \      $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null  \
738          &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1          &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.f >> genmake_tnc.log 2>&1  \
739            &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
740      RET_COMPILE=$?      RET_COMPILE=$?
741      test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1  
742      RETVAL=$?      #EH3  Remove test program execution for machines that either disallow
743      if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then      #EH3  execution or cannot support it (eg. cross-compilers)
744        #EH3
745        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
746        #EH3 RETVAL=$?
747        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
748    
749        if test "x$RET_COMPILE" = x0 ; then
750          HAVE_NETCDF=t          HAVE_NETCDF=t
751      else      else
752          # try again with "-lnetcdf" added to the libs          # try again with "-lnetcdf" added to the libs
753          $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null  \          $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null  \
754              &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \              &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.f >> genmake_tnc.log 2>&1  \
755              $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1              &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
756          RET_COMPILE=$?          RET_COMPILE=$?
757          test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1          if test "x$RET_COMPILE" = x0 ; then
         RETVAL=$?  
         if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then  
758              LIBS="$LIBS -lnetcdf"              LIBS="$LIBS -lnetcdf"
759              HAVE_NETCDF=t              HAVE_NETCDF=t
760          else          else
# Line 761  HAVE_SYSTEM= Line 810  HAVE_SYSTEM=
810  HAVE_FDATE=  HAVE_FDATE=
811  FC_NAMEMANGLE=  FC_NAMEMANGLE=
812  HAVE_CLOC=  HAVE_CLOC=
813    HAVE_STAT=
814  HAVE_NETCDF=  HAVE_NETCDF=
815  HAVE_ETIME=  HAVE_ETIME=
816    
# Line 775  BASH= Line 825  BASH=
825  PWD=`pwd`  PWD=`pwd`
826  MAKE=make  MAKE=make
827  AWK=awk  AWK=awk
828  THISHOSTNAME=`hostname`  THISHOST=`hostname`
829  THISCWD=`pwd`  THISCWD=`pwd`
830  THISDATE=`date`  THISDATE=`date`
831    THISUSER=`echo $USER`
832    THISVER=
833  MACHINE=`uname -a`  MACHINE=`uname -a`
834  EXECUTABLE=  EXECUTABLE=
835  EXEHOOK=  EXEHOOK=
# Line 811  gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STA Line 863  gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STA
863  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
864  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
865  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
866  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
867  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
868  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
869    
# Line 852  else Line 904  else
904      echo "none found"      echo "none found"
905  fi  fi
906    
907  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
908  #OPTIONS=  #OPTIONS=
909  #n=0  #n=0
910  #for i ; do  #for i ; do
# Line 864  fi Line 916  fi
916  #done  #done
917  #parse_options  #parse_options
918  ac_prev=  ac_prev=
919  for ac_option in $@ ; do  for ac_option in "$@" ; do
920    
921      G2ARGS="$G2ARGS \"$ac_option\""      G2ARGS="$G2ARGS \"$ac_option\""
922    
# Line 1036  if test -f ./.genmakerc ; then Line 1088  if test -f ./.genmakerc ; then
1088      echo      echo
1089  fi  fi
1090    
1091    #  Find the MITgcm ${ROOTDIR}
1092  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1093      tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'`      tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'`
1094      if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
# Line 1062  if test ! -d ${ROOTDIR} ; then Line 1115  if test ! -d ${ROOTDIR} ; then
1115      exit 1      exit 1
1116  fi  fi
1117    
1118    #  Find the MITgcm ${THISVER}
1119    if test -f "${ROOTDIR}/doc/tag-index" ; then
1120        THISVER=`grep checkpoint ${ROOTDIR}/doc/tag-index | head -1`
1121    fi
1122    
1123  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
1124  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1125      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
# Line 1278  else Line 1336  else
1336  fi  fi
1337  rm -f genmake_t*  rm -f genmake_t*
1338    
1339    printf "  Can we use stat() through C calls...  "
1340    check_HAVE_STAT
1341    if test "x$HAVE_STAT" != x ; then
1342        echo "yes"
1343    else
1344        echo "no"
1345    fi
1346    rm -f genmake_t*
1347    
1348  printf "  Can we create NetCDF-enabled binaries...  "  printf "  Can we create NetCDF-enabled binaries...  "
1349  check_netcdf_libs  check_netcdf_libs
1350  if test "x$HAVE_NETCDF" != x ; then  if test "x$HAVE_NETCDF" != x ; then
# Line 1330  if test ! -d ${TOOLSDIR} ; then Line 1397  if test ! -d ${TOOLSDIR} ; then
1397      exit 1      exit 1
1398  fi  fi
1399  if test "x$S64" = x ; then  if test "x$S64" = x ; then
1400      S64='$(TOOLSDIR)/set64bitConst.sh'      echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1401        RETVAL=$?
1402        if test "x${RETVAL}" = x0 ; then
1403            S64='$(TOOLSDIR)/set64bitConst.sh'
1404        else
1405            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1406            RETVAL=$?
1407            if test "x${RETVAL}" = x0 ; then
1408                S64='$(TOOLSDIR)/set64bitConst.csh'
1409            else
1410                cat <<EOF
1411    
1412    ERROR: neither of the two default scripts:
1413    
1414        ${TOOLSDIR}/set64bitConst.sh
1415        ${TOOLSDIR}/set64bitConst.csh
1416    
1417      are working so please check paths or specify (with \$S64) a
1418      working version of this script.
1419    
1420    EOF
1421                exit 1
1422            fi
1423        fi
1424  fi  fi
1425  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1426    
# Line 1475  done Line 1565  done
1565  rm -f ./.tmp_pack  rm -f ./.tmp_pack
1566  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1567    
1568    #  Check availability of NetCDF and then either build the MNC template
1569    #  files or delete mnc from the list of available packages.
1570    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1571    RETVAL=$?
1572    if test "x$RETVAL" = x0 ; then
1573        if test "x$HAVE_NETCDF" != xt ; then
1574            cat <<EOF
1575    
1576    *********************************************************************
1577    WARNING: the "mnc" package was enabled but tests failed to compile
1578      NetCDF applications.  Please check that:
1579    
1580      1) NetCDF is correctly installed for this compiler and
1581      2) the LIBS variable (within the "optfile") specifies the correct
1582           NetCDF library to link against.
1583    
1584      Due to this failure, the "mnc" package is now DISABLED.
1585    *********************************************************************
1586    
1587    EOF
1588            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1589            DISABLE="$DISABLE mnc"
1590        else
1591            ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1
1592            RETVAL=$?
1593            if test "x${RETVAL}" = x0 ; then
1594                rm -f make_mnc.errors
1595            else
1596                echo "Error: problem encountered while building source files in pkg/mnc:"
1597                cat make_mnc.errors 1>&2
1598                exit 1
1599            fi
1600        fi
1601    fi
1602    
1603  echo "  applying package dependency rules"  echo "  applying package dependency rules"
1604  ck=  ck=
1605  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
# Line 1559  for i in $PACKAGES ; do Line 1684  for i in $PACKAGES ; do
1684      fi      fi
1685  done  done
1686    
 #  Build MNC templates and check for ability to build and use NetCDF  
 echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1  
 RETVAL=$?  
 if test "x$RETVAL" = x0 ; then  
     ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1  
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         rm -f make_mnc.errors  
     else  
         echo "Error: problem encountered while building source files in pkg/mnc:"  
         cat make_mnc.errors 1>&2  
         exit 1  
     fi  
     if test "x$HAVE_NETCDF" != xt ; then  
         cat <<EOF  
   
 WARNING: the "mnc" package has been enabled but tests failed to  
   compile and/or execute NetCDF applications.  Please check that:  
   
   1) NetCDF is installed for your compiler and  
   2) the LIBS variable (within the 'optfile") specifies the correct  
        NetCDF library to link against.  
     
 EOF  
     fi  
 fi  
   
1687  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
1688  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
1689  #  The following UGLY HACK sets multiple "#undef"s and it needs to go  #  The following UGLY HACK sets multiple "#undef"s and it needs to go
# Line 1732  for d in $alldirs ; do Line 1830  for d in $alldirs ; do
1830                          ;;                          ;;
1831                    ./FC_NAMEMANGLE.h)                    ./FC_NAMEMANGLE.h)
1832                          ;;                          ;;
1833                      ./BUILD_INFO.h)
1834                            ;;
1835                    *)                    *)
1836                          touch .links.tmp/$sf                          touch .links.tmp/$sf
1837                          deplist="$deplist $sf"                          deplist="$deplist $sf"
# Line 1788  echo "#    $THISDATE" >> $MAKEFILE Line 1888  echo "#    $THISDATE" >> $MAKEFILE
1888  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
1889  echo "#    $0 $G2ARGS" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
1890  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1891  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
1892    
1893  EXE_AD=$EXECUTABLE"_ad"  EXE_AD=$EXECUTABLE"_ad"
1894  EXE_FTL=$EXECUTABLE"_ftl"  EXE_FTL=$EXECUTABLE"_ftl"
# Line 1834  ENABLED_PACKAGES = ${ENABLED_PACKAGES} Line 1934  ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1934  DISABLED_PACKAGES = ${DISABLED_PACKAGES}  DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1935    
1936  # These files are created by Makefile  # These files are created by Makefile
1937  SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h  SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
1938    
1939  EOF  EOF
1940    
# Line 1877  CFLAGS = ${CFLAGS} Line 1977  CFLAGS = ${CFLAGS}
1977  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
1978  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
1979  # Flags and libraries needed for linking  # Flags and libraries needed for linking
1980  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
1981  # Name of the Mekfile  # Name of the Mekfile
1982  MAKEFILE=${MAKEFILE}  MAKEFILE=${MAKEFILE}
1983    
# Line 1938  makefile: Line 2038  makefile:
2038  cleanlinks:  cleanlinks:
2039          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2040    
2041  # Special targets ($SPECIAL_FILES) which are create by make  # Special targets (SPECIAL_FILES) which are create by make
2042  ${PACKAGES_DOT_H}:  ${PACKAGES_DOT_H}:
2043          @echo Creating \$@ ...          @echo Creating \$@ ...
2044          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
# Line 1949  FC_NAMEMANGLE.h: Line 2049  FC_NAMEMANGLE.h:
2049          @echo Creating \$@ ...          @echo Creating \$@ ...
2050          echo "$FC_NAMEMANGLE" > \$@          echo "$FC_NAMEMANGLE" > \$@
2051    
2052    BUILD_INFO.h:
2053            @echo Creating \$@ ...
2054    EOF
2055    
2056    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2057    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2058    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2059    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2060    
2061    cat >>$MAKEFILE <<EOF
2062    
2063  # The normal chain of rules is (  .F - .$FS - .o  )  # The normal chain of rules is (  .F - .$FS - .o  )
2064    
2065  %.o : %.F  ## This nullifies any default implicit rules concerning these two file types:
2066    ## %.o : %.F
2067    
2068  .F.$FS:  .F.$FS:
2069          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
# Line 2036  ad_tamc_output.f: ad_input_code.f Line 2148  ad_tamc_output.f: ad_input_code.f
2148  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
2149          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2150    
2151    adonlyfwd:
2152            patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2153    
2154    adtrick:
2155            patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2156    
2157  # ... FTL ...  # ... FTL ...
2158  ftlall: ftl_taf  ftlall: ftl_taf

Legend:
Removed from v.1.95  
changed lines
  Added in v.1.108

  ViewVC Help
Powered by ViewVC 1.1.22