# $Id$

AC_INIT(libpipi, 0.0)
AC_CONFIG_AUX_DIR(.auto)
AM_INIT_AUTOMAKE([no-define tar-ustar])
dnl AM_MAINTAINER_MODE

AM_CONFIG_HEADER(config.h)

AM_PROG_CC_C_O
AC_PROG_CPP

LT_MAJOR="0"
LT_MINOR="99"
LT_MICRO="13"
AC_SUBST(LT_MAJOR)
AC_SUBST(LT_MINOR)
AC_SUBST(LT_MICRO)
LT_VERSION="$LT_MAJOR:$LT_MINOR:$LT_MICRO"
AC_SUBST(LT_VERSION)
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
AC_LIBTOOL_CXX

AC_C_CONST
AC_C_INLINE

AC_CHECK_HEADERS(stdio.h stdarg.h inttypes.h endian.h stdint.h getopt.h)

ac_cv_have_getopt_long="no"
AC_CHECK_FUNCS(getopt_long,
 [ac_cv_have_getopt_long="yes"],
 [AC_CHECK_LIB(gnugetopt, getopt_long,
   [ac_cv_have_getopt_long="yes"
    GETOPT_LIBS="${GETOPT_LIBS} -lgnugetopt"])])
if test "$ac_cv_have_getopt_long" != "no"; then
  AC_DEFINE(HAVE_GETOPT_LONG, 1, Define to 1 if you have the `getopt_long' function.)
fi
AM_CONDITIONAL(NEED_GETOPT_LONG, test "$ac_cv_have_getopt_long" = "no")
AC_SUBST(GETOPT_LIBS)

# Optimizations
CFLAGS="${CFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer"
# Code qui fait des warnings == code de porc == deux baffes dans ta gueule
CFLAGS="${CFLAGS} -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Waggregate-return -Wmissing-prototypes -Wnested-externs -Wsign-compare"

# Use DevIL?
#AC_CHECK_HEADERS(IL/il.h,
# [ac_cv_my_have_il="yes"],
# [ac_cv_my_have_il="no"])
#CPPFLAGS="${save_CPPFLAGS}"
#AM_CONDITIONAL(USE_IL, test "${ac_cv_my_have_il}" = "yes")

# Use Windows?
#AC_CHECK_HEADERS(olectl.h,
# [ac_cv_my_have_ole="yes"],
# [ac_cv_my_have_ole="no"])
#CPPFLAGS="${save_CPPFLAGS}"
#AM_CONDITIONAL(USE_OLE, test "${ac_cv_my_have_ole}" = "yes")

# Use SDL?
ac_cv_my_have_sdl="no"
save_CPPFLAGS="${CPPFLAGS}"
AC_PATH_PROG(SDL_CONFIG, sdl-config, no)
if test "${SDL_CONFIG}" != "no"; then
  CPPFLAGS="${CPPFLAGS} `sdl-config --cflags`"
fi
AC_CHECK_HEADERS(SDL_image.h,
 [ac_cv_my_have_sdl="yes"],
 [ac_cv_my_have_sdl="no"])
CPPFLAGS="${save_CPPFLAGS}"
if test "${ac_cv_my_have_sdl}" != "no"; then
  AC_DEFINE(USE_SDL, 1, Define to 1 to use SDL_image)
fi
AM_CONDITIONAL(USE_SDL, test "${ac_cv_my_have_sdl}" = "yes")

# Use OpenCV?
ac_cv_my_have_opencv="no"
OPENCV="no"
PKG_CHECK_MODULES(OPENCV, opencv, [ac_cv_my_have_opencv="yes"])
if test "${ac_cv_my_have_opencv}" != "no"; then
  AC_DEFINE(USE_OPENCV, 1, Define to 1 to use OpenCV)
fi
AM_CONDITIONAL(USE_OPENCV, test "${ac_cv_my_have_opencv}" = "yes")

# Use Imlib2?
ac_cv_my_have_imlib2="no"
IMLIB2="no"
PKG_CHECK_MODULES(IMLIB2, imlib2, [ac_cv_my_have_imlib2="yes"])
if test "${ac_cv_my_have_imlib2}" != "no"; then
  AC_DEFINE(USE_IMLIB2, 1, Define to 1 to use Imlib2)
fi
AM_CONDITIONAL(USE_IMLIB2, test "${ac_cv_my_have_imlib2}" = "yes")

if test "${ac_cv_my_have_il}" = "no" -a "${ac_cv_my_have_ole}" = "no" -a "${ac_cv_my_have_sdl}" = "no" -a "${ac_cv_my_have_imlib2}" = "no" -a "${ac_cv_my_have_opencv}" = "no"; then
  AC_MSG_ERROR([[cannot find DevIL, OLE, SDL_Image, Imlib2 or OpenCV, please install one of them]])
fi

AC_CONFIG_FILES([
  Makefile
  pipi/Makefile
  src/Makefile
  genethumb/Makefile
  examples/Makefile
  test/Makefile
])
AC_CONFIG_FILES([
  pipi/pipi.pc
])

AC_OUTPUT