dnl autoconf for ippl. Copyright (C) 1999 Hugo Haas

dnl Initialisation
AC_INIT(Makefile.in)

dnl Version
VERSION=`cat $srcdir/VERSION`
AC_SUBST(VERSION)

echo "Configuring ippl $VERSION..."
echo

dnl Check compilers
AC_PROG_CC
AC_PROG_LEX
AC_PROG_YACC
AC_PROG_INSTALL

dnl Specifying the user used to run threads
DEFAULT_USER="nobody"
AC_ARG_WITH(user,
[ --with-user=USER      Specify which user will run the threads
                       by default (default: nobody)],
[ if test $withval != "yes" -a $withval != "no"; then
    DEFAULT_USER=$withval
  fi
])

dnl Options
AC_ARG_ENABLE(multithread,
[ --enable-multithread  Run a thread for each new packet logged],
[ if test $enableval = "yes"; then
    MULTITHREAD=" -D_MULTITHREAD_"
  fi
  AC_SUBST(MULTITHREAD)
])
AC_ARG_ENABLE(cache-debug,
[ --enable-cache-debug  Display DNS cache statistics],
[ if test $enableval = "yes"; then
    CACHE_DEBUG=" -DCACHE_DEBUG"
  fi
  AC_SUBST(CACHE_DEBUG)
])
AC_ARG_ENABLE(filter-debug,
[ --enable-filter-debug  Display filtering process],
[ if test $enableval = "yes"; then
    FILTER_DEBUG=" -DFILTER_DEBUG"
  fi
  AC_SUBST(FILTER_DEBUG)
])
AC_ARG_ENABLE(parsing-debug,
[ --enable-parsing-debug Shows configuration parsing process],
[ if test $enableval = "yes"; then
    PARSING_DEBUG=" -DPARSING_DEBUG"
    YACC_DEBUG_OPTIONS=" -dtv"
  fi
  AC_SUBST(PARSING_DEBUG)
  AC_SUBST(YACC_DEBUG_OPTIONS)
])
AC_ARG_ENABLE(all-warnings,
[ --enable-all-warnings Run the compiler in pedantic mode],
[ if test $enableval = "yes"; then
    PEDANTIC=" -pedantic"
  fi
  AC_SUBST(PEDANTIC)
])
AC_ARG_WITH(dmalloc,
[ --with-dmalloc        Link the program with the dmalloc library],
[ if test $withval = "yes"; then
    AC_CHECK_LIB(dmalloc, main, DMALLOC=" -ldmalloc")
  fi
   AC_SUBST(DMALLOC)
])


fail_pthread() {
  echo "Please update your pthread library:"
  echo "         http://pauillac.inria.fr/~xleroy/linuxthreads/"
  exit
}

dnl Check for functions
AC_CHECK_LIB(pthread, pthread_attr_init,, fail_pthread)
AC_CHECK_LIB(pthread, pthread_attr_setdetachstate,, fail_pthread)
AC_CHECK_LIB(pthread, pthread_attr_destroy,, fail_pthread)
AC_CHECK_LIB(pthread, pthread_create,, fail_pthread)
AC_CHECK_LIB(pthread, pthread_setcancelstate,, fail_pthread)
AC_CHECK_LIB(pthread, pthread_attr_setdetachstate,, fail_pthread)
AC_CHECK_LIB(pthread, pthread_cancel,, fail_pthread)
AC_CHECK_LIB(pthread, pthread_mutex_lock,, fail_pthread)
AC_CHECK_LIB(pthread, pthread_mutex_unlock,, fail_pthread)

# If $sysconfdir == /usr/etc, change it to /etc
if [[ $prefix = '/usr' -a $sysconfdir = '${prefix}/etc' ]]; then
    echo sysconfig is set to /usr/etc. Changing it to /etc.
    sysconfdir='/etc'
fi

dnl Default user
AC_SUBST(DEFAULT_USER)
echo "Using $DEFAULT_USER as the default user to run threads."

AC_OUTPUT(Makefile Makefile.common Source/Makefile Docs/Makefile)

echo
make configdump
echo
echo Now you can type \`\` make \'\'. Good luck!
