dnl
dnl
dnl    Pixie configure.in file
dnl
dnl
AC_INIT(src/common/algebra.cpp)
AM_INIT_AUTOMAKE(Pixie,1.3.16)
AM_CONFIG_HEADER(config.h)


dnl ---------------------------------------------------
dnl Check the compiler/programs
dnl
AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX
AM_PROG_LIBTOOL
AC_PROG_INSTALL
AC_PROG_MAKE_SET

dnl ---------------------------------------------------
dnl Check standard libraries
dnl
AC_CHECK_LIB(dl, dlopen,,[AC_MSG_ERROR([dl library is not found])],)
AC_CHECK_LIB(m, sin,,[AC_MSG_ERROR([math library is not found])],)
AC_CHECK_LIB(pthread, pthread_create,,[AC_MSG_ERROR([pthread library is not found])],)

dnl ---------------------------------------------------
dnl Find X
dnl
AC_PATH_X
AC_PATH_XTRA
X_LDFLAGS="$X_LDFLAGS -lX11 -lXext"

saved_CFLAGS="$CFLAGS"
saved_LDFLAGS="$LDFLAGS"
saved_LIBS="$LIBS"

CFLAGS="$CFLAGS $X_CFLAGS"
LDFLAGS="$X_LDFLAGS $X_LIBS $LDFLAGS"

AC_CHECK_LIB(X11, XOpenDisplay,,[AC_MSG_ERROR([X11 is not found, it is required by framebuffer])],)
AC_CHECK_LIB(Xext, XShmAttach,,[AC_MSG_ERROR([Xext is not found, it is required by framebuffer])],)

CFLAGS="$saved_CFLAGS"
LDFLAGS="$saved_LDFLAGS"
LIBS="$saved_LIBS"

dnl ---------------------------------------------------
dnl Find FLTK
dnl

have_fltk=false
AC_CHECK_LIB(fltk,main,LIBFLTK="-lfltk")
AC_CHECK_LIB(fltk_gl,main,[LIBFLTKGL="-lfltk_gl -lGL" have_fltk=true])
AM_CONDITIONAL(BUILD_SHOW, test x$have_fltk = xtrue)

dnl ---------------------------------------------------
dnl Find libtiff
dnl

saved_LIBS="$LIBS"

AC_CHECK_HEADER(tiffio.h,,AC_MSG_ERROR([tiffio.h not found]))
AC_CHECK_LIB(tiff,TIFFOpen,,[AC_MSG_ERROR([libtiff not found])],)

TIFF_LIBS="$LIBS"
LIBS="$saved_LIBS"

dnl ---------------------------------------------------
dnl Check system/headers
dnl
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h limits.h malloc.h sys/time.h unistd.h)

AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_HEADER_TIME

AC_FUNC_ALLOCA
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(ftime gethostname gettimeofday mkdir rmdir socket strdup strstr strtod strtol)

dnl ---------------------------------------------------
dnl Do variable substitution
dnl
AC_SUBST(LIBFLTK)
AC_SUBST(LIBFLTKGL)
AC_SUBST(X_LIBS)
AC_SUBST(X_CFLAGS)
AC_SUBST(X_LDFLAGS)
AC_SUBST(TIFF_LIBS)
AC_SUBST(BUILD_SHOW)

dnl ---------------------------------------------------
dnl Write the output
dnl
AC_OUTPUT(Makefile src/Makefile src/common/Makefile src/file/Makefile src/framebuffer/Makefile src/opengl/Makefile src/precomp/Makefile src/rgbe/Makefile src/sdr/Makefile src/sdrc/Makefile src/ri/Makefile src/rndr/Makefile src/texmake/Makefile src/sdrinfo/Makefile src/show/Makefile)

echo "------------------------------------------------"
echo "Type"
echo ">make"
echo ">make -install"
echo "to built Pixie"
echo








