/[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.85 by edhill, Wed Jul 14 21:26:53 2004 UTC revision 1.92 by edhill, Fri Jul 30 15:59:33 2004 UTC
# Line 1  Line 1 
1  #! /usr/bin/env sh  #! /usr/bin/env bash
2  #  #
3  # $Header$  # $Header$
4  #  #
# Line 122  EOF Line 122  EOF
122        stop        stop
123        end        end
124  EOF  EOF
125      test -e Makefile  &&  mv -f Makefile Makefile.bak      test -f Makefile  &&  mv -f Makefile Makefile.bak
126      cat <<EOF >> Makefile      cat <<EOF >> Makefile
127  %.$tfs : %.F  %.$tfs : %.F
128  .SUFFIXES:  .SUFFIXES:
# Line 131  genmake_hello.$tfs: genmake_hello.F Line 131  genmake_hello.$tfs: genmake_hello.F
131  EOF  EOF
132      $MAKE "genmake_hello."$tfs > /dev/null 2>&1      $MAKE "genmake_hello."$tfs > /dev/null 2>&1
133      RETVAL=$?      RETVAL=$?
134      if test "x$RETVAL" != x0 -o ! -e "genmake_hello."$tfs ; then      if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
135          if test "x$FS" = x ; then          if test "x$FS" = x ; then
136              FS='for'              FS='for'
137              FS90='fr9'              FS90='fr9'
# Line 149  EOF Line 149  EOF
149          fi          fi
150      fi      fi
151      rm -f genmake_hello.* Makefile      rm -f genmake_hello.* Makefile
152      test -e Makefile  &&  mv -f Makefile.bak Makefile      test -f Makefile  &&  mv -f Makefile.bak Makefile
153    
154      #  If we make it here, use the extensions      #  If we make it here, use the extensions
155      FS=$tfs      FS=$tfs
# Line 195  EOF Line 195  EOF
195              echo "    a system-default makedepend was not found."              echo "    a system-default makedepend was not found."
196                            
197              #  Try to build the cyrus implementation              #  Try to build the cyrus implementation
198              rm -f ./genmake_cy_md              build_cyrus_makedepend
             (  
                 cd $ROOTDIR/tools/cyrus-imapd-makedepend  \  
                     &&  ./configure > /dev/null 2>&1  \  
                     &&  make > /dev/null 2>&1  
                 if test -x ./makedepend.exe ; then  
                     $LN ./makedepend.exe ./makedepend  
                 fi  
                 ./makedepend ifparser.c > /dev/null 2>&1  \  
                     &&  echo "true"  
             ) > ./genmake_cy_md  
             grep true ./genmake_cy_md > /dev/null 2>&1  
199              RETVAL=$?              RETVAL=$?
200              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" != x0 ; then
                 MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'  
             else  
201                  MAKEDEPEND='$(TOOLSDIR)/xmakedepend'                  MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
202              fi              fi
203              rm -f ./genmake_cy_md              rm -f ./genmake_cy_md
204          fi          fi
205        else
206            #  echo "MAKEDEPEND=${MAKEDEPEND}"
207            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
208            RETVAL=$?
209            if test x"$RETVAL" = x0 ; then
210                build_cyrus_makedepend
211            fi
212      fi      fi
213  }  }
214    
215    
216    build_cyrus_makedepend()  {
217        rm -f ./genmake_cy_md
218        (
219            cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
220                &&  ./configure > /dev/null 2>&1  \
221                &&  make > /dev/null 2>&1
222            if test -x ./makedepend.exe ; then
223                $LN ./makedepend.exe ./makedepend
224            fi
225            ./makedepend ifparser.c > /dev/null 2>&1  \
226                &&  echo "true"
227        ) > ./genmake_cy_md
228        grep true ./genmake_cy_md > /dev/null 2>&1
229        RETVAL=$?
230        rm -f ./genmake_cy_md
231        if test "x$RETVAL" = x0 ; then
232            MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
233            return 0
234        else
235            echo "WARNING: unable to build cyrus-imapd-makedepend"
236            return 1
237        fi
238    }
239    
240  # Guess possible config options for this host  # Guess possible config options for this host
241  find_possible_configs()  {  find_possible_configs()  {
242    
# Line 251  find_possible_configs()  { Line 269  find_possible_configs()  {
269    
270      look_for_makedepend      look_for_makedepend
271    
272      # look for possible fortran compilers      #================================================================
273        #  look for possible C compilers
274        tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
275        p_CC=
276        for c in $tmp ; do
277            rm -f ./genmake_hello.c  ./genmake_hello
278            cat >> genmake_hello.c << EOF
279    #include <stdio.h>
280    int main(int argc, char **argv) {
281      printf("Hello!\n");
282      return 0;
283    }
284    EOF
285            $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
286            RETVAL=$?
287            if test "x${RETVAL}" = x0 ; then
288                p_CC="$p_CC $c"
289            fi
290        done
291        rm -f ./genmake_hello.c ./genmake_hello
292        if test "x${p_CC}" = x ; then
293            cat 1>&2 <<EOF
294    
295    Error: No C compilers were found in your path.  Please specify one using:
296    
297        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
298        2) the CC or MITGCM_CC environment variables.
299    
300    EOF
301            exit 1
302        else
303            echo "  The possible C compilers found in your path are:"
304            echo "   "$p_CC
305            if test "x$CC" = x ; then
306                CC=`echo $p_CC | $AWK '{print $1}'`
307                echo "  Setting C compiler to: "$CC
308            fi
309        fi
310    
311        #================================================================
312        #  look for possible FORTRAN compilers
313      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"
314      p_FC=      p_FC=
315      for c in $tmp ; do      for c in $tmp ; do
# Line 277  Error: No Fortran compilers were found i Line 335  Error: No Fortran compilers were found i
335    
336      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
337      2) a command-line option (eg. "-fc NAME"), or      2) a command-line option (eg. "-fc NAME"), or
338      3) the MITGCM_FC environment variable.      3) the FC or MITGCM_FC environment variables.
339    
340  EOF  EOF
341          exit 1          exit 1
# Line 448  Usage: "$0" [OPTIONS] Line 506  Usage: "$0" [OPTIONS]
506            will search for a working compiler by trying a list of            will search for a working compiler by trying a list of
507            "usual suspects" such as g77, f77, etc.            "usual suspects" such as g77, f77, etc.
508    
509        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
510              Use "NAME" as the C compiler.  By default, genmake
511              will search for a working compiler by trying a list of
512              "usual suspects" such as gcc, c89, cc, etc.
513    
514      -[no]ieee | --[no]ieee      -[no]ieee | --[no]ieee
515            Do or don't use IEEE numerics.  Note that this option            Do or don't use IEEE numerics.  Note that this option
516            *only* works if it is supported by the OPTFILE that            *only* works if it is supported by the OPTFILE that
# Line 483  EOF Line 546  EOF
546    
547  #  Build a CPP macro to automate calling C routines from FORTRAN  #  Build a CPP macro to automate calling C routines from FORTRAN
548  get_fortran_c_namemangling()  {  get_fortran_c_namemangling()  {
549    
550        #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
551        if test ! "x$FC_NAMEMANGLE" = x ; then
552            return 0
553        fi
554    
555      default_nm="#define FC_NAMEMANGLE(X) X ## _"      default_nm="#define FC_NAMEMANGLE(X) X ## _"
556            
557      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
# Line 500  WARNING: Please contact <MITgcm-support@ Line 569  WARNING: Please contact <MITgcm-support@
569  EOF  EOF
570          return 1          return 1
571      fi      fi
572      c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`      c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
573      RETVAL=$?      RETVAL=$?
574      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
575          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
# Line 530  WARNING: Please contact <MITgcm-support@ Line 599  WARNING: Please contact <MITgcm-support@
599  EOF  EOF
600          return 1          return 1
601      fi      fi
602      f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`      f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
603      RETVAL=$?      RETVAL=$?
604      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
605          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
# Line 607  EOF Line 676  EOF
676    
677    
678  check_netcdf_libs()  {  check_netcdf_libs()  {
679        echo "" > genmake_tnc.log
680      cat <<EOF > genmake_tnc.for      cat <<EOF > genmake_tnc.for
681        program fgennc        program fgennc
682  #include "netcdf.inc"  #include "netcdf.inc"
# Line 619  check_netcdf_libs()  { Line 689  check_netcdf_libs()  {
689        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
690        end        end
691  EOF  EOF
692      $CPP genmake_tnc.for > genmake_tnc.f  \      #echo "$CPP $DEFINES $INCLUDES"
693        $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null  \
694          &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1          &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1
695      RET_COMPILE=$?      RET_COMPILE=$?
696      test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1      test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
# Line 628  EOF Line 699  EOF
699          HAVE_NETCDF=t          HAVE_NETCDF=t
700      else      else
701          # try again with "-lnetcdf" added to the libs          # try again with "-lnetcdf" added to the libs
702          $CPP genmake_tnc.for > genmake_tnc.f  \          $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null  \
703              &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \              &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \
704              $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1              $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1
705          RET_COMPILE=$?          RET_COMPILE=$?
# Line 658  LN= Line 729  LN=
729  S64=  S64=
730  KPP=  KPP=
731  FC=  FC=
732    CC=
733  CPP=  CPP=
734  LINK=  LINK=
735  DEFINES=  DEFINES=
# Line 665  PACKAGES= Line 737  PACKAGES=
737  ENABLE=  ENABLE=
738  DISABLE=  DISABLE=
739  MAKEFILE=  MAKEFILE=
740  MAKEDEPEND=  #MAKEDEPEND=
741  PDEPEND=  PDEPEND=
742  DUMPSTATE=t  DUMPSTATE=t
743  PDEFAULT=  PDEFAULT=
# Line 771  for i in . $MODS ; do Line 843  for i in . $MODS ; do
843      fi      fi
844  done  done
845  printf "  getting local config information:  "  printf "  getting local config information:  "
846  if test -e $gm_local ; then  if test -f $gm_local ; then
847      echo "using $gm_local"      echo "using $gm_local"
848      . $gm_local      . $gm_local
849      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
# Line 792  fi Line 864  fi
864  #done  #done
865  #parse_options  #parse_options
866  ac_prev=  ac_prev=
867  for ac_option ; do  for ac_option in $@ ; do
868    
869      G2ARGS="$G2ARGS \"$ac_option\""      G2ARGS="$G2ARGS \"$ac_option\""
870    
# Line 888  for ac_option ; do Line 960  for ac_option ; do
960  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
961  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
962  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
963                        
964            -cc | --cc)
965                ac_prev=CC ;;
966            -cc=* | --cc=*)
967                CC=$ac_optarg ;;
968            
969          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
970              ac_prev=FC ;;              ac_prev=FC ;;
971          -fc=* | --fc=*)          -fc=* | --fc=*)
# Line 960  if test -f ./.genmakerc ; then Line 1037  if test -f ./.genmakerc ; then
1037  fi  fi
1038    
1039  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1040      if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'`
1041        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1042          ROOTDIR=".."          ROOTDIR=".."
1043      else      else
1044          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
# Line 1043  if test "x${AD_OPTFILE}" != xNONE ; then Line 1121  if test "x${AD_OPTFILE}" != xNONE ; then
1121      fi      fi
1122  fi  fi
1123    
1124  #  Check that FC, LINK, CPP, S64, LN, and MAKE are defined.  If not,  #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1125  #  either set defaults or complain and abort!  #  either set defaults or complain and abort!
1126  if test ! "x$BASH" = x ; then  if test ! "x$BASH" = x ; then
1127      # add a trailing space so that it works within the Makefile syntax (see below)      # add a trailing space so that it works within the Makefile syntax (see below)
# Line 1059  Error: no Fortran compiler: please speci Line 1137  Error: no Fortran compiler: please speci
1137  EOF  EOF
1138      exit 1      exit 1
1139  fi  fi
1140    if test "x$CC" = x ; then
1141        cat <<EOF 1>&2
1142    
1143    Error: no C compiler: please specify using one of the following:
1144      1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1145      2) the "-cc=XXX" command-line option
1146      3) the "./genmake_local" file
1147    EOF
1148        exit 1
1149    fi
1150  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1151      LINK=$FC      LINK=$FC
1152  fi  fi
# Line 1222  if test "x${PLATFORM}" = x ; then Line 1310  if test "x${PLATFORM}" = x ; then
1310  fi  fi
1311    
1312  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1313      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'`
1314        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1315          EXEDIR=../exe          EXEDIR=../exe
1316      else      else
1317          EXEDIR=.          EXEDIR=.
# Line 1340  else Line 1429  else
1429              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1430          done          done
1431          echo "    before group expansion packages are: $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1432          while ! expand_pkg_groups; do echo > /dev/null; done          RET=1
1433            while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1434          echo "    after group expansion packages are:  $PACKAGES"          echo "    after group expansion packages are:  $PACKAGES"
1435      fi      fi
1436  fi  fi
# Line 1449  while test "x$ck" != xtt ; do Line 1539  while test "x$ck" != xtt ; do
1539              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
1540              exit 1              exit 1
1541          fi          fi
1542          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
1543            #i=$(( $i + 1 ))
1544      done      done
1545      ck=$ck"t"      ck=$ck"t"
1546  done  done
# Line 1611  echo Line 1702  echo
1702  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
1703  echo "  setting INCLUDES"  echo "  setting INCLUDES"
1704  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
1705      if ! test -d $i ; then      if test ! -d $i ; then
 #       INCLUDES="$INCLUDES -I$i"  
 #   else  
1706          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
1707      fi      fi
1708  done  done
# Line 1688  echo "" >> f90srclist.inc Line 1777  echo "" >> f90srclist.inc
1777  echo "" >> hlist.inc  echo "" >> hlist.inc
1778  echo "" >> ad_flow_files.inc  echo "" >> ad_flow_files.inc
1779    
1780  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
1781      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
1782  fi  fi
1783  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
# Line 1761  MAKEDEPEND = ${MAKEDEPEND} Line 1850  MAKEDEPEND = ${MAKEDEPEND}
1850  # Special preprocessor (KAP on DECs, FPP on Crays)  # Special preprocessor (KAP on DECs, FPP on Crays)
1851  KPP = ${KPP}  KPP = ${KPP}
1852  # Fortran compiler  # Fortran compiler
1853  FC = ${FC}  FC = ${FC} in
1854  # Fortran compiler  # Fortran compiler
1855  F90C = ${F90C}  F90C = ${F90C}
1856    # C compiler
1857    CC = ${CC}
1858  # Link editor  # Link editor
1859  LINK = ${LINK} ${LDADD}  LINK = ${LINK} ${LDADD}
1860    

Legend:
Removed from v.1.85  
changed lines
  Added in v.1.92

  ViewVC Help
Powered by ViewVC 1.1.22