dnl Process this file with autoconf to produce a configure script.
AC_INIT(array_util.c)

dnl Init automake feature
AM_INIT_AUTOMAKE(array_util, 1.1)

dnl Checks for programs.
AC_PROG_CC

dnl Checks for libraries.
dnl Replace `main' with a function in -libs:
AC_CHECK_LIB(ibs, main)

#AC_SUBST(AC_LIBOBJS)
#AC_LIBOBJS = -lgtk

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h sys/ioctl.h unistd.h )

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL

dnl Set CFLAGS
CFLAGS=-g

dnl Check for directory with kernel source...
AC_MSG_CHECKING(for directory with kernel source)
AC_ARG_WITH(kernel,
  [  --with-kernel=dir       give the directory with kernel sources]
  [                        [/usr/src/linux]],
  kerneldir="$withval",
  if test -d "/lib/modules/`uname -r`/build" -o -L "/lib/modules/`uname -r`/build"; then
    kerneldir="/lib/modules/`uname -r`/build"
  else
    kerneldir="/usr/src/linux"
  fi
)
if test -d "$kerneldir" -o -L "$kerneldir"; then
  AC_MSG_RESULT(found $kerneldir )
else
  AC_MSG_ERROR(kernel source directory not found)
fi

CONFIG_KERNEL_SOURCE="$kerneldir"
AC_SUBST(CONFIG_KERNEL_SOURCE)

KERNEL_INC="-I$CONFIG_KERNEL_SOURCE/drivers/block -I$CONFIG_KERNEL_SOURCE/include -D__user="

CFLAGS="$CFLAGS $KERNEL_INC"
CPPFLAGS="$CPPFLAGS $KERNEL_INC"

dnl Check for compile.h (2.6.x kernels only?)
AC_CHECK_HEADERS(linux/compiler.h)

dnl Check Headers
AC_CHECK_HEADERS(ida_ioctl.h ida_cmd.h cpqarray.h,, AC_MSG_ERROR(You need to have the SmartArray patch installed.))
AC_EGREP_HEADER(blk_cnt, ida_ioctl.h,AC_MSG_RESULT(SmartArray patch version 1.0.1+ installed..), AC_MSG_ERROR(You need to have the SmartArray patch version 1.0.1+ installed.))

dnl Check for GLIB and GTK+
AM_PATH_GLIB(1.2.0,CFLAGS="$CFLAGS $GLIB_CFLAGS" LIBS="$LIBS $GLIB_LIBS" ,AC_MSG_ERROR(GLIB distribution not found.))
AM_PATH_GTK(1.2.0,CFLAGS="$CFLAGS $GTK_CFLAGS" LIBS="$LIBS $GTK_LIBS" ,AC_MSG_ERROR(GTK+ distribution not found.))
AM_PATH_IMLIB(1.9.6,CFLAGS="$CFLAGS $IMLIB_CFLAGS" LIBS="$LIBS $IMLIB_LIBS" ,AC_MSG_ERROR(Imlib distribution not found.))

AC_OUTPUT(Makefile)
