rm -f config.cache

AC_PREREQ(2.59)
AC_INIT([thumbnail_packer], [0.0.1], [tick@openmoko.com])
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([1.8 foreign])

AC_CANONICAL_BUILD
AC_CANONICAL_HOST

AC_PROG_CC
AM_PROG_LIBTOOL
AC_HEADER_STDC

AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION(0.14)


# Check Library Directory
if test "x${libdir}" = "x${exec_prefix}/lib"; then
   if test "x${exec_prefix}" = "xNONE"; then
      if test "x${prefix}" = "xNONE"; then
      	 libdir="${ac_default_prefix}/lib";
      else
      	 libdir="${prefix}/lib";
      fi
   else
      if test "x${prefix}" = "xNONE"; then
     	 libdir="${ac_default_prefix}/lib";
      else
     	 libdir="${prefix}/lib";
      fi
   fi
fi

#
# Set Library Directory in config.h
#
if test "x${libdir}" = "xNONE"; then
   if test "x${prefix}" = "xNONE"; then
      AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${ac_default_prefix}/lib", "Package libraries destination")
   else
      AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${prefix}/lib", "Package libraries destination")
   fi
else
   AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${libdir}", "Package libraries destination")
fi

dnl Set PACKAGE_BIN_DIR in config.h.
if test "x${datadir}" = 'x${prefix}/bin'; then
  if test "x${prefix}" = "xNONE"; then
    AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${ac_default_prefix}/bin", [Installation directory for user executables])
  else
    AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${prefix}/bin", [Installation directory for user executables])
  fi
else
  AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${bindir}", [Installation directory for user executables])
fi



#
# Set Data Directory in config.h
#
if test "x${prefix}" = "xNONE"; then
   datadir="${ac_default_prefix}/share/"
else
   datadir="${prefix}/share/"
fi
AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${datadir}", [Shared Data Directory])

if test "x${prefix}" = "xNONE"; then
   fontsdir="${ac_default_prefix}/share/fonts/truetype"
else
   fontsdir="${prefix}/share/fonts/truetype"
fi
AC_DEFINE_UNQUOTED(PACKAGE_FONTS_DIR, "${fontsdir}", [Shared Fonts Directory])


#
# Set Data Root and Locale Directory in config.h
#
AC_PREFIX_DEFAULT(/usr/local)
if test "x$prefix" = "xNONE"; then
  datarootdir=${ac_default_prefix}
else
  datarootdir=${prefix}/share
fi
localedir=${datarootdir}/locale
AC_SUBST(LOCALEDIR, "${localedir}")
AC_DEFINE_UNQUOTED(LOCALEDIR, "${localedir}", "Module Locale Directory")

#
# Check EFL Libs
#
PKG_CHECK_MODULES(EDJE, [edje >= 0.5.0])
AC_PATH_PROG(EDJE_CC, "edje_cc", "", $PATH)

#
# Check Enlightenment
#
AC_ARG_WITH(enlightenment-config,
[  --with-enlightenment-config=E_CONFIG    use enlightenment-config specified ],
[
  E_CONFIG=$withval;
  echo "using "$E_CONFIG" for enlightenment-config";
],[
  PROG="enlightenment-config";
  AC_PATH_PROG(E_CONFIG, $PROG, "", $PATH)
])
e_cflags=`pkg-config --cflags evas ecore ecore-evas edje etk`
e_libs=`pkg-config --libs evas ecore ecore-evas edje etk`
e_modules=`$E_CONFIG --module-dir`
AC_SUBST(e_cflags)
AC_SUBST(e_libs)
AC_SUBST(e_modules)

PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.6 gthread-2.0)
GLIB_CFLAGS=`pkg-config --cflags glib-2.0 gthread-2.0`
GLIB_LIBS=`pkg-config --libs glib-2.0 gthread-2.0`
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)

PKG_CHECK_MODULES(PACKAGEKIT, [packagekit >= 0.1.5])
PACKAGEKIT_CFLAGS=`pkg-config --cflags packagekit`
PACKAGEKIT_LIBS=`pkg-config --libs packagekit`
AC_SUBST(PKGAGEKIT_CFLGAS)
AC_SUBST(PKGAGEKIT_LIBS)

PKG_CHECK_MODULES(EDBUS, edbus)

AC_OUTPUT([
Makefile
],[])

