dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/vmaid.c)
PACKAGE=vmaid

dnl version number
MAJOR_VERSION=2
MINOR_VERSION=1
MICRO_VERSION=0
EXTRA_VERSION=
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION

AM_INIT_AUTOMAKE($PACKAGE,$VERSION)
AC_DEFINE_UNQUOTED(PACKAGE,"$PACKAGE")
AC_DEFINE_UNQUOTED(VERSION,"$VERSION")

dnl Getting the Canonical System Type
AC_CANONICAL_HOST
AC_DEFINE_UNQUOTED(BUILD_ENVIRONMENT,"${host}",Define to the build environment.)

dnl Specify a header configuration file
AM_CONFIG_HEADER(config.h)

dnl **************************************************************
dnl Checks for programs.
dnl **************************************************************
AC_PROG_CC
AC_PROG_INSTALL
AC_ISC_POSIX
AC_PROG_MAKE_SET
AM_MAINTAINER_MODE

dnl **************************************************************
dnl libtool
dnl **************************************************************
AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no)
AM_PROG_LIBTOOL

dnl **************************************************************
dnl Check for Multi thread.
dnl **************************************************************
AC_ARG_ENABLE(thread,
  [  --enable-thread[=ARG]     Use Multi thread [ARG=yes/no] default=yes])
if test "$enable_thread" != 'no'; then
  enable_thread='yes'
  AC_DEFINE(USE_THREAD,1,Define to 1 if enable thread.)
fi

dnl **************************************************************
dnl Check for GTK+.
dnl **************************************************************
if test "$enable_thread" = 'yes'; then
  AM_PATH_GTK_2_0(2.0.0,,AC_MSG_ERROR(Test for GTK+-2.0 failed.),gthread)
else
  AM_PATH_GTK_2_0(2.0.0,,AC_MSG_ERROR(Test for GTK+-2.0 failed.))
fi

dnl **************************************************************
dnl enable/disable libao support.
dnl **************************************************************
AC_ARG_WITH(libao,
  [  --with-libao[=ARG]        Use libao [ARG=yes/no] default=auto])
if test "$with_alsa" != 'yes'; then
  if test -z "$with_libao" & test "$enable_thread" = 'yes'; then
    XIPH_PATH_AO(with_libao='yes',with_alsa='no')
  elif test "$with_libao" = 'yes'; then
    if test "$enable_thread" != 'yes'; then
      AC_MSG_ERROR(libao needs Multi thread.)
    fi
    XIPH_PATH_AO(with_libao='yes',AC_MSG_ERROR(Test for libao failed.))
  fi
else
  with_libao='no'
fi
if test "$with_libao" = 'yes'; then
  AC_DEFINE(USE_LIBAO,1,Define to 1 if enable libao.)
else
  with_libao='no'
fi

dnl **************************************************************
dnl enable/disable ALSA support.
dnl **************************************************************
AC_ARG_WITH(alsa,
  [  --with-alsa[=ARG]         Use ALSA [ARG=yes/no] default=auto])
if test "$with_libao" != 'yes'; then
  if test -z "$with_alsa" & test "$enable_thread" = 'yes'; then
    AM_PATH_ALSA(0.9.0,with_alsa='yes',with_alsa='no')
  elif test "$with_alsa" = 'yes'; then
    if test "$enable_thread" != 'yes'; then
      AC_MSG_ERROR(ALSA needs Multi thread.)
    fi
    AM_PATH_ALSA(0.9.0,with_alsa='yes',AC_MSG_ERROR(Test for ALSA failed.))
  fi
else
  with_alsa='no'
fi
if test "$with_alsa" = 'yes'; then
  AC_DEFINE(USE_ALSA,1,Define to 1 if enable ALSA.)
else
  with_alsa='no'
fi

dnl **************************************************************
dnl enable/disable Win32 codec support.
dnl **************************************************************
AC_ARG_WITH(w32,
  [  --with-w32[=ARG]          Use W32Loader [ARG=yes/no] default=auto])
if test -z "$with_w32"; then
  case "$host" in
    i*86-*-linux*)
      with_w32='yes'
      ;;
    *)
      with_w32='no'
      ;;
  esac
fi
if test "$with_w32" = 'yes'; then
  AC_DEFINE(USE_W32LDR,1,Define to 1 if enable w32loader.)
else
  with_w32='no'
fi
AM_CONDITIONAL(WITH_W32,test "$with_w32" = 'yes')

dnl **************************************************************
dnl Check for Mime globs file.
dnl **************************************************************
AC_ARG_ENABLE(mime,
  [  --enable-mime[=FILE]      Enable mime globs file])
if test -z "$enable_mime" || test "$enable_mime" = 'yes'; then
  if test -f "${datadir}/mime/globs"; then
    mimefile="${datadir}/mime/globs"
  elif test -f '/usr/local/share/mime/globs'; then
    mimefile='/usr/local/share/mime/globs'
  elif test -f '/usr/share/mime/globs'; then
    mimefile='/usr/share/mime/globs'
  elif test "$enable_mime" = 'yes'; then
    mimefile="${datadir}/mime/globs"
  fi
elif test "$enable_mime" != 'no'; then
  mimefile="$enable_mime"
fi
if test -n "$mimefile"; then
  enable_mime='yes'
else
  enable_mime='no'
fi
AM_CONDITIONAL(ENABLE_MIME,test "$enable_mime" = 'yes')
AC_SUBST(mimefile)

dnl **************************************************************
dnl add /usr/local/include to $CFLAGS.
dnl Only when the directory exists and it wasn't there yet.
dnl **************************************************************
if test -d /usr/local/include; then
  tt=`echo "$CFLAGS" | sed -e 's+-I/usr/local/include ++g' -e 's+-I/usr/local/include$++g'`
  if test "$tt" = "$CFLAGS"; then
    CFLAGS="$CFLAGS -I/usr/local/include"
  fi
fi
if test -d /usr/local/lib; then
  tt=`echo "$CFLAGS" | sed -e 's+-L/usr/local/lib ++g' -e 's+-L/usr/local/lib$++g'`
  if test "$tt" = "$CFLAGS"; then
    CFLAGS="$CFLAGS -L/usr/local/lib"
  fi
fi

dnl **************************************************************
dnl Check for directories.
dnl **************************************************************
AC_SUBST(bindir)
AC_SUBST(libdir)
AC_SUBST(sysconfdir)

dnl **************************************************************
dnl Check for gettext.
dnl **************************************************************
ALL_LINGUAS='ja'
  my_save_CFLAGS="$CFLAGS"
AC_CHECK_LIB(intl, libintl_nl_domain_bindings, CFLAGS="$CFLAGS -D_nl_domain_bindings=libintl_nl_domain_bindings")
AM_GNU_GETTEXT
  CFLAGS="$my_save_CFLAGS"
AC_CHECK_FUNC(gettext,,AC_CHECK_LIB(intl,gettext))
localedir="${datadir}/locale"
AC_SUBST(localedir)

dnl **************************************************************
dnl Checks for header files.
dnl **************************************************************
AC_HEADER_STDC
AC_CHECK_HEADERS(arpa/inet.h arpa/nameser.h complex.h fcntl.h netdb.h netinet/in.h resolv.h strings.h sys/file.h sys/select.h sys/socket.h sys/stat.h sys/time.h sys/timeb.h sys/types.h unistd.h utime.h)

dnl **************************************************************
dnl Checks for typedefs, structures, and compiler characteristics.
dnl **************************************************************
AC_C_CONST
AC_C_VOLATILE
AC_STRUCT_TM
AC_TYPE_SIZE_T
if test "$CC" = 'gcc'; then
  CFLAGS="$CFLAGS -Wall"
fi

dnl **************************************************************
dnl Checks for library functions.
dnl **************************************************************
AC_FUNC_ALLOCA
AC_FUNC_MEMCMP
AC_FUNC_MKTIME
AC_FUNC_SETVBUF_REVERSED
AC_FUNC_STAT
AC_FUNC_STRCOLL
AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(flock ftruncate utime)

AC_OUTPUT([
Makefile
Makefile.msc
doc/Makefile
doc/en/Makefile
doc/ja/Makefile
intl/Makefile
po/Makefile.in
avicore/Makefile
w32loader/Makefile
misc/Makefile
orz/Makefile
src/Makefile
])

dnl **************************************************************
dnl Show some info.
dnl **************************************************************
AC_MSG_RESULT([
Configure Result :

   Package      : ${PACKAGE}
   Version      : ${VERSION}
   C Compiler   : ${CC} ${CFLAGS}
   Install path : ${prefix}
   Binary       : ${bindir}
   Library      : ${libdir}
   Config       : ${sysconfdir}
   Locale       : ${localedir}
   Mime globs   : ${mimefile}
   Multi thread : ${enable_thread}
   libao        : ${with_libao}
   ALSA         : ${with_alsa}
   Win32 codec  : ${with_w32}
   Environment  : ${host}
])
