dnl ####################################################################
dnl #   Copyright (c)
dnl #
dnl #   You may copy, distribute, and modify it freely as long as you  #
dnl #   preserve distribute, and modify it freely as long as you       # 
dnl #   preserve this copyright and permission notice.                 #
dnl #                                                                  #
dnl #
dnl ####################################################################
dnl 
dnl Process this file and acconfig.h by autoconf to produce a configure script.
dnl 

AC_INIT(./configure)

dnl AC_PREFIX_DEFAULT(`pwd`)

AC_CONFIG_AUX_DIR(./config)

AC_CONFIG_HEADER(./src/include/config.h)

AC_CANONICAL_SYSTEM

CONFIGSHELL=${CONFIG_SHELL:-/bin/sh}
AC_SUBST(CONFIGSHELL)

AC_ARG_PROGRAM

AC_PROG_AWK

AC_PROG_CC
AC_PROG_CPP

AC_HEADER_STDC

AC_HEADER_TIME
AC_CHECK_HEADERS(sys/time.h)

dnl AC_CHECK_TYPE(u_short,unsigned short)

AC_HEADER_SYS_WAIT

AC_PROG_RANLIB

VERSION=1.09
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_SUBST(VERSION)

dnl current working directory

CWD=`pwd`
AC_SUBST(CWD)

dnl deciding mpi package

AC_MSG_CHECKING(MPI package)

MPI=

AC_ARG_WITH(MPI, [
--with-MPI=mpich          Using mpich MPI (the defualt setting)
--with-MPI=lam            Using LAM MPI 
--with-MPI=sp2            Using sp2 MPI from IBM ], MPI=${withval}, MPI=mpich )

AC_CACHE_VAL(adlib_cv_mpipackage, adlib_cv_mpipackage=$MPI) 

AC_MSG_RESULT($adlib_cv_mpipackage)

MPI=$adlib_cv_mpipackage

AC_SUBST(MPI)

case "$MPI" in
  mpich )

  dnl check if mpi installed.
  mpirun=`which mpirun`
  if test $? = 1 && test ! -x "$mpirun" 
  then 
    echo "Please install mpich first ..."
    exit 1
  fi

  dnl ARCH = `tarch`

  ARCH=`tarch`

  dnl decide whether there is MPICC

  AC_CHECK_PROG(MPICC, mpiCC, mpiCC)

  dnl check whether mpiCC work.

  if test "$MPICC" = "mpiCC" 
  then
    AC_MSG_CHECKING(whether mpiCC configured)

    echo "void any(){}" > conftest.C

    rm -f conftest.o
    mpiCC -c conftest.C > /dev/null 2> /dev/null
    
    if test -f conftest.o
    then
      MPICCCONFIG=yes
    else
      MPICCCONFIG=no
    fi

    AC_MSG_RESULT($MPICCCONFIG)
     	
    rm -f conftest.C conftest.o
  fi  

  dnl deciding compiler and linker

  if test "$MPICCCONFIG" = "yes" 
  then
    CXX=mpiCC
    AC_SUBST(CXX)

    LIBKEY=
  else
    dnl    AC_PROG_CC
    dnl    AC_PROG_CPP
    dnl    AC_PROG_CXX

    dnl decide compiler and lib according to machine.
    LIBKEY="-lmpi"

    case $target in
      *ibm* )
        AC_CHECK_PROGS(CXX, xlC c++)        	
	if test "$CXX" = "xlC"
	then
	  LIBINLINE=
	  CPLINLINE=
	fi
        ;;

      *solaris* )
        AC_CHECK_PROGS(CXX, CC c++)
        LIBKEY="$LIBKEY -lsocket -lnsl" 
	if test "$CXX" = "CC"
	then
	  LIBINLINE=
	  CPLINLINE=+d
	fi
        ;;

      *dec* )
        AC_CHECK_PROGS(CXX, cxx c++)
        if test $CXX = cxx 
        then
          LIBKEY="$LIBKEY -lcomplex -lm"
	  LIBINLINE=-noinline
	  CPLINLINE=-noinline
        fi
        ;;

      *mips* )
        AC_CHECK_PROGS(CXX, CC c++)
	if test "$CXX" = "CC"
	then
          LIBKEY="$LIBKEY -lm"
          case $ARCH in
            IRIX64)
              CXX="CC -64"
              ;;
            IRIXN32)
              CXX="CC -n32"
              ;;
            IRIX32)
              CXX="CC -32"
              ;;
            *)
              ;;
          esac
	fi
        ;;

      *hpux* )
        AC_CHECK_PROGS(CXX, c++ CC)
	if test "$CXX" = "c++"
	then
          LIBKEY="$LIBKEY -lm -lV3"
	fi
	;;

      * ) 
        AC_CHECK_PROGS(CXX, c++)
        ;; 

    esac

  fi

  if test "$CXX" = "" ; then
    echo "Found no C++ compiler on $target"
    exit 1
  fi

dnl  AC_SUBST(LIBKEY)
  AC_SUBST(LIBINLINE)
  AC_SUBST(CPLINLINE)
  
  dnl get mpi prefix
  AC_MSG_CHECKING(MPI include dir)

  AC_CACHE_VAL(adlib_cv_mpi_inc, 
   MPI_PREFIX=`which mpirun | sed 's%/bin/mpirun%%'`
   if test ! -f $MPI_PREFIX/include/mpi.h
   then 
     echo "Please input the mpich install prefix:"
     read MPI_PREFIX
   fi  

   if test ! -f $MPI_PREFIX/include/mpi.h
   then 
     echo "Please install mpich first ..."
     exit 1
   fi
   adlib_cv_mpi_inc=$MPI_PREFIX/include
  )
  AC_MSG_RESULT($adlib_cv_mpi_inc)

  MPI_INC=-I$adlib_cv_mpi_inc
  AC_SUBST(MPI_INC)

  if test x"$MPI_PREFIX" = x 
  then
     MPI_PREFIX=`echo $adlib_cv_mpi_inc | sed 's%/include%%'`
  fi

  dnl get mpich exec_prefix
  if test "$MPICC" != "mpiCC" 
  then
    AC_MSG_CHECKING(MPI lib dir)
    dnl use prefix here, not quite good
    MPI_LIB=
    AC_CACHE_VAL(adlib_cv_mpi_lib, 
    [ 
      for DIRNAME in $MPI_PREFIX/lib/$ARCH/*  $MPI_PREFIX/lib/
      do
        test -f $DIRNAME/libmpi.a && MPI_LIB=$DIRNAME && MPICH_LIB='mpi'
        test -f $DIRNAME/libmpich.a && MPI_LIB=$DIRNAME && MPICH_LIB='mpich'
      done

      if test -z "$MPI_LIB"
      then 
        echo "MPI lib not found, please install mpich first ..."
        exit 1
      fi
      adlib_cv_mpi_lib=$MPI_LIB
    ] )
    AC_MSG_RESULT($adlib_cv_mpi_lib)

    AC_SUBST(MPICH_LIB)

    MPI_LIB=-L$adlib_cv_mpi_lib
    AC_SUBST(MPI_LIB) 
  fi

  AC_MSG_CHECKING(MPI run script)
  AC_CACHE_VAL(adlib_cv_mpi_run, adlib_cv_mpi_run=$MPI_PREFIX/bin/mpirun )
  AC_MSG_RESULT($adlib_cv_mpi_run)
  MPIRUN=$adlib_cv_mpi_run

  ;;


  chimp )

  echo Not supported 
  ;;


  sp2 )

  AC_CHECK_PROG(MPICC, mpCC, mpCC)

  if test "$MPICC" = "mpCC" 
  then 
    CXX=mpCC
  else
    echo "Please install SP2 mpCC first ..."
    exit 1
  fi

  MPI_INC=
  AC_SUBST(MPI_INC)

  MPI_LIB=
  AC_SUBST(MPI_LIB) 

  LIBKEY=
  AC_SUBST(LIBKEY)
  ;;

  lam )
  AC_CHECK_PROG(MPICC, hcc, hcc)

  if test "$MPICC" = "hcc" 
  then 
    CXX=hcc
    FCL=hf77
  else
    echo "Please install LAM hcp first ..."
    exit 1
  fi

  MPI_INC=
  AC_SUBST(MPI_INC)

  MPI_LIB=
  AC_SUBST(MPI_LIB) 

  LIBKEY="-lmpi"
  AC_SUBST(LIBKEY)

  MPI_PREFIX=`which lamd | sed 's%/bin/lamd%%'`
  AC_MSG_CHECKING(MPI run script)
  AC_CACHE_VAL(adlib_cv_mpi_run, adlib_cv_mpi_run=$MPI_PREFIX/bin/mpirun)
  MPIRUN=$adlib_cv_mpi_run
  AC_MSG_RESULT($adlib_cv_mpi_run)

  ;;

  * )
  echo The package does not support $MPI MPI.
  exit 1
  ;;

esac

AC_SUBST(MPIRUN)

dnl decide about overloading

dnl PERL=`which perl`
AC_CHECK_PROG(PERL,perl,perl)
if test "$PERL" = "" 
then
  echo "perl is needed to configure the package"
  exit 1
fi
dnl AC_SUBST(PERL)

AC_MSG_CHECKING(matching template subclass arguments)

dnl Check for restrictions on matching template subclass arguments

AC_CACHE_VAL(adlib_cv_tmpl_subcls_arg,
  cat > conftest.C <<EOF   
// From section 14.8.3 of the draft ANSI standard

template<class T> struct B {};
template<class T> struct D: public B<T> {};
template<class T> void f(B<T>&);
void g(B<int>& bi, D<int>& di) 
{
  f(bi); f(di);
}
EOF

  $CXX -c conftest.C > /dev/null 2> /dev/null

  if test $? = 0 
  then
    adlib_cv_tmpl_subcls_arg=UNRESTRICTED
  else
    adlib_cv_tmpl_subcls_arg=RESTRICTED
  fi
  rm -f conftest.C conftest.o

)
AC_MSG_RESULT($adlib_cv_tmpl_subcls_arg)

if test "$adlib_cv_tmpl_subcls_arg" = "RESTRICTED"
then
  TEMPLATE_SUBCLASS_ARG_MATCHING_OK=no
else
  TEMPLATE_SUBCLASS_ARG_MATCHING_OK=yes
fi
AC_SUBST(TEMPLATE_SUBCLASS_ARG_MATCHING_OK)

AC_MSG_CHECKING(matching template const arguments)

dnl Check for restrictions on matching const template arguments

AC_CACHE_VAL(adlib_cv_tmpl_const_arg,
  cat > conftest.C <<EOF   
// DEC cxx under OSF1 V3.0 fails this

template<class T> class A {} ;
template<class T> void f(const A<T> x) {}
void g() {
  A<float> a ;
  f(a) ;
}
EOF

  $CXX -c conftest.C > /dev/null 2> /dev/null

  if test $? = 0 
  then
    adlib_cv_tmpl_const_arg=UNRESTRICTED
  else
    adlib_cv_tmpl_const_arg=RESTRICTED
  fi
  rm -f conftest.C conftest.o

)
AC_MSG_RESULT($adlib_cv_tmpl_const_arg)

if test "$adlib_cv_tmpl_const_arg" = "RESTRICTED"
then
  TEMPLATE_CONST_ARG_MATCHING_OK=no
else
  TEMPLATE_CONST_ARG_MATCHING_OK=yes
fi
AC_SUBST(TEMPLATE_CONST_ARG_MATCHING_OK)

dnl compiler option
dnl AC_MSG_CHECKING(compiler option)

COMPILER_OPT=

dnl AC_ARG_ENABLE(STRONG, 
dnl --enable-STRONG           Package building flag (default as disabled),
dnl COMPILER_OPT=-Dstrong,
dnl COMPILER_OPT= )

dnl AC_MSG_RESULT($COMPILER_OPT)
AC_SUBST(COMPILER_OPT)


dnl when we want better performance

AC_MSG_CHECKING(optimize option)

OPTIMIZE=

AC_ARG_ENABLE(OPTIMIZE, 
--enable-OPTIMIZE         Package building flag (default as disabled),
OPTIMIZE=-O,
OPTIMIZE= )

AC_MSG_RESULT($OPTIMIZE)
AC_SUBST(OPTIMIZE)

dnl check cbrt
AC_MSG_CHECKING(for cbrt)
ac_link_save=$ac_link
ac_link="$ac_link $LIBKEY"
AC_TRY_LINK([#include <math.h>] , 
 [ cbrt(10.0) ] , 
 [AC_MSG_RESULT(yes)] 
 AC_DEFINE(HAVE_CBRT),
 [AC_MSG_RESULT(no)]
)
ac_link=$ac_link_save

dnl for adJava interface

dnl JAVA=`which java | sed 's%/bin/java%%'`
AC_CHECK_PROG(JAVA,java,java)

dnl if JDK is available

if test "JAVA" != ""
then
  AC_SUBST(JAVA)

  case $target in

    *aix* )
    JOS="aix"
    ;;

    *solaris* )
    JOS="solaris"
    ;;

    *)
    echo Java interface not tested on $target yet.
    ;;

  esac

  AC_SUBST(JOS)

#  adJava=adJava
  adJava=
else
  adJava=
fi

AC_SUBST(adJava)


dnl for pcrcFortran interface

F77GETARG="call getarg(i,s)"
F77IARGC="iargc()"
F90UNIX='!'

if test $MPI = "lam"
then
    AC_CHECK_PROG(FCL, hf77, hf77)
fi

FC_OPT=
case "$target" in
	
  *ibm* )

  if test "$MPICC" = yes 
  then
    AC_CHECK_PROG(FCL, mpxlf, mpxlf)
  fi
  if test "$FCL" = "" 
  then 
    AC_CHECK_PROGS(FCL, xlf90 xlf f77 g77)
  fi
  if test "$FCL" = "xlf90"
  then
    FC_OPT='-qfixed -w'
    AC_DEFINE(USE_F90)
  fi
  PLATFORM="-DAIX"
  ;;

  *dec* )

  AC_CHECK_PROGS(FCL, f90 f77 g77)
  if test "$FCL" = "f90"
  then
    AC_DEFINE(USE_F90)
  fi
  PLATFORM="-DDEC"
  ;;

  *solaris* )

  AC_CHECK_PROG(FCL, f90, f90)
  if test "$FCL" = "f90" 
  then
    cat > conftest.f <<EOF
      SUBROUTINE FOO
      END
EOF
    $FCL -c conftest.f > /dev/null 2> /dev/null
    if test $? = 0 
    then
      AC_DEFINE(USE_F90)
      FCL=f90
    else
      FCL=
    fi
  fi

  rm -f conftest.f conftest.o	

  if test "$FCL" = "" 
  then
    AC_CHECK_PROG(F77, f77, f77)
    FCL=$F77
  fi

  PLATFORM="-DSOLARIS"
  ;;

  *mips* )

  AC_CHECK_PROG(FCL, f90, f90)
  if test "$FCL" = "f90"
  then
    PLATFORM="-DMIPS"
    AC_DEFINE(USE_F90)
    case $ARCH in
      IRIX64)
	FCL="f90 -64"
	;;
      IRIXN32)
	FCL="f90 -n32"
	;;
      IRIX32)
	FCL="f90 -32"
	;;
      *)
	;;
    esac
  fi
  ;;

  *linux* ) 

  AC_CHECK_PROGS(FCL, g77 f77 fort77)
  if test "$FCL" = "fort77"
  then
    FC_OPT="-w"
  fi
  PLATFORM="-DF2C"
  ;;

  *hpux* ) 

  AC_CHECK_PROGS(FCL, fort77 f77)
  if test "$FCL" != ""
  then
    FC_OPT="+T"
    PLATFORM="-DHPUX"
  fi
  if test "$FCL" = "fort77"
  then
    FC_OPT=${FC_OPT}" -w"
  fi
  F77GETARG='call igetarg(i,s,80)'
  ;;

  * ) 
  AC_CHECK_PROGS(FCL, f77 fort77 g77 xlf)        	
  PLATFORM="-DUNIX"
  if test "$FCL" != ""
  then
    echo "pcrc Fortran interface is not test on $target." 
  fi
  ;; 

esac

dnl if Fortran compiler available
if test "$FCL" != ""
then
  dnl decide tailing underscore

  AC_MSG_CHECKING(subroutine name used by Fortran compiler)
  AC_CACHE_VAL(adlib_cv_tail,   
  cat > conftest.f <<EOF
      SUBROUTINE FOO_FOO
      END
EOF

  $FCL -c conftest.f > /dev/null 2> /dev/null

  NAME=`nm conftest.o | grep "foo_foo__"`
  if test "$NAME" != "" 
  then
    adlib_cv_tail=TWOSCORE
  else
    NAME=`nm conftest.o | grep "foo_foo_"`
    if test "$NAME" != ""   
    then
      adlib_cv_tail=ONESCORE
    else
      NAME=`nm conftest.o | grep "foo_foo"`
      if test "$NAME" != ""   
      then
        adlib_cv_tail=NONSCORE
      else
        echo "FORTRAM compiler generated name not supported yet"
        exit 1 
      fi
    fi
  fi

  rm -f conftest.f conftest.o
  )

  AC_MSG_RESULT($adlib_cv_tail)
  
  if test "$adlib_cv_tail" = TWOSCORE 
  then
    SUFFIX=__
  fi

  if test "$adlib_cv_tail" = ONESCORE 
  then
    SUFFIX=_
  fi

  if test "$adlib_cv_tail" = NONSCORE 
  then
    SUFFIX=
  fi

  AC_SUBST(SUFFIX)

  dnl decide how to link C++ library from Fortran

  if test "$CXX" = "c++" 
  then
    dnl CXXLIBKEY is not a good name here!
    CXXLIBKEY=`c++ -print-libgcc-file-name`
  else
    case $target in

    *ibm* )
    CXXLIBKEY="-lC"
    ;;

    *solaris* )
    CXXLIBKEY="-lcxx"
    ;;

    *dec* )
    CXXLIBKEY=""
    ;;

    *mips* )
    case $ARCH in
      IRIX64)
        CXXLIBKEY="-lC -lCsup"
	;;
      IRIXN32)
        CXXLIBKEY="-lC -lCsup"
	;;
      *)
        CXXLIBKEY="-lC"
	;;
    esac
    ;;

    *)
    echo linking Fortran with C++ not tested on $target yet.
    ;;

    esac
  fi

  pcrcFortran=pcrcFortran
else
  echo "No Fortran compiler found on this $target."
  pcrcFortran=
fi

dnl determine the special Fortran compiler's feature
AC_MSG_CHECKING(support 'byte' in Fortran Compiler $FCL)
AC_CACHE_VAL(ac_cv_prog_fortran_byte, ac_cv_prog_fortran_byte=$ac_cv_prog_fortran_byte)
if test x"$ac_cv_prog_fortran_byte" = x
then
  ac_cv_prog_fortran_byte=""
  cat > conftest.f <<EOF
        program try
        BYTE A
        end 
EOF
  if $FCL -c $FC_OPT conftest.f 1> /dev/null 2> /dev/null && test -f conftest.o
  then
	ac_cv_prog_fortran_byte="byte"
  else 
        cat > conftest.f <<EOF
          program try
          integer*1 A
          end 
EOF
        if $FCL -c $FC_OPT conftest.f 1> /dev/null 2> /dev/null && test -f conftest.o
        then
	    ac_cv_prog_fortran_byte="integer*1"
        fi
  fi
  rm -f conftest.*
fi
AC_MSG_RESULT($ac_cv_prog_fortran_byte)
if test x"$ac_cv_prog_fortran_byte" != "x"
then
   FORTRAN_BYTE=$ac_cv_prog_fortran_byte
else
   FORTRAN_BYTE='character*1'
fi
AC_SUBST(FORTRAN_BYTE)


AC_MSG_CHECKING(support 'word' in Fortran Compiler $FCL)
AC_CACHE_VAL(ac_cv_prog_fortran_word, ac_cv_prog_fortran_word=$ac_cv_prog_fortran_word)
if test x"$ac_cv_prog_fortran_word" = x
then
  ac_cv_prog_fortran_word=""
  cat > conftest.f <<EOF
        program try
        WORD A
        end 
EOF
  if $FCL -c $FC_OPT conftest.f 1> /dev/null 2> /dev/null && test -f conftest.o
  then
	ac_cv_prog_fortran_word="word"
  else
        cat > conftest.f <<EOF
          program try
          integer*2 A
          end 
EOF
        if $FCL -c $FC_OPT conftest.f 1> /dev/null 2> /dev/null && test -f conftest.o
        then
	    ac_cv_prog_fortran_word="integer*2"
        fi
  fi
  rm -f conftest.*
fi
AC_MSG_RESULT($ac_cv_prog_fortran_word)
if test x"$ac_cv_prog_fortran_word" != "x"
then
   FORTRAN_WORD=$ac_cv_prog_fortran_word
else
   FORTRAN_WORD='character*2'
fi
AC_SUBST(FORTRAN_WORD)

AC_SUBST(F77GETARG)
AC_SUBST(F77IARGC)
AC_SUBST(F90UNIX)


dnl deciding mpio (MPI2.0 IO) package
AC_MSG_CHECKING(MPIO package)

MPIO=
AC_ARG_WITH(MPIO, [
--with-MPIO=romio        Using MPI2.0 IO package from ROMIO],
MPIO=${withval},
MPIO=
)

AC_CACHE_VAL(adlib_cv_mpiopackage, adlib_cv_mpiopackage=$MPIO) 
if test x"$adlib_cv_mpiopackage" = x && test x"$MPIO" != x
then
   adlib_cv_mpiopackage=$MPIO
elif test "$MPICH_LIB" = 'mpich' 
then
dnl mpich  version after 1.1.1 will include romio, so nothing will do
   adlib_cv_mpiopackage=romio
fi
AC_MSG_RESULT($adlib_cv_mpiopackage)

if test x"$adlib_cv_mpiopackage" != x && test "$MPICH_LIB" != 'mpich'
then
LIBKEY="-lmpio "$LIBKEY
AC_DEFINE(HAVE_MPIO)

AC_MSG_CHECKING(MPIO include dir)

AC_CACHE_VAL(adlib_cv_mpio_inc,
[
if test x"$MPIO_INC" != x
then
  adlib_cv_mpio_inc=$MPIO_INC
  if test ! -f $MPIO_INC/mpio.h 
  then 
  echo "Please install mpio first ..."
  exit 1
  fi  
else
  MPIO_PREFIX=
  if test ! -f $MPIO_PREFIX/include/mpio.h 
  then 
    echo "Please input the MPIO package prefix:"
    read MPIO_PREFIX
  fi  

  if test ! -f $MPIO_PREFIX/include/mpio.h
  then 
    echo "Please install mpio first ..."
    exit 1
  fi
  adlib_cv_mpio_inc="$MPIO_PREFIX/include/"
fi
] )
MPIO_INC=-I$adlib_cv_mpio_inc
AC_MSG_RESULT($adlib_cv_mpio_inc)

if test x"$MPIO_PREFIX" = x 
then
     MPIO_PREFIX=`echo $adlib_cv_mpio_inc | sed 's%/include%%'`
fi

dnl get mpich exec_prefix
AC_MSG_CHECKING(MPIO lib dir)

AC_CACHE_VAL(adlib_cv_mpio_lib,
[  if test x$MPIO_LIB != x
   then
     if test ! -f "$MPIO_LIB/libmpio.a"
     then
       exit 1
     fi
   else
     if test -f "$MPIO_PREFIX/lib/$ARCH/libmpio.a"
     then
       MPIO_LIB="$MPIO_PREFIX/lib/$ARCH/"
     fi
     if test -z "$MPIO_LIB" ; then
       echo "MPIO lib not found, please install mpio first ..."
       exit 1
     fi
   fi
   adlib_cv_mpio_lib=$MPIO_LIB
] )
AC_MSG_RESULT($adlib_cv_mpio_lib)
MPIO_LIB="-L$adlib_cv_mpio_lib"

else
MPIO_INC=
MPIO_LIB=
fi

AC_SUBST(MPIO_INC)
AC_SUBST(MPIO_LIB) 

AC_MSG_CHECKING(asynchronous IO platform)
case $target in
  *ibm* ) 
	  AC_TRY_RUN(
	  [ #include <aio.h>
            main() {
	    int fd, n=1;
	    aio_handle_t aiocbp = (aio_handle_t)malloc(sizeof(struct aiocb));
	    fd = open("conftest.io", O_RDWR | O_CREAT , 0644);
            aiocbp->aio_buf = (char *)&n;
            aiocbp->aio_nbytes = sizeof(int);
  	    aiocbp->aio_whence = SEEK_CUR;
            aiocbp->aio_offset = 0;
            aio_read(fd, aiocbp);
	    close(fd); } ],
	  IO_PLATFORM=AIX,
	  IO_PLATFORM=UNIX,
	  IO_PLATFORM=UNIX
	  ) 
	  rm -f conftest.io;;
   * )    IO_PLATFORM=UNIX;;
esac
AC_MSG_RESULT($IO_PLATFORM)
AC_SUBST(IO_PLATFORM)

dnl check if compile runtime profile lib
AC_MSG_CHECKING(runtime profile lib)

PROFILE=
AC_ARG_ENABLE(PROFILE, 
--enable-PROFILE         Enable runtime profiling tool (default as disabled),
PROFILE='-DRUNTIME_PROFILE',
PROFILE=
)

AC_SUBST(PROFILE)
if test x"$PROFILE" != x
then
PROFILE_LIB=libPadlib.a
PCRC_PROFILELIB=libPpcrcf.a
PROFILE_IO_LIB="libPio.a"
AC_MSG_RESULT("yes")
else
AC_MSG_RESULT("no")
fi
AC_SUBST(PROFILE_LIB)
AC_SUBST(PROFILE_IO_LIB)
AC_SUBST(PCRC_PROFILELIB)

AC_SUBST(FC_OPT)
AC_SUBST(PLATFORM)
AC_SUBST(LIBKEY)
AC_SUBST(CXXLIBKEY)
AC_SUBST(pcrcFortran)

AC_SUBST(MPI)

AC_OUTPUT(
Makefile 
src/Makefile 
src/include/Makefile src/kernel/Makefile src/script/Makefile 
src/pcrcFortran/Makefile 
src/pcrcFortran/ma/Makefile src/pcrcFortran/intrinsic/Makefile
src/io/Makefile
src/include/generate_Array
src/include/generate_transformations
src/include/generate_block
src/include/generate_oc_block
man/Makefile
man/man1/Makefile
test/Makefile 
test/kernel/Makefile
test/adJava/Makefile 
test/pcrcFortran/Makefile
src/script/ad++:src/script/ad++.in
src/script/prun:src/script/prun.in
src/script/pcrcf:src/script/pcrcf.in 
src/script/cpgfile:src/script/cpgfile.in 
src/script/chpgfile:src/script/chpgfile.in 
src/script/rcopy:src/script/rcopy.in 
src/script/getproc:src/script/getproc.in 
src/adJava/Makefile
src/adJava/adjavac:src/adJava/adjavac.in
src/adJava/prunjava:src/adJava/prunjava.in
src/adJava/adlib/Makefile
src/io/passion_base.g:src/io/passion_base.h.in
src/pcrcFortran/farg.f:src/pcrcFortran/farg.f.in
src/pcrcFortran/extname.g:src/pcrcFortran/extname.h.in
src/pcrcFortran/intrinsic/intrinname.g:src/pcrcFortran/intrinsic/intrinname.h.in
src/pcrcFortran/ma/macommon.h:src/pcrcFortran/ma/macommon.h.in
src/pcrcFortran/ma/mafdecls.inc:src/pcrcFortran/ma/mafdecls.inc.in
src/pcrcFortran/ma/mafdecls.fh:src/pcrcFortran/ma/mafdecls.fh.in
test/kernel/runtests:test/kernel/runtests.in
test/adJava/runtests:test/adJava/runtests.in
test/pcrcFortran/runtests:test/pcrcFortran/runtests.in,

if test -f src/pcrcFortran/extname.h && diff src/pcrcFortran/extname.g src/pcrcFortran/extname.h > /dev/null
then
   /bin/rm -f src/pcrcFortran/extname.g
else
   /bin/mv src/pcrcFortran/extname.g src/pcrcFortran/extname.h
fi
if test -f src/pcrcFortran/intrinsic/intrinname.h && diff src/pcrcFortran/intrinsic/intrinname.g src/pcrcFortran/intrinsic/intrinname.h > /dev/null
then
   /bin/rm -f src/pcrcFortran/intrinsic/intrinname.g
else
   /bin/mv src/pcrcFortran/intrinsic/intrinname.g src/pcrcFortran/intrinsic/intrinname.h
fi
if test -f src/io/passion_base.h && diff src/io/passion_base.g src/io/passion_base.h > /dev/null
then
   /bin/rm -f src/io/passion_base.g
else
   /bin/mv src/io/passion_base.g src/io/passion_base.h
fi
chmod a+x src/include/generate_Array
chmod a+x src/include/generate_transformations
chmod a+x src/include/generate_block
chmod a+x src/include/generate_oc_block
chmod a+x src/script/ad++
chmod a+x src/script/prun
chmod a+x src/script/cpgfile
chmod a+x src/script/chpgfile
chmod a+x src/script/rcopy
chmod a+x src/script/getproc
dnl if test "$adJava" != ""
dnl then
  chmod a+x src/adJava/adjavac
  chmod a+x src/adJava/prunjava
dnl fi
if test -f src/script/pcrcf
then
  chmod a+x src/script/pcrcf
fi
chmod a+x test/kernel/runtests
chmod a+x test/adJava/runtests
chmod a+x test/pcrcFortran/runtests
)

echo Done!
