dnl
dnl Process this file with autoconf to produce a configure script.
dnl Autoconf script for Amaya and Thot.
dnl Daniel Veillard and Irene Vatton, 1997
dnl

dnl  ***************************************************************
dnl
dnl    GENERIC AUTOCONF STUFF : GUESS INFORMATIONS ON SYSTEM SETUP
dnl
dnl  ***************************************************************

AC_PREREQ(2.2)
AC_INIT(thotlib/internals/h/constpiv.h)
AC_REVISION

dnl
dnl Verify that configure is not being called in the Amaya directory
dnl
if test -d batch -a -f configure.in ; then
   echo 
   echo "****************************************************************"
   echo ERROR: You must invoke the configure script in a subidrectory
   echo under the Amaya tree.
   echo For example:
   echo "  cd Amaya ; mkdir obj ; cd obj ; ../configure [your options] "
   echo "****************************************************************"
   echo 
   exit 1
fi

dnl
dnl Checks for platform information
dnl

AC_CANONICAL_SYSTEM
AC_CONFIG_HEADER(config.h)

dnl
dnl Initializing Automake
dnl

AC_PROG_MAKE_SET
AC_ARG_PROGRAM

dnl
dnl Checks for programs.
dnl

AC_PROG_YACC
AC_PROG_CC
AC_PROG_CPP
AC_PROG_LEX
AC_PROG_AWK
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PATH_PROG(CP, cp, /bin/cp, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(MV, mv, /bin/mv, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(RM, rm, /bin/rm, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(MKDIR, mkdir, /bin/mkdir, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(ECHO, echo, /bin/echo, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(CAT, cat, /bin/cat, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(CHMOD, chmod, /bin/chmod, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(SED, sed, /bin/sed, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(AR, ar, /usr/bin/ar, $PATH:/bin:/usr/bin:/usr/ucb/bin)
AC_PATH_PROG(DIFF, diff, /usr/bin/diff, $PATH:/bin:/usr/bin:/usr/ucb/bin)

dnl
dnl Checks for libraries.
dnl

AC_CHECK_LIB(socket, socket, )
AC_CHECK_LIB(inet, connect)
AC_CHECK_LIB(nsl, t_accept)
AC_CHECK_LIB(dl, dlopen)
AC_PATH_X
AC_PATH_XTRA

dnl
dnl Check for libXp
dnl

for ac_dir in               \
  /usr/X11R6/lib        \
  /usr/X11R5/lib        \
                            \
  /usr/lib/X11R6        \
  /usr/lib/X11R5        \
                            \
  /usr/local/X11R6/lib  \
  /usr/local/X11R5/lib  \
                            \
  /usr/local/lib/X11R6  \
  /usr/local/lib/X11R5  \
                            \
  /usr/X11/lib          \
  /usr/lib/X11          \
  /usr/local/X11/lib    \
  /usr/local/lib/X11    \
                            \
  /usr/X386/lib         \
  /usr/x386/lib         \
  /usr/XFree86/lib/X11  \
                            \
  /usr/dt/lib           \
                            \
  /usr/lib              \
  /usr/local/lib        \
  /usr/unsupported/lib  \
  /usr/athena/lib       \
  /usr/local/x11r5/lib  \
  /usr/lpp/Xamples/lib  \
                            \
  /usr/lesstif/lib      \
  /usr/local/lesstif/lib\
  /usr/gnu/lesstif/lib  \
  $HOME/lesstif/lib     \
  ; \
do
  if test -r "$ac_dir/libXp.a" -o -r "$ac_dir/libXp.so"; then
     echo "\nfound libXp.a\n"
     X_PRE_LIBS="-lXp ${X_PRE_LIBS}"
     break
  fi
done
dnl
dnl Checks for header files.
dnl

AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT

AC_CHECK_HEADERS(stdio.h)
AC_CHECK_HEADERS(sys/types.h types.h)
AC_CHECK_HEADERS(sys/unistd.h unistd.h)
AC_CHECK_HEADERS(sys/fcntl.h fcntl.h)
AC_CHECK_HEADERS(sys/limits.h limits.h)
AC_CHECK_HEADERS(sys/stat.h stat.h)
AC_CHECK_HEADERS(sys/file.h)
AC_CHECK_HEADERS(sys/ioctl.h)
AC_CHECK_HEADERS(sys/time.h time.h)
AC_CHECK_HEADERS(sys/systeminfo.h)
AC_CHECK_HEADERS(sys/string.h strings.h)
AC_CHECK_HEADERS(sys/syslog.h syslog.h)
AC_CHECK_HEADERS(sys/socket.h socket.h)
AC_CHECK_HEADERS(appkit/appkit.h appkit.h)
AC_CHECK_HEADERS(apppkit/apppkit.h apppkit.h)
AC_CHECK_HEADERS(netinet/in.h in.h)
AC_CHECK_HEADERS(dn.h)
AC_CHECK_HEADERS(sys/ipc.h)
AC_CHECK_HEADERS(net/errno.h sys/errno.h errno.h)
AC_CHECK_HEADERS(pwd.h)
AC_CHECK_HEADERS(grp.h)
AC_CHECK_HEADERS(arpa/inet.h inet.h)
AC_CHECK_HEADERS(netdb.h)
AC_CHECK_HEADERS(manifest.h)
AC_CHECK_HEADERS(bsdtypes.h)
AC_CHECK_HEADERS(stdefs.h)
AC_CHECK_HEADERS(bsdtime.h)
AC_CHECK_HEADERS(sys/select.h select.h)
AC_CHECK_HEADERS(dnetdb.h)
AC_CHECK_HEADERS(libc.h)
AC_CHECK_HEADERS(stdlib.h)
AC_CHECK_HEADERS(malloc.h)
AC_CHECK_HEADERS(memory.h)
AC_CHECK_HEADERS(unixlib.h)
AC_CHECK_HEADERS(ctype.h)
AC_CHECK_HEADERS(cursesX.h curses.h)
AC_CHECK_HEADERS(sys/resource.h resource.h)
AC_HEADER_DIRENT
AC_CHECK_HEADERS(dir.h direct.h) dnl AC_HEADER_DIRENT only checks for some..
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
AC_HEADER_STAT
AC_CHECK_HEADERS(stdint.h)

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

AC_C_CONST
AC_C_INLINE
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_STRUCT_TIMEZONE
AC_TYPE_UID_T

dnl
dnl Checks for library functions.
dnl

AC_FUNC_ALLOCA
AC_TYPE_GETGROUPS
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP
AC_FUNC_MMAP
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(getcwd gethostname gettimeofday getwd mkdir mktime putenv select socket strdup strerror strftime strstr strtod strtol uname lstat strcasecmp strncasecmp strchr memcpy)



AC_ARG_WITH(GL,              [  --with-gl               enable Opengl canvas (experimental) ])
dnl
dnl GL canvas is disabled by default
dnl
dnl needs Opengl, glu, Xft (xfree 4 font server)
dnl needs GTK
dnl text WILL need freetype2, ftgl
dnl GL is for opengl
dnl Glu is for text drawing (until we switch) 
dnl GLU is for tesselation algortihms (until we extract it from this lib)
dnl (tesselation is used for polygons with holes in it...)
dnl gtkgl is for integration of opengl in GTK
if test "$with_gl" = "" ; then
 if test "$enable_gl" = "yes" ; then
    with_gl="yes"
  else
    with_gl="no"
  fi
fi  

GTK_OPTIONS=
AC_ARG_WITH(gtk, [  --without-gtk              use Motif instead of GTK])
if test "$withval" = "no" ; then
  if test "$with_gl" = "yes" ; then
    with_gtk="yes"
  else
    with_gtk="no"
  fi
else
  with_gtk="yes"
fi

if test "$with_gtk" = "yes" ; then
  for ac_dir in               \
    /usr/lib/glib/include     \
    /usr/X11R6/include        \
                              \
    /usr/include/X11R6        \
    /usr/local/X11R6/include  \
    /usr/local/include/X11R6  \
                              \
    /usr/X11/include          \
    /usr/include/X11          \
    /usr/local/X11/include    \
    /usr/local/include/X11    \
                              \
    /usr/X386/include         \
    /usr/x386/include         \
    /usr/XFree86/include/X11  \
    /usr/dt/include           \
    /usr/include              \
    /usr/local/include        \
    /usr/local/lib/glib/include  \
    ; \
  do
    if test -r "$ac_dir/gdk/gdk.h"; then
      no_gtk= ac_gtk_includes=$ac_dir
      break
    fi
  done

GTK_INCLUDES="`gtk-config --cflags`"
AC_SUBST(GTK_INCLUDES)
GTK_LIBRARIES="`gtk-config --libs`"
dnl GL doesn't need the imlib
if test "${with_gl}" != "yes" ; then
 GTK_LIBRARIES="${GTK_LIBRARIES} -lgdk_imlib"
fi

AC_SUBST(GTK_LIBRARIES)
GTK_OPTIONS="-D_GTK -D_SVGANIM -D_SVGLIB"
  no_motif=yes
  no_graphic=yes
else
dnl
dnl Checking for Motif libraries and includes
dnl
dnl Borrowed from Lesstif configure.in
dnl Lesstif is a Great Project (TM)
dnl

AC_DEFUN(AC_PATH_MOTIF_DIRECT,
[test -z "$motif_direct_test_library" && motif_direct_test_library=Xm
test -z "$motif_direct_test_function" && motif_direct_test_function=XmCreatePushButton
test -z "$motif_direct_test_include" && motif_direct_test_include=Xm/Xm.h
  for ac_dir in               \
    /usr/include/Motif1.2     \
    /usr/Motif1.2/include     \
    /sw/Lesstif/Motif2.0/include \
                              \
    /usr/motif/include        \
                              \
    /usr/X11R6/include        \
    /usr/X11R5/include        \
                              \
    /usr/include/X11R6        \
    /usr/include/X11R5        \
                              \
    /usr/local/X11R6/include  \
    /usr/local/X11R5/include  \
                              \
    /usr/local/include/X11R6  \
    /usr/local/include/X11R5  \
                              \
    /usr/X11/include          \
    /usr/include/X11          \
    /usr/local/X11/include    \
    /usr/local/include/X11    \
                              \
    /usr/X386/include         \
    /usr/x386/include         \
    /usr/XFree86/include/X11  \
                              \
    /usr/dt/include           \
                              \
    /usr/include              \
    /usr/local/include        \
    /usr/unsupported/include  \
    /usr/athena/include       \
    /usr/local/x11r5/include  \
    /usr/lpp/Xamples/include  \
                              \
    /usr/lesstif/include      \
    /usr/local/lesstif/include\
    /usr/gnu/lesstif/include  \
    $HOME/lesstif/include     \
    ; \
  do
    if test -r "$ac_dir/$motif_direct_test_include"; then
      no_motif= ac_motif_includes=$ac_dir
      break
    fi
  done

# Check for the libraries.
# See if we find them without any special options.
# Don't add to $LIBS permanently.
ac_save_LIBS="$LIBS"
LIBS="-l$motif_direct_test_library $LIBS"
# First see if replacing the include by lib works.
for ac_dir in `echo "$ac_motif_includes" | sed s/include/lib/` \
    /usr/lib/Motif1.2     \
    /usr/Motif1.2/lib     \
    /sw/Lesstif/Motif2.0/lib \
                          \
    /usr/motif/lib        \
                          \
    /usr/X11R6/lib        \
    /usr/X11R5/lib        \
                          \
    /usr/lib/X11R6        \
    /usr/lib/X11R5        \
                          \
    /usr/local/X11R6/lib  \
    /usr/local/X11R5/lib  \
                          \
    /usr/local/lib/X11R6  \
    /usr/local/lib/X11R5  \
                          \
    /usr/X11/lib          \
    /usr/lib/X11          \
    /usr/local/X11/lib    \
                          \
    /usr/X386/lib         \
    /usr/x386/lib         \
    /usr/XFree86/lib/X11  \
                          \
    /usr/lib              \
    /usr/local/lib        \
    /usr/unsupported/lib  \
    /usr/athena/lib       \
    /usr/local/x11r5/lib  \
    /usr/lpp/Xamples/lib  \
                          \
    /usr/lesstif/lib      \
    /usr/local/lesstif/lib\
    /usr/gnu/lesstif/lib  \
    $HOME/lesstif/lib     \
    ; \
do
  for ac_extension in a so sl la; do
    if test -r $ac_dir/lib${motif_direct_test_library}.$ac_extension; then
      no_motif= ac_motif_libraries=$ac_dir
      break 2
    fi
  done
done
LIBS="$ac_save_LIBS"
])

AC_DEFUN(AC_PATH_MOTIF,
[AC_REQUIRE_CPP()

motif_includes=NONE
motif_libraries=NONE

AC_MSG_CHECKING(for Motif)
if test "x$motif_includes" != xNONE && test "x$motif_libraries" != xNONE; then
    no_motif=
else
AC_CACHE_VAL(ac_cv_path_motif,
[# One or both of these vars are not set, and there is no cached value.
  no_motif=yes
AC_PATH_MOTIF_DIRECT

if test "$no_motif" = yes; then
    ac_cv_path_motif="no_motif=yes"
else
    ac_cv_path_motif="no_motif= ac_motif_includes=$ac_motif_includes ac_motif_libraries=$ac_motif_libraries"
fi])
eval "$ac_cv_path_motif"
fi

if test "$no_motif" = yes; then
  AC_MSG_RESULT(no)
  MOTIF_INCLUDES=
  MOTIF_LIBRARIES=
else
  test "x$motif_includes" = xNONE && motif_includes=$ac_motif_includes
  test "x$motif_libraries" = xNONE && motif_libraries=$ac_motif_libraries
  ac_cv_path_motif="no_motif= ac_motif_includes=$motif_includes ac_motif_libraries=$motif_libraries"
  AC_MSG_RESULT([libraries $motif_libraries, headers $motif_includes])
  if test "$motif_includes" != "/usr/include" ; then
    MOTIF_INCLUDES="-I$motif_includes"
  fi
  if test "$motif_libraries" != "/usr/lib" ; then
    MOTIF_LIBRARIES="-L$motif_libraries -lXm"
    case "${host}" in
        *-*sun-solaris* )
         MOTIF_LIBRARIES="${MOTIF_LIBRARIES} -R$motif_libraries"
        ;;
    esac
  else
  MOTIF_LIBRARIES="-lXm"
  fi
fi
AC_SUBST(MOTIF_INCLUDES)
AC_SUBST(MOTIF_LIBRARIES)
])

AC_PATH_MOTIF
fi

if test "${GCC}" = "yes"; then
   CPP="${CPP} -x c"
fi

dnl  ***************************************************************
dnl
dnl    SPECIFIC STUFF : CONFIGURATION OPTIONS FOR AMAYA
dnl
dnl  ***************************************************************

# We don't use our graphic libraries for the pure GTK version (without GL)

echo "with gtk is ${with_gtk}, with gl is ${with_gl}\n"

if test "${with_gtk}" != "yes" -o "${with_gl}" = "yes" ; then
  AC_ARG_WITH(graphic-libs, [  --with-graphic-libs    use static libjpeg, libpng.])
  if test "$withval" = "no" ; then
    no_graphic=yes
  fi
  if test "$withval" = "yes" ; then
    no_graphic=no
  fi
fi

if test "$no_graphic" = yes; then
dnl
    AC_MSG_CHECKING([for libjpeg version = 6b])
    AC_EGREP_CPP([x 62 *x],
        [#include <jpeglib.h>
         x JPEG_LIB_VERSION x],
dnl
        AC_MSG_RESULT([yes])
	JPEGINCL=''
        LIBJPEG='-ljpeg'
        MAKEJPEG=['#'],
dnl
        AC_MSG_RESULT([no])
	JPEGINCL='-I$(THOTDIR)/libjpeg'
        LIBJPEG='../libjpeg.a'      dnl LIBJPEG goes into amaya/Makefile.in
        )
dnl    
dnl
    AC_MSG_CHECKING([for libpng version = 1.0.x or 1.2.x])
    AC_EGREP_CPP([x \"1.[02]\..*\" *x],
        [#include <png.h>
	x PNG_LIBPNG_VER_STRING x],
dnl
        AC_MSG_RESULT([yes])
	PNGINCL=''
        LIBPNG='-lpng'
        LIBZ=''
	MAKEPNG=['#'],
dnl
        AC_MSG_RESULT([no])
  	PNGINCL='-I$(THOTDIR)/libpng -I$(THOTDIR)/libpng/zlib'
        LIBPNG='../libpng.a'
        LIBZ='../libz.a'
        )
else
    JPEGINCL='-I$(THOTDIR)/libjpeg'
    LIBJPEG='../libjpeg.a'
    PNGINCL='-I$(THOTDIR)/libpng -I$(THOTDIR)/libpng/zlib'
    LIBPNG='../libpng.a'
    LIBZ='../libz.a'
fi
dnl
AC_SUBST(LIBJPEG)
AC_SUBST(LIBPNG)
AC_SUBST(LIBZ)
AC_SUBST(MAKEJPEG)
AC_SUBST(MAKEPNG)

AMAYA_VER="7.0"

dnl
dnl We use a special versoin of cextract patched for alignment
dnl to build the signatures of the modules functions located in f subdirs
dnl
CEXTRACT_VER="1.7"
CEXTRACT_FLAGS="+O"


dnl
dnl Adjust the some variables depending on the host and compiler
dnl Thotlib NEED signed chars !!!
dnl

if test "${CC}" = "gcc" ; then
  CFLAGS="${CFLAGS} -W "
  case "${host}" in
      *-*-irix5* | *-*irix6* )
         CFLAGS="${CFLAGS} -fsigned-char"
      ;;
  esac
fi

if test "$ac_cv_c_const" = "no" ; then
  CFLAGS="${CFLAGS} -DCONST= "
fi

dnl
dnl Check for availability of amaya sources
dnl

build_amaya="yes"

if test "$with_amaya" = "no" ; then
    build_amaya="no"
else
  if test ! -f $srcdir/amaya/Makefile.in ; then
    AC_MSG_WARN(Amaya browser/editor sources not found, disabling Amaya build !)
    build_amaya="no"
  fi
fi

dnl
dnl Check for additionnal packages
dnl use AC_CONFIG_SUBDIRS to launch configure in the subdir
dnl

AC_ARG_WITH(i18n,            [  --without-i18n          disable internationalization support ])
dnl
dnl I18N support disabled by default
dnl

if test "$with_i18n" = "" ; then
  if test "$enable_i18n" = "no" ; then
    with_i18n="no"
  else
    with_i18n="yes"
  fi

fi  
if test "$with_i18n" = "yes" ; then
   I18N_OPTIONS=-D_I18N_
else
   with_i18n="no"
   I18N_OPTIONS=""
fi

if test "$with_gl" = "yes" ; then
  	AC_MSG_CHECKING([OpenGL])
	for ac_dir in               		\
		/usr/include 			\
		/usr/X11R6/include 		\
		/usr/local/include		\
		; \
	do  if test -r "$ac_dir/GL/gl.h" ; then
                gl_inc="yes"
		GL_INC_I="$ac_dir"
		if test "$ac_dir" != "/usr/include" ; then
		   GL_INCLUDES="-I$ac_dir"
		fi
		AC_MSG_RESULT([yes])
       	 	break	
    	    fi
	done	
  	AC_MSG_CHECKING([GLU])	
	for ac_dir in               		\
		/usr/include/GL			\
		/usr/include 			\
		/usr/X11R6/include/GL   	\
		/usr/X11R6/include 		\
		/usr/local/include		\
		/usr/local/include/GL		\
		; \
	do  if test -r "$ac_dir/glu.h" ; then
                glu_inc="yes"
		GL_INC_II="$ac_dir"
		if test "$ac_dir" != "/usr/include" ; then
			if test "$ac_dir" != "$GL_INC_I" ; then
		   	    GL_INCLUDES="$GL_INCLUDES -I$ac_dir"
			fi
		fi
		AC_MSG_RESULT([yes])
       	 	break	
    	    fi
	done	
  	AC_MSG_CHECKING([GTKGLAREA])	
	for ac_dir in               		\
		/usr/include/GL			\
		/usr/include 			\
		/usr/X11R6/include/GL   	\
		/usr/X11R6/include 		\
		/usr/local/include		\
		/usr/local/include/GL		\
		; \
	do  if test -r "$ac_dir/gtkgl/gtkglarea.h" ; then
                gtkgl_inc="yes"
		if test "$ac_dir" != "/usr/include" ; then
			if test "$ac_dir" != "$GL_INC_II" ; then
				if test "$ac_dir" != "$GL_INC_I" ; then
		   			GL_INCLUDES="$GL_INCLUDES -I$ac_dir"
				fi
			fi
		fi
		AC_MSG_RESULT([yes])
       	 	break	
    	    fi
	done	
  	AC_MSG_CHECKING([freetype])	
	for ac_dir in               		\
		/usr/include 			\
		/usr/X11R6/include 		\
		/usr/local/include		\
		; \
	do  if test -r "$ac_dir/ft2build.h" ; then
                freetype_inc="yes"
		GL_INCLUDES="$GL_INCLUDES `freetype-config --cflags`"
       	        AC_MSG_RESULT([yes])	
		break	
    	    fi
	done	
        AC_MSG_CHECKING([Xft])	
	for ac_dir in               		\
		/usr/include 			\
		/usr/X11R6/include 		\
		/usr/local/include		\
		/usr/include/X11/Xft		\
		/usr/X11R6/include/X11/Xft	\
		/usr/local/include/X11/Xft	\
		/usr/include/X11/Xft1		\
		/usr/X11R6/include/X11/Xft1	\
		/usr/local/include/X11/Xft1	\
		/usr/include/X11/Xft2		\
		/usr/X11R6/include/X11/Xft2	\
		/usr/local/include/X11/Xft2	\
		; \
	do  if test -r "$ac_dir/Xft.h" ; then
                xft_inc="yes"
		GL_INCLUDES="$GL_INCLUDES -I$ac_dir"
       	        AC_MSG_RESULT([yes])	
		break	
    	    fi
	done	
	AC_MSG_CHECKING([gcc3])	
	for ac_dir in               		\
		/usr/lib 			\
		/usr/X11R6/lib 		\
		/usr/local/lib		\
		; \
	do  if test -r "$ac_dir/libstdc++.so.5" ; then
                stdglu_inc="yes"
       	        AC_MSG_RESULT([yes])	
		break
    	    fi
	done
	if test "$gl_inc" = "" ; then	        
	 	AC_MSG_WARN(Opengl headers (gl.h) not found !!)
	   	AC_MSG_WARN(Disabling opengl build !)
	   	with_gl="no"
	    	GL_OPTIONS=	
	        GL_INCLUDES=	
		GL_LIBRARIES=
	        exit 1;
	fi
	if test "$glu_inc" = "" ; then
	 	AC_MSG_WARN(Glu headers (glu.h) not found !!)
	   	AC_MSG_WARN(Disabling opengl build !)
	
	   	with_gl="no"
	    	GL_OPTIONS=	
	        GL_INCLUDES=	
		GL_LIBRARIES=
	        exit 1;
	fi
	if test "$gtkgl_inc" = "" ; then
	 	AC_MSG_WARN(Gtkglarea headers (gktglarea.h) not found !!)
	   	AC_MSG_WARN(Disabling opengl build !)
	   	with_gl="no"
	    	GL_OPTIONS=	
	        GL_INCLUDES=	
		GL_LIBRARIES=
	        exit 1;
	fi
	if test "$freetype_inc" = "" ; then
	 	AC_MSG_WARN(Freetype 2 headers (ft2build.h) not found !!)
	   	AC_MSG_WARN(Disabling opengl build !)
	   	with_gl="no"
	    	GL_OPTIONS=	
	        GL_INCLUDES=
		GL_LIBRARIES=
	        exit 1;
	fi
	if test "$xft_inc" = "" ; then
	 	AC_MSG_WARN(Xft 2 headers (Xft.h) not found !!)
	   	AC_MSG_WARN(Disabling opengl build !)
	   	with_gl="no"
	    	GL_OPTIONS=	
	        GL_INCLUDES=
		GL_LIBRARIES=
	        exit 1;
	fi
	if test "$gl_inc" = "yes" ; then
		if test "$glu_inc" = "yes" ; then
			if test "$gtkgl_inc" = "yes" ; then
	                    if test "$freetype_inc" = "yes" ; then
	                    	if test "$xft_inc" = "yes" ; then
			    		if test "$stdglu_inc" = "yes" ; then
					   GL_LIBRARIES=" -lXmu -lXft -lfreetype -lGL -lGLU -lgtkgl -lstdc++"
					else
					   GL_LIBRARIES=" -lXmu -lXft -lfreetype -lGL -lGLU -lgtkgl"
					fi				
					GL_OPTIONS="-D_GL"
	  				no_motif=yes
				fi
			    fi
			fi
		fi
	fi
AC_SUBST(GL_INCLUDES)
AC_SUBST(GL_LIBRARIES)
PRINTIFNOTGL=" "
else
PRINTIFNOTGL=" print_prog"
fi
AC_SUBST(PRINTIFNOTGL)

AC_ARG_ENABLE(svg,           [  --disable-svg           remove SVG support ])
AC_ARG_ENABLE(annot,         [  --disable-annot         remove Annotations support ])
AC_ARG_ENABLE(raptor,        [  --disable-raptor        disable the raptor RDF parser ])
AC_ARG_ENABLE(generic-xml,   [  --disable-generic-xml   remove Generic XML support ])

dnl
dnl plugins support is disabled by default
dnl

if test "$with_plugin" = "" ; then
  if test "$enable_plugin" = "yes" ; then
    with_plugin="yes"
  else
    with_plugin="no"
  fi
fi  

dnl
dnl svg is enabled by default
dnl
if test "$with_svg" = "" ; then
    if test "$enable_svg" = "no" ; then
	with_svg="no"
    else
	with_svg="yes"
    fi
fi

dnl
dnl annotations is enabled by default
dnl
if test "$with_annot" = "" ; then
    if test "$enable_annot" = "no" ; then
	with_annot="no"
    else
	with_annot="yes"
    fi
else
    with_annot="yes"
fi


dnl
dnl The raptor RDF parser is enabled by default
dnl
if test "$with_raptor" = "" ; then
    if test "$enable_raptor" = "no" ; then
	with_raptor="no"
    else
	with_raptor="yes"
    fi
else
    with_raptor="yes"
fi

dnl
dnl Generic XML support enabled by default
dnl
if test "$with_generic_xml" = "" ; then
    if test "$enable_generic_xml" = "no" ; then
	with_generic_xml="no"
	GENERIC_XML_OPTIONS=
    else
	with_generic_xml="yes"
	GENERIC_XML_OPTIONS=-DXML_GENERIC
    fi
fi

AC_ARG_WITH(dav,            [  --with-dav             enable WebDAV support (experimental) ])
dnl
dnl DAV support disabled by default
dnl
if test "$with_dav" = "" ; then
  if test "$enable_dav" = "yes" ; then
    with_dav="yes"
  else
    with_dav="no"
  fi
fi  

if test "$with_dav" = "yes" ; then
   DAV_OPTIONS=-DDAV
   DAVDIR="davlib"
   LIBDAV="libwwwdav"
   WITHDAV="--with-dav" 
   WWWDAV="-lwwwdav" 
else
   with_dav="no"
   DAV_OPTIONS=""
   DAVDIR=""
   LIBDAV=""
   WITHDAV="" 
   WWWDAV="" 
fi


if test "$build_amaya" = "yes" ; then
    if test ! -f $srcdir/../libwww/Makefile.in ; then
	AC_MSG_WARN(libwww sources not found !!)
	AC_MSG_WARN(Disabling Amaya build !)
	build_amaya="no"
    fi

    if test ! -f $srcdir/amaya/MathML.S ; then
	if test "$with_math" = "yes" ; then
	    AC_MSG_WARN(MathML sources not found !!)
	    AC_MSG_WARN(Disabling Math build !)
	    with_math="no"
	    MATH_OPTIONS=
	fi
    fi

    if test ! -f $srcdir/amaya/SVG.S ; then
	if test "$with_svg" = "yes" ; then
	    AC_MSG_WARN(SVG sources not found !!)
	    AC_MSG_WARN(Disabling SVG build !)
	    with_svg="no"
	    SVG_OPTIONS=
	fi
    fi

    if test ! -f $srcdir/annotlib/Makefile.in ; then
	if test "$with_annot" = "yes" ; then
	    AC_MSG_WARN(Annotation makefile not found !!)
	    AC_MSG_WARN(Disabling Annotations build !)
	    with_annot="no"
	fi
    fi

    if test "$with_annot" = "yes" -a "$with_raptor" = "yes" ; then
       if test ! -d "$srcdir/libraptor" ; then
          AC_MSG_WARN(Raptor source dir not found !!)
	  AC_MSG_WARN(Disabling raptor build !)
	  MAKERAPTOR=['#']
	  with_raptor="no"
       else
	   AMAYA_ANNOT_OPTIONS="$AMAYA_ANNOT_OPTIONS -DRAPTOR_RDF_PARSER -I\$(THOTDIR)/libraptor"
 	   AMAYA_RAPTOR_LIBS="../libraptor/.libs/libraptor.a"
	   AMAYA_RAPTOR_SRC="amaya_comp_libraptor"
	   AMAYA_RAPTOR_INCLUDES="-I\$(THOTDIR)/libraptor"
       fi
    else
       AC_MSG_WARN(Disabling raptor build as annotations are disabled !)
       MAKERAPTOR=['#']
       with_raptor="no"
    fi

    dnl control whether we should use libwww's rdf parser
    if test "$with_raptor" = "yes" ; then
       dnl not all the function calls have been cleared as of today, 
       dnl we still need libwww's rdf parser 
       MAKE_LIBWWW_RDF_PARSER=
       LIBWWW_RDF_PARSER=
    else
       MAKE_LIBWWW_RDF_PARSER="libwwwxml"
       LIBWWW_RDF_PARSER="-lwwwxml"
    fi

    if test "$with_plugin" = "yes" ; then
        AC_MSG_WARN(The plugin library isn't supported anymore in Amaya !!)
	AC_MSG_WARN(Disabling plugin build !)
	with_plugin="no"
    fi


    if test ! -f $srcdir/davlib/Makefile.in ; then
	if test "$with_dav" = "yes" ; then
	    AC_MSG_WARN(WebDAV makefile not found !!)
	    AC_MSG_WARN(Disabling WebDAV build !)
	    with_dav="no"
            DAVDIR=""
            LIBDAV=""
            WITHDAV="" 
            WWWDAV="" 
	fi
    fi
   

fi

dnl
dnl The options for each library or binary
dnl

THOT_OPTIONS="$GTK_OPTIONS $I18N_OPTIONS $GL_OPTIONS"
AMAYA_OPTIONS="$MATH_OPTIONS $SVG_OPTIONS $GTK_OPTIONS $GENERIC_XML_OPTIONS $I18N_OPTIONS $GL_OPTIONS"
#PLUGIN_OPTIONS="-DPLUGIN_TRACE -DXP_UNIX"
AMAYA_ANNOT_OPTIONS="$AMAYA_ANNOT_OPTIONS $I18N_OPTIONS"

IMGLIBS="-ljpeg -lpng -lz"
EXTRA_LIBS=

dnl
dnl Set up the PATHs needed
dnl

API="\$(THOTDIR)/thotlib/include"
VAR="\$(THOTDIR)/thotlib/internals/var"
INCL="\$(THOTDIR)/thotlib/internals/h"
FUNC="\$(THOTDIR)/thotlib/internals/f"

dnl
dnl Set up the include variables.
dnl

THOTINCLUDES="-I${API} -I${VAR} -I${INCL} -I${FUNC} ${JPEGINCL} ${PNGINCL}"
APIINCLUDES=-I${API}
 
if test "${VPATHOPT}" = "" ; then
	VPATHOPT="VPATH"
fi

dnl
dnl Exports the current values of the variables.
dnl

AC_SUBST(AMAYA_VER)
AC_SUBST(CEXTRACT_VER)
AC_SUBST(CEXTRACT_FLAGS)

AC_SUBST(THOTINCLUDES)
AC_SUBST(APIINCLUDES)
AC_SUBST(VPATHOPT)

AC_SUBST(GTK_OPTIONS)
AC_SUBST(THOT_OPTIONS)
AC_SUBST(AMAYA_OPTIONS)
AC_SUBST(PLUGIN_OPTIONS)
AC_SUBST(AMAYA_ANNOT_OPTIONS)
AC_SUBST(IMGLIBS)
AC_SUBST(EXTRA_LIBS)

AC_SUBST(DAVDIR)
AC_SUBST(LIBDAV)
AC_SUBST(WITHDAV)
AC_SUBST(WWWDAV)

AC_SUBST(MAKERAPTOR)
AC_SUBST(AMAYA_RAPTOR_LIBS)
AC_SUBST(AMAYA_RAPTOR_SRC)
AC_SUBST(AMAYA_RAPTOR_INCLUDES)
AC_SUBST(MAKE_LIBWWW_RDF_PARSER)
AC_SUBST(LIBWWW_RDF_PARSER)

AC_SUBST(SUBDIRS)

dnl
dnl Include the option Makefile.xxx fragment according to the configure options
dnl

if test "$with_plugin" = "yes" ; then
    AC_SUBST_FILE(plugin_frag)
    plugin_frag=$srcdir/pluginlib/Makefile.plugin
else
    AC_SUBST_FILE(plugin_frag)
    plugin_frag=/dev/null
fi

    AC_SUBST_FILE(www_frag)
    www_frag=$srcdir/amaya/Makefile.libwww

if test "$with_math" = "no" ; then
    AC_SUBST_FILE(math_frag)
    math_frag=/dev/null
else
    AC_SUBST_FILE(math_frag)
    math_frag=$srcdir/amaya/Makefile.math
fi

if test "$with_svg" = "no" ; then
    AC_SUBST_FILE(svg_frag)
    svg_frag=/dev/null
else
    AC_SUBST_FILE(svg_frag)
    svg_frag=$srcdir/amaya/Makefile.svg
fi

if test "$with_annot" = "yes" ; then
    AC_SUBST_FILE(annot_frag)
    annot_frag=$srcdir/annotlib/Makefile.annot
else
    AC_SUBST_FILE(annot_frag)
    annot_frag=/dev/null
fi

if test "$with_dav" = "yes" ; then
    AC_SUBST_FILE(dav_frag)
    dav_frag=$srcdir/davlib/Makefile.dav
fi

dnl  ***************************************************************
dnl
dnl      FINAL STEP : PRODUCE ALL THE MAKEFILES AND CONFIG FILES
dnl
dnl  ***************************************************************

EXTRA_MAKEFILE_IN=
make_output="Makefile Options.orig:Options.in tools/Makefile \
       libjpeg/Makefile libpng/Makefile libpng/zlib/Makefile \
       tools/mkdep/Makefile \
       tools/cextract-1.7/Makefile thotlib/Makefile \
       thotlib/include/Makefile batch/Makefile tablelib/Makefile"

if test "$build_amaya" = "yes" ; then

    make_output="$make_output amaya/Makefile pluginlib/Makefile"
    EXTRA_MAKEFILE_IN="$srcdir/amaya/Makefile.in \
    $srcdir/amaya/Makefile.libwww"

    if test "$$with_plugin" = "yes" ; then
       make_output="$make_output pluginlib/Makefile"
       EXTRA_MAKEFILE_IN="$srcdir/pluginlib/Makefile.in \
       $srcdir/pluginlib/Makefile.plugin"
    fi

    if test "$with_annot" = "yes" ; then
       make_output="$make_output annotlib/Makefile"
       EXTRA_MAKEFILE_IN="$srcdir/annotlib/Makefile.in"
    fi

    if test "$with_dav" = "yes" ; then
       make_output="$make_output davlib/Makefile"
       EXTRA_MAKEFILE_IN="$srcdir/davlib/Makefile.in"
    fi

fi

AC_SUBST(EXTRA_MAKEFILE_IN)
AC_OUTPUT($make_output , [
dnl
dnl This fragment of shell code is executed after the
dnl Makefile(s) dump ...
dnl

echo timestamp > stamp-h

dnl
dnl Check for an upgrade in the Options numbers
dnl

if test -f Options ; then
   oldversion=`grep Version Options`
   newversion=`grep Version Options.orig`
   if test "$oldversion" != "$newversion" ; then
       echo WARNING : Options files have changed, old options saved to Options.old
       cp Options Options.old
       cp Options.orig Options
       exit 1
   fi
fi
])

if test "$build_amaya" = "yes" ; then
    echo Amaya configured with libWWW
    if test "$with_plugin" = "yes" ; then
        echo Amaya configured with Plugins support
    fi
    if test "$with_math" = "yes" ; then
	echo Amaya configured with Math support
    fi
    if test "$with_svg" = "yes" ; then
	echo Amaya configured with SVG support
    fi
    if test "$with_annot" = "yes" ; then
	echo Amaya configured with Annotations support
    fi
    if test "$with_raptor" = "yes" ; then
	echo Amaya configured with the Raptor RDF parser
    fi
    if test "$with_generic_xml" = "yes" ; then
	echo Amaya configured with generic XML suppport
    fi
    if test "$with_i18n" = "yes" ; then
	echo Amaya configured with internationalization suppport
    fi 
    if test "$with_gl" = "yes" ; then
	echo Amaya configured with Opengl Canvas Rendering \(experimental\)
    fi
    if test "$with_dav" = "yes" ; then
	echo Amaya configured with WebDAV support \(experimental\)
    fi
fi

if test "$no_graphic" = "yes" ; then
    echo "Amaya configured with system graphic libraries (libjpeg, libpng, zlib)"
else
    echo "Amaya configured with static graphic libraries (libjpeg, libpng, zlib)"
    if test "$with_gtk" = "yes" -o "$with_gl" = "yes" ; then
      echo "  N.B. This option may not work in your platform. If Amaya crashes"
      echo "  when opening a PNG file. Recompile it using the system libraries."
    fi
fi

if test "$with_gtk" = "yes" ; then
    echo "Amaya configured with GTK"
else 
  if test "$no_motif" = "yes" ; then
    echo "Motif seems not installed on this machine"
    echo "Amaya need Motif 1.2 or 2.0"
  else
    if test "$motif_includes" = "" ; then
      echo "Motif includes were not found"
      echo "Amaya might not compile"
      echo "Edit your Option file"
    else
      if test "$motif_libraries" = "" ; then
        echo "Motif libraries were not found"
        echo "Amaya might not compile"
        echo "Edit your Option file"
      fi
    fi
  fi
fi

echo ""
echo "Now type \"make\" (GNU make preferably) to build the binaries"
echo ""
