#! /bin/sh
# /*@@
#   @file      cygwin
#   @date      Thu Jun 24 22:56:51 1999
#   @author    Tom Goodale
#   @desc 
#   Known architecture file for Windows using cygwin.
#   @enddesc 
#   @version $Header: /CCT/Projects/XiRel/SPEC2006/CactusBSSN/lib/make/known-architectures/cygwin,v 1.1.1.1 2009/02/03 01:02:30 jtao Exp $
# @@*/

if test "$CCTK_CONFIG_STAGE" = "preferred-compilers" ; then

  if test -z "$CC"; then
    echo Setting C compiler to cl
    CC="cl"
  fi

  if test -z "$CXX"; then
    echo Setting C++ compiler to cl
    CXX="cl /TP"
  fi

  if test -z "$LD"; then
    LD='$(CC)'
  fi

  if test -z "$FPP" -a -z "$FPPFLAGS"; then
    FPP='/usr/bin/cpp'
    FPPFLAGS='-traditional'
    echo Setting FPP to $FPP
    echo Setting FPPFLAGS to $FPPFLAGS
  fi

else

  CCTK_WriteLine cctk_Archdefs.h '/* WIN stuff */'
  CCTK_WriteLine cctk_Archdefs.h '#define WIN32'

  CYGWIN_CC_COMP=

  if test "`$CC 2>&1 | grep -i microsoft`" ; then 
    CYGWIN_CC_COMP=microsoft
  elif test "`$CC 2>&1 | grep -i intel`" ; then 
    CYGWIN_CC_COMP=intel
#  elif test "`$CC 2>&1 | grep -i gcc`" ; then
#    CYGWIN_CC_COMP=gnu
  else
    echo Unknown Windows C compiler.
    echo Please add appropriate information to 
    echo $srcdir/known-architectures/cygwin
    echo and send the updated file to CactusMaint
    echo We will try anyway ...
    CYGWIN_CC_COMP=unknown
  fi

  CYGWIN_CXX_COMP=

  if test "`$CXX 2>&1 | grep -i microsoft`" ; then 
    CYGWIN_CXX_COMP=microsoft
  elif test "`$CXX 2>&1 | grep -i intel`" ; then 
    CYGWIN_CXX_COMP=intel
#  elif test "`$CXX 2>&1 | grep -i gcc`" ; then
#    CYGWIN_CXX_COMP=gnu
  else
    echo Unknown Windows C++ compiler.
    echo Please add appropriate information to 
    echo $srcdir/known-architectures/cygwin
    echo and send the updated file to CactusMaint
    echo We will try anyway ...
    CYGWIN_CXX_COMP=unknown
  fi

  CYGWIN_F90_COMP=

  if test -n "$F90" ; then 
    if test "`$F90 2>&1 | grep -i digital`" ; then 
        CYGWIN_F90_COMP=digital
    elif test "`$F90 2>&1 | grep -i compaq`" ; then 
        CYGWIN_F90_COMP=compaq
    elif test "`$F90 2>&1 | grep -i intel`" ; then 
        CYGWIN_F90_COMP=intel
    elif test "`$F90 2>&1 | grep -i g77`" ; then
        CYGWIN_F90_COMP=gnu
    else
        echo Unknown Windows f90 compiler.
        echo Please add appropriate information to 
        echo $srcdir/known-architectures/cygwin
        echo and send the updated file to CactusMaint
        echo We will try anyway ...
       CYGWIN_F90_COMP=unknown
    fi
  else
    CYGWIN_F90_COMP=none
  fi

# /Gd means use __cdecl, it's /Gz for __stdcall

  case "$CYGWIN_CC_COMP" in
    microsoft|intel)
      : ${CFLAGS="/nologo /Gd"}
      : ${C_OPTIMISE_FLAGS="/Oxy-"}
      : ${CCOMPILEONLY="/c /Fo"}
      : ${OPTIONSEP="# not even a single a single space under cygwin"}
      ;;
    *)
      ;;
  esac

  case "$CYGWIN_CXX_COMP" in
    microsoft|intel)
      : ${CXXFLAGS="/nologo /Gd"}
      : ${CXX_OPTIMISE_FLAGS="/Oxy-"}
      : ${CREATEEXE="/Fe"}
      : ${CCOMPILEONLY="/c /Fo"}
      : ${CACTUSLIBLINKLINE='/link /libpath:"$(call TRANSFORM_DIRS,$(CCTK_LIBDIR))" $(foreach lib,$(ALLCACTUSLIBS), $(LIBNAME_PREFIX)$(lib)$(LIBNAME_SUFFIX))'}
      GENERAL_LIBRARIES='$(foreach i,$(LIBDIRS),/libpath:"$(call TRANSFORM_DIRS,$(i))") $(LIBS:%=%.lib) /NODEFAULTLIB:libcd /NODEFAULTLIB:libcmt'
      : ${OPTIONSEP="# not even a single a single space under cygwin"}
      ;;
    *)
      ;;
  esac

  case "$CYGWIN_F90_COMP" in
     digital)
     : ${F90_LIBS="dfor dfconsol dfport"} 
     : ${FCOMPILEONLY="/compile_only /object:"}
     : ${F90FLAGS="/fast /iface:cref"}
     : ${F77FLAGS="/fast /iface:cref"}
     CCTK_WriteLine cctk_Archdefs.h '#define WIN32_DIGITAL_FORTRAN'
     ;;
     compaq)
     : ${F90_LIBS="dfor dfconsol dfport"} 
     : ${FCOMPILEONLY="/compile_only /object:"}
     : ${F90FLAGS="/nologo /fast /iface:cref"}
     : ${F77FLAGS="/nologo /fast /iface:cref"}
     CCTK_WriteLine cctk_Archdefs.h "#define WIN32_DIGITAL_FORTRAN"
     ;;
     intel)
     : ${F90_LIBS=""} 
     : ${FCOMPILEONLY="/c /Fo"}
     : ${F90FLAGS="/nologo"}
     : ${F77FLAGS="/nologo"}
     ;;
     gnu)
     : ${F90_LIBS="g2c"} 
     : ${FCOMPILEONLY="-c -o"}
     : ${F90FLAGS=""}
     : ${F77FLAGS=""}
     ;;
     *)
     :
     ;;
  esac

  DIRSEP="\\\\"

# Convert //a to a: 

  GET_WD="cygpath -wa ."

  TRANSFORM_DIRS='$(shell cygpath -wa $(1))'

# The -nostdinc stops it picking stdio.h, etc, from the GNU headers.
# The -x c++ is because some of the Windows headers contain C++ comments
  C_DEPEND='$(CPP) -x c++ -E -MM -nostdinc -D_WIN32 $(CPPFLAGS) '
  CXX_DEPEND='$(CPP) -x c++ -E -MM -nostdinc -D_WIN32 $(CPPFLAGS) '

# Add in system include dirs from $(INCLUDE).  These may contain spaces.
# The -D_M_IX86 is necessary for things like winnt.h.  Since this is
# only used for generating dependencies, it shouldn't make a difference
# if we use this same flag on ia64.
  C_DEPEND_OUT='-D_M_IX86 -I"$(strip $(subst ;," -I",$(INCLUDE)))" > $@'
  CXX_DEPEND_OUT='-D_M_IX86 -I"$(strip $(subst ;," -I",$(INCLUDE)))" > $@'

  MKDIR="mkdir "
  MKDIRFLAGS=" -p "

  LIBNAME_PREFIX=""
  LIBNAME_SUFFIX=".lib"

  LIBS="$F90_LIBS wsock32"

# The Windows file system requires perl backup files to be made when
# doing in place editing
  PERL_BACKUP_NECESSARY='yes'

  if test "x$cross_compiling" = "xyes" ; then
    case "$host_cpu" in
      i?86)
        ENDIAN=little
        SIZEOF_LONG_LONG=8
        SIZEOF_LONG_INT=4
        SIZEOF_INT=4
        SIZEOF_SHORT_INT=2

        SIZEOF_LONG_DOUBLE=8
        SIZEOF_DOUBLE=8
        SIZEOF_FLOAT=4

        SIZEOF_POINTER=4
      ;;
      ia64)
        ENDIAN=little
        SIZEOF_LONG_LONG=8
        SIZEOF_LONG_INT=8
        SIZEOF_INT=4
        SIZEOF_SHORT_INT=2

        SIZEOF_LONG_DOUBLE=8
        SIZEOF_DOUBLE=8
        SIZEOF_FLOAT=4

        SIZEOF_POINTER=8
      ;;
      *)
        echo "Don't know details for cross-compilation to $host_cpu"
    esac
  fi

# MPI stuff
#
# Windows has no native MPI, so we don't set any NATIVE_MPI_XXX variables.
# This is caught by lib/make/extras/MPI/NATIVE then.

fi
