dnl $Id$
dnl
dnl Copyright (c) 2004-2007
dnl         The Thunar development team. All rights reserved.
dnl
dnl Written for Thunar by Benedikt Meurer <benny@xfce.org>.
dnl

dnl ***************************
dnl *** Version information ***
dnl ***************************
m4_define([thunar_verinfo], [4:2:2])
m4_define([thunar_version_api], [1])
m4_define([thunar_version_major], [0])
m4_define([thunar_version_minor], [8])
m4_define([thunar_version_micro], [1])
m4_define([thunar_version_build], [r@REVISION@])
m4_define([thunar_version_tag], [svn])
m4_define([thunar_version], [thunar_version_major().thunar_version_minor().thunar_version_micro()ifelse(thunar_version_tag(), [svn], [thunar_version_tag()-thunar_version_build()], [thunar_version_tag()])])

dnl *******************************************
dnl *** Debugging support for SVN snapshots ***
dnl *******************************************
m4_define([thunar_debug_default], [ifelse(thunar_version_tag(), [svn], [yes], [minimum])])

dnl ***************************
dnl *** Initialize autoconf ***
dnl ***************************
AC_COPYRIGHT([Copyright (c) 2004-2007
        The Thunar development team. All rights reserved.
        
Written for Thunar by Benedikt Meurer <benny@xfce.org>.])
AC_INIT([Thunar], [thunar_version()], [http://bugzilla.xfce.org/], [Thunar])
AC_PREREQ([2.50])
AC_CANONICAL_TARGET()
AC_REVISION([$Id$])

dnl ***************************
dnl *** Initialize automake ***
dnl ***************************
AM_INIT_AUTOMAKE([1.8 dist-bzip2 tar-ustar])
AM_CONFIG_HEADER([config.h])
AM_MAINTAINER_MODE()

dnl *******************************
dnl *** Check for UNIX variants ***
dnl *******************************
AC_AIX()
AC_ISC_POSIX()
AC_MINIX()

dnl ********************************
dnl *** Check for basic programs ***
dnl ********************************
AC_PROG_CC()
AC_PROG_LD()
AC_PROG_INSTALL()
AC_PROG_INTLTOOL()
AC_CHECK_PROGS([PERL], [perl5 perl])

dnl **************************
dnl *** Initialize libtool ***
dnl **************************
AC_DISABLE_STATIC()
AC_PROG_LIBTOOL()

dnl **************************************
dnl *** Substitute version information ***
dnl **************************************
THUNAR_VERINFO=thunar_verinfo()
THUNAR_VERSION_API=thunar_version_api()
THUNAR_VERSION_MAJOR=thunar_version_major()
THUNAR_VERSION_MINOR=thunar_version_minor()
THUNAR_VERSION_MICRO=thunar_version_micro()
AC_SUBST([THUNAR_VERINFO])
AC_SUBST([THUNAR_VERSION_API])
AC_SUBST([THUNAR_VERSION_MAJOR])
AC_SUBST([THUNAR_VERSION_MINOR])
AC_SUBST([THUNAR_VERSION_MICRO])

dnl ***********************************************
dnl *** Determine the u32 type required for tdb ***
dnl ***********************************************
AC_CHECK_SIZEOF([int])
AC_CHECK_SIZEOF([long])
AC_CHECK_SIZEOF([short])
AC_MSG_CHECKING([for 32bit unsigned integer])
case 4 in
$ac_cv_sizeof_int)   TDB_U32_TYPE="unsigned int" ;;
$ac_cv_sizeof_long)  TDB_U32_TYPE="unsigned long" ;;
$ac_cv_sizeof_short) TDB_U32_TYPE="unsigned short" ;;
esac
AC_SUBST([TDB_U32_TYPE])
AC_MSG_RESULT([$TDB_U32_TYPE])

dnl ***********************************************
dnl *** Work-around system-specific limitations ***
dnl ***********************************************
AC_SYS_LARGEFILE()

dnl **********************************
dnl *** Check for standard headers ***
dnl **********************************
AC_CHECK_HEADERS([ctype.h dirent.h errno.h fcntl.h fnmatch.h fstab.h grp.h \
                  limits.h locale.h math.h memory.h mntent.h paths.h pwd.h \
                  regex.h sched.h setjmp.h signal.h stdarg.h stdlib.h \
                  string.h syslog.h sys/xattr.h sys/extattr.h sys/cdio.h \
                  sys/mman.h sys/mount.h sys/param.h sys/resource.h sys/stat.h \
                  sys/statfs.h sys/statvfs.h sys/time.h sys/ucred.h sys/uio.h \
                  sys/vfs.h sys/wait.h time.h wchar.h wctype.h])

dnl ************************************
dnl *** Check for standard functions ***
dnl ************************************
AC_FUNC_MMAP()
AC_CHECK_FUNCS([attropen extattr_get_fd fgetxattr futimes getdents getfsspec \
                getfsstat lchmod localeconv localtime_r mbrtowc mkdtemp mkfifo \
                posix_madvise pread pwrite readdir_r sched_yield setgroupent \
                setmntent setpassent setpriority statfs statvfs statvfs1 \
                strcoll strlcpy strptime symlink syslog])

dnl ******************************************
dnl *** Linux/glibc specified work-arounds ***
dnl ******************************************
AC_MSG_CHECKING([whether we need _BSD_SOURCE and _XOPEN_SOURCE])
AC_TRY_LINK([#include <features.h>],
[
  if (__GLIBC_PREREQ (2, 0));
],
[
  AC_DEFINE([_XOPEN_SOURCE], [600], [Required to unbreak glibc])
  AC_DEFINE([_BSD_SOURCE], [1], [Required to unbreak glibc])
  AC_MSG_RESULT([yes])
],
[
  AC_MSG_RESULT([no])
])

dnl **************************************************************
dnl *** Check for f_mntonname in statfs (trash implementation) ***
dnl **************************************************************
AC_CHECK_MEMBERS([struct statfs.f_mntonname],,,
[
#include <sys/param.h>
#include <sys/mount.h>
])

dnl ******************************
dnl *** Check for i18n support ***
dnl ******************************
XDT_I18N([@LINGUAS@])

dnl ***********************************
dnl *** Check for required packages ***
dnl ***********************************
XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.2])
XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.6.4])
XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.6.4])
XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.6.0])
XDT_CHECK_PACKAGE([GDK_PIXBUF], [gdk-pixbuf-2.0], [2.6.0])
XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.2.2])

dnl *********************************************
dnl *** Check for libpng (with various names) ***
dnl *********************************************
XDT_CHECK_PACKAGE([LIBPNG], [libpng], [1.2.0], [],
[
  dnl # libpng.pc not found, try with libpng12.pc
  XDT_CHECK_PACKAGE([LIBPNG], [libpng12], [1.2.0])
])

dnl ********************************************
dnl *** Check for session management support ***
dnl ********************************************
XDT_CHECK_LIBSM()

dnl **********************************
dnl *** Optional support for D-BUS ***
dnl **********************************
XDT_CHECK_OPTIONAL_PACKAGE([DBUS], [dbus-glib-1],
                           [0.34], [dbus], [D-BUS support])

dnl *******************************************************
dnl *** Optional support for gconf (GNOME thumbnailers) ***
dnl *******************************************************
XDT_CHECK_OPTIONAL_PACKAGE([GCONF], [gconf-2.0],
                           [2.4.0], [gnome-thumbnailers],
                           [GNOME thumbnailer support])

dnl *************************************************
dnl *** Optional support for startup notification ***
dnl *************************************************
XDT_CHECK_OPTIONAL_PACKAGE([LIBSTARTUP_NOTIFICATION],
                           [libstartup-notification-1.0],
                           [0.4], [startup-notification],
                           [startup notification library])

dnl ******************************
dnl *** Check for FreeType 2.x ***
dnl ******************************
FREETYPE_LIBS=""
FREETYPE_CFLAGS=""
AC_PATH_PROG([FREETYPE_CONFIG], [freetype-config], [no])
if test x"$FREETYPE_CONFIG" != x"no"; then
  AC_MSG_CHECKING([FREETYPE_CFLAGS])
  FREETYPE_CFLAGS="`$FREETYPE_CONFIG --cflags`"
  AC_MSG_RESULT([$FREETYPE_CFLAGS])

  AC_MSG_CHECKING([FREETYPE_LIBS])
  FREETYPE_LIBS="`$FREETYPE_CONFIG --libs`"
  AC_MSG_RESULT([$FREETYPE_LIBS])
fi
AM_CONDITIONAL([HAVE_FREETYPE], [test x"$FREETYPE_CONFIG" != x"no"])
AC_SUBST([FREETYPE_CFLAGS])
AC_SUBST([FREETYPE_LIBS])

dnl *************************
dnl *** Check for libjpeg ***
dnl *************************
LIBJPEG_LIBS=""
LIBJPEG_CFLAGS=""
AC_CHECK_LIB([jpeg], [jpeg_start_decompress],
[
  AC_CHECK_HEADER([jpeglib.h],
  [
    LIBJPEG_LIBS="-ljpeg -lm"
    AC_DEFINE([HAVE_LIBJPEG], [1], [Define to 1 if libjpeg is found])
    AC_DEFINE([HAVE_JPEGLIB_H], [1], [Define to 1 if jpeglib.h is found])
  ])
], [-lm])
AC_SUBST([LIBJPEG_CFLAGS])
AC_SUBST([LIBJPEG_LIBS])

dnl *************************
dnl *** Check for gtk-doc ***
dnl *************************
GTK_DOC_CHECK([1.0])

dnl **************************
dnl *** Check for xsltproc ***
dnl **************************
AC_ARG_ENABLE([xsltproc], [AC_HELP_STRING([--enable-xsltproc], [Use xsltproc to build documentation @<:@default=no@:>@])],, [enable_xsltproc=no])
if test x"$enable_xsltproc" = x"yes"; then
  AC_PATH_PROG([XSLTPROC], [xsltproc], [no])
  if test x"$XSLTPROC" = x"no"; then
    enable_xsltproc=no
  fi
fi
AM_CONDITIONAL([ENABLE_XSLTPROC], [test x"$enable_xsltproc" = x"yes"])

dnl ************************
dnl *** Check for xml2po ***
dnl ************************
AC_ARG_ENABLE([xml2po], [AC_HELP_STRING([--enable-xml2po], [Use xml2po to translate documentation @<:@default=no@:>@])],, [enable_xml2po=no])
if test x"$enable_xml2po" = x"yes"; then
  AC_PATH_PROG([XML2PO], [xml2po], [no])
  if test x"$XML2PO" = x"no"; then
    enable_xml2po=no
  fi
fi
AM_CONDITIONAL([ENABLE_XML2PO], [test x"$enable_xml2po" = x"yes"])

dnl ******************************************
dnl *** Check for operating system support ***
dnl ******************************************
BM_THUNAR_VFS_OS_IMPL()

dnl ****************************************************
dnl *** Check for file system monitor implementation ***
dnl ****************************************************
BM_THUNAR_VFS_MONITOR_IMPL()

dnl ***********************************************
dnl *** Check for volume manager implementation ***
dnl ***********************************************
BM_THUNAR_VFS_VOLUME_IMPL()

dnl ***********************************
dnl *** Check for debugging support ***
dnl ***********************************
AC_ARG_ENABLE([debug],
AC_HELP_STRING([--enable-debug=@<:@no/minimum/yes/full@:>@], [Turn on debugging @<:@default=thunar_debug_default@:>@]),
  [], [enable_debug=thunar_debug_default])
AC_MSG_CHECKING([whether to enable debugging support])
if test x"$enable_debug" = x"full" -o x"$enable_debug" = x"yes"; then
  dnl Print the result
  AC_MSG_RESULT([$enable_debug])

  dnl Make sure we detect possible errors (if supported)
  save_CFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS -Wall -Werror"
  AC_MSG_CHECKING([whether $CC accepts -Wall -Werror])
  AC_COMPILE_IFELSE(AC_LANG_SOURCE([int x;]), [
    AC_MSG_RESULT([yes])
    PLATFORM_CFLAGS="$PLATFORM_CFLAGS -Wall -Werror"
  ], [
    AC_MSG_RESULT([no])
  ])
  CFLAGS="$save_CFLAGS"

  dnl Paranoia for --enable-debug=full
  if test x"$enable_debug" = x"full"; then
    dnl Enable extensive debugging
    PLATFORM_CPPFLAGS="$PLATFORM_CPPFLAGS -DG_ENABLE_DEBUG"

    dnl Use -O0 -g3 if the compiler supports it
    save_CFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS -O0 -g3"
    AC_MSG_CHECKING([whether $CC accepts -O0 -g3])
    AC_COMPILE_IFELSE(AC_LANG_SOURCE([int x;]), [
      AC_MSG_RESULT([yes])
      PLATFORM_CFLAGS="$PLATFORM_CFLAGS -O0 -g3"
    ], [
      AC_MSG_RESULT([no])
    ])
    CFLAGS="$save_CFLAGS"
  fi
else
  dnl Print the result
  AC_MSG_RESULT([$enable_debug])

  dnl Disable debugging (release build)
  PLATFORM_CPPFLAGS="$PLATFORM_CPPFLAGS -DNDEBUG"

  dnl Disable object cast checks
  PLATFORM_CPPFLAGS="$PLATFORM_CPPFLAGS -DG_DISABLE_CAST_CHECKS"

  dnl Disable all checks for --enable-debug=no
  if test x"$enable_debug" = x"no"; then
    PLATFORM_CPPFLAGS="$PLATFORM_CPPFLAGS -DG_DISABLE_ASSERT -DG_DISABLE_CHECKS"
  fi
fi

dnl **************************************
dnl *** Check for linker optimizations ***
dnl **************************************
AC_MSG_CHECKING([whether $LD accepts --as-needed])
case `$LD --as-needed -v 2>&1 </dev/null` in
*GNU* | *'with BFD'*)
  LDFLAGS="$LDFLAGS -Wl,--as-needed"
  AC_MSG_RESULT([yes])
  ;;
*)
  AC_MSG_RESULT([no])
  ;;
esac
AC_MSG_CHECKING([whether $LD accepts -O1])
case `$LD -O1 -v 2>&1 </dev/null` in
*GNU* | *'with BFD'*)
  PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -Wl,-O1"
  AC_MSG_RESULT([yes])
  ;;
*)
  AC_MSG_RESULT([no])
  ;;
esac

dnl ****************************************
dnl *** Check for ELF visibility support ***
dnl ****************************************
AC_ARG_ENABLE([visibility], AC_HELP_STRING([--disable-visibility], [Don't use ELF visibility attributes]), [], [enable_visibility=yes])
have_gnuc_visibility=no
if test x"$enable_visibility" != x"no"; then
  dnl Check whether the compiler supports the visibility attribute
  save_CFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS -Wall -Werror"
  AC_MSG_CHECKING([whether $CC supports the GNUC visibility attribute])
  AC_COMPILE_IFELSE(AC_LANG_SOURCE(
  [
    void __attribute__ ((visibility("default"))) test_default (void) {}
    void __attribute__ ((visibility("hidden"))) test_hidden (void) {}
    int main (int argc, char **argv) { test_default (); test_hidden (); return 0; }
  ]),
  [
    have_gnuc_visibility=yes
    AC_MSG_RESULT([yes])
  ],
  [
    AC_MSG_RESULT([no])
  ])
  CFLAGS="$save_CFLAGS"
fi
if test x"$have_gnuc_visibility" = x"yes"; then
  PLATFORM_CPPFLAGS="$PLATFORM_CPPFLAGS -DHAVE_GNUC_VISIBILITY"
fi
AM_CONDITIONAL([HAVE_GNUC_VISIBILITY], [test x"$have_gnuc_visibility" = x"yes"])

dnl *********************************
dnl *** Substitute platform flags ***
dnl *********************************
AC_MSG_CHECKING([PLATFORM_CPPFLAGS])
AC_MSG_RESULT([$PLATFORM_CPPFLAGS])
AC_SUBST([PLATFORM_CPPFLAGS])
AC_MSG_CHECKING([PLATFORM_CFLAGS])
AC_MSG_RESULT([$PLATFORM_CFLAGS])
AC_SUBST([PLATFORM_CFLAGS])
AC_MSG_CHECKING([PLATFORM_LDFLAGS])
AC_MSG_RESULT([$PLATFORM_LDFLAGS])
AC_SUBST([PLATFORM_LDFLAGS])

dnl ************************************
dnl *** Check for additional plugins ***
dnl ************************************
BM_THUNAR_PLUGIN_APR()
BM_THUNAR_PLUGIN_SBR()
BM_THUNAR_PLUGIN_TPA()
BM_THUNAR_PLUGIN_UCA()

AC_OUTPUT([
Makefile
Thunar.spec
docs/Makefile
docs/design/Makefile
docs/manual/Makefile
docs/manual/C/Makefile
docs/manual/C/Thunar.xml
docs/manual/C/images/Makefile
docs/manual/es/Makefile
docs/manual/es/Thunar.xml
docs/manual/es/images/Makefile
docs/manual/eu/Makefile
docs/manual/eu/Thunar.xml
docs/manual/eu/images/Makefile
docs/manual/fr/Makefile
docs/manual/fr/Thunar.xml
docs/manual/fr/images/Makefile
docs/manual/ja/Makefile
docs/manual/ja/Thunar.xml
docs/manual/ja/images/Makefile
docs/manual/pl/Makefile
docs/manual/pl/Thunar.xml
docs/manual/pl/images/Makefile
docs/manual/ru/Makefile
docs/manual/ru/Thunar.xml
docs/manual/ru/images/Makefile
docs/manual/zh_TW/Makefile
docs/manual/zh_TW/Thunar.xml
docs/manual/zh_TW/images/Makefile
docs/papers/Makefile
docs/reference/Makefile
docs/reference/thunar-vfs/Makefile
docs/reference/thunar-vfs/version.xml
docs/reference/thunarx/Makefile
docs/reference/thunarx/version.xml
examples/Makefile
examples/tex-open-terminal/Makefile
icons/Makefile
icons/16x16/Makefile
icons/24x24/Makefile
icons/48x48/Makefile
icons/scalable/Makefile
pixmaps/Makefile
plugins/Makefile
plugins/thunar-apr/Makefile
plugins/thunar-sbr/Makefile
plugins/thunar-sendto-email/Makefile
plugins/thunar-tpa/Makefile
plugins/thunar-uca/Makefile
po/Makefile.in
po-doc/Makefile
tdb/Makefile
tdb/tdbconfig.h
tests/Makefile
tests/data/Makefile
thunar/Makefile
thunar-vfs/Makefile
thunar-vfs/thunar-vfs-1.pc
thunar-vfs/thunar-vfs-config.h
thunarx/Makefile
thunarx/thunarx-1.pc
thunarx/thunarx-config.h
])

dnl ***************************
dnl *** Print configuration ***
dnl ***************************
echo
echo "Build Configuration:"
echo
echo "* Operating system support:  $ac_bm_thunar_vfs_os_impl"
if test x"$DBUS_FOUND" = x"yes"; then
echo "* D-BUS support:             yes"
else
echo "* D-BUS support:             no"
fi
echo "* File System Monitor:       $ac_bm_thunar_vfs_monitor_impl"
if test x"$GCONF_FOUND" = x"yes"; then
echo "* GNOME Thumbnailers:        yes"
else
echo "* GNOME Thumbnailers:        no"
fi
if test x"$LIBSTARTUP_NOTIFICATION_FOUND" = x"yes"; then
echo "* Startup Notification:      yes"
else
echo "* Startup Notification:      no"
fi
echo "* Volume Manager:            $ac_bm_thunar_vfs_volume_impl"
echo "* Debug Support:             $enable_debug"
echo
echo "Additional Plugins:"
echo
echo "* Advanced Properties:       $ac_bm_thunar_plugin_apr"
echo "* Simple Builting Renamers:  $ac_bm_thunar_plugin_sbr"
echo "* Trash Panel Applet:        $ac_bm_thunar_plugin_tpa"
echo "* User Customizable Actions: $ac_bm_thunar_plugin_uca"
echo
