AC_INIT([Icecast], [2.0-kh31], [karl@xiph.org])

AC_PREREQ(2.54)
AC_CONFIG_SRCDIR(src/main.c)
dnl Process this file with autoconf to produce a configure script.

AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE

AC_PROG_CC
AC_CANONICAL_HOST
AC_PROG_LIBTOOL

dnl Set some options based on environment

DEBUG="-g"
if test -z "$GCC"; then
    XIPH_CPPFLAGS="-D_REENTRANT"
    case $host in 
        *-*-irix*)
                XIPH_CPPFLAGS="$XIPH_CPPFLAGS -w -signed"
                PROFILE="-p -g3 -O2 -signed -D_REENTRANT"
                ;;
        *-*-solaris*)
                XIPH_CFLAGS="-xO4 -xcg92"
                XIPH_CPPFLAGS="$XIPH_CPPFLAGS -v -w -fsimple -fast"
                PROFILE="-xpg -g -Dsuncc"
                ;;
        *)
                XIPH_CFLAGS="-O"
                PROFILE="-g -p"
                ;;
    esac

    case "$host" in
        *openbsd* | *irix*)
        ;;
        *) AC_DEFINE([_XOPEN_SOURCE], 600, [Define if you have POSIX and XPG specifications])
        ;;
    esac

else
    XIPH_CPPFLAGS="-Wall -ffast-math -fsigned-char"
    PROFILE="-pg -g"
    AC_DEFINE([_GNU_SOURCE], 1, [Define to include GNU extensions to POSIX])
fi

dnl Checks for programs.

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC

AC_CHECK_HEADERS([alloca.h])
AC_CHECK_HEADERS(pwd.h, AC_DEFINE(CHUID, 1, [Define if you have pwd.h]),,)
AC_CHECK_HEADERS(unistd.h, AC_DEFINE(CHROOT, 1, [Define if you have unistd.h]),,)

dnl Checks for typedefs, structures, and compiler characteristics.

dnl Check for types

dnl Checks for library functions.
AC_CHECK_FUNCS(localtime_r nanosleep poll)
XIPH_NET

dnl -- configure options --

XIPH_PATH_XSLT
XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$XSLT_CFLAGS])
XIPH_VAR_PREPEND([XIPH_LIBS],[$XSLT_LIBS])

XIPH_PATH_VORBIS(, AC_MSG_ERROR([must have Ogg Vorbis v1.0 installed!]))
XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$VORBIS_CFLAGS])
XIPH_VAR_PREPEND([XIPH_LIBS],[$VORBIS_LIBS])

XIPH_PATH_THEORA(, AC_MSG_WARN([Theora support disabled!]))
XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$THEORA_CFLAGS])
XIPH_VAR_PREPEND([XIPH_LIBS],[$THEORA_LIBS])

XIPH_PATH_SPEEX(, AC_MSG_WARN([Speex support disabled!]))
XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$SPEEX_CFLAGS])
XIPH_VAR_PREPEND([XIPH_LIBS],[$SPEEX_LIBS])

ACX_PTHREAD(, AC_MSG_ERROR([POSIX threads missing]))
XIPH_VAR_APPEND([XIPH_CFLAGS],[$PTHREAD_CFLAGS])
XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$PTHREAD_CPPFLAGS])
XIPH_VAR_PREPEND([XIPH_LIBS],[$PTHREAD_LIBS])

dnl -- YP support --
AC_ARG_ENABLE([yp],
        AC_HELP_STRING([--disable-yp],[disable YP directory support]),
        enable_yp="$enableval",
        enable_yp="yes")
if test "x$enable_yp" = "xyes"
then
XIPH_PATH_CURL([
    AC_CHECK_DECL([CURLOPT_NOSIGNAL],
        [ AC_DEFINE([USE_YP], 1, [Define to compile in YP support code])
        ICECAST_OPTIONAL="$ICECAST_OPTIONAL geturl.o yp.o"
        XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$CURL_CFLAGS])
        XIPH_VAR_PREPEND([XIPH_LIBS],[$CURL_LIBS])
        ], [ AC_MSG_NOTICE([Your curl dev files are too old (7.10 or above required), YP disabled])
        ], [#include <curl/curl.h>
        ])
    ],[ AC_MSG_NOTICE([libcurl not found, YP disabled])
    ])
else
    AC_MSG_NOTICE([YP support disabled])
fi
# don't log ip's in the access log
AC_ARG_ENABLE([log-ip],
        AC_HELP_STRING([--disable-log-ip],[disable logging of IP's in access log]),
        enable_logging_ip="$enableval",
        enable_logging_ip="yes"
        )
if test x$enable_logging_ip = xyes; then
        AC_DEFINE([HAVE_LOGGING_IP],,[Define to log IP to access log])
fi

dnl Make substitutions

AC_SUBST(XIPH_CPPFLAGS)
AC_SUBST(XIPH_CFLAGS)
AC_SUBST(XIPH_LIBS)
AC_SUBST(PTHREAD_CPPFLAGS)
AC_SUBST(PTHREAD_CFLAGS)
AC_SUBST(PTHREAD_LIBS)
AC_SUBST(LIBTOOL_DEPS)
AC_SUBST(LIBS)
AC_SUBST(DEBUG)
AC_SUBST(CFLAGS)
AC_SUBST(PROFILE)
AC_SUBST(ICECAST_OPTIONAL)

AC_OUTPUT([Makefile conf/Makefile debian/Makefile src/Makefile src/avl/Makefile
src/httpp/Makefile src/thread/Makefile src/log/Makefile
src/net/Makefile src/timing/Makefile doc/Makefile web/Makefile
admin/Makefile win32/Makefile win32/res/Makefile])
