dnl Process this file with autoconf to produce a configure script.

# Original Author was Kalle@kde.org
# I lifted it in some mater. (Stephan Kulow)
# I used much code from Janos Farkas
# Heavily tweaked and modified for Scribus by Craig Ringer

dnl Quick `configure.in.in' survival guide:
dnl
dnl AC_MSG_WARN([warning message])
dnl     prints the warning and continues
dnl AC_MSG_ERROR([error message])
dnl     prints the error and stops configure
dnl AC_PATH_PROG([VARNAME],[programname],[notfoundvalue],[search path])
dnl     Searches for programname along search path or default path and sets
dnl     VARNAME to the path to the program, if found. If not found and
dnl     notfoundvalue provided, sets VARNAME to notfoundvalue, otherwise "".
dnl AC_CHECK_LIB(lib_basename, lib_symbol, [command_if_success], [command_if_fail])
dnl     Looks for a library with basename lib_basename, ie libfreetype.so.3.0.0
dnl     might be found for lib_basename=libfreetype, and checks for the lib_symbol
dnl     symbol inside. The symbol is usually an important function, a version symbol,
dnl     etc. Runs the specified commands on failure (lib not found OR symbol not found)
dnl     or success, as appropriate.
dnl AC_CHECK_HEADER(headerfilename.h, [successcommand], [failcommand])
dnl     Search for headerfilename.h. If found, run successcommand, otherwise
dnl     run failcommand.
dnl AC_SUBST(VARNAME)
dnl     "export" VARNAME so that it's defined in the Makefile.in with the value
dnl     it was set to in this script. Thus:
dnl         LIBFRED=" -lfred "
dnl         AC_SUBST(LIBFRED)
dnl     will let you use $(LIBFRED) in the Makefile.am .
dnl AC_DEFINE_UNQUOTED(VARNAME, VALUE, [comment in config.h])
dnl     Sets VARNAME to VALUE in config.h, so it can be tested for in preprocessor
dnl     macros in the source. The supplied comment is included in config.h .
dnl
dnl configure.in.in is written in shell script, plus M4 macros that expand into
dnl yet more shell script. Some M4 macros are provided by autoconf and automake,
dnl some by libtool, and some are provided by KDE. In general, if its
dnl UPPER_CASE(WITH_BRACKETS) it'll be an M4 macro, and if it looks like shell
dnl script it probably is. Variables are boring old shell variables unless exported
dnl to somewhere using AC_SUBST(...) or AC_DEFINE_UNQUOTED(...) and friends.
dnl
dnl `dnl' is an M4 comment, # is a shell comment. The only differences are that
dnl M4 macros in shell comments still get expanded so if you want to "comment out"
dnl code with M4 macros you must use dnl, and that dnl comments are omitted from
dnl configure.in .
dnl
dnl Note that you should NOT assume the user has bash. Ensure that you TEST YOUR CODE
dnl with ash or a similar "primitive" shell before committing.
dnl
dnl Blame any errors in the above entirely on Craig Ringer. Please see the
dnl autoconf documentation (ha!) for details on these and more.

AC_INIT(acinclude.m4) dnl a source file from your sub dir

dnl This is so we can use kde-common
AC_CONFIG_AUX_DIR(admin)

AC_CANONICAL_SYSTEM 
AC_ARG_PROGRAM

dnl Automake doc recommends to do this only here. (Janos)
AM_INIT_AUTOMAKE(scribus,1.3.4)

dnl Check for --enable-lib64
KDE_CHECK_LIB64

dnl Add the libs and includes from --with-extra-libs and --with-extra-includes
KDE_CHECK_EXTRA_LIBS

dnl KDE_SET_PREFIX

AC_PREFIX_DEFAULT(/usr/local)
if test "x$prefix" = "xNONE"; then
  prefix=$ac_default_prefix
  ac_configure_args="$ac_configure_args --prefix $prefix"
fi

dnl Look for pkg-config, which we use to find fontconfig and
dnl will probably need for other things in future.
PKG_CONFIG=""
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)

dnl Define a handy function to print a message for when libraries
dnl can't be found. This can be called from configure.in.in, and from
dnl configure.in.bot (which is, after all, just tacked on the bottom
dnl during the generation of configure).

libmissing_text="\
You may need to install some additional libraries or packages (on Linux,
that may mean -dev or -devel packages too). Also check your environment
variables. If you're on a 64 bit machine, maybe you need to add
--enable-libsuffix=64 to the configure arguments.
See the BUILDING file for further details and troubleshooting information. "

missing_libs=""

# Usage: libmissing libfreetype required
#        libmissing libfontconfig optional
# to report a missing library
libmissing() {
	# name of library
	libname="${1}"
	# one of "optional" or "required"
	liboptional="${2}"

	terminate=no
	missing_libs="${libname} ${missing_libs}"
	if test "${liboptional}" = "required"; then
		terminate=yes
		reqword="required"
		endmsg="This library is required for Scribus to build. Configure will now terminate."
	elif test "${liboptional}" = "optional"; then
		reqword="optional"
		endmsg="This library is optional, and Scribus will build without it. Continuing."
	else
		endmsg=""
	fi

	AC_MSG_WARN([
-------------------------------------------------------------------------------
The ${reqword} library ${libname} could not be found. See the BUILDING file.

${libmissing_text}
${endmsg}
-------------------------------------------------------------------------------
])

	if test "$terminate" = "yes"; then
		AC_MSG_ERROR([Required library ${libname} not found])
	fi

}
# end libmissing()

dnl Use gcc symbol visibility?
dnl This should probably default to "yes" in future.
AC_ARG_ENABLE(gcc_symbol_visibility,
			  [  --enable-gcc-symbol-visibility  Use -fvisiblity with gcc for smaller binaries.],
			  [use_gcc_symbol_visibility="yes"])
KDE_CHECK_COMPILER_FLAG(fvisibility=hidden, [have_visibility=yes])
AC_MSG_CHECKING([whether to use gcc symbol visibility controls])
if test "$use_gcc_symbol_visibility" = "yes" -a "$have_visibility" = "yes"; then
	# see http://people.redhat.com/drepper/dsohowto.pdf , http://gcc.gnu.org/wiki/Visibility
	gcc_visibility_flags="$CXXFLAGS -fvisibility=hidden -DHAVE_GCC_SYMBOL_VISIBILITY=1"
	GCC_C_VISIBILITY_FLAGS="$gcc_visibility_flags"
	GCC_CXX_VISIBILITY_FLAGS="$gcc_visibility_flags -fvisibility-inlines-hidden "
	AC_MSG_RESULT([yes])
else
	GCC_C_VISIBILITY_FLAGS=""
	GCC_CXX_VISIBILITY_FLAGS=""
	AC_MSG_RESULT([no - disabled or no compiler support])
fi
AC_SUBST(GCC_C_VISIBILITY_FLAGS)
AC_SUBST(GCC_CXX_VISIBILITY_FLAGS)

LIBART_LIBS=""
LIBART_CFLAGS=""
LIBART_CONFIG=""

AC_PATH_PROG(LIBART_CONFIG,
			 libart2-config,
			 [],
			 [$PATH ${prefix}/bin ${exec_prefix}/bin /usr/local/bin /usr/nekoware/bin /opt/local/bin])

if test -n "$LIBART_CONFIG"; then
  vers=`$LIBART_CONFIG --version 2>/dev/null | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
  if test -n "$vers" && test "$vers" -ge 2003008
  then
     LIBART_LIBS="`$LIBART_CONFIG --libs`"
     LIBART_CFLAGS="`$LIBART_CONFIG --cflags`"
     AC_DEFINE_UNQUOTED(HAVE_LIBART, 1, [Defines if your system has the libart library])
  else
     libmissing libart required
	 AC_MSG_ERROR([You need at least libart 2.3.8 . See the BUILDING file.])
  fi
else
  libmissing libart required
  AC_MSG_ERROR([You need at least libart 2.3.8 . See the BUILDING file.])
fi

hacairo=no
LIBCAIRO_LIBS=""
LIBCAIRO_CFLAGS=""
COMPILE_CAIRO=no
AC_ARG_ENABLE(cairo, [  --enable-cairo     Enables building with cairo support],
[if test "x$enable_cairo" = "xyes" || test "x$enable_cairo" = "xfull"; then
	COMPILE_CAIRO=yes
	AC_MSG_CHECKING([Checking for cairo with pkg-config])
	if test -n "$PKG_CONFIG"; then
		LIBCAIRO_LIBS="`$PKG_CONFIG cairo --libs`"
		LIBCAIRO_CFLAGS="`$PKG_CONFIG cairo --cflags`"
		if test -n "$LIBCAIRO_LIBS" || test -n "$LIBCAIRO_CFLAGS"; then
			AC_MSG_RESULT([found])
			hacairo=yes
		else
			AC_MSG_RESULT([not found])
		fi
	else
		AC_MSG_RESULT([failed: pkg-config not found])
	fi
	if test $hacairo = yes; then
		LIBART_LIBS=""
		LIBART_CFLAGS=""
		AC_DEFINE_UNQUOTED(HAVE_CAIRO, 1, [Defines if your system has the cairo library])
	else
		libmissing cairo optional
		AC_MSG_WARN([Couldn't find a usable cairo])
	fi
fi])
AM_CONDITIONAL(COMPILE_CAIRO, test x$COMPILE_CAIRO = xyes)
AC_SUBST(LIBCAIRO_LIBS)
AC_SUBST(LIBCAIRO_CFLAGS)

AC_SUBST(LIBART_LIBS)
AC_SUBST(LIBART_CFLAGS)
AC_C_BIGENDIAN

dnl Check for freetype, which Scribus *requires* to build
LIBFREETYPE_LIBS=""
LIBFREETYPE_CFLAGS=""

FREETYPE_CONFIG=""
AC_PATH_PROG(FREETYPE_CONFIG,
			 freetype-config,
			 [],
			 [$PATH ${prefix}/bin ${exec_prefix}/bin /usr/local/bin /opt/local/bin /usr/bin /usr/nekoware/bin /usr/X11/bin])

hafree=no
hafree_post219=
if test -n "$FREETYPE_CONFIG"; then
	LIBFREETYPE_LIBS="`$FREETYPE_CONFIG --libs`"
	LIBFREETYPE_CFLAGS="`$FREETYPE_CONFIG --cflags`"
	AC_CHECK_LIB(freetype, FT_Get_First_Char, [hafree=yes],[hafree=no], "$LIBFREETYPE_LIBS")
	AC_CHECK_LIB(freetype, FT_Get_Next_Char, [hafree=yes],[hafree=no], "$LIBFREETYPE_LIBS")
	if test $hafree = yes; then
		AC_DEFINE_UNQUOTED(HAVE_FREETYPE, 1, [Defines if your system has the libfreetype library])
	else
		libmissing libfreetype required
		AC_MSG_ERROR([You need at least freetype 2.1.0])
	fi

	dnl Warn the user if they have less than freetype 2.1.9
	dnl Changed to fatal error
	AC_MSG_CHECKING(freetype version > 2.1.9)
	SAVE_CFLAGS="${CFLAGS}"
	CFLAGS=" ${LIBFREETYPE_CFLAGS} "
	AC_TRY_COMPILE([
	#include <ft2build.h>
	#include FT_FREETYPE_H
	],[
	#if FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 1 && FREETYPE_PATCH < 9
	#error freetype 2.1 older than 2.1.9
	#endif
	], [hafree_post219=yes], [hafree_post219=no])
	CFLAGS="${SAVE_CFLAGS}"
	AC_MSG_RESULT($hafree_post219)
	if test hafree_post219 = no; then
		AC_MSG_WARN([Your libfreetype is too old - version 2.1.9 or newer strongly recommended])
	fi

	dnl Export the includes and lib path settings required to build with freetype.
	AC_SUBST(LIBFREETYPE_LIBS)
	AC_SUBST(LIBFREETYPE_CFLAGS)
else
	libmissing libfreetype required
	AC_MSG_ERROR([You need at least freetype 2.1.0])
fi

dnl Try to find fontconfig using fontconfig-config or pkg-config.
hafontconfig=no
LIBFONTCONFIG_LIBS=""
LIBFONTCONFIG_CFLAGS=""
FONTCONFIG_CONFIG=""

dnl Try to find fontconfig with pkg-config if we have pkg-config
AC_MSG_CHECKING([Checking for fontconfig with pkg-config])
if test -n "$PKG_CONFIG"; then
	LIBFONTCONFIG_LIBS="`$PKG_CONFIG fontconfig --libs`"
	LIBFONTCONFIG_CFLAGS="`$PKG_CONFIG fontconfig --cflags`"
	if test -n "$LIBFONTCONFIG_LIBS" || test -n "$LIBFONTCONFIG_CFLAGS"; then
		AC_MSG_RESULT([found])
	else
		AC_MSG_RESULT([not found])
	fi
else
	AC_MSG_RESULT([failed: pkg-config not found])
fi

dnl If fontconfig not found with pkg-config, try to find fontconfig-config
dnl and use that to look for fontconfig.
if test -z "$LIBFONTCONFIG_LIBS" && test -z "$LIBFONTCONFIG_CFLAGS"; then
	dnl Seems we didn't find fontconfig with pkg-config, so search for the old
	dnl fontconfig-config program instead.
	AC_PATH_PROG(FONTCONFIG_CONFIG,
				 fontconfig-config,
				 [],
				 [$PATH ${prefix}/bin ${exec_prefix}/bin /usr/local/bin /opt/local/bin /usr/bin /usr/nekoware/bin /usr/X11/bin])
	if test -n "$FONTCONFIG_CONFIG"; then
		dnl found fontconfig-config, use it's results
		LIBFONTCONFIG_LIBS="`$FONTCONFIG_CONFIG --libs`"
		LIBFONTCONFIG_CFLAGS="`$FONTCONFIG_CONFIG --cflags`"
	else
		AC_MSG_WARN([Couldn't find fontconfig-config or find fontconfig with pkg-config])
	fi
fi

dnl Check to see if we can compile fontconfig
SAVE_CFLAGS="${CFLAGS}"
SAVE_LDFLAGS="${LDFLAGS}"
CFLAGS="${CFLAGS} ${LIBFONTCONFIG_CFLAGS}"
LDFLAGS="${LDFLAGS} ${LIBFONTCONFIG_LIBS}"
AC_CHECK_LIB(fontconfig, FcPatternBuild, [hafontconfig=yes],[hafontconfig=no])
CFLAGS="${SAVE_CFLAGS}"
LDFLAGS="${SAVE_LDFLAGS}"
if test $hafontconfig = yes; then
	AC_DEFINE_UNQUOTED(HAVE_FONTCONFIG, 1, [Defines if your system has the libfontconfig library])
else
	libmissing libfontconfig optional
	AC_MSG_WARN([Couldn't find a usable libfontconfig])
fi
AC_SUBST(LIBFONTCONFIG_LIBS)
AC_SUBST(LIBFONTCONFIG_CFLAGS)


XML_LIBS=""
XML_CFLAGS=""

XML_CONFIG=""
AC_PATH_PROG(XML_CONFIG,
			 xml2-config,
			 [],
			 [${PATH} ${prefix}/bin ${exec_prefix}/bin /usr/local/bin /opt/local/bin /usr/bin /usr/nekoware/bin /usr/X11/bin])

dnl check for LibXML2
haxml=no
haxml26=no
AC_ARG_ENABLE(xml, [  --disable-xml       Don't use libxml2 and turn off some Scribus features.], [disable_xml2="yes"])
if test "$disable_xml2" != "yes"; then
	if test -n "$XML_CONFIG"; then
		XML_LIBS="`$XML_CONFIG --libs`"
		XML_CFLAGS="`$XML_CONFIG --cflags`"
		SAVE_LDFLAGS="$LDFLAGS"
		LDFLAGS="$all_libraries $XML_LDFLAGS $LDFLAGS"
		AC_CHECK_LIB(xml2, attribute, [haxml=yes],[haxml=no])
		LDFLAGS="$SAVE_LDFLAGS"
		if test $haxml = yes; then
			AC_DEFINE_UNQUOTED(HAVE_XML, 1, [Defines if your system has the libxml2 library])
			AC_SUBST(XML_LIBS)
			AC_SUBST(XML_CFLAGS)
		else
			libmissing libxml2
			AC_MSG_WARN([Couldn't find a usable libxml2])
		fi
		vers=`$XML_CONFIG --version 2>/dev/null | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
		if test -n "$vers" && test "$vers" -ge 2006000
		then
			AC_DEFINE_UNQUOTED(HAVE_XML26, 1, [Defines if your system has the libxml2 library6])
			haxml26=yes
		fi
	else
		libmissing libxml2 optional
		AC_MSG_WARN([Couldn't find a usable libxml2])
	fi
fi

dnl check for -lsocket
AC_CHECK_LIB(socket,socket,
if test "$uname" != "IRIX"; then
	LIBS="-lsocket $LIBS"
else
	echo "Not using -lsocket since you are running IRIX."
fi)
AC_CHECK_LIB(nsl,gethostbyaddr,
if test "$uname" != "IRIX"; then
	LIBS="-lnsl $LIBS"
else
	echo "Not using -lnsl since you are running IRIX."
fi)

dnl Check for lcms
dnl TODO look for lcms using pkg-config too
dnl TODO: convert to use --with-lcms= and AC_ARG_WITH(...)
LIBLCMS=""
hacms=
# CR - we now require lcms
# AC_ARG_ENABLE(lcms, [  --disable-lcms     Don't use colour management (default=no)], [disable_lcms="yes"])

# If lcms hasn't been explicitly disabled, look for it and see
# if we can use it.
if test "$disable_lcms" != "yes"; then
	# See if liblcms.so is on our search path and looks vaguely valid
	SAVE_LDFLAGS="$LDFLAGS"
	LDFLAGS="$all_ldflags $LDFLAGS"
	export LDFLAGS
	AC_CHECK_LIB(lcms, _cmsChannelsOf, [LIBLCMS="-llcms";hacms=yes],[LIBLCMS="";hacms=no],[-lm])
	hacmsh=
	lcms_h=
	# and search for lcms.h, which may or may not be in an lcms/ subdir
	AC_CHECK_HEADER(lcms.h, [hacmsh=yes],[hacmsh=no])
	if test $hacmsh = no; then
		AC_CHECK_HEADER(lcms/lcms.h, [hacmsh=yes],[hacmsh=no])
		if test $hacmsh = yes; then
			AC_DEFINE_UNQUOTED(CMS_INC, "lcms/lcms.h", [ColorManagementInclude])
			lcms_h="lcms/lcms.h"
		fi
	else
		AC_DEFINE_UNQUOTED(CMS_INC, "lcms.h", [ColorManagementInclude])
		lcms_h="lcms.h"
	fi
	if test $hacmsh = no; then
		# There's not much point finding -llcms if we can't find the header file...
		hacms=no
	fi
	LDFLAGS="$SAVE_LDFLAGS"
fi
dnl Attempt to check that lcms is new enough
if test $hacms = yes; then
	AC_MSG_CHECKING(liblcms version > 1.1.2)
	AC_TRY_COMPILE([
	#include "$lcms_h"
	],[
	#if LCMS_VERSION < 112
	#error liblcms is too old, need LittleCMS 1.1.2 or newer
	#endif
	], [], [hacms=pre112])
	AC_MSG_RESULT($hacms)
fi

AC_SUBST(LIBLCMS)
if test $hacms = yes && test $hacmsh = yes; then
	AC_DEFINE_UNQUOTED(HAVE_CMS, 1, [ColorManagement])
else
	libmissing liblcms required
fi

dnl Checks for libtiff - library exists, tiffvers.h can be found, and new enough.
LIBTIFF=""
hastif=
dnl Check if we have libtiff
SAVE_LDFLAGS="$LDFLAGS"
LDFLAGS="$all_libraries $LDFLAGS"
AC_CHECK_LIB(tiff, TIFFOpen, [LIBTIFF="-ltiff";hastif=yes],[LIBTIFF="";hastif=no],[-lm])
LDFLAGS="$SAVE_LDFLAGS"
if test $hastif = yes; then
	dnl Check for tiffvers.h
	SAVE_CFLAGS="$CFLAGS"
	CFLAGS="$all_includes $CFLAGS"
	AC_CHECK_HEADER(tiffvers.h, [], [LIBTIFF="";hastif=no])
	if test $hastif = yes; then
		dnl Now attempt to check if libtiff is new enough
		AC_MSG_CHECKING(libtiff version > 3.6.0)
		AC_TRY_COMPILE([
		#include "tiffvers.h"
		],[
		#if TIFFLIB_VERSION < 20031007
		#error libtiff is too old, need libtiff 3.6.0 or newer.
		#endif
		], [], [LIBTIFF="";hastif=pre36])
		AC_MSG_RESULT($hastif)
	fi
	CFLAGS="$SAVE_CFLAGS"
fi
if test "${hastif}" != "yes"; then
	libmissing libtiff required
fi
AC_SUBST(LIBTIFF)
if test $hastif = yes; then
	AC_DEFINE_UNQUOTED(HAVE_TIFF, 1, [Tifflib])
fi

LIBDL2=""
AC_CHECK_LIB(c, dlopen, [LIBDL2="-lc"],[LIBDL2=""])
AC_SUBST(LIBDL2)

dnl generate the config header
AM_CONFIG_HEADER(config.h) dnl at the distribution this done

dnl Checks for programs.
AC_CHECK_COMPILERS
AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no)
KDE_PROG_LIBTOOL

kde_python_link_found=no
KDE_CHECK_PYTHON(2.3)
COMPILE_PYTHON=
AC_ARG_WITH(python, [  --without-python     Do not compile the Scripter Plugin],[ COMPILE_PYTHON=no ],[ COMPILE_PYTHON=yes ])
if test "$COMPILE_PYTHON" != "no"; then
	if test "$enable_mac" = yes ; then
		dnl Mac OS X always has Python, but the KDE config scripts don't know
		dnl how to find it. We just hardcode the values here.
		AC_DEFINE_UNQUOTED(HAVE_PYTHON_23, 1, [Python])
		PYTHONINC='-I/System/Library/Frameworks/Python.framework/Headers'
		PYTHONLIB='-L/System/Library/Frameworks/Python.framework -framework Python'
		PYTHONMODDIR='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3'
		COMPILE_PYTHON=yes
	elif test "$kde_python_link_found" = yes; then
		dnl Configure found the Python libs
		COMPILE_PYTHON=yes
	else
		dnl Configure didn't find python libs
		COMPILE_PYTHON=no
	fi
fi
AM_CONDITIONAL(COMPILE_PYTHON, test x$COMPILE_PYTHON = xyes)

AC_ARG_ENABLE(cups, [  --disable-cups        Do not compile support for CUPS printing],[disable_cups=yes])
LIBCUPS=""
hacups=no
if test "$disable_cups" != "yes" ; then
	# Look for cups.h
	SAVE_CFLAGS="$CFLAGS"
	CFLAGS="$all_includes $CFLAGS"
	AC_CHECK_HEADER(cups/cups.h, [hacups_h=yes],[hacups_h=no])
	CFLAGS="$SAVE_CFLAGS"
	AC_CHECK_PROG(hacups_cfg, cups-config, yes, no)
	echo "'$hacups_cfg' '$hacups_h'" >/tmp/cfg
	if test "x$hacups_h" = "xyes" && test "x$hacups_cfg" = "xyes"; then
		# We have the CUPS libs and headers, so enable
		# the use of CUPS and tell the build where to
		# find it.
		LIBCUPS="`cups-config --libs`"
		AC_DEFINE_UNQUOTED(HAVE_CUPS, 1, [Cups])
		AC_SUBST(LIBCUPS)
		hacups=yes
	else
		libmissing libcups optional
		AC_MSG_WARN([libcups could not be found. Printing functionality will be limited.])
		hacups=no
	fi
else
	hacups=no
fi

dnl While we don't use GhostScript during compilation - at least not
dnl currently - and can run without it, we check for it in configure
dnl to give users an early warning if it's missing.
AC_PATH_PROG(GS_PATH, gs)
AC_MSG_CHECKING([GhostScript version])
if test -z "${GS_PATH}" ; then
	AC_MSG_RESULT([gs not found])
	AC_MSG_WARN("GhostScript not found - gs 8.x is required for full features.")
else
	GS_VER_MAJOR=`gs --version | cut -d . -f 1`
	GS_VER_MINOR=`gs --version | cut -d . -f 2`
	AC_MSG_RESULT([${GS_VER_MAJOR}.${GS_VER_MINOR}])
	if (( "${GS_VER_MAJOR}" < 7 )) ; then
		AC_MSG_WARN("GhostScript found, but older than v7. v8 recommended.")
	elif (( "${GS_VER_MAJOR}" < 8 )) ; then
		AC_MSG_WARN("GhostScript v7 found. v8 recommended.")
	fi
fi

COMPILE_DEBUG=no
AC_ARG_ENABLE(debug, [  --enable-debug     Enables debugging information (recommended for snapshots)],
[if test "x$enable_debug" = "xyes" || test "x$enable_debug" = "xfull"; then
	COMPILE_DEBUG=yes
    if test "$enable_mac" = "yes"; then
        CXXFLAGS="$CXXFLAGS -g3 "
        CFLAGS="$CFLAGS -g3 "
    else
        CXXFLAGS="$CXXFLAGS -g3 -fno-inline -O0 "
        CFLAGS="$CFLAGS -g3 -fno-inline -O0 "
    fi
fi])
AM_CONDITIONAL(COMPILE_DEBUG, test x$COMPILE_DEBUG = xyes)

dnl Compile and link the gdk-pixbuf sources unless building
dnl a Mac-native build.
AM_CONDITIONAL(LINK_PIXBUF, test "$enable_mac" != "yes" )

build_mac_bundle=no
AC_ARG_ENABLE(bundle, [  --enable-bundle     Make an executable suitable for use in a .app bundle (INCOMPLETE)], [build_mac_bundle=yes])
if test "$build_mac_bundle" = "yes"; then
	AC_DEFINE_UNQUOTED(BUILD_MAC_BUNDLE, 1, [Are we building an executable to be included in MacOS/X .app bundle?])
fi
if test "$enable_mac" != "yes" && test "$build_mac_bundle" = "yes"; then
	AC_MSG_ERROR([--enable-bundle only makes sense with --enable-mac])
fi
AM_CONDITIONAL(BUILD_MAC_BUNDLE, test "$build_mac_bundle" = "yes")

dnl On Mac OS X and Darwin we need to link the final binary to CoreFoundation.
if test "$enable_mac" = "yes"; then
	COREFOUNDATION_LIBS="-framework CoreFoundation"
else
	COREFOUNDATION_LIBS=
fi
AC_SUBST(COREFOUNDATION_LIBS)

dnl Some platforms require special libtool flags to build dynamically loadable
dnl modules or plugins correctly. While libtool should take care of this with
dnl a fixed set of arguments, in case we need to change it later this is being
dnl made a configure-time substitution.
MODULE_LINK_FLAGS=" -module "
AC_SUBST(MODULE_LINK_FLAGS)

all_libraries="$all_libraries $USER_LDFLAGS"
all_includes="$all_includes $USER_INCLUDES"
AC_SUBST(all_includes)
AC_SUBST(all_libraries)

AH_TOP([
/*
 * Prevent code from including config.h directly. You should include
 * scconfig.h instead. This lets us handle win-config.h correctly, and
 * may do more later.
 */
#ifndef _SCCONFIG_H
#error "Include <scconfig.h> rather than using <config.h> directly"
#endif
])

AC_PATH_QT

dnl Should we compile the new Boost::Python-based Python plugin?
AC_ARG_ENABLE(scripter2,
			  [  --enable-scripter2   Enable compilation of extended Python scripting],
			  [use_scripter2="yes"])
AC_MSG_CHECKING([If we should build Boost::Python-based Python scripting])
BOOST_PYTHON_CXXFLAGS=""
BOOST_PYTHON_LDFLAGS=""
if test "$use_scripter2" = "yes"; then
	dnl TODO : check for Boost::Python
	have_boost_python=yes
	if test "$have_boost_python" = "yes" ; then
		AC_DEFINE_UNQUOTED(HAVE_BOOST_PYTHON, 1, "Boost::Python is available")
		AC_DEFINE_UNQUOTED(HAVE_SCRIPTER2, 1, "We'll build and use the extended scripter")
		BOOST_PYTHON_CXXFLAGS=" -fexceptions -Wno-extra -Wno-unused "
		BOOST_PYTHON_LDFLAGS=" -lboost_python "
		AC_MSG_RESULT([yes])
	else
		AC_MSG_RESULT([no])
	fi
else
	AC_MSG_RESULT([no])
fi
AM_CONDITIONAL(HAVE_SCRIPTER2, test "$use_scripter2" = "yes")
AC_SUBST(BOOST_PYTHON_CXXFLAGS)
AC_SUBST(BOOST_PYTHON_LDFLAGS)


AC_ARG_ENABLE(qt4-test,
			  [  --disable-qt4-test   Skip a sanity check with Qt4 detection. Don't report bugs if you use this.],
			  [notestqt4="yes"])
if ! test "$notestqt4" = "yes" ; then
	dnl We have to do our Qt version check only after KDE's magic has found Qt
	dnl Note that configure does this test with gcc, not g++, so we need to use
	dnl CFLAGS not CXXFLAGS. Also, if QT_INCLUDES is the same as X_INCLUDES,
	dnl only X_INCLUDES must be set, so we must include both. Just use $all_includes
	dnl to work around the mess.
	SAVE_CFLAGS="${CFLAGS}"
	CFLAGS="$all_includes ${CFLAGS}"
	AC_MSG_CHECKING([if we're trying to compile against Qt 4])
	dnl If this snippet compiles correctly, we're using an older Qt and are fine.
	dnl If it fails, we know we're using Qt 4. We don't need to test for Qt 3.3
	dnl here, AC_PATH_QT has done that for us.
	AC_TRY_COMPILE([
	#include <qglobal.h>
	],[
	#if QT_VERSION >= 0x040000
	#error Scribus does not support Qt 4
	#endif
	], [using_qt4=no], [using_qt4=yes])
	if test "${using_qt4}" = "yes"; then
		AC_MSG_RESULT([Qt 4 found])
		AC_MSG_ERROR([Scribus does not yet support Qt 4])
	else
		AC_MSG_RESULT([Usable Qt 3.x found])
	fi
	CFLAGS="${SAVE_CFLAGS}"
fi

dnl Check to see if we're using gcc4, and if so disable a couple of warning flags that
dnl produce spurious warnings with qt3. Do not rely on the using_gcc4 flag elsewhere, instead
dnl check specific compiler capabilities with KDE_CHECK_COMPILER_FLAG(...) etc. We test this
dnl flag because gcc3 also supports it, but it only ends up being enabled under gcc4 due to changes
dnl in the behaviour of -Wall -W .
AC_TRY_COMPILE([
], [
#if __GNUC__ < 4
#error __GNUC__ < 4, not using gcc4
#endif
],
[ using_gcc4="yes" ], [ using_gcc4="no" ])
if test "$using_gcc4" = "yes"; then
dnl	CXXFLAGS="$CXXFLAGS -Wno-non-virtual-dtor -Wstring-literal-comparison"
CXXFLAGS="$CXXFLAGS -Wno-non-virtual-dtor"
fi
dnl unset the flag to prevent abuse (DO NOT rely on this flag)
unset using_gcc4
