--- comp.orig	2012-12-05 05:49:41.000000000 +0900
+++ comp	2013-02-27 15:56:56.000000000 +0900
@@ -97,6 +97,8 @@
 if ($TARGET == ibm-bg)     set OK=true
 if ($TARGET == linux32)    set OK=true
 if ($TARGET == linux64)    set OK=true
+if ($TARGET == freebsd32)    set OK=true
+if ($TARGET == freebsd64)    set OK=true
 if ($TARGET == mac32)      set OK=true
 if ($TARGET == mac64)      set OK=true
 if ($TARGET == necsx)      set OK=true
@@ -149,6 +151,8 @@
 if  ($TARGET == ibm-bg)       set BLAS3=true
 if (($TARGET == linux32) && ($GMS_MATHLIB != none)) set BLAS3=true
 if (($TARGET == linux64) && ($GMS_MATHLIB != none)) set BLAS3=true
+if (($TARGET == freebsd32) && ($GMS_MATHLIB != none)) set BLAS3=true
+if (($TARGET == freebsd64) && ($GMS_MATHLIB != none)) set BLAS3=true
 if  ($TARGET == mac32)        set BLAS3=true
 if  ($TARGET == mac64)        set BLAS3=true
 if  ($TARGET == sgi32)        set BLAS3=true
@@ -579,6 +583,26 @@
    endif
 endif
 #
+if ($TARGET == freebsd32) then
+                          setenv MACHIN '*I32'
+   if ($MODULE == ddi)    setenv MACHIN '*SOC'
+   if ($MODULE == iolib)  setenv MACHIN '*UNX'
+   if ($MODULE == unport) setenv MACHIN '*L32'
+endif
+#
+if ($TARGET == freebsd64) then
+                          setenv MACHIN '*I64'
+   if ($MODULE == ddi)    setenv MACHIN '*SOC'
+   if ($MODULE == iolib)  setenv MACHIN '*UNX'
+   if ($MODULE == unport) then
+      if ($GMS_FORTRAN == ifort) then
+         setenv MACHIN '*INT'
+      else
+         setenv MACHIN '*L64'
+      endif
+   endif
+endif
+
 if ($TARGET == mac32) then
                           setenv MACHIN '*I32'
    if ($MODULE == ddi)    setenv MACHIN '*SOC'
@@ -1640,6 +1664,137 @@
    endsw
 #                     ... end of Linux on 32 bit processors.
 endif
+if ($TARGET == freebsd32) then
+#
+#  there are three supported 32 bit compilers: g77, gfortran, ifort
+#          g77,
+#             the gnu FORTRAN being included in older Linux distributions
+#             lacks support for unit numbers over 99, or REAL*16
+#          gfortran,
+#             the gnu FORTRAN being included in newer Linux distributions
+#             this allows unit numbers over 99, but not REAL*16
+#          Intel's commercial ifort,
+#             supports unit numbers above 99 and REAL*16 (runs all of GAMESS)
+
+    switch ($GMS_FORTRAN)
+#
+#   The meaning of g77's flags are
+#      -O0, -O1, -O2, -O3 are the optimization levels, -O means -O1
+#      -Wno-globals -fno-globals together suppress argument type checking.
+#      -fautomatic defeats use of static storage
+#      -malign-double uses 64 bit data alignment
+#   g77 does not support FORTRAN logical units above 99, or 128 bit math.
+#
+   case g77:
+   set OPT = '-O2'
+   if ($MODULE == ormas1) set OPT='-O2 -fno-move-all-movables' # RH9, g77 3.3
+   if ($MODULE == zheev)  set OPT='-O0'  # defensive compiling
+   if (($MODULE == qeigen) || ($MODULE == int2c)) then
+      mv -f $MODULE_F $MODULE.junk
+      sed -e "s/Q-/D-/g" \
+          -e "s/Q+00/D+00/g" \
+          -e "s/REAL\*16/DOUBLE PRECISION/" $MODULE.junk > $MODULE_F
+      rm -f $MODULE.junk
+   endif
+   if (($MODULE == iolib) || ($MODULE == inputa) || \
+       ($MODULE == gamess) || ($MODULE == mp2ims)) then
+      mv -f $MODULE_F $MODULE.junk
+      sed -e "s/MXUNIT=299/MXUNIT=99/g" $MODULE.junk > $MODULE_F
+      rm -f $MODULE.junk
+   endif
+   set echo
+   g77 -c $OPT -malign-double -fautomatic \
+           -Wno-globals -fno-globals $MODULE_F
+   unset echo
+   breaksw
+#
+#   gfortran was included with Fedora Core distributions starting around FC4.
+#   This is a 32 bit version, i.e. not using -fdefault-integer-8!
+#   Unlike g77, gfortran allows for unit numbers above 100.
+#   Like g77, gfortran does not support quadruple precision.
+#      -Ox optimization level is from the gcc back end, x can be 0,1,2,3
+#      -std=legacy  suppresses warnings about use of f77 constructs.
+#
+   case gfortran:
+   set OPT='-O2'
+   if ($MODULE == zheev)  set OPT='-O0'  # defensive compiling
+   if ($MODULE == pcmcv2) set OPT='-O1'  # EFP+CPCM, ala Francois, v4.1.2
+   if ($GMS_GFORTRAN_VERNO == 4.6) then
+      if ($MODULE == cosmo)  set OPT='-O0'   # this issue seen in 4.6.x
+      if ($MODULE == tddgrd) set OPT='-O0'   # this issue seen in 4.6.1
+   endif
+   if ($GMS_GFORTRAN_VERNO == 4.7) then
+      if ($MODULE == cosmo)  set OPT='-O0'
+      if ($MODULE == dcscf)  set OPT='-O0'
+      if ($MODULE == rohfcc) set OPT='-O0'
+      if ($MODULE == tddgrd) set OPT='-O0'
+   endif
+#        as of 4.6 tested in late 2011, gfortran can do q.p.!
+   switch ($GMS_GFORTRAN_VERNO)
+      case 4.0:
+      case 4.1:
+      case 4.2:
+      case 4.3:
+      case 4.4:
+      case 4.5:
+         set extraflags=''
+         if (($MODULE == qeigen) || ($MODULE == int2c)) then
+            mv -f $MODULE_F $MODULE.junk
+            sed -e "s/Q-/D-/g" \
+                -e "s/Q+00/D+00/g" \
+                -e "s/REAL\*16/DOUBLE PRECISION/" $MODULE.junk > $MODULE_F
+            rm -f $MODULE.junk
+         endif
+         breaksw
+      case 4.6:
+      case 4.7:
+         set extraflags='-fno-whole-file'
+         breaksw
+      default:
+         echo Unrecognized gfortran version
+         exit 4
+         breaksw
+   endsw
+#
+   set echo
+   %%FC%% -c $OPT -std=legacy $MODULE_F
+   unset echo
+   breaksw
+#
+#    3. Intel Fortran Compiler for Linux
+#
+#    Note that this is more agressive (-O3 compared to -O2) than the
+#    64 bit compile below.  If an ifort version gives you problems,
+#    drop the optimization back to -O2.
+#    Dmitri likes to use "-O3 -xN -ssp -unroll8 -ip -pad -opt_report",
+#    but that may cause certain ifort versions to fail on some files.
+#    See http://staff.aist.go.jp/d.g.fedorov/compgms.html for aggressive
+#    optimizations in 32 bit mode, as a function of the ifort version.
+#
+   case ifort:
+   set OPT = '-O3'
+   if ($MODULE == delocl) set OPT='-O0'  # from Cheol
+   if ($MODULE == prpamm) set OPT='-O0'  # for exam13
+   if ($MODULE == zheev)  set OPT='-O0'
+   set EXTRAOPT=" "
+   if ($GMS_IFORT_VERNO >=  8) set EXTRAOPT="$EXTRAOPT -assume byterecl"
+   if ($GMS_IFORT_VERNO >= 10) set EXTRAOPT="$EXTRAOPT -vec-report0"
+   if ($GMS_IFORT_VERNO  < 12) set EXTRAOPT="$EXTRAOPT -w95 -cm"
+   if ($GMS_IFORT_VERNO >= 12) set EXTRAOPT="$EXTRAOPT -warn nousage -inline-level=0"
+   set echo
+   ifort -c -i4 $OPT -ftz -auto $EXTRAOPT $MODULE_F
+   unset echo
+   breaksw
+#
+   default:
+      echo "Please spell your Linux 32 bit FORTRAN compiler name correctly."
+      exit 4
+      breaksw
+   endsw
+#                     ... end of FreeBSD on 32 bit processors.
+endif
+
+
 #
 #   ------ Linux on 64 bit chips ------
 #   This should work on any 64 bit Linux release, for any type of
@@ -1897,6 +2052,136 @@
    endsw
 #                     ... end of Linux on 64 bit processors.
 endif
+
+if ($TARGET == freebsd64) then
+#
+#  there are two supported 64 bit compilers: gfortran, ifort
+#
+   switch ($GMS_FORTRAN)
+
+   case gfortran:
+#           -finit-real=<zero|inf|-inf|nan>  could be interesting debug opt
+#           -fno-automatic forces static storage of all local variables
+#           -fno-whole-file suppresses argument's data type checking
+      set OPT='-O2'
+      if (".$GMS_DEBUG_FLAGS" != .) set OPT="$GMS_DEBUG_FLAGS"
+
+      if ($GMS_GFORTRAN_VERNO == 4.6) then
+         if ($MODULE == cosmo)  set OPT='-O0'   # this issue seen in 4.6.1
+         if ($MODULE == tddgrd) set OPT='-O0'   # exam41, seen in 4.6.1
+      endif
+      if ($GMS_GFORTRAN_VERNO == 4.7) then
+         if ($MODULE == cosmo)  set OPT='-O0'
+         if ($MODULE == dcscf)  set OPT='-O0'   # exam44, seen in 4.7 only
+         if ($MODULE == rohfcc) set OPT='-O0'   # exam47, seen in 4.7 only
+         if ($MODULE == tddgrd) set OPT='-O0'
+      endif
+      if ($MODULE == zheev)  set OPT='-O0'  # defensive compiling
+
+      set EXTRAOPT=" "
+
+      if (($MODULE == cchem) || ($MODULE == ga)) then
+         mv $MODULE.f $MODULE.F
+         set MODULE_F=$MODULE.F
+         if ($GMS_LIBCCHEM == true) then
+            if ($MODULE == cchem) set EXTRAOPT="-DHAVE_CCHEM $extraflags"
+            if ($MODULE == ga)    set EXTRAOPT="-I$GMS_PATH/libcchem/ga/include"
+         endif
+      endif
+#
+#        as of 4.6 tested in late 2011, gfortran can do q.p.!
+      switch ($GMS_GFORTRAN_VERNO)
+         case 4.0:
+         case 4.1:
+         case 4.2:
+         case 4.3:
+         case 4.4:
+         case 4.5:
+            if (($MODULE == qeigen) || ($MODULE == int2c)) then
+               mv -f $MODULE_F $MODULE.junk
+               sed -e "s/Q-/D-/g" \
+                   -e "s/Q+00/D+00/g" \
+                   -e "s/REAL\*16/DOUBLE PRECISION/" $MODULE.junk > $MODULE_F
+               rm -f $MODULE.junk
+            endif
+            breaksw
+         case 4.6:
+         case 4.7:
+            set EXTRAOPT="$EXTRAOPT -fno-whole-file"
+            breaksw
+         default:
+            echo Unrecognized gfortran version
+            exit 4
+            breaksw
+      endsw
+
+      set echo
+      %%FC%% -c -fdefault-integer-8 $OPT -std=legacy $EXTRAOPT $MODULE_F
+      unset echo
+      breaksw
+
+   case ifort:
+#     -i4/-i8 set default integer length
+#     -On can have n=1,2,3.  Use of 3 caused problems with earlier
+#          compilers, so it isn't being used here.  Try it if you like.
+#     stack storage for locals is governed by -auto versus -save.
+#     -assume byterecl was introduced at ifort 8.0 (older versions will
+#        print a message saying this flag is ignored).  Newer versions
+#        need this so that direct access file opens are measured in
+#        bytes rather than the new default in v8.0, namely 4-byte units.
+#     -vec-report0 suppresses loop vectorization messages (new in 10.0)
+#     -w95 suppresses Hollerith initialization and other f90-like warnings
+#     -cm  means suppress comments about programming practices,
+#          these two options spelled '-warn nousage' at version 12.
+#     -WB means warn but don't fail on out-of-bounds array references
+#     -ftz flushes underflow results to zero
+#
+      set OPT = '-O2'
+      if (".$GMS_DEBUG_FLAGS" != .) set OPT="$GMS_DEBUG_FLAGS"
+#       alas, I'm so tired of hearing about so many versions failing to
+#       diagonalize, that this time critical code is run w/o optimization.
+#       Very many (all?) ifort versions have problems with eigen.src.
+      if ($MODULE == eigen)  set OPT='-O0' # read note just above.
+      if ($MODULE == fmo)    set OPT='-O1' # 12.0.4, exam37
+      if ($MODULE == guess)  set OPT='-O0' # 10.0, exam39
+      if ($MODULE == locpol) set OPT='-O1' # 10.0, makefp/gmres
+      if ($MODULE == morokm) set OPT='-O0' # Jan Fredin
+      if ($MODULE == prpel)  set OPT='-O1' # 10.0, exam13
+      if (($MODULE == rohfcc) && ($GMS_IFORT_VERNO == 12)) \
+                             set OPT='-O0' # exam42+exam47 (op.sh.CC,IP-EOM)
+      if ($MODULE == tdxitr) set OPT='-O1' # 10.0, exam39
+      if ($MODULE == vscf)   set OPT='-O0' # intensities for combinations
+      if ($MODULE == zheev)  set OPT='-O0' # defensive compiling
+
+      set EXTRAOPT=" "
+
+      if (($MODULE == cchem) || ($MODULE == ga)) then
+         mv $MODULE.f $MODULE.F
+         set MODULE_F=$MODULE.F
+         if ($GMS_LIBCCHEM == true) then
+            if ($MODULE == cchem) set EXTRAOPT="-DHAVE_CCHEM"
+            if ($MODULE == ga)    set EXTRAOPT="-I$GMS_PATH/libcchem/ga/include"
+         endif
+      endif
+
+      if ($GMS_IFORT_VERNO >=  8) set EXTRAOPT="$EXTRAOPT -assume byterecl"
+      if ($GMS_IFORT_VERNO >= 10) set EXTRAOPT="$EXTRAOPT -vec-report0"
+      if ($GMS_IFORT_VERNO  < 12) set EXTRAOPT="$EXTRAOPT -w95 -cm"
+      if ($GMS_IFORT_VERNO >= 12) set EXTRAOPT="$EXTRAOPT -warn nousage -inline-level=0"
+      set echo
+      ifort -c -i8 $OPT -ftz -auto $EXTRAOPT $MODULE_F
+      unset echo
+      breaksw
+#
+   default:
+      echo "Please spell your FreeBSD 64 bit FORTRAN compiler name correctly."
+      exit 4
+      breaksw
+   endsw
+#                     ... end of FreeBSD on 64 bit processors.
+endif
+
+
 #
 #   Apple Macintosh system using OS X
 #    jargon: 10.0=cheetah, 10.1=puma,     10.2=jaguar,   10.3=panther,
