AC_PREREQ(2.50)
AC_INIT()
AM_INIT_AUTOMAKE(faac,1.0beta)

AM_CONFIG_HEADER(config.h)

CFLAGS=${CFLAGS:-"-O2 -NDEBUG -Wall"}
CXXFLAGS=${CXXFLAGS:-"-O2 -NDEBUG -Wall"}
AC_PROG_CC
AM_PROG_LIBTOOL

AC_CONFIG_SUBDIRS(libmp4v2)

AC_CHECK_HEADERS(getopt.h)

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

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_CHECK_TYPES(uint64_t)
AC_CHECK_TYPES(uint32_t)
AC_CHECK_TYPES(uint16_t)
AC_CHECK_TYPES(u_int64_t)
AC_CHECK_TYPES(u_int32_t)
AC_CHECK_TYPES(u_int16_t)
AC_CHECK_TYPES(int64_t)
AC_CHECK_TYPES(int32_t)
AC_CHECK_TYPES(int16_t)

AC_CHECK_LIB(gnugetopt, getopt_long)

AC_C_BIGENDIAN

AC_OUTPUT(libfaac/Makefile frontend/Makefile include/Makefile Makefile)
