# $Id: configure.in,v 1.1 2008/10/07 17:19:26 stulleamgym Exp $

# Copyright 1999, 2000 Scott Thomas Haug <eldamitri@users.sourceforge.net>
# Copyright (C) 2002 Thijmen Klok <thijmen@id3lib.org>
#  
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without 
# modifications, as long as this notice is preserved.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# require autoconf 2.13
AC_PREREQ(2.13)

# init autoconf (and check for presence fo reconf)
AC_INIT(reconf)

ID3LIB_NAME=id3lib

dnl The following has been adapted from glib (http://www.gtk.org)
dnl
dnl we need to AC_DIVERT_PUSH/AC_DIVERT_POP these variable definitions so they
dnl are available for $ac_help expansion (don't we all *love* autoconf?)
#AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
ifdef([AC_DIVERSION_NOTICE], [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)],
			      [AC_DIVERT_PUSH(NOTICE)])

# Making releases:
#   ID3LIB_PATCH_VERSION += 1;
#   ID3LIB_INTERFACE_AGE += 1;
#   ID3LIB_BINARY_AGE += 1;
# if any functions have been added, set ID3LIB_INTERFACE_AGE to 0.
# if backwards compatibility has been broken,
# set ID3LIB_BINARY_AGE _and_ ID3LIB_INTERFACE_AGE to 0.
#

ID3LIB_MAJOR_VERSION=3
ID3LIB_MINOR_VERSION=8
ID3LIB_PATCH_VERSION=3
ID3LIB_ADDED_VERSION=
ID3LIB_VERSION=$ID3LIB_MAJOR_VERSION.$ID3LIB_MINOR_VERSION.$ID3LIB_PATCH_VERSION$ID3LIB_ADDED_VERSION

ID3LIB_INTERFACE_AGE=0
ID3LIB_BINARY_AGE=0
AC_DIVERT_POP()dnl

AC_SUBST(ID3LIB_NAME)
AC_SUBST(ID3LIB_MAJOR_VERSION)
AC_SUBST(ID3LIB_MINOR_VERSION)
AC_SUBST(ID3LIB_PATCH_VERSION)
AC_SUBST(ID3LIB_VERSION)
AC_SUBST(ID3LIB_INTERFACE_AGE)
AC_SUBST(ID3LIB_BINARY_AGE)

# for documentation purposes
DOX_DIR_HTML=api
DOX_DIR_LATEX=latex
DOX_DIR_MAN=man
DOX_DIR_RTF=rtf

AC_SUBST(DOX_DIR_HTML)
AC_SUBST(DOX_DIR_LATEX)
AC_SUBST(DOX_DIR_MAN)
AC_SUBST(DOX_DIR_RTF)

# libtool versioning
LT_RELEASE=$ID3LIB_MAJOR_VERSION.$ID3LIB_MINOR_VERSION
LT_CURRENT=`expr $ID3LIB_PATCH_VERSION - $ID3LIB_INTERFACE_AGE`
LT_REVISION=$ID3LIB_INTERFACE_AGE
LT_AGE=`expr $ID3LIB_BINARY_AGE - $ID3LIB_INTERFACE_AGE`
AC_SUBST(LT_RELEASE)
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)

VERSION=$ID3LIB_VERSION
PACKAGE=$ID3LIB_NAME

dnl This is a hack to get the release date using cvs checkin macros
ID3LIB_FULLNAME=$ID3LIB_NAME-$ID3LIB_VERSION

AC_SUBST(ID3LIB_FULLNAME)

AM_CONFIG_HEADER(config.h)

AM_INIT_AUTOMAKE($PACKAGE,$VERSION)

AC_ISC_POSIX

dnl Initialize libtool
AM_PROG_LIBTOOL

dnl Initialize maintainer mode
AM_MAINTAINER_MODE

#AC_CANONICAL_HOST

dnl figure debugging default, prior to $ac_help setup
dnl
ifdef([AC_DIVERSION_NOTICE], [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)],
			      [AC_DIVERT_PUSH(NOTICE)])
if test `expr $ID3LIB_MINOR_VERSION \% 2` = 1 ; then
        debug_default=yes
else
        debug_default=minimum
fi
AC_DIVERT_POP()dnl

dnl declare --enable-* args and collect ac_help strings
AC_ARG_ENABLE(ansi,  [  --enable-ansi           turn on strict ansi [default=no]], , enable_ansi=no)
dnl 
AC_SUBST(ID3LIB_DEBUG_FLAGS)

dnl Checks for programs
AC_PROG_CC
AC_PROG_CXX
AC_PROG_CXXCPP
AC_PROG_INSTALL

dnl for executable extensions
AC_EXEEXT

dnl Checks for libraries.
AC_CHECK_LIB(z,uncompress,AC_DEFINE_UNQUOTED(HAVE_ZLIB))#,,
#  AC_MSG_ERROR([id3lib requires zlib to process compressed frames]))

AM_CONDITIONAL(ID3_NEEDZLIB, test x$ac_cv_lib_z_uncompress = xno)
AM_CONDITIONAL(ID3_NEEDDEBUG, test x$enable_debug = xyes)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(zlib.h wchar.h sys/param.h unistd.h )

dnl check wheter iconv is the part of libc.
AC_CHECK_HEADERS( iconv.h, has_iconv=1,  has_iconv=0)

dnl if we have iconv library, we have to decide if it 
dnl is present in libc

ICONV_LIB=
if test $has_iconv = 1; then
  AC_MSG_CHECKING(where to find iconv_open)
  exec 6>/dev/null
  AC_CHECK_FUNCS(iconv_open, iconv_in_libc=1, iconv_in_libc=0)
  AC_CHECK_LIB(iconv, iconv_open, iconv_in_iconv=1, iconv_in_iconv=0)
  AC_CHECK_LIB(iconv, libiconv_open, libiconv_in_iconv=1, libiconv_in_iconv=0)
  if test ! x$silent = xyes; then
    exec 6>&1
  fi
  #standalone library rules over libc
  if test $iconv_in_iconv = 1 -o $libiconv_in_iconv = 1; then
    AC_MSG_RESULT(libiconv)
    ICONV_LIB=-liconv
  elif test $iconv_in_libc = 1; then
    AC_MSG_RESULT(libc)
  else
    AC_MSG_RESULT(not found (panic))
    AC_MSG_ERROR([iconv.h found, while iconv library not found])
  fi
  #we have iconv at this moment, better check which call to use
  AC_MSG_CHECKING(whether iconv takes const char ** or char **)
  AC_TRY_COMPILE([#include <iconv.h>],[
		{
		size_t iconv (iconv_t a, const char ** b, size_t *c, char **d, size_t *e);
		}],
		iconv_oldstyle=1, iconv_oldstyle=0)
  if test $iconv_oldstyle = 1; then
    AC_MSG_RESULT(const char **)
    AC_DEFINE(ID3LIB_ICONV_OLDSTYLE)
    #we'll check out the need of
    #typecast in the call of iconv_open
    AC_MSG_CHECKING(whether to typecast in iconv)
    AC_TRY_COMPILE([#include <iconv.h>],[
                   {
                      const char *src = "nothing";
                      char *outbuf;
                      size_t insize = 0;
                      size_t outsize = 0;
                      iconv_t cd;
                      iconv(cd, &src, &insize, &outbuf, &outsize);
                   }],
                   iconv_cast=0, iconv_cast=1)
    if test $iconv_cast = 1; then
      AC_MSG_RESULT(yes)
      AC_DEFINE(ID3LIB_ICONV_CAST_OK)
    else
      AC_MSG_RESULT(no)
    fi

  else
    AC_MSG_RESULT(char **)
    #we'll check out the need of
    #typecast in the call of iconv_open
    AC_MSG_CHECKING(whether to typecast in iconv)
    AC_TRY_COMPILE([#include <iconv.h>],[
                   {
                      char *src = "nothing";
                      char *outbuf;
                      size_t insize = 0;
                      size_t outsize = 0;
                      iconv_t cd;
                      iconv(cd, &src, &insize, &outbuf, &outsize);
                   }],
                   iconv_cast=0, iconv_cast=1)
    if test $iconv_cast = 1; then
      AC_MSG_RESULT(yes)
      AC_DEFINE(ID3LIB_ICONV_CAST_OK)
    else
      AC_MSG_RESULT(no)
    fi
  fi

fi
if test "x$ICONV_LIB" != "x"; then
  LIBS="$LIBS $ICONV_LIB"
fi

dnl Check for c++ features
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
AC_CHECK_HEADERS(libcw/sys.h)
AC_CHECK_HEADERS(cctype climits cstdio cstdlib bitset cstring)
AC_CHECK_HEADERS(fstream iostream iomanip vector \
	,,AC_MSG_ERROR([Missing a vital header file for id3lib - download them here: http://gcc.gnu.org/libstdc++/ or better - compile a newer compiler like gcc3.x])
)
AC_CHECK_HEADERS(               \
  string                        \
  iomanip.h                     \
  ,,AC_MSG_ERROR([Missing a vital header file for id3lib])
)

dnl Checks for the portability of certain c++ features: the bool type and
dnl for-loop scoping
ID3_CXX_PORTABILITY

ID3_CXX_WARNINGS

AC_LANG_RESTORE

ID3_DEBUG
ID3_UNICODE

dnl Check for functions.

# AC_FUNC_MEMCMP
AC_CHECK_FUNCS(getopt_long)
AM_CONDITIONAL(ID3_NEEDGETOPT_LONG, test x$ac_cv_func_getopt_long = xno)

AC_CHECK_FUNCS(mkstemp)
AC_CHECK_FUNCS(
  truncate                      \
  ,,AC_MSG_ERROR([Missing a vital function for id3lib])
)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T

dnl
dnl Checks with local macros
dnl

dnl Provides a --honor-std option to the configure script that honors the
dnl std namespace.  Must be used AFTER configuring ALL compilers.
dnl LF_HONOR_STD

dnl ACCONFIG TEMPLATE
dnl 
dnl /* config.h defines these preprocesser symbols to be used by id3lib for
dnl  * determining internal versioning information.  The intent is that these
dnl  * macros will be made available in the library via constants, functions,
dnl  * or static methods.
dnl  */
dnl #undef HAVE_ZLIB
dnl #undef HAVE_GETOPT_LONG
dnl #undef _ID3LIB_NAME
dnl #undef _ID3LIB_VERSION
dnl #undef _ID3LIB_FULLNAME
dnl #undef _ID3LIB_MAJOR_VERSION
dnl #undef _ID3LIB_MINOR_VERSION
dnl #undef _ID3LIB_PATCH_VERSION
dnl #undef _ID3LIB_INTERFACE_AGE
dnl #undef _ID3LIB_BINARY_AGE
dnl #undef _ID3_COMPILED_WITH_DEBUGGING
dnl /* */
dnl END ACCONFIG

AC_DEFINE_UNQUOTED(_ID3LIB_NAME,                 "$ID3LIB_NAME")
AC_DEFINE_UNQUOTED(_ID3LIB_VERSION,              "$ID3LIB_VERSION")
AC_DEFINE_UNQUOTED(_ID3LIB_FULLNAME,             "$ID3LIB_FULLNAME")
AC_DEFINE_UNQUOTED(_ID3LIB_MAJOR_VERSION,         $ID3LIB_MAJOR_VERSION)
AC_DEFINE_UNQUOTED(_ID3LIB_MINOR_VERSION,         $ID3LIB_MINOR_VERSION)
AC_DEFINE_UNQUOTED(_ID3LIB_PATCH_VERSION,         $ID3LIB_PATCH_VERSION)
AC_DEFINE_UNQUOTED(_ID3LIB_INTERFACE_AGE,         $ID3LIB_INTERFACE_AGE)
AC_DEFINE_UNQUOTED(_ID3LIB_BINARY_AGE,            $ID3LIB_BINARY_AGE)
AC_DEFINE_UNQUOTED(_ID3_COMPILED_WITH_DEBUGGING, "${enable_debug}")

CONDITIONAL_SUBDIRS=
if test "x$ac_cv_lib_z_uncompress" = "xno"; then
  CONDITIONAL_SUBDIRS="$CONDITIONAL_SUBDIRS zlib"
fi
AC_CONFIG_SUBDIRS(zlib)

CFLAGS="$CFLAGS -Wall"

AC_OUTPUT(                      \
  Makefile                      \
  doc/Makefile                  \
  m4/Makefile                   \
  include/Makefile              \
  include/id3/Makefile          \
  id3com/Makefile               \
  id3com/Sample/Makefile        \
  src/Makefile                  \
  examples/Makefile             \
  prj/Makefile			\
  libprj/Makefile
)
