dnl ####################################################################
dnl #   Copyright (c) 1996 NPACT Working Group. You may copy,          #
dnl #   distribute, and modify it freely as long as you preserve this  #
dnl #   copyright and permission notice.                               #
dnl #                                                                  #
dnl #   NPACT Working Group is a joint force of                        #
dnl #      NPAC at Syracuse University,                                #
dnl #      PACT at Harbin Institute of Technology, and                 #
dnl #      PACT at Peking University                                   #
dnl #                                                                  #
dnl ####################################################################
dnl
dnl
dnl Process this file and acconfig.h by autoconf to produce a configure script.

AC_INIT(./configure)

AC_PREFIX_DEFAULT(`pwd`)
AC_CONFIG_AUX_DIR(./config)
AC_CONFIG_HEADER(./src/include/config.h)

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

AC_CANONICAL_SYSTEM
AC_ARG_PROGRAM

AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX

AC_HEADER_STDC

dnl AC_CHECK_TYPE(u_short,unsigned short)
AC_HEADER_SYS_WAIT

dnl AC_C_CROSS
dnl AC_CHECK_SIZEOF(int)
dnl AC_CHECK_SIZEOF(char)
dnl AC_CHECK_SIZEOF(double)
dnl AC_CHECK_SIZEOF(float)

AC_PROG_RANLIB

CWD=`pwd`
AC_SUBST(CWD)

AC_CHECK_PROG(frontEnd, hpf2dep, yes, no)

AC_MSG_CHECKING(the frontEnd system install prefix)
AC_CACHE_VAL(ac_cv_frontend_prefix, ac_cv_frontend_prefix=$FEPREFIX)

if [ test "$ac_cv_frontend_prefix" = "" ]
then 
  if [ test $frontEnd = yes ]
  then
    ac_cv_frontend_prefix=`which hpf2dep | sed 's%/bin/hpf2dep%%'`
  else
    ac_cv_frontend_prefix=/usr/local
  fi
fi
AC_MSG_RESULT($ac_cv_frontend_prefix)

if [ test ! -f $ac_cv_frontend_prefix/include/compilerApi.h ]
then
  echo "Please input the frontEnd system install prefix:" 
  read ac_cv_frontend_prefix
fi

if [ test ! -f $ac_cv_frontend_prefix/include/compilerApi.h ]
then
  echo
  echo "ERROR: the frontEnd system is not correct installed!"; exit
fi

FEPREFIX=$ac_cv_frontend_prefix

AC_SUBST(FEPREFIX)

dnl echo "the FEPREFIX is " $FEPREFIX

AC_MSG_CHECKING(the frontEnd system install exec_prefix)
AC_CACHE_VAL(ac_cv_frontend_exec_prefix, ac_cv_frontend_exec_prefix=$FEEXECPREFIX)

if [ test "$ac_cv_frontend_exec_prefix" = "" ]
then 
  ac_cv_frontend_exec_prefix=$ac_cv_frontend_prefix
fi
AC_MSG_RESULT($ac_cv_frontend_exec_prefix)

if  [ test ! -f $ac_cv_frontend_exec_prefix/lib/libxsage.a ]
then 
  echo "Please input the frontEnd system install exec_prefix:"
  read ac_cv_frontend_exec_prefix
fi

if  [ test ! -f $ac_cv_frontend_exec_prefix/lib/libxsage.a ]
then
  echo
  echo "ERROR: the frontEnd system is not correct installed!"; exit
fi

FEEXECPREFIX=$ac_cv_frontend_exec_prefix
AC_SUBST(FEEXECPREFIX)

dnl echo "the FEEXECPREFIX is " $FEEXECPREFIX


dnl check Adlib

AC_CHECK_PROG(Adlib, pcrcf, yes, no)

if [ test $Adlib = yes ]
then
  ADLIBEXECPREFIX=`which pcrcf | sed 's%/bin/pcrcf%%'`
  AC_SUBST(ADLIBEXECPREFIX)	
  FCL=`$ADLIBEXECPREFIX/bin/pcrcf -f`
  AC_SUBST(FCL)	
else
  echo "Please input the Adlib install exec_prefix:"
  read ADLIBEXECPREFIX
  AC_SUBST(ADLIBEXECPREFIX)	
  FCL=`$ADLIBEXECPREFIX/bin/pcrcf -f`
  AC_SUBST(FCL)	
fi


AC_OUTPUT(
Makefile src/Makefile 
testsuite/Makefile
src/include/Makefile src/script/Makefile 
src/trans0/Makefile src/trans1/Makefile src/trans2/Makefile
src/tof77/Makefile
testsuite/Makefile
testsuite/generator/Makefile testsuite/simple/Makefile testsuite/hpfA/Makefile
src/script/chkir:src/script/chkir.in
src/script/hpf2nf:src/script/hpf2nf.in
src/script/hpfc:src/script/hpfc.in
)

chmod a+x src/script/chkir
chmod a+x src/script/hpf2nf
chmod a+x src/script/hpfc

echo Done!



