dnl $Id: configure.in.in 17966 2005-10-03 10:43:54Z benny $
dnl
dnl Copyright (c) 2004-2005
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], [0:0:0])
m4_define([thunar_version_api], [1])
m4_define([thunar_version_major], [0])
m4_define([thunar_version_minor], [1])
m4_define([thunar_version_micro], [2])
m4_define([thunar_version_build], [r00119])
m4_define([thunar_version_tag], [svn])
m4_define([thunar_version], [thunar_version_major().thunar_version_minor().thunar_version_micro()ifelse(thunar_version_tag(), [], [], [thunar_version_tag()-thunar_version_build()])])

dnl ***************************
dnl *** Initialize autoconf ***
dnl ***************************
AC_COPYRIGHT([Copyright (c) 2004-2005
        The Thunar development team. All rights reserved.
        
Written for Thunar by Benedikt Meurer <benny@xfce.org>.])
AC_INIT([Thunar], [thunar_version()], [benny@xfce.org], [Thunar])
AC_PREREQ([2.50])
AC_CANONICAL_TARGET()
AC_REVISION([$Id: configure.in.in 17966 2005-10-03 10:43:54Z benny $])

dnl ***************************
dnl *** Initialize automake ***
dnl ***************************
AM_INIT_AUTOMAKE([AC_PACKAGE_TARNAME()], [AC_PACKAGE_VERSION()])
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 *** Check for standard headers ***
dnl **********************************
AC_CHECK_HEADERS([dirent.h errno.h fcntl.h fnmatch.h fstab.h grp.h locale.h \
                  math.h memory.h mmintrin.h pwd.h stdlib.h string.h \
                  sys/xattr.h sys/extattr.h sys/cdio.h sys/mman.h \
                  sys/mount.h sys/stat.h sys/time.h sys/param.h time.h])

dnl ************************************
dnl *** Check for standard functions ***
dnl ************************************
AC_FUNC_MMAP()
AC_CHECK_FUNCS([attropen extattr_get_fd fgetxattr lchmod localtime_r readdir_r \
                setgroupent setpassent])

dnl ***************************************
dnl *** Check for working posix_madvise ***
dnl ***************************************
m4_define([posix_madvise_test],
[
posix_madvise (0, 0, POSIX_MADV_NORMAL);
posix_madvise (0, 0, POSIX_MADV_SEQUENTIAL);
posix_madvise (0, 0, POSIX_MADV_RANDOM);
posix_madvise (0, 0, POSIX_MADV_WILLNEED);
posix_madvise (0, 0, POSIX_MADV_DONTNEED);
])
AC_MSG_CHECKING([for working posix_madvise])
AC_TRY_LINK([#include <sys/mman.h>], posix_madvise_test(),
[
  AC_DEFINE([HAVE_POSIX_MADVISE], [1], [Define if posix_madvise is working])
  AC_MSG_RESULT([yes])
],
[
  dnl As usual, Linux/glibc doesn't work properly out-of-the-box
  ac_save_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$CPPFLAGS -D__USE_XOPEN2K"
  AC_TRY_LINK([#include <sys/mman.h>], posix_madvise_test(),
  [
    AC_DEFINE([HAVE_POSIX_MADVISE], [1], [Define if posix_madvise is working])
    AC_MSG_RESULT([yes])
  ],
  [
    CPPFLAGS="$ac_save_CPPFLAGS"
    AC_MSG_RESULT([no])
  ])
])

dnl ******************************
dnl *** Check for i18n support ***
dnl ******************************
XDT_I18N([de el es hu ja])

dnl ***********************************
dnl *** Check for required packages ***
dnl ***********************************
XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.1])
XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.6.0])
XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.6.0])
XDT_CHECK_PACKAGE([LIBPNG], [libpng12], [1.2.0])

dnl **********************************
dnl *** Optional support for cairo ***
dnl **********************************
XDT_CHECK_OPTIONAL_PACKAGE([CAIRO], [cairo], [0.5], [cairo], [Cairo])

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 gtk-doc ***
dnl *************************
GTK_DOC_CHECK([1.0])

dnl ***************************
dnl *** Check for Gamin/FAM ***
dnl ***************************
LIBFAM_CFLAGS=""
LIBFAM_LIBS=""
have_libfam=no
XDT_CHECK_PACKAGE([LIBFAM], [gamin], [0.1.0], [have_libfam=yes],
[
  dnl Fallback to a generic FAM check
  AC_CHECK_HEADERS([fam.h],
  [
    AC_CHECK_LIB([fam], [FAMOpen], [have_libfam="yes" LIBFAM_LIBS="-lfam"])
  ])
])
if test x"$have_libfam" = x"yes"; then
  dnl Define appropriate symbols
  AC_DEFINE([HAVE_FAM_H], [1], [Define to 1 if you have the <fam.h> header file.])
  AC_DEFINE([HAVE_LIBFAM], [1], [Define to 1 if the File Alteration Monitor is available.])

  dnl Check for FAMNoExists (currently Gamin only)
  save_LIBS="$LIBS"
  LIBS="$LIBS $LIBFAM_LIBS"
  AC_CHECK_FUNCS([FAMNoExists])
  LIBS="$save_LIBS"
fi
AC_SUBST([LIBFAM_CFLAGS])
AC_SUBST([LIBFAM_LIBS])

dnl ************************************
dnl *** Check for the system flavour ***
dnl ************************************
AC_MSG_CHECKING([for system flavour])
case "$target_os" in
*bsd*)
  FLAVOUR="bsd"
  ;;
*)
  FLAVOUR="sysv"
  ;;
esac
AC_MSG_RESULT([$FLAVOUR])

dnl **********************************************************
dnl *** Create links for the volume manager implementation ***
dnl **********************************************************
AC_CONFIG_LINKS(
[
  thunar-vfs/thunar-vfs-volume-impl.c:thunar-vfs/thunar-vfs-volume-$FLAVOUR.c
  thunar-vfs/thunar-vfs-volume-impl.h:thunar-vfs/thunar-vfs-volume-$FLAVOUR.h
])

dnl ***********************************
dnl *** Check for debugging support ***
dnl ***********************************
AC_ARG_ENABLE([debug], AC_HELP_STRING([--disable-debug], [Disable debugging support]), [], [enable_debug=yes])
AC_MSG_CHECKING([whether to enable debugging support])
if test x"$enable_debug" != x"no"; then
  PLATFORM_CFLAGS="$PLATFORM_CFLAGS -O0 -g3 -DG_DISABLE_DEPRECATED -Werror -Wall"
  AC_MSG_RESULT([yes])

  dnl Check whether the compiler accepts the -fno-strict-aliasing
  dnl switch, as certain packages - like Glib - still don't work
  dnl properly with newer compilers.
  save_CFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS -fno-strict-aliasing"
  AC_MSG_CHECKING([whether $CC accepts -fno-strict-aliasing])
  AC_COMPILE_IFELSE(AC_LANG_SOURCE([int x;]), [
    AC_MSG_RESULT([yes])
    PLATFORM_CFLAGS="$PLATFORM_CFLAGS -fno-strict-aliasing"
  ], [
    AC_MSG_RESULT([no])
  ])
  CFLAGS="$save_CFLAGS"
else
  PLATFORM_CPPFLAGS="$PLATFORM_CPPFLAGS -DG_DISABLE_ASSERT -DG_DISABLE_CAST_CHECKS -DG_DISABLE_CHECKS"
  AC_MSG_RESULT([no])

  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
fi

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
  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])
  ])
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_SUBST([PLATFORM_CFLAGS])
AC_SUBST([PLATFORM_CPPFLAGS])
AC_SUBST([PLATFORM_LDFLAGS])

AC_OUTPUT([
Makefile
docs/Makefile
docs/design/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/open-terminal-here/Makefile
icons/Makefile
icons/24x24/Makefile
icons/48x48/Makefile
po/Makefile.in
pixmaps/Makefile
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
])
