
#########################################################################
#########################################################################
#
AC_INIT(BR_Global.h)

PATH="$PATH:/usr/bin/X11"
export PATH

#########################################################################
#                          Programs Checks                              #
#########################################################################
#
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET

AC_PATH_PROG(FLEX, flex, /usr/local/bin/flex)
AC_PATH_PROG(BISON, bison, /usr/local/bin/bison)
AC_PATH_PROG(YACC, yacc, /bin/yacc)
AC_PATH_PROG(MAKEDEPEND, makedepend, /usr/local/bin/makedepend)


#########################################################################
#                              X11 Check                                #
#########################################################################
#
AC_PATH_X

if test "x$no_x" = "xyes"; then 
  AC_MSG_ERROR([
*** X libraries or include files not found. Check 'config.log' for 
*** more details.])
fi

AC_MSG_CHECKING([for extra X11 libraries])
AC_DEFUN(XC_X_EXTRA,
[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_EXTRA_LIBS="${EXTRA_LIBRARIES}"'
EOF
  if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
    # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
    eval `${MAKE-make} acfindx 2>/dev/null | grep -v make`
  fi
  cd ..
  rm -fr conftestdir
fi
])
XC_X_EXTRA
if test -z "$X_EXTRA_LIBS"; then 
  AC_MSG_RESULT("none")
else
  AC_MSG_RESULT($X_EXTRA_LIBS)
fi

saved_cflags="$CFLAGS"
saved_ldflags="$LDFLAGS"
if test -n "$x_includes"; then
  CFLAGS="$CFLAGS -I$x_includes"
  XC_X_INCLUDES="-I$x_includes"
fi
if test -n "$x_libraries"; then
  LDFLAGS="$LDFLAGS -L$x_libraries"
  XC_X_LDPATH="-L$x_libraries"
fi

AC_CHECK_LIB(X11, XOpenDisplay,
  x_libs="-lX11 $X_EXTRA_LIBS", 
  AC_MSG_ERROR([
*** Wrong X11 configuration :
***   Try to put the 'xmkmf' command in your execution PATH or try to
***   use the configure script parameters (--x-includes=DIR, --x-libraries=DIR)
***   in order to set the X11 configuration.]),
  $X_EXTRA_LIBS)

CFLAGS="$saved_cflags"
LDFLAGS="$saved_ldflags"

AC_SUBST(XC_X_INCLUDES)
AC_SUBST(XC_X_LDPATH)
AC_SUBST(x_libs)


#########################################################################
#                          Includes Checks                              #
#########################################################################
#
dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS(sys/time.h string.h malloc.h unistd.h memory.h sys/select.h)
AC_HEADER_SYS_WAIT


#########################################################################
#                     Compiler Environment Checks                       #
#########################################################################
#
AC_C_CONST
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_CHECK_TYPE(fd_set, int)

AC_FUNC_ALLOCA
AC_FUNC_GETPGRP
AC_FUNC_SETPGRP
AC_TYPE_SIGNAL

AC_CHECK_FUNCS(strerror)
if test $ac_cv_func_strerror = no; then
  AC_MSG_CHECKING([Check for sys_errlist])
  AC_TRY_LINK(
    [#include <stdio.h>],
    [printf(sys_errlist[sys_nerr]);],
    xc_stdio_syserr=yes, xc_stdio_syserr=no)
  if test $xc_stdio_syserr = yes; then 
    AC_MSG_RESULT("yes")
    AC_DEFINE(HAVE_STDIO_SYSERR)
  else
    AC_TRY_LINK(
      [#include <stdio.h>],
      [extern char *sys_errlist[];
       extern int sys_nerr;
       printf(sys_errlist[sys_nerr]);],
      xc_syserr=yes, xc_syserr=no)
    if test $xc_syserr = yes; then
      AC_MSG_RESULT("yes")
      AC_DEFINE(HAVE_SYSERR)
    else
      AC_MSG_RESULT("no")
      AC_CHECK_FUNCS(perror)
    fi
  fi
fi

if test $ac_cv_header_sys_wait_h = no; then
AC_MSG_CHECKING([Check for BSD waitpid()])
AC_TRY_COMPILE(
  [#include <sys/types.h>
#include <sys/wait.h>],
  [union wait  child_status;
   pid_t       child_pid;
   waitpid(child_pid, &child_status, WUNTRACED);],
  xc_bsd_waitpid=yes, xc_bsd_waitpid=no)
if test $xc_bsd_waitpid = yes; then 
  AC_MSG_RESULT("yes")
  AC_DEFINE(HAVE_BSD_WAITPID)
else
  AC_MSG_RESULT("no")
fi
fi

AC_CHECK_FUNCS(usleep select nanosleep, break)

AC_CHECK_FUNCS(kill sigsend, break)

AC_CHECK_FUNCS(bzero strdup getcwd sigprocmask strcasecmp)


#########################################################################
#                           Special Checks                              #
#########################################################################
#

#########################################################################
#########################################################################
#
AC_OUTPUT(Smac/Makefile Makefile)
