dnl $Id: configure.in,v 1.124 2002/10/11 08:48:27 msato Exp $
dnl $RWC_Release: Omni-1.6 $
dnl $RWC_Copyright:
dnl  Omni Compiler Software Version 1.5-1.6
dnl  Copyright (C) 2002 PC Cluster Consortium
dnl  
dnl  This software is free software; you can redistribute it and/or modify
dnl  it under the terms of the GNU Lesser General Public License version
dnl  2.1 published by the Free Software Foundation.
dnl  
dnl  Omni Compiler Software Version 1.0-1.4
dnl  Copyright (C) 1999, 2000, 2001.
dnl   Tsukuba Research Center, Real World Computing Partnership, Japan.
dnl  
dnl  Please check the Copyright and License information in the files named
dnl  COPYRIGHT and LICENSE under the top  directory of the Omni Compiler
dnl  Software release kit.
dnl  
dnl  
dnl  $
dnl	This file is an input file used by the GNU "autoconf" program to
dnl	generate the file "configure", which is run during Omni installation
dnl	to configure the system for the local environment.

# --------------------------------------------------------------------
# Let the initiation begin....

AC_INIT(include/exc_platform.h.in)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# Set Omni version

omniVersion=1.5
AC_SUBST(omniVersion)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# prefix directory check and modify

if test "${prefix}" = "NONE"; then
    prefix=/usr/local
fi

orgPrefix=${prefix}
AC_SUBST(orgPrefix)

t=`echo ${prefix} | egrep '^/.*$'`
if test "x${t}" = "x${prefix}"; then
    prefix="\$(DESTDIR)${prefix}"
else
    prefix="\$(DESTDIR)/${prefix}"
fi
unset t

if test "${exec_prefix}" = "NONE"; then
    orgExec_prefix=${orgPrefix}
    exec_prefix='${prefix}'
else
    orgExec_prefix=${exec_prefix}
    t=`echo ${exec_prefix} | egrep '^/.*$'`
    if test "x${t}" = "x${exec_prefix}"; then
	exec_prefix="\$(DESTDIR)${exec_prefix}"
    else
	exec_prefix="\$(DESTDIR)/${exec_prefix}"
    fi
fi
AC_SUBST(orgExec_prefix)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# First of all, check on what system we are running.

HOSTARCH=`./utils/config.guess | grep -v Linking`
CPU=`echo $HOSTARCH | awk -F- '{ print $1 }' | sed 's/\./_/g'`
OS=`echo $HOSTARCH | awk -F- '{ print $3 }' | sed 's/\./_/g'`

case $CPU in
    i*86)
        CPU=i386;;
    alpha*)
	CPU=alpha;;
esac

case $OS in
    sunos*)
        OS=sunos;;
    solaris*)
        OS=solaris;;
    freebsd*)
	OS=freebsd;;
    netbsd*)
	OS=netbsd;;
    irix*)
	OS=irix;;
    aix*)
	OS=aix;;
    darwin*)
	OS=darwin;;
    cygwin*)
	OS=cygwin32;;
esac

AC_SUBST(OS)
AC_SUBST(CPU)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# Next, check what CC will be used, and set compile flags

ccType="unknown"

isSunCC=no
sunCCPre6=0
isMipsCC=no
isAIXCC=no
isGcc=no
isIntelCC=no
isPGICC=no

mustCFlags=""
mustCppFlags=""

optCFlags=""
warnCFlags=""
debCFlags=""

userOptCFlags=""
userDebCFlags=""

debCppFlags="-DNDEBUG"
userCppFlags=""

osCppFlags=""
osCFlags=""

ccCom=""
AC_ARG_WITH(cc,
    [  --with-cc=CC            specify C compiler to use ("cc" default)],
    [ccCom=$withval], [ccCom=""])

AC_ARG_WITH(opt,
    [  --with-opt=OPT          specify C compiler options for optimization],
    [userOptCFlags=$withval], [userOptCFlags=""])

AC_ARG_WITH(debug,
    [  --with-debug=OPT        specify C compiler options for debuggable executaable file creation],
    [userDebCFlags=$withval], [userDebCFlags=""])

AC_ARG_WITH(cppflag,
    [  --with-cppflag=OPT      specify C preprocessor options],
    [userCppFlags=$withval], [userCppFlags=""])


oCC=${CC}
oCFLAGS=${CFLAGS}
progCC=""
AC_ARG_ENABLE(gcc,
    [  --enable-gcc            allow use of gcc if available],
    [exc_ok=$enableval], [exc_ok=no])
if test "$exc_ok" = "yes"; then
    AC_PROG_CC
    progCC=${CC}
fi
CFLAGS=${oCFLAGS}
CC=${oCC}

if test "x${ccCom}" != "x"; then
    CC=${ccCom}
elif test "x${progCC}" != "x"; then
    CC=${progCC}
fi

if test "x${CC}" = "x"; then
   CC=cc
fi

AC_ARG_ENABLE(debug,
    [  --enable-debug          enable generate executable with debug symbol (false default).],
    [doDebug=$enableval], [doDebug=no])
if test "x${doDebug}" = "xyes"; then
    debCFlags="-g"
    debCppFlags="-DDEBUG"
fi

# Check it's GCC by command name
cCom=`echo ${CC} | awk '{ print $1 }'`
if test "x${GCC}" = "xyes" -o "`basename ${cCom}`" = "gcc" ; then
    isGcc=yes
fi
if test "x${isGcc}" = "xno"; then
    # Check it's GCC by command line option
    tmp=/tmp/.OmniConfCC
    ${cCom} -v > $tmp 2>&1
    if test $? -eq 0; then
	chk=`tail -1 $tmp | awk '{ print $3 }'`
	case $chk in
	    egcs*|2.*|3.*)
		isGcc=yes;;
	    *)
		case ${OS} in
		    darwin*)
			chk=`tail -1 $tmp | grep gcc`
			if test "x${chk}" = "x"; then
			    isGcc=no
			else
			    isGcc=yes
			fi;;
		    *)
			isGcc=no;;
		esac;;
	esac
    fi
    rm -f $tmp
fi

# OK now it must be decided gcc or not.
if test "x${isGcc}" = "xno"; then
    case $OS in
        linux*)
	    tmp=/tmp/.OmniConf.$$
	    ${CC} -V > $tmp 2>&1
	    x=`grep 'Intel(R) C++ Compiler ' $tmp`
	    if test "X${x}" != "X"; then
		isIntelCC=yes
	    fi
	    rm -f $tmp
	    ${CC} -V > $tmp 2>&1
	    x=`grep 'The Portland Group, Inc.' $tmp`
	    if test "X${x}" != "X"; then
		isPGICC=yes
	    fi
	    rm -f $tmp
	    ;;
	solaris*)
	    tmp=/tmp/.OmniConf.$$
	    ${CC} -V > $tmp 2>&1
	    if test $CPU = i386; then
		cStr='cc: PC'
	    else
		cStr='WorkShop'
	    fi
	    x=`grep "$cStr" $tmp`
	    if test "X${x}" != "X"; then
		isSunCC=yes
		case $CPU in
		    sparc*)
			cStr='WorkShop Compilers'
			x=`grep "$cStr" $tmp`
			if test "X${x}" != "X"; then
			    sunCCPre6=1
			fi;;
		esac
	    fi
	    rm -f $tmp
	    ;;
	irix*)
	    tmp=/tmp/.OmniConf.$$
	    ${CC} -version > $tmp 2>&1
	    x=`grep 'MIPSpro' $tmp`
	    if test "X${x}" != "X"; then
		isMipsCC=yes
	    fi
	    rm -f $tmp
	    ;;
	aix*)
	    # XXXXX FIXEME: Are there any other compilers running on AIX???
	    # Anyway asume it's XLC.
	    isAIXCC=yes
	    ;;
    esac
fi

# GCC
if test "x${isGcc}" = "xyes"; then
    # for old gcc/systems ...
    mustCppFlags="-D__USE_FIXED_PROTOTYPES__"
    warnCFlags="-Wall"
    optCFlags="-O2"
    CPP="$CC -E"
    case ${CPU} in
	powerpc*)
	    warnCFlags="${warnCFlags} -Wno-long-double"
	    case ${OS} in
		darwin*)
    		    mustCppFlags="${mustCppFlags} -traditional-cpp"
		    CPP="${CPP} -traditional-cpp";;
		*)
		    true;;
	    esac;;
	*)
	    true;;
    esac
    ccType=gcc
fi

# Intel CC
if test "X${isIntelCC}" = "Xyes"; then
  optCFlags="-O3"
  warnCFlags="-w2"
  ccType=IntelCC
fi

# PGI CC
if test "X${isPGICC}" = "Xyes"; then
  optCFlags="-fast"
  mustCFlags="-Mreentrant -Masmkeyword"
  ccType=PGICC
fi

# Sun CC
if test "X${isSunCC}" = "Xyes"; then
    mustCppFlags="-D__EXTENSIONS__"
    if test $sunCCPre6 -eq 0; then
	mustCppFlags="${mustCppFlags} -DSUN_WS_CC_6"
    fi
    mustCFlags="-v"
    debCFlags="${debCFlags} -xs"
    if test $CPU = i386; then
	oLvl=4
    else
	oLvl=5
    fi
    optCFlags="-fast -xO${oLvl}"
    ccType=SunCC
fi

# Mips CC
if test "X${isMipsCC}" = "Xyes"; then
    optCFlags="-O3"
    ccType=MipsCC
fi

# AIX XLC
if test "X${isAIXCC}" = "Xyes"; then
    CC=cc_r
    mustCppFlags="-DUSE_PROTOTYPE"
    optCFlags="-O3 -qstrict"
    ccType=AIXCC
fi

# Generate cpu/os specifier
changequote(<<, >>)dnl
CPUDEF=-DOMNI_CPU_`echo $CPU | tr '[a-z]' '[A-Z]'`
OSDEF=-DOMNI_OS_`echo $OS | tr '[a-z]' '[A-Z]'`
changequote([, ])dnl

# OS specifics.
case ${OS} in
    netbsd*)
	osCppFlags="-I/usr/pkg/include";;
    *)
	true;;
esac

# Finally, emit.
AC_SUBST(CC)
AC_SUBST(ccType)

CPPFLAGS="${CPPFLAGS} ${CPUDEF} ${OSDEF} ${debCppFlags} ${userCppFlags} ${mustCppFlags} ${osCppFlags}"
AC_SUBST(CPPFLAGS)

if test "x${doDebug}" != "xyes"; then
    if test "x${userOptCFlags}" = "x"; then
	optOpt=${optCFlags}
    else
 	optOpt=${userOptCFlags}
    fi
else
    if test "x${userDebCFlags}" = "x"; then
	optOpt=${debCFlags}
    else
 	optOpt=${userDebCFlags}
    fi
fi
CFLAGS="${CFLAGS} ${warnCFlags} ${optOpt} ${mustCFlags} ${osCFlags}"
AC_SUBST(CFLAGS)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# Generic config from here.

#--------------------------------------------------------------------
#	alloca check.
#--------------------------------------------------------------------
AC_FUNC_ALLOCA

#--------------------------------------------------------------------
#       On AIX systems, libbsd.a has to be linked in to support
#       non-blocking file IO.  This library has to be linked in after
#       the MATH_LIBS or it breaks the pow() function.  The way to
#       insure proper sequencing, is to add it to the tail of MATH_LIBS.
#        This library also supplies gettimeofday.
#--------------------------------------------------------------------
libbsd=no
if test "`uname -s`" = "AIX" ; then
    AC_CHECK_LIB(bsd, gettimeofday, libbsd=yes)
    if test $libbsd = yes; then
	MATH_LIBS="$MATH_LIBS -lbsd"
    fi
fi

#--------------------------------------------------------------------
#	Supply substitutes for missing POSIX header files.  Special
#	notes:
#	    - stdlib.h doesn't define strtol, strtoul, or
#	      strtod insome versions of SunOS
#	    - some versions of string.h don't declare procedures such
#	      as strstr
#--------------------------------------------------------------------
AC_CHECK_HEADER(errno.h, , AC_DEFINE(NO_ERRNO_H))
AC_CHECK_HEADER(limits.h, , AC_DEFINE(NO_LIMITS_H))
AC_CHECK_HEADER(stdlib.h, , AC_DEFINE(NO_STDLIB_H))
AC_CHECK_HEADER(string.h, , AC_DEFINE(NO_STRING_H))
AC_CHECK_HEADER(strings.h, , AC_DEFINE(NO_STRINGS_H))
AC_CHECK_HEADER(unistd.h, , AC_DEFINE(NO_UNISTD_H))
AC_CHECK_HEADER(stdarg.h, AC_DEFINE(HAVE_STDARG_H),)

AC_CHECK_HEADER(locale.h, haveLocale=yes, haveLocale=no)
if test "X${haveLocale}" = "Xyes"; then
	AC_DEFINE(HAVE_LOCALE_H)
	AC_EGREP_HEADER(setlocale, locale.h, AC_DEFINE(HAVE_SETLOCALE),)
fi

AC_CHECK_HEADER(ieeefp.h, , AC_DEFINE(NO_IEEEFP_H))
AC_CHECK_HEADER(float.h, , AC_DEFINE(NO_FLOAT_H)) 
AC_CHECK_HEADER(netdb.h, , AC_DEFINE(NO_NETDB_H))
AC_CHECK_HEADER(sys/socket.h, , AC_DEFINE(NO_SYS_SOCKET_H))
AC_CHECK_HEADER(netinet/in.h, , AC_DEFINE(NO_NETINET_IN_H))
AC_CHECK_HEADER(arpa/inet.h, , AC_DEFINE(NO_ARPA_INET_H))
AC_CHECK_HEADER(sys/resource.h, , AC_DEFINE(NO_RESOURCE_H))

AC_EGREP_HEADER(strdup, string.h, AC_DEFINE(HAVE_STRDUP),)

#------------------------------------------------------------------------------
#       Find out all about time handling differences.
#------------------------------------------------------------------------------
AC_CHECK_HEADERS(sys/time.h)
AC_HEADER_TIME

#--------------------------------------------------------------------
#	Check for various typedefs and provide substitutes if
#	they don't exist.
#--------------------------------------------------------------------
AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UID_T

#--------------------------------------------------------------------
#	endian check
#--------------------------------------------------------------------
AC_C_BIGENDIAN

#--------------------------------------------------------------------
#	The code below deals with several issues related to gettimeofday:
#	1. Some systems don't provide a gettimeofday function at all
#	   (set NO_GETTOD if this is the case).
#	2. SGI systems don't use the BSD form of the gettimeofday function,
#	   but they have a BSDgettimeofday function that can be used instead.
#	3. See if gettimeofday is declared in the <sys/time.h> header file.
#	   if not, set the GETTOD_NOT_DECLARED flag so that tclPort.h can
#	   declare it.
#--------------------------------------------------------------------
AC_CHECK_FUNC(BSDgettimeofday, AC_DEFINE(HAVE_BSDGETTIMEOFDAY),
	AC_CHECK_FUNC(gettimeofday, , AC_DEFINE(NO_GETTOD)))
AC_MSG_CHECKING([for gettimeofday declaration])
AC_EGREP_HEADER(gettimeofday, sys/time.h, AC_MSG_RESULT(present), [
    AC_MSG_RESULT(missing)
    AC_DEFINE(GETTOD_NOT_DECLARED)
])

# Generic config end here.
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# checking gcc union size bug

gccUnionBug=unknown
rm -f ./gccBug.* ./gccBug
if test "x${isGcc}" = "xyes"; then
    AC_MSG_CHECKING([gcc has large union size bug])
    # check 512MB union.
    oSz='0x1fffffff'
    ${CC} ${CPPFLAGS} ${CFLAGS} -DLARGE_BUF=${oSz} -o ./gccBug ./utils/gccUnionBug.c > /dev/null 2>&1
    if test -x ./gccBug; then
	sz=`./gccBug`
	if test "x${sz}" = "x${oSz}"; then
	    gccUnionBug=no
	else
	    gccUnionBug=yes
	fi
    else
	gccUnionBug=yes
    fi
    AC_MSG_RESULT([$gccUnionBug])
fi
rm -f ./gccBug.* ./gccBug
AC_SUBST(gccUnionBug)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# OpenMP runtime checking

def_thread_type=""
def_lock_type=""
available_threads=""
available_locks=""
ignore_pair=""
ompcLibAsmSrcs=""

# Default thread type
AC_ARG_WITH(thread,
    [  --with-thread=TYPE      specify the default thread type to use. one of 'pthread', 'sproc' and 'solaris' (default: 'solaris' on Solaris, 'sproc' on IRIX, 'pthread' on others).],
    [thread_type=$withval], [thread_type=""])

# Default lock type
AC_ARG_WITH(lock,
    [  --with-lock=TYPE        specify the default lock mechanism to use. one of 'spin' and 'mutex' (default: 'spin' on i386, mips, alpha and sparc, 'mutex' on others).],
    [lock_type=$withval], [lock_type=""])

case $OS in
    solaris*)
	def_thread_type=solaris
	def_lock_type=spin
	available_locks="mutex spin"
	available_threads="solaris pthread"
	case $CPU in
	    sparc*)
		ompcLibAsmSrcs="asm_sparc.s";;
	esac
	;;
    irix*)
	def_thread_type=sproc
	def_lock_type=spin
	available_locks="mutex spin"
	available_threads="pthread sproc"
	ignore_pair="sproc mutex"
	;;
    *)
	def_thread_type=pthread
	def_lock_type=mutex
	available_locks="mutex"
	available_threads="pthread"
	case $CPU in
	    i386*|mips*)
		def_lock_type=spin
		available_locks="mutex spin";;
	    sparc*)
		def_lock_type=spin
		available_locks="mutex spin"
		ompcLibAsmSrcs="asm_sparc.s";;
	    alpha*)
		def_lock_type=spin
		available_locks="mutex spin"
		ompcLibAsmSrcs="asm_alpha.s";;
	    rs6000*)
		available_locks="mutex spin";;
	    *)
		true;;
	esac
	;;
esac

if test "X${thread_type}" = "X"; then
    thread_type=${def_thread_type}
fi

if test "X${lock_type}" = "X"; then
    lock_type=${def_lock_type}
fi

case $lock_type in
    spin*)
	case $CPU in
	    i386*|mips*|sparc*|alpha*|rs6000*)
		true;;
	    *)
		AC_MSG_RESULT([spin lock is only available on i386, mips, alpha, sparc and rs6000 architectures.])
		exit 1;;
	esac;;
    *)
	true;;
esac

THREAD_DEF=""
case $thread_type in
    solaris*)
	THREAD_DEF="-DUSE_SOL_THREAD"
	;;
    sproc*)
	THREAD_DEF="-DUSE_SPROC"
	;;
    *)
	THREAD_DEF="-DUSE_PTHREAD"
	;;
esac

LOCK_DEF=""
case $lock_type in
    mutex*)
	LOCK_DEF=""
	;;
    spin*)
	LOCK_DEF="-DUSE_SPIN_LOCK"
	;;
esac

OMPC_LIB_ASM=${ompcLibAsmSrcs}
AC_SUBST(OMPC_LIB_ASM)
AC_SUBST(THREAD_DEF)
AC_SUBST(LOCK_DEF)

AC_SUBST(available_threads)
AC_SUBST(available_locks)
AC_SUBST(thread_type)
AC_SUBST(lock_type)
AC_SUBST(ignore_pair)


# StackThreads
AC_ARG_ENABLE(stackThreads,
    [  --enable-stackThreads   enable StackThreads (false default).],
    [doStackThread=$enableval], [doStackThread=no])
LIBOMPST_DIR=""
if test "x${doStackThread}" = "xyes"; then
    LIBOMPST_DIR=lib/libompst
fi
AC_SUBST(LIBOMPST_DIR)
AC_SUBST(doStackThread)

# shmem
AC_ARG_ENABLE(shmem,
    [  --enable-shmem          enable unix shared memory runtime (false default).],
    [doUnixShmem=$enableval], [doUnixShmem=no])
AC_SUBST(doUnixShmem)

# scash
AC_ARG_ENABLE(scash,
    [  --enable-scash          enable scash runtime (false default).],
    [doScash=$enableval], [doScash=no])
AC_SUBST(doScash)

if test "x${doUnixShmem}" = "xyes" -a "x${doScash}" = "xyes"; then
    AC_MSG_RESULT(unix shared mamory and scash are exclusive.)
    exit 1
fi

LIBOMPSM_DIR=""
if test "x${doUnixShmem}" = "xyes" -o "x${doScash}" = "xyes"; then
    LIBOMPSM_DIR=lib/libompsm
fi
AC_SUBST(LIBOMPSM_DIR)

AC_ARG_WITH(scoreDir,
    [  --with-scoreDir=DIR     specify where SCore is installed.],
    [scoreDir=$withval], [scoreDir=""])

scoreNickname=""
if test "x${doScash}" = "xyes"; then
    if test "x${scoreDir}" = "x"; then
	if test -z ${RWCROOT}; then
	    scoreDir=/opt/score
	else
	    scoreDir=${RWCROOT}
	fi
    fi

    if test ! -d ${scoreDir}; then
	AC_MSG_RESULT(can't find ${scoreDir})
	exit 1
    fi
	    
    if test -x ${scoreDir}/deploy/config.nickname; then
	scoreNickname=`${scoreDir}/deploy/config.nickname`
    else
	AC_MSG_RESULT(can't find ${scoreDir}/deploy/config.nickname)
	exit 1
    fi
fi
AC_SUBST(scoreNickname)
AC_SUBST(scoreDir)

SHMEM_FLAGS=""
SHMEM_SRC="Unused"
SCASH_INC=""
if test "x${doUnixShmem}" = "xyes"; then
    SHMEM_FLAGS="-DUSE_UNIX_SHMEM"
    SHMEM_SRC=ompsm_unix_shmem
fi
if test "x${doScash}" = "xyes"; then
    SHMEM_FLAGS="-DUSE_SCASH"
    SCASH_INC="-I${scoreDir}/include"
    SHMEM_SRC=ompsm_scash
fi
AC_SUBST(SHMEM_FLAGS)
AC_SUBST(SCASH_INC)
AC_SUBST(SHMEM_SRC)

# OpenGR
AC_ARG_ENABLE(openGR,
    [  --enable-openGR         enable OpenGR directive support (false default).],
    [doOpenGR=$enableval], [doOpenGR=no])
LIBOGR_DIR=""
OPENGR_DEF=""
OPENGR_HDR=""
OPENGR_SRCS=""
OPENGR_OBJS=""
OGRCC_DRIVER=""
GRIDRPC_DEF=""
GRIDRPC_LIBS=""
if test "x${doOpenGR}" = "xyes"; then
    if test "x${GLOBUS_INSTALL_PATH}" = "x"; then
	AC_MSG_RESULT([GLOBUS_INSTALL_PATH environmental variable not set. exit.])
	exit 1
    fi
    if test "x${NS_DIR}" = "x"; then
	AC_MSG_RESULT([NS_DIR environmental variable not set. exit.])
	exit 1
    fi
    if test -x "${NS_DIR}/bin/globusflags"; then
	true
    else
	AC_MSG_RESULT([can't find ${NS_DIR}/bin/globusflags. exit.])
	exit 1
    fi
    gRPCOpt=`sh ${NS_DIR}/bin/globusflags GLOBUS_GRAM_CLIENT GLOBUS_IO SSL LDAP 2>/dev/null`
    if test $? -eq 0; then
	for i in / ${gRPCOpt}
	do
	    case ${i} in
		/)
		    continue;;
		-D*|-I*|-U*)
		    GRIDRPC_DEF="${GRIDRPC_DEF} ${i}";;
		-L*|-l*)
		    GRIDRPC_LIBS="${GRIDRPC_LIBS} ${i}";;
		*)
		    true;;
	    esac
	done
    else
	AC_MSG_RESULT([can't exec ${NS_DIR}/bin/globusflags. exit.])
	exit 1
    fi
    LIBOGR_DIR='lib/libogr'
    OPENGR_DEF='-DUSE_OPENGR_PRAGMA'
    OPENGR_HDR='opengr.h'
    OPENGR_SRCS="C-ogr-pragma.c C-ogr-hash.c"
    OPENGR_OBJS=`echo ${OPENGR_SRCS} | sed "s:\.c:\.o:g"`
    OGRCC_DRIVER='ogrcc ogrc++'
    GRIDRPC_DEF="-I${NS_DIR}/include -I${NS_DIR}/include/expat ${GRIDRPC_DEF}"
    GRIDRPC_LIBS="-L${NS_DIR}/lib -lnsclient -lnslib -lnsutil -lnet -lxmlread ${GRIDRPC_LIBS}"
fi
AC_SUBST(doOpenGR)
AC_SUBST(LIBOGR_DIR)
AC_SUBST(OPENGR_DEF)
AC_SUBST(OPENGR_HDR)
AC_SUBST(OPENGR_SRCS)
AC_SUBST(OPENGR_OBJS)
AC_SUBST(OGRCC_DRIVER)
AC_SUBST(GRIDRPC_DEF)
AC_SUBST(GRIDRPC_LIBS)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# Use Java or not

useJava=yes
EXC_JAVADIR=exc-tools-java/exc
TLOGVIEW_DIR=tools/tlogview
JMPSTAT_DIR=tools/jmpstat
AC_ARG_WITH(jvm,
    [  --with-jvm              use Java runtime/development tools environment (true default).],
    [useJava=$withval], [useJava=yes])
if test "x${useJava}" = "xno"; then
    cFile=./utils/etjClass.tar
    if test -f $cFile; then
	AC_MSG_RESULT([Choosing Java-free configuraion, --enable-jexcBinary flag is implied.])
    else
	AC_MSG_RESULT([Using Omni without Java needs pre-compiled exc-tools-java class files, but can't find them (${cFile}). exit.])
	exit 1
    fi
    EXC_JAVADIR=""
    TLOGVIEW_DIR=""
    JMPSTAT_DIR=""
fi
AC_SUBST(EXC_JAVADIR)
AC_SUBST(TLOGVIEW_DIR)
AC_SUBST(JMPSTAT_DIR)
AC_SUBST(useJava)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# jexc backend support.

jexcBackend=""
jexcDir=""
AC_ARG_ENABLE(jexcBinary,
    [  --enable-jexcBinary     enable using of binary executable version of xobj to C translator in omni compile driver. Experimental now (false default).],
    [doJexcBackend=$enableval], [doJexcBackend=no])
# Force jexc if useJava == no
if test "x${useJava}" = "xno"; then
    doJexcBackend=yes
fi

if test "x${doJexcBackend}" = "xyes"; then
    jexcDir=./tools/jexc
    jexcBackend="C-back F-back"
#   Enabling followings when shmem translator is supported.
#   if test "x${doUnixShmem}" = "xyes" -o "x${doScash}" = "xyes"; then
#	jexcBackend="${jexcBackend} C-back.sm F-back.sm"
#   fi
    if test "x${doOpenGR}" = "xyes"; then
	jexcBackend="${jexcBackend} C-back.ogr"
    fi
fi
AC_SUBST(doJexcBackend)
AC_SUBST(jexcDir)
AC_SUBST(jexcBackend)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# check has "long long"

hasLL=no
AC_MSG_CHECKING([has long long])
AC_TRY_COMPILE([],[long long int x;], [hasLL=yes], [hasLL=no])
AC_MSG_RESULT($hasLL)
hasLLFlags=""
if test $hasLL = yes; then
    hasLLFlags="-DHAS_LONGLONG"
    AC_DEFINE(HAS_LONGLONG)
fi

hasLD=no
AC_MSG_CHECKING([has long double])
AC_TRY_COMPILE([],[long double x;], [hasLD=yes], [hasLD=no])
AC_MSG_RESULT($hasLD)
hasLDFlags=""
if test $hasLD = yes; then
    hasLDFlags="-DHAS_LONGDOUBLE"
    AC_DEFINE(HAS_LONGDOUBLE)
fi

AC_CHECK_SIZEOF(unsigned short)
AC_CHECK_SIZEOF(unsigned int)
AC_CHECK_SIZEOF(unsigned long)
llTyp=''
if test $hasLL = yes; then
    AC_CHECK_SIZEOF(unsigned long long)
    llTyp='longlongint'
fi
AC_CHECK_SIZEOF(float)
AC_CHECK_SIZEOF(double)
ldTyp=''
if test $hasLD = yes; then
    AC_CHECK_SIZEOF(long double)
    ldTyp='longdouble'
fi
AC_CHECK_SIZEOF(void *)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# align

for i in char short int long "$llTyp" float double "$ldTyp"
do
    if test "x${i}" = x; then
	continue
    fi
    getAlign=0
    rm -rf ./align ./align.*
    case $i in
	longlongint)
	    AC_MSG_CHECKING([default align of long long int]);;
	longdouble)
	    AC_MSG_CHECKING([default align of long double]);;
	*)
	    AC_MSG_CHECKING([default align of $i]);;
    esac
    ${CC} ${CPPFLAGS} ${CFLAGS} ${hasLLFlags} ${hasLDFlags} -DCHECK_TYPE=$i ./utils/align.c -o align
    if test -x ./align; then
	getAlign=`./align | grep -v Linking`
    fi
    if test $getAlign -eq 0; then
	AC_MSG_RESULT(can't determine????)
	exit 1
    else
	AC_MSG_RESULT($getAlign)
	case $i in
	    char)
		AC_DEFINE_UNQUOTED(CHAR_ALIGN, $getAlign);;
	    short)
		AC_DEFINE_UNQUOTED(SHORT_ALIGN, $getAlign);;
	    int)
		AC_DEFINE_UNQUOTED(INT_ALIGN, $getAlign);;
	    long)
		AC_DEFINE_UNQUOTED(LONG_ALIGN, $getAlign);;
	    longlongint)
		AC_DEFINE_UNQUOTED(LONGLONG_ALIGN, $getAlign);;
	    float)
		AC_DEFINE_UNQUOTED(FLOAT_ALIGN, $getAlign);;
	    double)
		AC_DEFINE_UNQUOTED(DOUBLE_ALIGN, $getAlign);;
	    longdouble)
		AC_DEFINE_UNQUOTED(LONGDOUBLE_ALIGN, $getAlign);;
	esac
    fi
    rm -rf ./align ./align.*
done
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# i386 double-align

if test ${CPU} = "i386" -a "x${isGcc}" = "xyes"; then
    for i in char short int long "$llTyp" float double "$ldTyp"
    do
	if test "x${i}" = x; then
	    continue
	fi
	getAlign=0
	rm -rf ./align ./align.*
	case $i in
	    longlongint)
		AC_MSG_CHECKING([i386 double-align of long long int]);;
	    longdouble)
		AC_MSG_CHECKING([i386 double-align of long double]);;
	    *)
		AC_MSG_CHECKING([i386 double-align of $i]);;
	esac
	${CC} ${CPPFLAGS} ${CFLAGS} -malign-double ${hasLLFlags} ${hasLDFlags} -DCHECK_TYPE=$i ./utils/align.c -o align
	if test -x ./align; then
	    getAlign=`./align | grep -v Linking`
	fi
	if test $getAlign -eq 0; then
	    AC_MSG_RESULT(can't determine????)
	    exit 1
	else
	    AC_MSG_RESULT($getAlign)
	    case $i in
		char)
		    AC_DEFINE_UNQUOTED(I386_CHAR_ALIGN2, $getAlign);;
		short)
		    AC_DEFINE_UNQUOTED(I386_SHORT_ALIGN2, $getAlign);;
		int)
		    AC_DEFINE_UNQUOTED(I386_INT_ALIGN2, $getAlign);;
		long)
		    AC_DEFINE_UNQUOTED(I386_LONG_ALIGN2, $getAlign);;
		longlongint)
		    AC_DEFINE_UNQUOTED(I386_LONGLONG_ALIGN2, $getAlign);;
		float)
		    AC_DEFINE_UNQUOTED(I386_FLOAT_ALIGN2, $getAlign);;
		double)
		    AC_DEFINE_UNQUOTED(I386_DOUBLE_ALIGN2, $getAlign);;
		longdouble)
		    AC_DEFINE_UNQUOTED(I386_LONGDOUBLE_ALIGN2, $getAlign);;
	    esac
	fi
	rm -rf ./align ./align.*
    done
fi
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# 32/64 bit int type

rm -rf ./szchk ./szchk.*
AC_MSG_RESULT([Creating size check program])
${CC} ${CPPFLAGS} ${CFLAGS} ${hasLLFlags} ./utils/size.c -o szchk
if test ! -x ./szchk; then
    AC_MSG_RESULT([can't create size check program. exit.])
    exit 1
fi

F2C_INT64_FLAGS=""
for i in 16 32 64
do
    AC_MSG_CHECKING([$i bit integer])
    typName=`./szchk $i`
    if test "x${typName}" = "xunknown"; then
	case $i in
	    16)
		TYPE_INT16="short"
		AC_SUBST(TYPE_INT16)
		asump=${TYPE_INT16};;
	    32)
		TYPE_INT32="int"
		AC_SUBST(TYPE_INT32)
		asump=${TYPE_INT32};;
	    64)
		TYPE_INT64="long long int"
		AC_SUBST(TYPE_INT64)
		asump=${TYPE_INT64};;
	esac
	AC_MSG_RESULT([not supported. use $asump])
    else
	AC_MSG_RESULT([$typName])
	case $i in
	    16)
		AC_DEFINE(HAS_INT16)
		TYPE_INT16=${typName}
		AC_SUBST(TYPE_INT16);;
	    32)
		AC_DEFINE(HAS_INT32)
		TYPE_INT32=${typName}
		AC_SUBST(TYPE_INT32);;
	    64)
		AC_DEFINE(HAS_INT64)
		F2C_INT64_FLAGS="-DAllow_TYQUAD"
		TYPE_INT64=${typName}
		AC_SUBST(TYPE_INT64);;
	esac
    fi
done
AC_SUBST(F2C_INT64_FLAGS)
rm -rf ./szchk ./szchk.*
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# check size of integer enough to hold size of void *

AC_MSG_CHECKING([integer type enough to hold void pointer])
${CC} -I. ${CPPFLAGS} ${CFLAGS} ${hasLLFlags} ./utils/chkvoidp.c -o chkvoidp
voidPint="unknown"
if test -x ./chkvoidp; then
    voidPint=`./chkvoidp`
else
    AC_MSG_RESULT([can't create check program. exit.])
    exit 1
fi
if test "x${voidPint}" = "xunknown"; then
    AC_MSG_RESULT([can't determine????])
    exit 1
else
    AC_MSG_RESULT([$voidPint])
fi
INT_ENUFF_FOR_VOIDP=$voidPint
AC_SUBST(INT_ENUFF_FOR_VOIDP)
rm -f ./chkvoidp.* ./chkvoidp
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# check 64 bit virtual address

AC_MSG_CHECKING([64 bit virtual address])
${CC} -I. ${CPPFLAGS} ${CFLAGS} ./utils/addr64.c -o ./addr64
addrIs64="unknown"
if test -x ./addr64; then
    addrIs64=`./addr64`
else
    AC_MSG_RESULT([can't create check program. exit.])
    exit 1
fi
if test "x$addrIs64" = "xunknown"; then
    AC_MSG_RESULT([can't determine????])
    exit 1
else
    if test "x$addrIs64" = "x8"; then
	AC_MSG_RESULT([yes])
	AC_DEFINE(ADDR_IS_64)
    else
	AC_MSG_RESULT([no])
    fi
fi
rm -f ./addr64.* ./addr64
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# has printf "%qd"

rm -f ./hasqd.* ./hasqd
AC_MSG_CHECKING([has quad-precision print format])
${CC} -I. ${CPPFLAGS} ${CFLAGS} ./utils/hasqd.c -o ./hasqd > /dev/null 2>&1
hasQD=no
if test -x ./hasqd; then
    ret=`./hasqd`
    if test "x$ret" = "xqd" -o "x$ret" = "x%qd"; then
	hasQD=no
    else
	hasQD=yes
    fi
fi
AC_MSG_RESULT([${hasQD}])
if test "x${hasQD}" = "xyes"; then
    AC_DEFINE(HAS_QUAD_PRINT)
fi
rm -f ./hasqd.* ./hasqd
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# quad real support

if test "${OS}" = "linux"; then
    gmpIncDir=/usr/include
    gmpLibDir=/usr/lib
else
    gmpIncDir=/usr/local/include
    gmpLibDir=/usr/local/lib
fi

gmpIncOpt=""
gmpDirOpt=""
qRealPrecBits=128

AC_ARG_ENABLE(mreal,
    [  --enable-mreal          enable multiple precision real (and real*16) support of Fortran 77 (false default).],
    [doQReal=$enableval], [doQReal=no])

AC_ARG_WITH(gmpLibDir,
    [  --with-gmpLibDir=DIR    specify where the GNU-MP library is for quad-real support.],
    [gmpLibDir=$withval], [true])

AC_ARG_WITH(gmpIncDir,
    [  --with-gmpIncDir=DIR    specify where the GNU-MP include headers are for quad-real support.],
    [gmpIncDir=$withval], [true])

if test "x${doQReal}" = "xyes"; then
    if test -f ${gmpIncDir}/gmp.h; then
	true
    else
	AC_MSG_RESULT([can't find ${gmpIncDir}/gmp.h. exit.])
	exit 1
    fi
    gmpLibs=`ls ${gmpLibDir}/libgmp.* 2> /dev/null`
    if test "x${gmpLibs}" = "x"; then
	AC_MSG_RESULT([can't find ${gmpLibDir}/libgmp.*. exit.])
	exit 1
    fi
    gmpIncOpt="-I${gmpIncDir}"
    gmpLibOpt="-L${gmpLibDir} -lgmp"
fi

AC_ARG_WITH(precision,
    [  --with-precision=NUM    specify the default precision of real*16 in bits (128).],
    [qRealPrecBits=$withval], [qRealPrecBits=128])


# libgmp check
omniLimbT="int"
omniExpT="int"
omniQRealPrecInLimb="1"
omniQRealFillGap=""
if test "x${doQReal}" = "xyes"; then
    omniQPrec=$qRealPrecBits
    AC_DEFINE(ENABLE_QREAL)
    AC_DEFINE_UNQUOTED(OMNI_QREAL_PREC, $omniQPrec)

    qcCC () {
	rm -f $2 ${2}.*
	${CC} -I. ${CPPFLAGS} ${CFLAGS} -DENABLE_QREAL ${hasLLFlags} ${gmpIncOpt} $3 $1 -o $2 ${gmpLibOpt}
	if test -x $2; then
	    ret=`$2 $4`
	    if test "x${ret}" = "x"; then
		AC_MSG_RESULT([can't determine??. exit.])
		exit 1
	    else
		rm -f $2 ${2}.*
		echo ${ret}
	    fi
	else
	    AC_MSG_RESULT([can't create check program. exit.])
	    exit 1
	fi
    }

    # check size of mp_exp_t
    AC_MSG_CHECKING([size of GNU-MP mp_exp_t])
    eSz=`qcCC utils/csMPexp.c ./csMPexp`
    AC_MSG_RESULT([${eSz}])
    omniExpT=""
    case ${eSz} in
	2)
	    omniExpT=${TYPE_INT16};;
	4)
	    omniExpT=${TYPE_INT32};;
	8)
	    omniExpT=${TYPE_INT64};;
	*)
	    AC_MSG_RESULT([can't determine basic type of mp_exp_t ??. exit.])
	    exit 1;;
    esac
    AC_DEFINE_UNQUOTED(OMNI_SIZEOF_QEXP_T, $eSz)

    # check size of mp_limb_t
    AC_MSG_CHECKING([size of GNU-MP mp_limb_t])
    lSz=`qcCC utils/csMPlimb.c ./csMPlimb`
    AC_MSG_RESULT([${lSz}])
    omniLimbT=""
    case ${lSz} in
	2)
	    omniLimbT=${TYPE_INT16};;
	4)
	    omniLimbT=${TYPE_INT32};;
	8)
	    omniLimbT=${TYPE_INT64};;
	*)
	    AC_MSG_RESULT([can't determine basic type of mp_limb_t ??. exit.])
	    exit 1;;
    esac
    AC_DEFINE_UNQUOTED(OMNI_SIZEOF_QLIM_T, $lSz)

    # check how many mp_limb_t the GNU-MP needed for N bit precision.
    AC_MSG_CHECKING([how many mp_limb_t needed for $omniQPrec bit precision])
    omniQRealPrecInLimb=`qcCC utils/cMPlb.c ./cMPlb '' $omniQPrec`
    AC_MSG_RESULT([$omniQRealPrecInLimb])
    AC_DEFINE_UNQUOTED(OMNI_QLIM_LEN, $omniQRealPrecInLimb)

    # check _omQReal_t needs a gap between _mp_exp and _mp_d[omniQRealPrecInLimb].
    AC_MSG_CHECKING([_omQReal_t needs a gap between _mp_exp and _mp_d])
    gapInByte=`expr $lSz - $eSz`
    subStr=""
    if test ${gapInByte} -gt 0; then
	case ${gapInByte} in
	    2)
		# lim == int, exp == short
		subStr="${TYPE_INT16} _gap_;";;
	    4)
		# lim == long long, exp == int
		subStr="${TYPE_INT32} _gap_;";;
	    *)
		# lim == long long, exp == short
		changequote(<<, >>)dnl
		subStr="char _gap_[${gapInByte}];"
		changequote([, ])dnl
		;;
	esac
    fi
    if test "x${subStr}" != "x"; then
	AC_MSG_RESULT([yes, put a \"${subStr}\" member in _omQReal_t.])
	omniQRealFillGap=${subStr}
	AC_DEFINE(OMNI_QREAL_NEED_GAP_MEMBER)
	AC_DEFINE_UNQUOTED(OMNI_QREAL_GAP_SIZE, ${gapInByte})
    else
	omniQRealFillGap="/* if ((sizeof(mp_exp_t) < sizeof(mp_limb_t)), here must be a gap filling member. */"
	AC_MSG_RESULT([no])
    fi

    # check libgmp has an mpf_floor(), appeared in gmp3 later.
    oLIBS=${LIBS}
    LIBS="${LIBS} ${gmpLibOpt}"
    oCFLAGS=${CFLAGS}
    CFLAGS="${CFLAGS} ${CPPFLAGS} -DENABLE_QREAL ${gmpIncOpt}"
    AC_MSG_CHECKING([mpf_floor() in $LIBS])
    hasFloor=no
    AC_TRY_LINK(
	[
	    #include "gmp.h"
	],
	[
	    mpf_t a;
	    mpf_t b;
	    (void)mpf_floor(a, b);
	],
	[AC_MSG_RESULT(yes); hasFloor=yes],
	[AC_MSG_RESULT(no)]
    )
    LIBS=${oLIBS}
    CFLAGS=${oCFLAGS}
    if test "x${hasFloor}" = "xno"; then
	AC_MSG_RESULT([You have to use gmp3 or later. exit.])
	exit 1
    fi
fi

AC_SUBST(doQReal)
AC_SUBST(gmpIncOpt)
AC_SUBST(gmpLibOpt)
AC_SUBST(omniQPrec)
AC_SUBST(omniExpT)
AC_SUBST(omniLimbT)
AC_SUBST(omniQRealPrecInLimb)
AC_SUBST(omniQRealFillGap)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# check sample code installation

EXAMPLES_DIR=""
# install source
AC_ARG_ENABLE(installSample,
    [  --enable-installSample  install OpenMP source examples (false default).],
    [doExamples=$enableval], [doExamples=no])
if test "x${doExamples}" = "xyes"; then
    EXAMPLES_DIR="tests"
fi
AC_SUBST(EXAMPLES_DIR)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# Document dir

AC_ARG_ENABLE(scoreDoc,
    [  --enable-scoreDoc       set document install directory suitable for SCore release.],
    [scoreDoc=$enableval], [scoreDoc=no])
if test "x$scoreDoc" = "xyes"; then
    DOC_DIR=doc
else
    DOC_DIR=lib/openmp/doc
fi
AC_SUBST(DOC_DIR)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# wrapper support.

AC_ARG_ENABLE(wrapper,
    [  --enable-wrapper         enable using of wrapper for select omni by backend compiler(false default).],
    [doWrapper=$enableval], [doWrapper=no])
if test "x${doWrapper}" != "xno"; then
  wrapperOrgPrefix="${orgPrefix}"
  wrapperPrefix="${prefix}"
  if test "${exec_prefix}" = '${prefix}' ; then
    wrapperExecPrefix='${wrapper_prefix}'
  else
    t=`echo ${orgExec_prefix} | egrep '^/.*$'`
    if test "x${t}" = "x${orgExec_prefix}"; then
	wrapperExecPrefix="\$(DESTDIR)${orgExec_prefix}"
    else
	wrapperExecPrefix="\$(DESTDIR)/${orgExec_prefix}"
    fi
  fi
  t=`echo ${orgPrefix} | egrep '^/.*$'`
  if test "x${t}" = "x${orgPrefix}"; then
    orgPrefix="${orgPrefix}/lib/openmp/${ccType}"
    prefix="\$(DESTDIR)${orgPrefix}"
  else
    orgPrefix="${orgPrefix}/lib/openmp/${ccType}"
    prefix="\$(DESTDIR)/${orgPrefix}"
  fi
  unset t  
  exec_prefix='${prefix}'
  orgExec_prefix=""
else
  wrapperOrgPrefix=""
  wrapperPrefix=""
  wrapperExecPrefix=""
fi
AC_SUBST(wrapperOrgPrefix)
AC_SUBST(wrapperPrefix)
AC_SUBST(wrapperExecPrefix)
AC_SUBST(doWrapper)

AC_ARG_ENABLE(wrapperDefault,
    [  --enable-wrapper-default enable using this compiler for default backend compiler, when enabled wrapper(false default).],
    [doWrapperDefault=$enableval], [doWrapperDefault=no])
if test "x${doWrapper}" = "xno"; then
    doWrapperDefault=no
fi
wrapperInstallDefault=no
if test "x${doWrapperDefault}" != "xno"; then
    wrapperInstallDefault=yes
fi
AC_SUBST(wrapperInstallDefault)
AC_SUBST(doWrapperDefault)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# Various command check

# Check ranlib
AC_PROG_RANLIB
if test "x${isGcc}" = "xno"; then
    case $OS in
	solaris*|irix*)
	    RANLIB=':';;
    esac
fi

if test "${OS}" = "cygwin32"; then
    INSTALLCOM='install -c'
    MKDIRCOM='mkdir -p'
else
    INSTALLCOM='$(TOPDIR)/utils/install-sh -c'
    MKDIRCOM='$(TOPDIR)/utils/mkdirhier'
fi

AR="ar cr"

STGCC=stgcc
if test "x${doStackThread}" = "xyes"; then
    AC_PATH_PROG(STGCC, stgcc, stgcc, ${PATH}:/bin:/usr/bin:/usr/local/bin:/opt/bin:/opt/local/bin)
fi

YACCCOM=""
AC_PATH_PROG(YACCCOM, bison, yacc, ${PATH}:/usr/local/bin:/opt/bin:/opt/local/bin:/opt/gnu/bin:/usr/bin:/bin)
if test "`basename $YACCCOM`" = "bison"; then
    YACCCOM="$YACCCOM -y"
fi

JAVACCOM=""
AC_PATH_PROG(JAVACCOM, javac, javac, ${PATH}:/bin:/usr/bin:/usr/local/bin:/opt/bin:/opt/local/bin)

JAVACOM=""
AC_PATH_PROG(JAVACOM, java, java, ${PATH}:/bin:/usr/bin:/usr/local/bin:/opt/bin:/opt/local/bin)

JARCOM=""
AC_PATH_PROG(JARCOM, jar, jar, ${PATH}:/bin:/usr/bin:/usr/local/bin:/opt/bin:/opt/local/bin)

ZIPCOM=""
AC_PATH_PROG(ZIPCOM, zip, zip, ${PATH}:/bin:/usr/bin:/usr/local/bin:/opt/bin:/opt/local/bin)

GENJAR='$(TOPDIR)/utils/genjar'

AC_SUBST(AR)

AC_SUBST(INSTALLCOM)
AC_SUBST(MKDIRCOM)
AC_SUBST(STGCC)
AC_SUBST(YACCCOM)

AC_SUBST(ZIPCOM)
AC_SUBST(JAVACCOM)
AC_SUBST(JAVACOM)
AC_SUBST(JARCOM)
AC_SUBST(GENJAR)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# For benchtool

# check Perl versoin is 5
PERL5=""
AC_PATH_PROGS(PERL5, perl5 perl)

inDev=0
if test "$PERL5" = ""; then
    inDev=0
else
    inDev=0
    isPerlVersion5=no
    AC_MSG_CHECKING([Perl version is 5])
    pTmp=/tmp/.btoolPerlChk.$$
    ${PERL5} -v > ${pTmp} 2>&1
    chk=`grep 'This is perl, version 5' ${pTmp}`
    if test "x${chk}" = "x"; then
	AC_MSG_RESULT([no])
	isPerlVersion5=no
    else
	AC_MSG_RESULT([yes])
	isPerlVersion5=yes
    fi
    rm -f ${pTmp}
    unset chk pTmp

fi
AC_SUBST(PERL5)

# check bash
BASH2=""
AC_PATH_PROGS(BASH2, bash2 bash, ${PATH}:/bin:/usr/bin:/usr/local/bin:/opt/bin:/opt/local/bin)
AC_SUBST(BASH2)

# check for mm5, parkbench
HOSTARCH=`./utils/config.guess | grep -v Linking`
PPTGT=""
MM5TGT=""

case $HOSTARCH in
    i*86-pc-linux*)
        PPTGT=linux
        MM5TGT=Linux;;
    alpha*-unknown-linux*)
        PPTGT=linux
        MM5TGT=ALPHA_OMNI_OMP;;
    i386-pc-solaris*)
        PPTGT=sol2
        MM5TGT=SUN_OMNI_OMP;;
    sparc-sun-solaris*)
        PPTGT=sol2
        MM5TGT=SUN_OMNI_OMP;;
    mips-sgi-irix*)
        PPTGT=orig2k
        MM5TGT=MIPS_OMNI_OMP;;
esac

AC_SUBST(MM5TGT)
AC_SUBST(PPTGT)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# check Java VM is kaffe
isKaffe=no
if test "x${useJava}" = "xyes"; then
    AC_MSG_CHECKING([Kaffe])
    jTmp=/tmp/.omniJavaChk.$$
    ${JAVACCOM} > ${jTmp} 2>&1
    chk=`grep 'kjc: no source file given' ${jTmp}`
    if test "x${chk}" = "x"; then
	chk=`grep 'usage: at.dms.kjc.Main' ${jTmp}`
	if test "x${chk}" = "x"; then
	    AC_MSG_RESULT([no])
	else
	    AC_MSG_RESULT([yes])
	    isKaffe=yes
	fi
    else
        AC_MSG_RESULT([yes])
        isKaffe=yes
    fi
    rm -f ${jTmp}
    unset chk jTmp
fi
AC_SUBST(isKaffe)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# check Java VM is IBM Java2
isIBMJava2=no
if test "x${useJava}" = "xyes"; then
    AC_MSG_CHECKING([IBM Java2])
    jTmp=/tmp/.omniJavaChk.$$
    ${JAVACOM} -fullversion > ${jTmp} 2>&1
    chk=`grep 'J2RE 1.3.0 IBM' ${jTmp}`
    if test "x${chk}" = "x"; then
	AC_MSG_RESULT([no])
    else
	AC_MSG_RESULT([yes])
	isIBMJava2=yes
    fi
    rm -f ${jTmp}
    unset chk jTmp
fi
AC_SUBST(isIBMJava2)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# Misc.
javaType=unknown
if test "x${useJava}" = "xyes"; then
    if test "x${isKaffe}" = "xyes"; then
	javaType=kaffe
    elif test "x${isIBMJava2}" = "xyes"; then
	javaType=ibm
    fi
fi
AC_SUBST(javaType)
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# Finally, sed.

defsTmp=.defsTmp.$$
echo '@DEFS@' > ${defsTmp}.in
echo ${CPUDEF} >> ${defsTmp}.in
echo ${OSDEF} >> ${defsTmp}.in

if test ${inDev} -eq 1; then
    if test "x${isPerlVersion5}" = "xyes"; then 
	    BENCHTOOL_DIR=tools/benchtool
	    BENCH_MK=${BENCHTOOL_DIR}/Makefile
    else
	    BENCHTOOL_DIR=''
	    BENCH_MK=''
    fi
    FTEST_MK=tests/F-test/Makefile
    FTESTOMP_MK=tests/F-test/OMP-test/Makefile
else
    BENCHTOOL_DIR=''
    BENCH_MK=''
    FTEST_MK=''
    FTESTOMP_MK=''
fi
AC_SUBST(BENCHTOOL_DIR)

AC_OUTPUT(
$defsTmp
Makefile
include/Makefile
include/exc_platform.h
include/omp.h
include/omniQReal.h
C-front/Makefile
Cxx-front/Makefile
F-front/Makefile
exc-tools-java/exc/object/Xcodegen/Makefile
exc-tools-java/exc/Makefile
lib/libompc/Makefile
lib/libompst/Makefile
lib/libompsm/Makefile
lib/libogr/Makefile
lib/libf2c/f2c.h
lib/libf2c/Makefile
lib/libtlog/Makefile
lib/runtime/Makefile
tools/jexc/Makefile
tools/tlogview/Makefile
tools/jmpstat/Makefile
tools/driver/Makefile
tools/driver/omniDriver
tools/wrapper/Makefile
tools/wrapper/wrapper
tests/Makefile
tests/cg/Makefile
tests/laplace/Makefile
tests/laplace-f77/Makefile
tests/tiny/Makefile
tests/C-test/Makefile
utils/genjar
doc/Makefile
$BENCH_MK
$FTEST_MK
$FTESTOMP_MK
)

chmod 755 utils/genjar
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# Epilogue

checkNull () {
    if test -z "$1"; then
	return 0
    else
	return 1
    fi
}

genConfHdr () {
    dstHdr=./include/omniConfig.h
    dstHdr2=./include/omniBackend.h
    tmpHdr=/tmp/.tmpHdr.$$
    > $tmpHdr
    for i in $*
    do
	case $i in
	    -I*)
		true;;
	    -D*)
		def=`echo $i | sed 's/-D//'`
		hasEq=`echo ${def} | grep '=' 2>/dev/null`
		checkNull "${hasEq}"
		if test $? -eq 0; then
		    case ${def} in
			OMNI_OS_*|OMNI_CPU_*)
			    echo "#ifndef ${def}" >> $tmpHdr
			    echo "#define ${def} 1" >> $tmpHdr
			    echo "#endif /* !${def} */" >> $tmpHdr;;
			*)
			    echo "#define ${def} 1" >> $tmpHdr;;
		    esac
		else
		    mcr=`echo ${def} | awk -F'=' '{ print $1 }'`
		    val=`echo ${def} | awk -F'=' '{ print $NF }'`
		    if test $val -eq 0; then
			echo "#undef ${mcr}" >> $tmpHdr
		    else
			echo "#define ${mcr} ${val}" >> $tmpHdr
		    fi
		fi;;
	    -U*)
		def=`echo $i | sed 's/-U//'`
		echo "#undef ${def}" >> $tmpHdr;;
	esac
    done

    AC_MSG_RESULT([creating ${dstHdr}])
    cat $tmpHdr ./include/exc_platform.h > $dstHdr
    AC_MSG_RESULT([creating ${dstHdr2}])
    cat $tmpHdr ./include/omniBackend.h.in > $dstHdr2
    rm -f $tmpHdr
}

		    
genLibTargetTmpl () {
    dir=$1
    tmpl=${dir}/target.tmpl
    AC_MSG_RESULT(creating ${tmpl})
    > ${tmpl}
    ./utils/genLibTarget --locks="${available_locks}" --threads="${available_threads}" \
	--def_lock=${lock_type} --def_thread=${thread_type} --ignore_combo="${ignore_pair}" \
	--os=${OS} --cpu=${CPU} \
	`(cd ${dir}; make checkObj)` > ${tmpl}
}

genLibTargetTmplf77 () {
    dir=$1
    tmpl=${dir}/target.tmpl
    oOpt=""
    if test "x${doStackThread}" = "xyes"; then
	oOpt="${oOpt} --use-StackThread"
    fi
    if test "x${doScash}" = "xyes"; then
	oOpt="${oOpt} --use-scash --score_dir=${scoreDir}"
    fi
    if test "x${doUnixShmem}" = "xyes"; then
	oOpt="${oOpt} --use-shmem"
    fi
    AC_MSG_RESULT(creating ${tmpl})
    > ${tmpl}
    ./utils/genLibTargetf77 --locks="${available_locks}" --threads="${available_threads}" \
	--def_lock=${lock_type} --def_thread=${thread_type}  --ignore_combo="${ignore_pair}" \
	--os=${OS} --cpu=${CPU} ${oOpt} \
	`(cd ${dir}; make checkObj)` > ${tmpl}
}

genSysConf () {
    tmpl=./tools/driver/system.conf
    AC_MSG_RESULT(creating ${tmpl})
    rm -f ${tmpl}
    ./utils/genSystemTmpl --os=${OS} --cpu=${CPU} --gccBug=${gccUnionBug} --useJava=${useJava} --javaType=${javaType} > ${tmpl}
}

genLibTargetTmpl lib/libompc
genLibTargetTmplf77 lib/libf2c
genSysConf
genConfHdr `cat ${defsTmp}`
rm -f ${defsTmp} ${defsTmp}.in

if test "x${useJava}" = "xno"; then
    AC_MSG_RESULT([untar'ing exc-tools-java class file])
    cTarF=etjClass.tar
    (cd exc-tools-java; tar xf ../utils/$cTarF)
fi
