dnl Process this file with autoconf to produce a configure script.
AC_INIT(cccp.c)

dnl Specify the autoconf file.
AC_CONFIG_HEADER(autoconfig.h)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_YACC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS(fcntl.h malloc.h sys/time.h unistd.h stdlib.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_PID_T
AC_STRUCT_TM
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)

dnl Checks for library functions.
AC_FUNC_ALLOCA
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(strerror strstr bcmp)

dnl Check the gcc version

if test ! "x$GCC" = "x" ; then

   AC_MSG_CHECKING([if we can use gcc instead of cxref-cpp])

   AC_TRY_RUN([
   #if defined(__GNUC__) && __GNUC__>=2 && __GNUC_MINOR__>=8
   int main() {exit(0);}
   #else
   int main() {exit(1);}
   #endif
   ],
   [newGCC=yes])

   if test "x$newGCC" = "x" ; then

      AC_MSG_RESULT(no)

      $CC -E -v -dM - < /dev/null > ./conftest.gcc 2>&1

      changequote(<<, >>)dnl
      PREDEFINES=`egrep -e -lang-c ./conftest.gcc | tr ' ' '\012' | egrep -e '^-[AD]' | tr '\012' ' '`
      changequote([, ])dnl

      INCLUDE_DIR1=`awk '/include <.+> search/,/End of search/ {if(i==1)print $1;i++}' ./conftest.gcc`
      INCLUDE_DIR2=`awk '/include <.+> search/,/End of search/ {if(i==2)print $1;i++}' ./conftest.gcc`
      INCLUDE_DIR3=`awk '/include <.+> search/,/End of search/ {if(i==3)print $1;i++}' ./conftest.gcc`

      CXREF_CPP=cxref-cpp

   else

      AC_MSG_RESULT(yes)

   fi

else

   AC_MSG_WARN(the C compiler is not gcc, you may have problems)

fi

AC_SUBST(PREDEFINES)
AC_SUBST(INCLUDE_DIR1)
AC_SUBST(INCLUDE_DIR2)
AC_SUBST(INCLUDE_DIR3)

AC_SUBST(CXREF_CPP,cxref-cpp)

dnl Create the output files.
AC_OUTPUT(Makefile)
