dnl ------------------------------------------------------------
dnl 
dnl $Id: configure.in,v 1.6.4.4 2000/07/02 14:53:10 yamauchi Exp $
dnl configure.in for Mpi2Java (C) 1999-2000 YAMAUCHI Hitoshi 
dnl @author YAMAUCHI Hitoshi
dnl
dnl  checking what javac is available : fast_javac or javac
dnl  checking java verison
dnl  setting some pathes
dnl
dnl ------------------------------------------------------------

AC_INIT(host/Mpi2MPI.java)

dnl ------------------------------------------------------------
dnl checking compiler 
dnl ------------------------------------------------------------

dnl ------------------------------
dnl If there is environment variable JAVAC, use it.
dnl ------------------------------
if test "X"${JAVAC} != "X" ; then
    AC_MSG_RESULT("found environment variable \$JAVAC")
    JAVAC=${JAVAC}
else
    AC_CHECK_PROG(JDKJAVAC, javac, javac, none)	
    if test ${JDKJAVAC} != "none" ; then 
	   JAVAC=${JDKJAVAC}
    fi
fi
if test "X"${JAVAC} = "X" ; then
   echo "I can not find Java compiler, please check $PATH. "
   echo "Or, you can set environment variable JAVAC as java compiler. "
   exit 1;
fi   

AC_SUBST(JAVAC)
AC_MSG_RESULT("java compiler is $JAVAC")

dnl ------------------------------------------------------------
dnl checking java version 
dnl ------------------------------------------------------------
AC_CHECK_PROG(JAVA, java, java, none)	
if test ${JAVA} = "none" ; then
    echo "I can not find java command"
    exit 1;
fi   

echo "checking java version... " 
JAVA_GETVERSIONTest=GETVERSIONTest.java 
CLASS_GETVERSIONTest=GETVERSIONTest.class
GETVERSIONTest=GETVERSIONTest
changequote(, )dnl 
cat << EOFEOF > ${JAVA_GETVERSIONTest}
public class GETVERSIONTest { 
    public static void main(String [] args)
    {
	String s = System.getProperty("java.version");
	System.out.println("Java version is " + s);
	if((s.charAt(0) == '1') && (s.charAt(1) == '.'))
	{
	    try {
	        char [] c = new char[1];
		c[0] = s.charAt(2);
		int minor = Integer.parseInt(new String(c));
		if(minor >= 2)
		{
	            System.exit(1);	// success
		}else
		{
		    System.exit(0);	// fail
		}
	    } catch (NumberFormatException e)
	    {
	        System.exit(-1);	// fail	with exception
	    }
        }
    }
}
EOFEOF
changequote([, ])dnl 
echo "compiling getversion..."
${JAVAC} ${JAVA_GETVERSIONTest}
echo "running getversion..."
${JAVA}  ${GETVERSIONTest}
if test $? -ge 1 ; then
    version_ok="yes"
else 
    version_ok="no"
fi
rm -f ${JAVA_GETVERSIONTest} ${CLASS_GETVERSIONTest}


if test ${version_ok} = "no" ; then
   AC_MSG_RESULT(NO ... java version is ${version_num} < 1.2.)
   echo "This java compiler seems not after version 1.2."
   echo "Please use version 1.2 or later. But I create Makefile."
else
   AC_MSG_RESULT(OK ... java version is ${version_num} >= 1.2.)
fi

dnl ------------------------------------------------------------
dnl Where is the MPIJAVALIB.
dnl 	If variable $MPIJAVALIB is, use it.
dnl     Or, find prunjava of mpiJava and search according it. 
dnl ------------------------------------------------------------
AC_MSG_CHECKING([mpiJava library path])
if test "X"${MPIJAVALIB} != "X" ; then
   AC_MSG_RESULT([find environment variable as ${MPIJAVALIB}])
elif test -d ../../../../../../../mpiJava-1.2/lib/ ; then
   MPIJAVALIB=`pwd`/../../../../../../../mpiJava-1.2/lib
else
   AC_MSG_RESULT([no env MPIJAVALIB and search others])
   AC_PATH_PROGS(PRUNJAVAPATH, prunjava, none)
   if test ${PRUNJAVAPATH} = "none" ; then
      AC_MSG_ERROR([not found prunjava script ... please set environment variable ${MPIJAVALIB} as mpiJava/lib.])
   else
      MPIJAVAROOT=`echo ${PRUNJAVAPATH} | sed 's%/src/scripts/prunjava%%'`
      AC_MSG_RESULT([mpiJava root seems ${MPIJAVAROOT}])
   fi
   MPIJAVALIB=${MPIJAVAROOT}/lib
fi

AC_MSG_CHECKING([MPIJAVALIB])
if test -d ${MPIJAVALIB} ; then 
   AC_SUBST(MPIJAVALIB)
   AC_MSG_RESULT([found ${MPIJAVALIB}])
else
   AC_MSG_ERROR([not found ... re-check mpiJava/lib path and set to environment variable MPIJAVALIB.])
fi

dnl ------------------------------------------------------------
dnl hostname
dnl ------------------------------------------------------------
HOSTNAME=`hostname`
AC_SUBST(HOSTNAME)

dnl ------------------------------------------------------------
dnl enable Profile Trace
dnl ------------------------------------------------------------
AC_MSG_CHECKING(--enable-profile option      )
AC_ARG_ENABLE(profile,
        [  --enable-profile     Build a profiling version.],
        [mpi2_profile_mon="yes"], [mpi2_profile_mon="no"])
if test "$mpi2_profile_mon" = yes; then
	USE_PROFILE_MONITOR="true"
else
	USE_PROFILE_MONITOR="false"
fi
AC_SUBST(USE_PROFILE_MONITOR)
AC_MSG_RESULT($mpi2_profile_mon)

AC_MSG_CHECKING(--enable-IBMpmarray option   )
AC_ARG_ENABLE(IBMpmarray,
        [  --enable-IBMpmarray  Build a using IBM pmarray version.],
        [IBM_pmarray="yes"], [IBM_pmarray="no"])
if test "$IBM_pmarray" = yes; then
    USE_IBM_PROGRAM_MARKERARRAY="true"
else
    USE_IBM_PROGRAM_MARKERARRAY="false"
fi
AC_SUBST(USE_IBM_PROGRAM_MARKERARRAY)
AC_MSG_RESULT($IBM_pmarray)

AC_MSG_CHECKING(--enable-MPI2pmarray option  )
AC_ARG_ENABLE(MPI2pmarray,
        [  --enable-MPI2pmarray Build a using MPI2 pmarray version.],
        [MPI2_pmarray="yes"], [MPI2_pmarray="no"])
if test "$MPI2_pmarray" = yes; then
    USE_MPI2_PROGRAM_MARKERARRAY="true"
else
    USE_MPI2_PROGRAM_MARKERARRAY="false"
fi
AC_SUBST(USE_MPI2_PROGRAM_MARKERARRAY)
AC_MSG_RESULT($MPI2_pmarray)

dnl ------------------------------------------------------------
dnl enable assertion
dnl ------------------------------------------------------------
AC_MSG_CHECKING(--enable-assertion option    )
AC_ARG_ENABLE(assertion,
        [  --enable-assertion   Build an assertionable version.],
        [assertion="yes"], [assertion="no"])
if test "$enable_assertion" = "yes" ; then
    NOWDEBUGGING="true"
else
    enable_assertion="no"
    NOWDEBUGGING="false"
fi
AC_SUBST(NOWDEBUGGING)
AC_MSG_RESULT($enable_assertion)


dnl ------------------------------------------------------------
dnl linking Makefile.common 
dnl ------------------------------------------------------------
AC_LINK_FILES(Makefile.common, common/Makefile)
AC_LINK_FILES(Makefile.common, dda/Makefile)
AC_LINK_FILES(Makefile.common, host/Makefile)
AC_LINK_FILES(Makefile.common, net/Makefile)
AC_LINK_FILES(Makefile.common, obj/Makefile)		   
AC_LINK_FILES(Makefile.common, radiosity/Makefile)			   
AC_LINK_FILES(Makefile.common, raytrace/Makefile)
AC_LINK_FILES(Makefile.common, shading/Makefile)   
AC_LINK_FILES(Makefile.common, sysparam/Makefile)
AC_LINK_FILES(Makefile.common, util/Makefile)
AC_LINK_FILES(Makefile.common, jdk12src/Makefile)

dnl ------------------------------------------------------------
dnl output as Makefile
dnl ------------------------------------------------------------
AC_OUTPUT(Makefile.build sampledat/parallel/tes.sh sysparam/Config.java sampledat/1PE/4tri/tes.sh)
