AC_INIT([Icecast], [2.0-kh52], [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([dist-bzip2])
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
        # for system header breakage
        *bsd* | *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 poll)
AC_SEARCH_LIBS(nanosleep, rt posix4,
        AC_DEFINE(HAVE_NANOSLEEP, 1, [Define if you have nanosleep]))
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_VAR_APPEND([XIPH_LDFLAGS],[$VORBIS_LDFLAGS])

XIPH_PATH_THEORA(, AC_MSG_WARN([Theora not found disabled!]))
XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$THEORA_CFLAGS])
XIPH_VAR_PREPEND([XIPH_LIBS],[$THEORA_LIBS])
XIPH_VAR_APPEND([XIPH_LDFLAGS],[$THEORA_LDFLAGS])

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

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])

XIPH_PATH_CURL([
    AC_CHECK_DECL([CURLOPT_NOSIGNAL],
        [ AC_DEFINE([HAVE_AUTH_URL], 1, [Define to compile in auth URL support code])
        ICECAST_OPTIONAL="$ICECAST_OPTIONAL auth_url.o"
        enable_curl="yes"
        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)])
        ], [#include <curl/curl.h>
        ])
    ],[ AC_MSG_NOTICE([libcurl not found])
    ])
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" -a "x$enable_curl" = xyes
then
    AC_DEFINE([USE_YP], 1, [Define to compile in YP support code])
    ICECAST_OPTIONAL="$ICECAST_OPTIONAL yp.o"
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

# use the older format_vorbis with metadata updates
AC_ARG_ENABLE([vorbis-updates],
        AC_HELP_STRING([--enable-vorbis-updates],[Allow for metadata via URL, only vorbis supported]),
        vorbis_updates="$enableval",
        vorbis_updates="no"
        )
if test x$vorbis_updates = xyes; then
    ICECAST_OPTIONAL="$ICECAST_OPTIONAL format_vorbis.o"
else
    ICECAST_OPTIONAL="$ICECAST_OPTIONAL format_ogg.o"
fi

dnl Make substitutions

AC_SUBST(XIPH_CPPFLAGS)
AC_SUBST(XIPH_CFLAGS)
AC_SUBST(XIPH_LIBS)
AC_SUBST(XIPH_LDFLAGS)
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])
