dnl ####################################################################
dnl #   Copyright (c) 1998                                             #
dnl #                                                                  #
dnl #   You may copy, distribute, and modify it freely as long as you  #
dnl #   preserve this copyright and permission notice.                 #
dnl #                                                                  #
dnl #                                                                  #           
dnl ####################################################################
dnl 
dnl 
dnl #########################################################
dnl #/*                                                     #
dnl # * File         : configure.in                         #
dnl # * Author       : Guansong Zhang                       #
dnl # * Created      : Fri Jun 19 11:44:00 1998             #
dnl # * Revision     : $Revision: 1.6 $                     #
dnl # * Updated      : $Date: 1999/03/01 21:32:32 $         #
dnl # */                                                    #
dnl #########################################################

AC_INIT(./configure)

AC_PREFIX_DEFAULT(`pwd`)
AC_CONFIG_AUX_DIR(./config)

dnl cwd

CWD=`pwd`
AC_SUBST(CWD)


dnl an inline which function

which () {
  oldIFS=$IFS

  IFS=:
  for dir in $PATH
  do
    if test -x $dir/$1; then
       found="$dir/$1"; 
       echo $found; 
       break ;
    fi
  done;

  if test -z "$found" ; then
    echo $1; # echo input if not found.
  fi 

  IFS=$oldIFS 
}

######
dnl function to find JAVA package
#####
javadir () {
    JAVAPATH=`which javac | sed 's%/bin/javac%%'`
    if test -f $JAVAPATH/bin/java ; then
    return
    else
    echo "Please input the absolute path for java package:"
    read JAVAPATH
    while :
    do
    if test -f $JAVAPATH/bin/javac ; then
        break
    else
        echo "Wrong java installed path!  No javac in $JAVAPATH/bin ."
        echo "Please input the absolute path for java package:"
        read JAVAPATH
    fi
    done
    return
    fi

## Searching and setting java class path

    if test "$CLASSPATH" = ""
    then
    CLASSPATH=
    else
    CLASSPATH=$CLASSPATH
    fi
    AC_SUBST(CLASSPATH)

}

javadir;JAVA="$JAVAPATH"
echo checking jdk is at $JAVA


#### End Searching JAVA package #####

dnl if JDK is available

#if test "$JAVA" != "" -a "$MPI" = "mpich"
if test "$JAVA" != ""
 then
  AC_SUBST(JAVA)

  case $target in

    *aix* )
    JOS="aix"
    ;;

    *solaris* )
    JOS="solaris"
    changequote(,)
    javaversion=`$JAVAPATH/bin/java -version 2>&1|  grep 'java version' | \
                 sed -e 's/^.*"\([0-9].[0-9]\).*$/\1/'`
    changequote([,])
    ;;

    *irix* )
    JOS="irix"
    changequote(,)
    javaversion=`$JAVAPATH/bin/java -version 2>&1|  grep 'java version' | \
                  sed -e 's/^.*Sun \([0-9].[0-9]\).*$/\1/'`
    changequote([,])
     ;;

    *linux*)
    JOS="linux"
    changequote(,)
    javaversion=`$JAVAPATH/bin/java -version 2>&1|  grep 'java version' | \
                 sed -e 's/^.*"\([0-9].[0-9]\).*$/\1/'`
    changequote([,])
    ;;

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

  esac
fi

echo checking java target is $JOS
AC_SUBST(JOS)

###
dnl setting java thread option.
###
if test "$javaversion" = "1.2" ; then
   JAVATHREAD="-native"
   echo "checking java thread option is -native"
else
   echo "checking java thread option is -green"
fi
AC_SUBST(JAVATHREAD)

# end of java thread

AC_MSG_CHECKING(prunjava)

AC_CACHE_VAL(hpjdk_cv_adlib, 
  ADLIB=`which prunjava | sed 's%/bin/prunjava%%'`

  if test ! -f $ADLIB/bin/prunjava ; then
    echo "Please input Adlib install prefix:"
    read ADLIB
  fi;

  hpjdk_cv_adlib=$ADLIB
) 

AC_MSG_RESULT($hpjdk_cv_adlib)

ADLIB=$hpjdk_cv_adlib

AC_SUBST(ADLIB)

AC_OUTPUT(
src/tools/gen:src/tools/gen.in
src/tools/parse:src/tools/parse.in
src/tools/unparse:src/tools/unparse.in
src/tools/iunparse:src/tools/iunparse.in
src/tools/prettify:src/tools/prettify.in
src/tools/iprettify:src/tools/iprettify.in
src/tools/hpj2j:src/tools/hpj2j.in
src/tools/hpjavac:src/tools/hpjavac.in
src/tools/mjava:src/tools/mjava.in
src/hpjava/compiler/testsuite/runtests:src/hpjava/compiler/testsuite/runtests.in
test/fromJikes/jikestst/hpj/src/runtests:test/fromJikes/jikestst/hpj/src/runtests.in
)

chmod a+x src/tools/gen
chmod a+x src/tools/parse
chmod a+x src/tools/unparse
chmod a+x src/tools/iunparse
chmod a+x src/tools/prettify
chmod a+x src/tools/iprettify
chmod a+x src/tools/hpj2j
chmod a+x src/tools/hpjavac
chmod a+x src/tools/mjava
chmod a+x src/hpjava/compiler/testsuite/runtests
chmod a+x test/fromJikes/jikestst/hpj/src/runtests

echo Done!

