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 written by Zheng Gengbin
dnl   e-mail:  zheng.gb@svr.bimp.pku.edu.cn
dnl
dnl Process this file and acconfig.h by autoconf to produce a configure script.

AC_INIT(./config)

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

dnl determine CC initial flag
if eval "test \"`echo '$''{'ac_cv_prog_CC'}'`\" = 'gcc'"
then
  CFLAGS="-g"
else
  CFLAGS="-g"
fi

dnl determine CXX initial flag
if eval "test \"`echo '$''{'ac_cv_prog_CXX'}'`\" = 'c++'"
then
  CXXFLAGS="-g"
else
  CXXFLAGS="-g"
fi

AC_HEADER_STDC
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

dnl The following is for LEX
AC_PROG_LEX

dnl this check seems not good enough so we have the following things ...
AC_DECL_YYTEXT

dnl check if flex add -l flag
AC_MSG_CHECKING(whether $ac_cv_prog_LEX accept -l flag)
AC_CACHE_VAL(ac_cv_lex_l_flag,
ac_cv_lex_l_flag=no
if eval "test \"`echo '$''{'ac_cv_prog_LEX'}'`\" = 'flex'"
then
  cat > conftest.l <<EOF
%{
%}
%%
%{
%}
EOF

 flex -l conftest.l 1> /dev/null 2> /dev/null
 test $? = 0  && ac_cv_lex_l_flag=yes
fi
)
if eval "test \"`echo '$''{'ac_cv_lex_l_flag'}'`\" = 'yes'"
then
	LLFLAG=-l    
	AC_MSG_RESULT(yes)
else
	LLFLAG=      
	AC_MSG_RESULT(no)
fi
AC_SUBST(LLFLAG)

dnl determine char or unsigned char yytext
AC_MSG_CHECKING(whether the yytext is defined as unsigned char)
AC_CACHE_VAL(ac_cv_prog_yytext_unsigned, 
cat > conftest.l <<EOF
%{
%}
%%
%{
%}
EOF

${ac_cv_prog_LEX} ${LLFLAG} conftest.l 1>/dev/null 2>/dev/null

LEX_OUTPUT_ROOT=$ac_cv_prog_lex_root
AC_EGREP_CPP(
  changequote(,)dnl
[[unsigned.*yytext[^a-z_]]],
  changequote([,])dnl
  [
	`cat $LEX_OUTPUT_ROOT.c`
  ]
  , ac_cv_prog_yytext_unsigned=yes ,
    ac_cv_prog_yytext_unsigned=no  )
)

if eval "test \"`echo '$''{'ac_cv_prog_yytext_unsigned'}'`\" = 'yes'"
then
  AC_DEFINE(IS_UNSIGNED_CHAR)  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi
	
dnl check whether the yytext is pointer .
AC_MSG_CHECKING(whether the yytext is defined as pointer )
AC_CACHE_VAL(ac_cv_prog_yytext_pointer, 
AC_EGREP_CPP(
  changequote(,)dnl
[[char[ ]*\*[ ]*yytext;]],
  changequote([,])dnl
  [
	`cat $LEX_OUTPUT_ROOT.c`
  ]
  , ac_cv_prog_yytext_pointer=yes ,
    ac_cv_prog_yytext_pointer=no )
)

if eval "test \"`echo '$''{'ac_cv_prog_yytext_pointer'}'`\" = 'yes'"
then
  AC_DEFINE(YYTEXT_IS_POINTER)  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi

rm -f conftest.l
rm -f "$LEX_OUTPUT_ROOT.c"

dnl The following is for YACC
AC_PROG_YACC
AC_CHECK_LIB(y,main,YYLIB_L="-ly",YYLIB_L="")
AC_SUBST(YYLIB_L)

AC_CHECK_LIB(l,main,LEXLIB_L="-ll",LEXLIB_L="")
AC_SUBST(LEXLIB_L)

dnl determine the special yacc flag used in HP9000
AC_MSG_CHECKING(special YYFLAGS )
YYFLAG_L=" -dvt "
if eval "test \"`echo '$''{'ac_cv_prog_YACC'}'`\" = 'yacc'"
then
  case "$target" in
    *hpux* )   YYFLAG_L="-Nc10000 -Na20000 -Nm20000 -Ns2500 -Nl1200 -Np2000 -dvt";;
  esac
fi
AC_MSG_RESULT(set as \"$YYFLAG_L\")
AC_SUBST(YYFLAG_L)

dnl set configure for Motif
AC_MSG_CHECKING(checking for X)
AC_CACHE_VAL(ac_cv_char_xincludes_val, X_INCLUDES=$ac_cv_char_xincludes_val)
AC_CACHE_VAL(ac_cv_char_ldoptions_val, LDOPTIONS=$ac_cv_char_ldoptions_val)
if eval "test -z \"`echo '$''{'X_INCLUDES'}'`\" " && eval "test -z \"`echo '$''{'LDOPTIONS'}'`\" "
then
rm -fr conftestdir
if mkdir conftestdir
then
  cd conftestdir
  # Make sure to not put "make" in the Imakefile rules, since we grep it out.
  cat > Imakefile <<'EOF'
acfindx:
	@echo 'X_INCLUDES="${STD_INCLUDES}";LDOPTIONS="${LDOPTIONS}";INCROOT="${INCROOT}"'
EOF
 if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile
 then
   eval `${MAKE-make} acfindx 2>/dev/null | grep -v make`
 fi
 cd ..
 rm -fr conftestdir
fi
if eval "test -z \"`echo '$''{'X_INCLUDES'}'`\" "
then
  if eval "test -n \"`echo '$''{'INCROOT'}'`\" "
  then
    X_INCLUDES=-I$INCROOT
  fi
fi
ac_cv_char_xincludes_val=$X_INCLUDES
ac_cv_char_ldoptions_val=$LDOPTIONS
fi  
AC_MSG_RESULT(\"header.. $X_INCLUDES lib.. $LDOPTIONS\")
AC_SUBST(X_INCLUDES)
AC_SUBST(LDOPTIONS)

if test -d src/tools/Vdump
then
   AC_DEFINE(WANT_LIST)
fi

PREFIX=$prefix ; EXEC_PREFIX=$exec_prefix
test "x$prefix" = xNONE && PREFIX=$ac_default_prefix
test "x$exec_prefix" = xNONE && EXEC_PREFIX='${PREFIX}'
SRCDIR=`pwd`
LIBDIR=`eval echo $EXEC_PREFIX/lib`
test ! x`echo $LIBDIR |cut -f1 -d/` = x  &&  LIBDIR="$SRCDIR/$LIBDIR"
AC_DEFINE_UNQUOTED(LIBDIR,"$LIBDIR")
AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")

AC_OUTPUT(
 Makefile src/Makefile 
 src/include/Makefile src/basicop/Makefile src/xsageop/Makefile 
 src/tools/Makefile  src/tools/dump/Makefile  src/tools/unparse/Makefile 
 src/hpf2dep/Makefile src/hpfsc/Makefile  
 src/java2dep/Makefile
 testsuite/Makefile 
 testsuite/hpf/Makefile testsuite/java/Makefile
 testsuite/hpf/examples/Makefile testsuite/hpf/syntax/Makefile testsuite/hpf/semantics/Makefile
 testsuite/java/simple/Makefile
 exampleUse/Makefile
 src/hpf2dep/fpp:src/hpf2dep/fpp.in
 src/java2dep/jpp:src/java2dep/jpp.in
)

chmod a+x src/hpf2dep/fpp
chmod a+x src/java2dep/jpp

echo Done!



