
AC_INIT(README)
AC_CANONICAL_SYSTEM
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(gtk-sharp, @GTK_SHARP_VERSION@)
AM_MAINTAINER_MODE

API_VERSION=@ASSEMBLY_VERSION@
AC_SUBST(API_VERSION)
POLICY_VERSIONS="@POLICY_VERSIONS@"
AC_SUBST(POLICY_VERSIONS)

PACKAGE_VERSION=gtk-sharp-2.0
AC_SUBST(PACKAGE_VERSION)

WIN64DEFINES=

case "$host" in
	x86_64-*-mingw*|x86_64-*-cygwin*)
		WIN64DEFINES="-define:WIN64LONGS"
		platform_win32=yes
		AC_DEFINE(PLATFORM_WIN32,1,[Platform is Win32])
		if test "x$cross_compiling" = "xno"; then
			CC="gcc -mno-cygwin -g"
			HOST_CC="gcc"
		fi
		;;
	*-*-mingw*|*-*-cygwin*)
		platform_win32=yes
		AC_DEFINE(PLATFORM_WIN32,1,[Platform is Win32])
		if test "x$cross_compiling" = "xno"; then
			CC="gcc -mno-cygwin -g"
			HOST_CC="gcc"
		fi
		;;
	*)
		platform_win32=no
		;;
esac

AM_CONDITIONAL(PLATFORM_WIN32, test x$platform_win32 = xyes)

AC_CHECK_TOOL(CC, gcc, gcc)
AC_PROG_CC
AM_PROG_CC_STDC
AC_PROG_INSTALL

dnl may require a specific autoconf version
dnl AC_PROG_CC_FOR_BUILD
dnl CC_FOR_BUILD not automatically detected
CC_FOR_BUILD=$CC
BUILD_EXEEXT=
if test "x$cross_compiling" = "xyes"; then
	CC_FOR_BUILD=cc
	BUILD_EXEEXT=""
fi
AC_SUBST(CC_FOR_BUILD)
AC_SUBST(HOST_CC)
AC_SUBST(BUILD_EXEEXT)

# Set STDC_HEADERS
AC_HEADER_STDC
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL

# not 64 bit clean in cross-compile
AC_CHECK_SIZEOF(void *, 4)

CFLAGS="${CFLAGS} -g -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes  -Wmissing-prototypes -Wnested-externs  -Wshadow -Wpointer-arith -Wno-cast-qual -Wcast-align -Wwrite-strings"

if test "x$enable_maintainer_mode" = "xyes"; then
DEBUG_FLAGS='-debug'
else
DEBUG_FLAGS=
AC_ARG_ENABLE(debug, [  --enable-debug          Build debugger (.mdb) files for dlls],
	DEBUG_FLAGS='-debug'
)
fi

CSDEFINES='@VERSIONCSDEFINES@'
CSFLAGS="$DEBUG_FLAGS $CSDEFINES $WIN64DEFINES"
AC_SUBST(CSFLAGS)

GTK_SHARP_VERSION_CFLAGS='@VERSIONCFLAGS@'
AC_SUBST(GTK_SHARP_VERSION_CFLAGS)

AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
if test "x$PKG_CONFIG" = "xno"; then
	AC_MSG_ERROR([You need to install pkg-config])
fi

dnl for use on the build system
BUILD_GTK_CFLAGS=`$PKG_CONFIG --cflags gtk+-2.0`
BUILD_GTK_LIBS=`$PKG_CONFIG --libs gtk+-2.0`
AC_SUBST(BUILD_GTK_CFLAGS)
AC_SUBST(BUILD_GTK_LIBS)

AC_CHECK_SIZEOF(off_t)
OFF_T_FLAGS="-define:OFF_T_$ac_cv_sizeof_off_t"
AC_SUBST(OFF_T_FLAGS)

MONO_REQUIRED_VERSION=1.0
PKG_CHECK_MODULES(MONO_DEPENDENCY, mono >= $MONO_REQUIRED_VERSION, has_mono=true, has_mono=false)

AC_PATH_PROG(GACUTIL, gacutil, no)
if test "x$GACUTIL" = "xno" ; then
	AC_MSG_ERROR([No gacutil tool found. You need to install either the mono or .Net SDK.])
fi

AC_PATH_PROG(AL, al, no)
if test "x$AL" = "xno" ; then
	AC_MSG_ERROR([No al tool found. You need to install either the mono or .Net SDK.])
fi

if test "x$has_mono" = "xtrue"; then
GACUTIL_FLAGS='/package $(PACKAGE_VERSION) /gacdir $(DESTDIR)$(prefix)/lib'
GENERATED_SOURCES=generated/*.cs
AC_PATH_PROG(RUNTIME, mono, no)

# If mono is found, it's in the path.  Require it to be in the path at runtime as well
if test "x$RUNTIME" != "no" ; then
	RUNTIME=mono
fi

AC_PATH_PROG(CSC, mcs, no)
if test `uname -s` = "Darwin"; then
	LIB_PREFIX=
	LIB_SUFFIX=.dylib
else
	LIB_PREFIX=.so
	LIB_SUFFIX=
fi
SDCHECK="`$GACUTIL /l |grep ^System.Drawing, | head -n1 |cut -f1 -d','`"
if test "x$SDCHECK" = "xSystem.Drawing"; then
	enable_dotnet=yes
else
	enable_dotnet=no
fi
else
AC_PATH_PROG(CSC, csc.exe, no)
GACUTIL_FLAGS=
GENERATED_SOURCES=generated\\\\*.cs
enable_dotnet=yes

if test x$CSC = "xno"; then
	AC_MSG_ERROR([You need to install either mono or .Net])
else
RUNTIME=
LIB_PREFIX=
LIB_SUFFIX=.dylib
fi
fi

CS="C#"
if test "x$CSC" = "xno" ; then
	AC_MSG_ERROR([No $CS compiler found])
fi

AC_SUBST(RUNTIME)
AC_SUBST(CSC)
AC_SUBST(GACUTIL)
AC_SUBST(GACUTIL_FLAGS)
AC_SUBST(LIB_PREFIX)
AC_SUBST(LIB_SUFFIX)
AC_SUBST(GENERATED_SOURCES)

PKG_CHECK_MODULES(MONO_CAIRO, mono-cairo >= $MONO_REQUIRED_VERSION, enable_mono_cairo=no, enable_mono_cairo=yes)
AC_SUBST(MONO_CAIRO_LIBS)

GTK_REQUIRED_VERSION=@GTK_REQUIRED_VERSION@
GLIB_REQUIRED_VERSION=@GLIB_REQUIRED_VERSION@

PKG_CHECK_MODULES(GLIB, gobject-2.0 >= $GLIB_REQUIRED_VERSION)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)

PKG_CHECK_MODULES(GIO, gio-2.0 >= $GLIB_REQUIRED_VERSION)
AC_SUBST(GIO_CFLAGS)
AC_SUBST(GIO_LIBS)

PKG_CHECK_MODULES(PANGO, pango)
AC_SUBST(PANGO_CFLAGS)
AC_SUBST(PANGO_LIBS)

PKG_CHECK_MODULES(ATK, atk)
AC_SUBST(ATK_CFLAGS)
AC_SUBST(ATK_LIBS)

PKG_CHECK_MODULES(GTK, gtk+-2.0 >= $GTK_REQUIRED_VERSION)
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)

GLADE_REQUIRED_VERSION=2.3.6
enable_glade=no
AC_ARG_ENABLE(glade-sharp, AC_HELP_STRING([--disable-glade-sharp], [Disable glade-sharp bindings]))
if test "x$enable_glade_sharp" != "xno"; then
	PKG_CHECK_MODULES(GLADE, libglade-2.0 >= $GLADE_REQUIRED_VERSION, enable_glade=yes, enable_glade=no)
	AC_SUBST(GLADE_CFLAGS)
	AC_SUBST(GLADE_LIBS)
fi

AC_PATH_PROG(MDOC, mdoc, no)
if test "x$MDOC" = "xno"; then
  enable_monodoc=no
  doc_sources_dir=
else
  enable_monodoc=yes
  doc_sources_dir="`pkg-config --variable=sourcesdir monodoc`"
fi
AC_SUBST(MDOC)

AM_CONDITIONAL(ENABLE_MONO_CAIRO, test "x$enable_mono_cairo" = "xyes")
AM_CONDITIONAL(ENABLE_GLADE, test "x$enable_glade" = "xyes")
AM_CONDITIONAL(ENABLE_DOTNET, test "x$enable_dotnet" = "xyes")
AM_CONDITIONAL(ENABLE_MONODOC, test "x$enable_monodoc" = "xyes")
AM_CONDITIONAL(ENABLE_MONOGETOPTIONS, test "x$has_mono" = "xtrue")

AC_SUBST(CFLAGS)

AC_OUTPUT([
AssemblyInfo.cs
Makefile
policy.config
gtk-sharp-2.0-lib.wxs
gtk-sharp-2.0-dev.wxs
sources/Makefile
parser/Makefile
parser/gapi-2.0.pc
parser/gapi2-fixup
parser/gapi2-parser
generator/Makefile
generator/gapi2-codegen
glib/Makefile
glib/glib-sharp-2.0.pc
glib/glib-sharp.dll.config
glib/glue/Makefile
gio/Makefile
gio/gio-sharp-2.0.pc
gio/gio-sharp.dll.config
gio/glue/Makefile
cairo/Makefile
pango/Makefile
pango/pango-sharp.dll.config
pango/glue/Makefile
atk/Makefile
atk/atk-sharp.dll.config
atk/glue/Makefile
gdk/Makefile
gdk/gdk-sharp.dll.config
gdk/glue/Makefile
gtk/Makefile
gtk/gtk-sharp-2.0.pc
gtk/gtk-sharp.dll.config
gtk/glue/Makefile
glade/Makefile
glade/glade-sharp.dll.config
glade/glade-sharp-2.0.pc
glade/glue/Makefile
gtkdotnet/Makefile
gtkdotnet/gtk-dotnet.dll.config
gtkdotnet/gtk-dotnet-2.0.pc
doc/Makefile
sample/GtkDemo/Makefile
sample/Makefile
sample/pixmaps/Makefile
sample/test/Makefile
sample/valtest/Makefile
sample/valtest/valtest.exe.config
sample/opaquetest/Makefile
sample/opaquetest/opaquetest.exe.config
sample/gio/Makefile
sample/gtk-gio/Makefile
])

if test x$platform_win32 = xyes; then
   # Get rid of 'cyg' prefixes in library names
   sed -e "s/\/cyg\//\/\//" libtool > libtool.new; mv libtool.new libtool; chmod 755 libtool
fi

if test "x$enable_mono_cairo" = "xyes"; then
  cairo_comment="building local copy"
else
  cairo_comment="using system assembly"
fi

echo "---"
echo "Configuration summary"
echo ""
echo "   * Installation prefix = $prefix"
echo "   * $CS compiler: $CSC $CSFLAGS"
echo ""
echo "   Optional assemblies included in the build:"
echo ""
if test "x$enable_glade_sharp" = "xno"; then
echo "      * glade-sharp.dll: disabled"
else
echo "      * glade-sharp.dll: $enable_glade"
fi
echo "      * gtk-dotnet.dll: $enable_dotnet"
echo "      * Mono.Cairo.dll: $cairo_comment"
echo ""
echo "      NOTE: if any of the above say 'no' you may install the"
echo "            corresponding development packages for them, rerun"
echo "            autogen.sh to include them in the build."
echo ""
echo "   * Documentation build enabled: $enable_monodoc "
if test "x$enable_monodoc" = "xyes" -a "x$doc_sources_dir" != "x$prefix/lib/monodoc/sources"; then
  echo "      WARNING: The install prefix is different than the monodoc prefix."
  echo "               Monodoc will not be able to load the documentation."
fi
echo "---"

