AC_INIT(vte.pc.in)
VERSION=`grep ^Version: $srcdir/vte.spec | awk '{print $NF}'`
AM_INIT_AUTOMAKE(vte,$VERSION)

AC_ISC_POSIX
AC_PROG_CC
AC_STDC_HEADERS
AM_PROG_CC_STDC
AM_MAINTAINER_MODE

AM_PROG_LIBTOOL
ALL_LINGUAS="am ar az be bg bn ca cs cy da de el en_CA en_GB es et eu fa fi fr ga gu he hr hu id is it ja ko li lt lv mk ml mn ms ne nl nn no pa pl pt pt_BR ro ru sk sl sq sr sr@Latn sv tr uk vi wa zh_CN zh_TW"

AM_GLIB_GNU_GETTEXT
AC_CHECK_DECLS(bind_textdomain_codeset,,,[#include "libintl.h"])

AC_PATH_XTRA
CFLAGS="$X_CFLAGS $CFLAGS"
LIBS="$X_LIBS $LIBS"

if pkg-config --exists "gtk+-2.0 >= 2.2" ; then
	MODULEGTK="gtk+-2.0 >= 2.2"
	AC_DEFINE(GDK_MULTIHEAD_SAFE,1,[Force use of GDK's multihead-safe APIs.])
else
	MODULEGTK="gtk+-2.0"
fi
PKG_CHECK_MODULES(GLIB,glib-2.0)
PKG_CHECK_MODULES(GOBJECT,[glib-2.0 gobject-2.0])
PKG_CHECK_MODULES(GTK,[glib-2.0 gobject-2.0 $MODULEGTK])

wantedmodules="glib-2.0 gobject-2.0 $MODULEGTK fontconfig"

# Let the user specify the default terminal emulation.
AC_ARG_WITH(default-emulation,
AS_HELP_STRING(--with-default-emulation=xterm,default terminal type to be emulated),
emulation=$withval,emulation=xterm)
AC_DEFINE_UNQUOTED(VTE_DEFAULT_EMULATION,"$emulation",[The default terminal type to be emulated.])
VTE_DEFAULT_EMULATION=$emulation
AC_SUBST(VTE_DEFAULT_EMULATION)

# Use Xft2 if Pango has Xft2 support and it isn't disabled.
if test "$have_x" = yes ; then
	AC_ARG_WITH(xft2,[AS_HELP_STRING(--with-xft2,enable drawing using Xft2)],with_xft2=$withval,with_xft2=yes)
	if test $with_xft2 = yes ; then
		if pkg-config --exists pangoxft '>=' 1.1.0 ; then
			AC_DEFINE(HAVE_XFT2,1,[Whether we have Xft2])
			wantedmodules="$wantedmodules pangoxft >= 1.1.0"
			wantedmodules="xft >= 2.0 $wantedmodules"
		else
			AC_MSG_WARN([Xft2 not detected])
		fi
	fi
fi

# Use PangoX if we have it and it isn't disabled.
if test "$have_x" = yes ; then
	AC_ARG_WITH(pangox,[AS_HELP_STRING(--with-pangox,enable drawing using PangoX)],with_pangox=$withval,with_pangox=yes)
	if test $with_pangox = yes ; then
		if pkg-config --exists pangox ; then
			AC_DEFINE(HAVE_PANGOX,1,[Whether we have PangoX])
			wantedmodules="$wantedmodules pangox"
		else
			AC_MSG_WARN([PangoX not detected])
		fi
	fi
fi

# Use glX if we have it and it isn't disabled.
if test "$have_x" = yes ; then
	AC_ARG_WITH(glX,[AS_HELP_STRING(--with-glX,enable drawing using glX)],with_glx=$withval,with_glx=no)
	if test $with_glx = yes ; then
		have_gl=0
		have_libgl=0
		AC_CHECK_HEADERS(GL/glx.h)
		if test $ac_cv_header_GL_glx_h = yes ; then
			AC_CHECK_FUNC(glXQueryExtension,[have_gl=1],AC_CHECK_LIB(GL,glXQueryExtension,[have_gl=1;have_libgl=1]))
		fi
		if test $have_gl = 1 ; then
			AC_DEFINE(HAVE_GL,1,[Whether we have GL and glX.])
		fi
		if test $have_libgl = 1 ; then
			LIBS="-lGLU -lGL $LIBS"
		fi
	fi
fi

# Search for the required modules.
PKG_CHECK_MODULES(VTE,[$wantedmodules])
NEEDEDPACKAGES="$wantedmodules"
AC_SUBST(NEEDEDPACKAGES)

# Require Freetype2.  We use our local copy of the macro because packages of
# freetype's development files don't always include the proper macro.
VTE_CHECK_FT2(6.1.0,,[AC_MSG_ERROR([You must have freetype 2.0.2 or later to build vte.])])

# Temporarily pull in the Freetype cflags and libs for checking what's
# available in this version.
savecflags="$CFLAGS"
CFLAGS="$CFLAGS $FT2_CFLAGS"
savecppflags="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $FT2_CFLAGS"
if test -d "$ac_x_includes" ; then
	CFLAGS="$CFLAGS -I$ac_x_includes"
	CPPFLAGS="$CPPFLAGS -I$ac_x_includes"
fi
AC_CHECK_HEADERS(ft2build.h)
if test x$ac_cv_header_ft2build_h != xyes ; then
	AC_MSG_ERROR([You must have freetype 2.0.2 or later to build vte.])
fi

AC_CHECK_DECL(ft_render_mode_mono,[AC_DEFINE(HAVE_DECL_ft_render_mode_mono,1,Define if your freetype2 installation defines ft_render_mode_mono.)],,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])

AC_CHECK_DECL(FT_RENDER_MODE_MONO,[AC_DEFINE(HAVE_DECL_FT_RENDER_MODE_MONO,1,Define if your freetype2 installation defines FT_RENDER_MODE_MONO.)],,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])

AC_CHECK_DECLS(FT_LOAD_NO_HINTING,,,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])

AC_CHECK_DECLS(FT_RENDER_MODE_LIGHT,,,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])

AC_CHECK_DECLS(FT_RENDER_MODE_NORMAL,,,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])

AC_CHECK_DECL(FT_PIXEL_MODE_MONO,[AC_DEFINE(HAVE_DECL_FT_PIXEL_MODE_MONO,1,Define if your freetype2 build declares FT_PIXEL_MODE_MONO.)],,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])
AC_CHECK_DECL(ft_pixel_mode_mono,[AC_DEFINE(HAVE_DECL_ft_pixel_mode_mono,1,Define if your freetype2 build declares ft_pixel_mode_mono.)],,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])

AC_CHECK_DECLS(FT_PIXEL_MODE_GRAY2,,,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])
AC_CHECK_DECLS(FT_PIXEL_MODE_GRAY4,,,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])

AC_CHECK_DECL(FT_PIXEL_MODE_GRAY,[AC_DEFINE(HAVE_DECL_FT_PIXEL_MODE_GRAY,1,Define if your freetype2 build declares FT_PIXEL_MODE_GRAY.)],,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])
AC_CHECK_DECL(ft_pixel_mode_grays,[AC_DEFINE(HAVE_DECL_ft_pixel_mode_grays,1,Define if your freetype2 build declares ft_pixel_mode_grays.)],,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])

AC_CHECK_DECLS(FT_PIXEL_MODE_LCD,,,[
#ifdef HAVE_FT2BUILD_H
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
])

CFLAGS="$savecflags"
CPPFLAGS="$savecppflags"

# Use all available features under glibc, and disable accidental use of
# deprecated functionality.
AC_EGREP_CPP(glibc,
		[
		 #include <stdio.h>
		 #ifdef __GLIBC__
		 glibc
		 #endif
		],
		AC_DEFINE(_GNU_SOURCE,1,[Use all glibc features.]))
AC_DEFINE(_XOPEN_SOURCE_EXTENDED,1,[Needed to get declarations for msg_control and msg_controllen on Solaris])
AC_DEFINE(_XOPEN_SOURCE,1,[Needed to get declarations for msg_control and msg_controllen on Solaris])
AC_DEFINE(__EXTENSIONS__,1,[Needed to get declarations for msg_control and msg_controllen on Solaris])

AC_ARG_ENABLE(deprecation,[AS_HELP_STRING(--enable-deprecation,prohibit VTE from using deprecated GLib/Pango/GDK/GTK+ features)],usedeprecation=$enableval,usedeprecation=no)
if test "$usedeprecation" = yes ; then
AC_DEFINE(G_DISABLE_DEPRECATED,1,[Disable deprecated GLib features.])
AC_DEFINE(GDK_DISABLE_DEPRECATED,1,[Disable deprecated GDK features.])
AC_DEFINE(GDK_PIXBUF_DISABLE_DEPRECATED,1,[Disable deprecated gdk-pixbuf features.])
AC_DEFINE(GTK_DISABLE_DEPRECATED,1,[Disable deprecated GTK+ features.])
AC_DEFINE(PANGO_DISABLE_DEPRECATED,1,[Disable deprecated Pango features.])
fi

# Miscellaneous definitions.
AC_DEFINE(VTE_UTF8_BPC,6,[Maximum number of bytes used per UTF-8 character.])
AC_DEFINE(VTE_INVALID_SOURCE,-1,[A number which can never be a valid source ID.])
AC_DEFINE_UNQUOTED(PACKAGE,"$PACKAGE",[Package name.])

# Check for headers.
AC_CHECK_HEADERS(sys/select.h sys/termios.h sys/un.h stropts.h termios.h wchar.h)
AC_HEADER_TIOCGWINSZ

# Check for PTY handling functions.
AC_CHECK_FUNCS(cfmakeraw getpgid getpt grantpt unlockpt ptsname ptsname_r)

# Pull in the right libraries for various functions which might not be
# bundled into an exploded libc.
AC_CHECK_FUNC(socket,[have_socket=1],AC_CHECK_LIB(socket,socket,[have_socket=1; LIBS="$LIBS -lsocket"]))
AC_CHECK_FUNC(socketpair,[have_socketpair=1],AC_CHECK_LIB(socket,socketpair,[have_socketpair=1; LIBS="$LIBS -lsocket"]))
AC_CHECK_FUNC(recvmsg,[have_recvmsg=1],AC_CHECK_LIB(socket,recvmsg,[have_recvmsg=1; LIBS="$LIBS -lsocket -lnsl"]))
if test x$have_socket = x1 ; then
	AC_DEFINE(HAVE_SOCKET,1,[Define if you have the socket function.])
fi
if test x$have_socketpair = x1 ; then
	AC_DEFINE(HAVE_SOCKETPAIR,1,[Define if you have the socketpair function.])
fi
if test x$have_recvmsg = x1 ; then
	AC_DEFINE(HAVE_RECVMSG,1,[Define if you have the recvmsg function.])
fi
AC_CHECK_FUNC(floor,,AC_CHECK_LIB(m,floor,LIBS=["$LIBS -lm"]))

# Look for ncurses or curses or termcap.
AC_CHECK_HEADER(ncurses.h,[AC_CHECK_HEADER(term.h,[AC_CHECK_LIB(ncurses,tgetent,[LIBS="-lncurses $LIBS";AC_DEFINE(HAVE_NCURSES,1,[Define if you have ncurses.h and libncurses])])])])
if test x$ac_cv_lib_ncurses_tgetent != xyes ; then
	AC_CHECK_HEADER(curses.h,[AC_CHECK_HEADER(term.h,[AC_CHECK_LIB(curses,tgetent,[LIBS="-lcurses $LIBS";AC_DEFINE(HAVE_CURSES,1,[Define if you have curses.h and libcurses])])])])
	if test x$ac_cv_lib_curses_tgetent != xyes ; then
		AC_CHECK_HEADER(termcap.h,[AC_CHECK_LIB(termcap,tgetent,[LIBS="-ltermcap $LIBS";AC_DEFINE(HAVE_TERMCAP,1,[Define if you have termcap.h and libtermcap])])])
		if test x$ac_cv_header_termcap_h != xyes ; then
			AC_MSG_ERROR([You must have at least one of ncurses, curses, or libtermcap installed to build vte.])
		fi
	fi
fi

# Save the names of these other libraries.
OTHERCFLAGS="$X_CFLAGS"
AC_SUBST(OTHERCFLAGS)
OTHERLIBS="$LIBS"
AC_SUBST(OTHERLIBS)

# Enable debugging messages and additional run-time checks.
AC_ARG_ENABLE(debugging,[AS_HELP_STRING(--enable-debugging,enable extra debugging checks and logging messages)],DEBUG=$enableval,DEBUG=no)
if test x$DEBUG != x ; then
	if test x$DEBUG != xno ; then
		if test x$GCC = xyes ; then
			AC_CHECK_CC_OPT(-std=c99,vte_std_c99)
			CFLAGS="${CFLAGS} $vte_std_c99"
			CFLAGS="${CFLAGS} -Wall"
			CFLAGS="${CFLAGS} -Waggregate-return"
			CFLAGS="${CFLAGS} -Wcast-align"
			CFLAGS="${CFLAGS} -Wimplicit"
			CFLAGS="${CFLAGS} -Wmissing-declarations"
			CFLAGS="${CFLAGS} -Wmissing-prototypes"
			CFLAGS="${CFLAGS} -Wpointer-arith"
			CFLAGS="${CFLAGS} -Wstrict-prototypes"
			CFLAGS="${CFLAGS} -Wuninitialized"
			#CFLAGS="${CFLAGS} -Wsign-compare"
			#CFLAGS="${CFLAGS} -Wunused-value"
		fi
		VTE_DEBUG=1
	fi
fi
if test x$VTE_DEBUG = x1 ; then
	AC_MSG_RESULT([enabling debug checks and messages])
	AC_DEFINE(VTE_DEBUG,1,[Enable debugging messages.])
fi

wcs_funcs_includes="
#ifdef HAVE_STRING_H
# if !STDC_HEADERS && HAVE_MEMORY_H
#  include <memory.h>
# endif
# include <string.h>
#else
# ifdef HAVE_STRINGS_H
#  include <strings.h>
# endif
#endif
#ifdef HAVE_WCHAR_H
# include <wchar.h>
#endif
"

AC_CHECK_TYPES(wint_t, AC_DEFINE(HAVE_WINT_T, , [Defined when the wint_t type is supported]), ,$wcs_funcs_includes)

# Search for Python.
BUILD_PYTHON=true
AC_ARG_ENABLE(python, [AS_HELP_STRING(--enable-python,Build python bindings [default=yes])],[
if test x"$enableval" != xno ; then
	BUILD_PYTHON=true
else
	BUILD_PYTHON=false
fi],BUILD_PYTHON=true)

if $BUILD_PYTHON ; then
	AM_PATH_PYTHON
	if test -z "$PYTHON" ; then
		BUILD_PYTHON=false
	fi
fi

if $BUILD_PYTHON ; then
	AC_MSG_CHECKING(for python >= 2.2)
	prog="
import sys, string
minver = (2,2,0,'final',0)
if sys.version_info < minver:
	sys.exit(1)
sys.exit(0)
"
	if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
	then
		AC_MSG_RESULT([okay])
	else
		BUILD_PYTHON=false
		AC_MSG_RESULT([too old])
	fi
fi

if $BUILD_PYTHON ; then
	AM_CHECK_PYTHON_HEADERS(,BUILD_PYTHON=false)
fi

if $BUILD_PYTHON ; then
	AC_MSG_CHECKING([for pygtk-2.0])
	if pkg-config --exists pygtk-2.0 ; then
		AC_MSG_RESULT([found])
		PKG_CHECK_MODULES(PYGTK,[pygtk-2.0])
		PYGTK_DATADIR=`pkg-config --variable=datadir pygtk-2.0`
		AC_SUBST(PYGTK_DATADIR)
	else
		AC_MSG_RESULT([not found])
		BUILD_PYTHON=false
	fi
fi

if ! $BUILD_PYTHON ; then
	AC_MSG_RESULT([Python bindings disabled.])
fi

AC_SUBST(PYTHONREV)
AC_SUBST(PYTHONMODULES)
AM_CONDITIONAL(BUILD_PYTHON_MODULES, $BUILD_PYTHON)

# If we can find libzvt on the system, set up to build a variant of "reflect"
# which uses it.
REFLECT_ZVT=false
if pkg-config --exists libzvt-2.0 ; then
	REFLECT_ZVT=true
	ZVT_DEFS=-DHAVE_ZVT
	PKG_CHECK_MODULES(ZVT,[gtk+-2.0 libzvt-2.0])
fi
AC_SUBST(ZVT_DEFS)
AM_CONDITIONAL(REFLECT_USE_ZVT, $REFLECT_ZVT)

mylibdir=`eval echo $libdir`
mylibexecdir=`eval echo $libexecdir`
mydatadir=`eval echo $datadir`
if test x$exec_prefix = xNONE ; then
	if test x$prefix = xNONE ; then
		mylibdir=` echo $mylibdir  | sed s,NONE,$ac_default_prefix,g`
		mylibexecdir=` echo $mylibexecdir  | sed s,NONE,$ac_default_prefix,g`
	else
		mylibdir=` echo $mylibdir  | sed s,NONE,$prefix,g`
		mylibexecdir=` echo $mylibexecdir  | sed s,NONE,$prefix,g`
	fi
fi
if test x$prefix = xNONE ; then
	mydatadir=`echo $mydatadir | sed s,NONE,$ac_default_prefix,g`
fi
AC_DEFINE_UNQUOTED(PKGLIBDIR,"$mylibdir/$PACKAGE",
                   [The location where package-specific helpers can be found.])
AC_DEFINE_UNQUOTED(LIBEXECDIR,"$mylibexecdir",
                   [The location where package-specific helpers can be found.])
AC_DEFINE_UNQUOTED(DATADIR,"$mydatadir",
                   [The location where arch-independent package-specific data can be found.])
AC_DEFINE_UNQUOTED(LOCALEDIR,"$mydatadir/locale",
                   [The location where locale data can be found.])

GETTEXT_PACKAGE=vte
AC_SUBST(GETTEXT_PACKAGE)

AC_ARG_ENABLE(gnome-pty-helper, [AS_HELP_STRING(--enable-gnome-pty-helper,Build a setuid helper for opening ptys [default=yes])], enable_gnome_pty_helper="$enableval", enable_gnome_pty_helper=yes)
if test "$enable_gnome_pty_helper" != no; then
	AC_DEFINE(VTE_USE_GNOME_PTY_HELPER,1,[Define if you intend to use gnome-pty-helper.])
	AC_CONFIG_SUBDIRS(gnome-pty-helper)
fi
AM_CONDITIONAL(BUILD_GNOME_PTY_HELPER,[test "$enable_gnome_pty_helper" != no])

################################################################################

# This is a check for gtk-doc which you can insert into your configure.in.
# You shouldn't need to change it at all.

##################################################
# Check for gtk-doc.
##################################################

AC_ARG_WITH(html-dir, [AS_HELP_STRING(--with-html-dir=PATH,path to installed docs)])

if test "x$with_html_dir" = "x" ; then
  HTML_DIR='${datadir}/gtk-doc/html'
else
  HTML_DIR=$with_html_dir
fi

AC_SUBST(HTML_DIR)

AC_CHECK_PROG(GTKDOC, gtkdoc-mkdb, true, false)

gtk_doc_min_version=0.6
if $GTKDOC ; then 
    gtk_doc_version=`gtkdoc-mkdb --version`
    AC_MSG_CHECKING([gtk-doc version ($gtk_doc_version) >= $gtk_doc_min_version])

    IFS="${IFS= 	}"; vte_save_IFS="$IFS"; IFS="."
    set $gtk_doc_version
    for min in $gtk_doc_min_version ; do
        cur=$1; shift
        if test -z $min ; then break; fi
        if test -z $cur ; then GTKDOC=false; break; fi
        if test $cur -gt $min ; then break ; fi
        if test $cur -lt $min ; then GTKDOC=false; break ; fi
    done
    IFS="$vte_save_IFS"

    if $GTKDOC ; then
      AC_MSG_RESULT(yes)
    else
      AC_MSG_RESULT(no)
    fi
fi

dnl Let people disable the gtk-doc stuff.
AC_ARG_ENABLE(gtk-doc, [AS_HELP_STRING(--enable-gtk-doc,Use gtk-doc to build documentation [default=auto])], enable_gtk_doc="$enableval", enable_gtk_doc=auto)

if test x$enable_gtk_doc = xauto ; then
  if test x$GTKDOC = xtrue ; then
    enable_gtk_doc=yes
  else
    enable_gtk_doc=no 
  fi
fi

AM_CONDITIONAL(ENABLE_GTK_DOC, test x$enable_gtk_doc = xyes)

################################################################################

AM_CONFIG_HEADER(config.h)

AC_OUTPUT([
Makefile
src/Makefile
termcaps/Makefile
python/Makefile
po/Makefile.in
doc/Makefile
doc/openi18n/Makefile
doc/reference/Makefile
vte.pc
vte-uninstalled.pc
])
