dnl Process this file with autoconf to produce a configure script.
AC_REVISION($Revision: 1.3 $)dnl
AC_PREREQ(2.50)
AC_INIT(include/osip2/osip.h)

AC_MSG_NOTICE([osip2                                       The GNU Open SIP library.])
AC_MSG_NOTICE([Copyright (C) 2001,2002,2003,2004,2005,2006 Aymeric MOIZARD - <jack@atosc.org>])


dnl *********************************************************************
dnl Source packaging numbers
OSIP_MAJOR_VERSION=3
OSIP_MINOR_VERSION=0
OSIP_MICRO_VERSION=0

SONAME_MAJOR_VERSION=4
SONAME_MINOR_VERSION=0
SONAME_MICRO_VERSION=0

OSIP_VERSION=$OSIP_MAJOR_VERSION.$OSIP_MINOR_VERSION.$OSIP_MICRO_VERSION

LIBOSIP_SO_VERSION=$SONAME_MAJOR_VERSION:$SONAME_MINOR_VERSION:$SONAME_MICRO_VERSION

AC_SUBST(LIBOSIP_SO_VERSION, $LIBOSIP_SO_VERSION)

AC_SUBST(OSIP_VERSION)

if test "x$PRERELEASE" = "x"; then
 VERSION=$OSIP_VERSION
else
 VERSION="$OSIP_VERSION-$PRERELEASE"
fi

PACKAGE=libosip2

AC_MSG_RESULT([Configuring ${PACKAGE} ${VERSION}])
OS=`uname|sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
AC_MSG_RESULT([Building Package on ${OS}])



dnl *********************************************************************
dnl Initialize automake stuff
AC_CONFIG_AUX_DIR(scripts)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
dnl AM_ACLOCAL_INCLUDE(scripts)

AC_CANONICAL_HOST                                                               

dnl Checks for programs.

AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL


dnl Initialize libtool
AM_PROG_LIBTOOL

dnl declare --enable-* args and collect ac_help strings

AC_ARG_ENABLE(debug,
[  --enable-debug          turn on debugging.],
enable_debug=$enableval,enable_debug="yes")

AC_ARG_ENABLE(trace,
[  --enable-trace          turn on trace.],
enable_trace=$enableval,enable_trace="yes")

AC_ARG_ENABLE(mpatrol,
[  --enable-mpatrol        turn on memory leak detection with patrol.],
enable_mpatrol=$enableval,enable_mpatrol="no")

AC_ARG_ENABLE(gprof,
[  --enable-gprof          turn on profiling support.],
enable_gprof=$enableval,enable_gprof="no")

dnl build with multithreaded support (need semaphore).
AC_ARG_ENABLE(mt,
[  --enable-mt             compile oSIP without multi-thread support.],
enable_mt=$enableval,enable_mt="yes")

dnl support for linux-thread or posix thread (pthread.h)
AC_ARG_ENABLE(pthread,
[  --enable-pthread        enable support for POSIX threads. (default=autodetect)],
enable_pthread=$enableval,enable_pthread="no")

dnl support for semaphore.h (linux/sun...)
AC_ARG_ENABLE(semaphore,
[  --enable-semaphore      enable support for semaphore (semaphore.h)],
enable_semaphore=$enableval,enable_semaphore="no")

dnl support for sysV semaphore in sys/sem.h (BSD/linux...)
AC_ARG_ENABLE(sysv,
[  --enable-sysv           enable support for sysV semaphore (sys/sem.h).],
enable_sysv=$enableval,enable_sysv="no")

dnl support for gperf.
AC_ARG_ENABLE(gperf,
[  --enable-gperf          enable support for gperf (improve the parser speed).],
enable_gperf=$enableval,enable_gperf="no")

dnl libdict support.
AC_ARG_ENABLE(hashtable,
[  --enable-hashtable      compile oSIP with hashtable (libdict) support.],
enable_hashtable=$enableval,enable_hashtable="no")

dnl support for gperf.
AC_ARG_ENABLE(test,
[  --enable-test           enable building test programs).],
enable_test=$enableval,enable_test="no")

dnl compile with mt support
if test "x$enable_mt" = "xyes"; then
  if test "x$enable_pthread" = "xyes"; then
    SIP_FSM_FLAGS="-DOSIP_MT -DHAVE_PTHREAD"
    FSM_LIB="-lpthread"
  else
    SIP_FSM_FLAGS="-DOSIP_MT"
dnl    ACX_PTHREAD()
  fi
fi

if test "x$enable_gperf" = "xyes"; then
  SIP_PARSER_FLAGS="$SIP_PARSER_FLAGS -DUSE_GPERF"
fi

AM_CONDITIONAL(COMPILE_TESTS, test "x$enable_test" != "xno")

if test "x$enable_semaphore" = "xyes"; then
  SIP_FSM_FLAGS="$SIP_FSM_FLAGS -DHAVE_SEMAPHORE_H"
  AC_CHECK_HEADERS(semaphore.h)
elif test "x$enable_sysv" = "xyes"; then
  SIP_FSM_FLAGS="$SIP_FSM_FLAGS -DHAVE_SYS_SEM_H"
  AC_CHECK_HEADERS(sys/sem.h)
else
  AC_CHECK_HEADERS(semaphore.h)
  AC_CHECK_HEADERS(sys/sem.h)
fi

case $OS in
  linux*)
     SIP_EXTRA_FLAGS="$SIP_EXTRA_FLAGS -pedantic"
     ;;
  irix*)
     ;;
  hpux* | hp-ux*)
     ;;
  aix*)
     ;;
  osf*)
     ;;
  sunos*)
     ;;
  darwin*)
     ;;
  *)
     ;;
esac

if test "x$enable_hashtable" = "xyes"; then
   AC_CHECK_HEADERS([dict/dict.h],
                   [AC_DEFINE([HAVE_DICT_DICT_H], [], [Define to 1 if you have <dict/dict.h> header file])],
                   [AC_MSG_ERROR([libdict library not installed. Please install or use --disable-hashtable])])
   EXTRA_LIB="$EXTRA_LIB -ldict"
fi

if test "x$enable_debug" = "xyes"; then
  SIP_EXTRA_FLAGS="$SIP_EXTRA_FLAGS -g"
  CFLAGS=`echo $CFLAGS | sed 's/-O.//'`
fi

if test "x$enable_trace" = "xyes"; then
  SIP_EXTRA_FLAGS="$SIP_EXTRA_FLAGS -DENABLE_TRACE"
fi

if test "x$enable_mpatrol" = "xyes"; then
  SIP_EXTRA_FLAGS="$SIP_EXTRA_FLAGS -DENABLE_MPATROL"
  EXTRA_LIB="$EXTRA_LIB -lmpatrolmt -lelf -lpthread"
fi

if test "x$enable_gprof" = "xyes"; then
  SIP_EXTRA_FLAGS="$SIP_EXTRA_FLAGS -pg"
  EXTRA_LIB="$EXTRA_LIB -lc_p"
fi

dnl Checks for libraries. (those one are needed for sun)
AC_CHECK_LIB(posix4,sem_open,[FSM_LIB="$FSM_LIB -lposix4 -mt"])
AC_CHECK_LIB(nsl,nis_add,[FSM_LIB="$FSM_LIB -lnsl"])
AC_CHECK_LIB(socket,sendto,[FSM_LIB="$FSM_LIB -lsocket"])
AC_CHECK_LIB(c, lrand48, AC_DEFINE([HAVE_LRAND48], [], [Defined if you have lrand48]))

AC_CACHE_CHECK([whether -Wall works], Wall_flag, [
  saved_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="-Wall"
  AC_TRY_COMPILE(, , Wall_flag=yes, Wall_flag=no)
  CPPFLAGS=$saved_CPPFLAGS
])

if test "x$Wall_flag" = xyes; then
  CPPFLAGS="$CPPFLAGS -Wall"
fi

AC_CACHE_CHECK([whether -Wcast-align works], Wcast_align_flag, [
  saved_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="-Wcast-align"
  AC_TRY_COMPILE(, , Wcast_align_flag=yes, Wcast_align_flag=no)
  CPPFLAGS=$saved_CPPFLAGS
])

if test "x$Wcast_align_flag" = xyes; then
  CPPFLAGS="$CPPFLAGS -Wcast-align"
fi

AC_CACHE_CHECK([whether -Wchar-subscripts works], Wchar_subscripts_flag, [
  saved_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="-Wchar-subscripts"
  AC_TRY_COMPILE(, , Wchar_subscripts_flag=yes, Wchar_subscripts_flag=no)
  CPPFLAGS=$saved_CPPFLAGS
])

if test "x$Wchar_subscripts_flag" = xyes; then
  CPPFLAGS="$CPPFLAGS -Wchar-subscripts"
fi

AC_CACHE_CHECK([whether -Wformat works], Wformat_flag, [
  saved_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="-Wformat"
  AC_TRY_COMPILE(, , Wformat_flag=yes, Wformat_flag=no)
  CPPFLAGS=$saved_CPPFLAGS
])

if test "x$Wformat_flag" = xyes; then
  CPPFLAGS="$CPPFLAGS -Wformat"
fi

AC_CACHE_CHECK([whether -Winline works], Winline_flag, [
  saved_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="-Winline"
  AC_TRY_COMPILE(, , Winline_flag=yes, Winline_flag=no)
  CPPFLAGS=$saved_CPPFLAGS
])

if test "x$Winline_flag" = xyes; then
  CPPFLAGS="$CPPFLAGS -Winline"
fi

AC_CACHE_CHECK([whether -Wmissing-declarations works], Wmissing_declarations_flag, [
  saved_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="-Wmissing-declarations"
  AC_TRY_COMPILE(, , Wmissing_declarations_flag=yes, Wmissing_declarations_flag=no)
  CPPFLAGS=$saved_CPPFLAGS
])

if test "x$Wmissing_declarations_flag" = xyes; then
  CPPFLAGS="$CPPFLAGS -Wmissing-declarations"
fi

AC_CACHE_CHECK([whether -Wmissing-prototypes works], Wmissing_prototypes_flag, [
  saved_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="-Wmissing-prototypes"
  AC_TRY_COMPILE(, , Wmissing_prototypes_flag=yes, Wmissing_prototypes_flag=no)
  CPPFLAGS=$saved_CPPFLAGS
])

if test "x$Wmissing_prototypes_flag" = xyes; then
  CPPFLAGS="$CPPFLAGS -Wmissing-prototypes"
fi

AC_CACHE_CHECK([whether -Wnested-externs works], Wnested_externs_flag, [
  saved_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="-Wnested-externs"
  AC_TRY_COMPILE(, , Wnested_externs_flag=yes, Wnested_externs_flag=no)
  CPPFLAGS=$saved_CPPFLAGS
])

if test "x$Wnested_externs_flag" = xyes; then
  CPPFLAGS="$CPPFLAGS -Wnested-externs"
fi

AC_CACHE_CHECK([whether -Wpointer-arith works], Wpointer_arith_flag, [
  saved_CPPFLAGS=$CPPFLAGS
  CPPFLAGS="-Wpointer-arith"
  AC_TRY_COMPILE(, , Wpointer_arith_flag=yes, Wpointer_arith_flag=no)
  CPPFLAGS=$saved_CPPFLAGS
])

if test "x$Wpointer_arith_flag" = xyes; then
  CPPFLAGS="$CPPFLAGS -Wpointer-arith"
fi

SIP_CFLAGS="$SIP_CFLAGS $CFLAGS"

AC_SUBST(SIP_CFLAGS)

AC_SUBST(SIP_EXTRA_FLAGS)
AC_SUBST(SIP_PARSER_FLAGS)
AC_SUBST(SIP_FSM_FLAGS)

AC_SUBST(EXTRA_LIB)
AC_SUBST(PARSER_LIB)
AC_SUBST(FSM_LIB)

dnl Checks for header files.

dnl This is to be removed for autoconf2.50
AC_HEADER_STDC
AC_CHECK_HEADERS(string.h)
AC_CHECK_HEADERS(strings.h)
AC_CHECK_HEADERS(stdlib.h)
AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(sys/types.h)
dnl !This is to be removed for autoconf2.50

AC_CHECK_HEADERS(sys/unistd.h)
AC_CHECK_HEADERS(ctype.h)
AC_CHECK_HEADERS(stdio.h)
AC_CHECK_HEADERS(stdarg.h)
AC_CHECK_HEADERS(varargs.h)
AC_CHECK_HEADERS(fcntl.h)
AC_CHECK_HEADERS(time.h)
AC_CHECK_HEADERS(sys/time.h)
AC_CHECK_HEADERS(sys/select.h)
AC_CHECK_HEADERS(assert.h)
AC_CHECK_HEADERS(signal.h)
AC_CHECK_HEADERS(sys/signal.h)
AC_CHECK_HEADERS(malloc.h)

AC_CHECK_TYPES([struct timeval],,,[
     #if TIME_WITH_SYS_TIME
     # include <sys/time.h>
     # include <time.h>
     #else
     # if HAVE_SYS_TIME_H
     #  include <sys/time.h>
     # else
     #  include <time.h>
     # endif
     #endif
])

AC_OUTPUT(
libosip2.pc
Makefile
scripts/Makefile
src/Makefile
src/osipparser2/Makefile
src/osip2/Makefile
src/test/Makefile
src/test/res/Makefile
include/Makefile
include/osip2/Makefile
include/osipparser2/Makefile
include/osipparser2/headers/Makefile
help/Makefile
help/man/Makefile
help/doxygen/Makefile
debian/Makefile
platform/Makefile
platform/rpm/Makefile
platform/vsnet/Makefile
include/osip2/doxygen.dox)

