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

dnl version number
MAJOR_VERSION=1
MINOR_VERSION=8
MICRO_VERSION=12
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(VMAID_BUILD_ENVIRONMENT, "${host}")

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

dnl **************************************************************
dnl Checks for programs.
dnl **************************************************************
dnl AC_ARG_PROGRAM
AC_PROG_AWK
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
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)
fi

dnl **************************************************************
dnl Check for GTK+.
dnl **************************************************************
AC_ARG_ENABLE(gtk2,
  [  --enable-gtk2[=ARG]     Use Gtk+-2.0 [ARG=yes/no/auto] default=auto])
if test "$enable_gtk2" = "no"; then
  if test "$enable_thread" == "yes"; then
    AM_PATH_GTK(1.2.0,,AC_MSG_ERROR(Test for GTK+ failed.),gthread)
  else
    AM_PATH_GTK(1.2.0,,AC_MSG_ERROR(Test for GTK+ failed.))
  fi
elif test "$enable_gtk2" != "yes"; then
  if test "$enable_thread" == "yes"; then
    AM_PATH_GTK(1.2.0,enable_gtk2="no",enable_gtk2="yes",gthread)
  else
    AM_PATH_GTK(1.2.0,enable_gtk2="no",enable_gtk2="yes")
  fi
fi
if test "$enable_gtk2" = "yes"; then
  if test "$enable_thread" == "yes"; then
    AM_PATH_GTK_2_0(2.0.0,AC_DEFINE(USE_GTK2),AC_MSG_ERROR(Test for GTK+-2.0 failed.),gthread)
  else
    AM_PATH_GTK_2_0(2.0.0,AC_DEFINE(USE_GTK2),AC_MSG_ERROR(Test for GTK+-2.0 failed.))
  fi
fi

dnl **************************************************************
dnl enable/disable Win32 codec support.
dnl **************************************************************
AC_ARG_WITH(w32,
  [  --with-w32[=DIR]        support Win32])
if test -z "$with_w32" || test "$with_w32" = "yes"; then
  if test -d "${prefix}/lib/win32"; then
    with_w32="${prefix}/lib/win32"
  elif test -d "/usr/local/lib/win32"; then
    with_w32="/usr/local/lib/win32"
  elif test -d "/usr/lib/win32"; then
    with_w32="/usr/lib/win32"
  fi
  if test "$with_w32" = "yes"; then
    with_w32="${libdir}/win32"
  fi
fi
if test -z "$with_w32"; then
  with_w32="no"
else
  dnl ***  check for i386_set_ldt supported by *BSD.
  AC_CHECK_LIB(i386,i386_set_ldt,AC_DEFINE(HAVE_I386_SET_LDT, 1) LIBS="$LIBS -li386",AC_CHECK_LIB(c,i386_set_ldt,AC_DEFINE(HAVE_I386_SET_LDT, 1)))
  dnl ***  check for thread-safe libraly supported by *BSD.
  AC_CHECK_LIB(pthread,pthread_create,LIBS="$LIBS -pthread",AC_CHECK_LIB(c_r,pthread_create,LIBS="$LIBS -pthread"))
fi
AM_CONDITIONAL(WITH_W32,test "$with_w32" != "no")
if test "$with_w32" != "no"; then
  w32codecdir="$with_w32"
  AC_SUBST(w32codecdir)
fi

dnl **************************************************************
dnl enable/disable  native codec support.
dnl **************************************************************
AC_MSG_CHECKING(--enable-codec)
AC_ARG_ENABLE(codec, [  --enable-codec         native codec support.])
AC_MSG_RESULT($enable_codec)
AM_CONDITIONAL(USE_CODEC,[test "x$enable_codec" = xyes])
dnl AC_SUBST(USE_CODEC)
if test "x$enable_codec" = "xyes"; then
  AC_DEFINE(USE_CODEC)
fi 
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 sysconfdir.
dnl **************************************************************
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(bits/sigset.h fcntl.h pthread.h strings.h sys/file.h sys/stat.h sys/types.h unistd.h)

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

dnl **************************************************************
dnl Checks for library functions.
dnl **************************************************************
AC_FUNC_MEMCMP
AC_FUNC_MMAP
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(flock strstr)

AC_OUTPUT([
Makefile
avicore/Makefile
dllloader/Makefile
intl/Makefile
m4/Makefile
misc/Makefile
po/Makefile.in
src/Makefile
])

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

   Package      : ${PACKAGE}
   Version      : ${VERSION}
   C Compiler   : ${CC} ${CFLAGS}
   Install path : ${prefix}
   Gtk+-2.0     : ${enable_gtk2}
   Multi thread : ${enable_thread}
   Win32 codec  : ${with_w32}
   Config       : ${sysconfdir}
   Locale       : ${localedir}
   Environment  : ${host}
])
