AC_INIT
AM_INIT_AUTOMAKE(playfair,0.4)

AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)

dnl Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

AM_CONFIG_HEADER(config.h)

dnl Checks for header files required for mp4.h
AC_HEADER_STDC
AC_CHECK_HEADERS(stdint.h inttypes.h)
AC_CHECK_HEADERS(mathf.h)
AC_CHECK_HEADERS(float.h)
AC_CHECK_FUNCS(strchr memcpy)
AC_CHECK_HEADERS(sys/time.h)
AC_HEADER_TIME

dnl DRMS 
AC_CHECK_HEADERS(errno.h sys/stat.h sys/types.h limits.h)
AC_CHECK_HEADERS(sysfs/libsysfs.h)
AC_CHECK_HEADERS(IOKit/IOKitLib.h,
  [AC_CHECK_LIB(IOKit, main,
    [AC_DEFINE(HAVE_IOKIT_IOKITLIB_H, 1, [Define if you have the IOKit API])
     MP4FF_LIBS="-framework IOKit -framework CoreFoundation"
     PLAYFAIR_LIBS="-framework IOKit -framework CoreFoundation"
     CLI_LIBS="-framework IOKit -framework CoreFoundation"
     AC_SUBST(MP4FF_LIBS)
     AC_SUBST(PLAYFAIR_LIBS)
     AC_SUBST(CLI_LIBS)])])
AC_CHECK_FUNCS(getpwuid)

AC_C_INLINE
AC_C_BIGENDIAN

AC_TYPE_OFF_T

AC_DEFUN(MY_CHECK_TYPEDEF_FROM_INCLUDE,
[
   AC_MSG_CHECKING([for $1])
   AC_TRY_COMPILE([$2],
                  [$1;],
                  libfaad_ok=yes, libfaad_ok=no)
   if test $libfaad_ok = yes; then
      AC_DEFINE($3, 1, [Define if needed])
      AC_MSG_RESULT([yes])
   else
      AC_MSG_RESULT([no])
fi
])


MY_CHECK_TYPEDEF_FROM_INCLUDE([float32_t temp],
        [#include <sys/types.h>,
        #include <sys/float.h>], [HAVE_FLOAT32_T])

AC_CHECK_FUNCS(strsep)

MY_CHECK_TYPEDEF_FROM_INCLUDE([in_port_t temp],
        [#include <sys/types.h>
         #include <netinet/in.h>], [HAVE_IN_PORT_T])
MY_CHECK_TYPEDEF_FROM_INCLUDE([socklen_t temp],
        [#include <sys/types.h>
         #include <sys/socket.h>], HAVE_SOCKLEN_T)
MY_CHECK_TYPEDEF_FROM_INCLUDE([fpos_t foo; foo.__pos = 0;],
        [#include <stdio.h>],
        [HAVE_FPOS_T_POS])


AC_CONFIG_FILES(Makefile src/Makefile)
AC_CONFIG_FILES(src/mp4ff/Makefile src/mp4v2/Makefile)
AC_CONFIG_FILES(src/playfair/Makefile src/cli/Makefile)
AC_OUTPUT
