AC_INIT(mysql-administrator, 1.2.12) 
AC_CONFIG_SRCDIR(source/linux/main.cc)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)

AM_CONFIG_HEADER(source/linux/config.h)

#
# standard stuff
#
AC_CANONICAL_HOST
AC_PROG_CC
AC_PROG_CXX

AC_PROG_RANLIB

AC_CHECK_PROG(PKG_CONFIG, pkg-config)


#
# internal libraries
#
AC_CHECK_FILE(../mysql-gui-common/library/base-library, [],
	        AC_MSG_ERROR([mysql-gui-common source tree must be present in the same directory as this program]))

#AC_CHECK_FILE(../mysql-gui-common/source/linux/libmacommongui.a, [],
#	AC_MSG_ERROR([mysql-gui-common source tree must be compiled and present in the same directory as this program]))


#
# Library
#
AC_CHECK_LIB(util, forkpty, UTIL_LIBS="-lutil")
AC_SUBST(UTIL_LIBS)

#
# pcre
#
AC_CHECK_PROG(PCRE_CFLAGS,pcre-config,[yes])
if test "$PCRE_CFLAGS" != yes; then
        AC_MSG_ERROR([Could not find pcre-config script. Make sure the pcre libraries are installed])
else
        PCRE_CFLAGS=`pcre-config --cflags`
fi
AC_SUBST(PCRE_CFLAGS)


AC_CHECK_PROG(PCRE_LIBS,pcre-config,`pcre-config --libs`)
if test -z "$PCRE_LIBS"; then
        AC_MSG_ERROR([Could not find pcre-config script. Make sure the pcre libraries are installed])
fi
AC_SUBST(PCRE_LIBS)

# cant put result directly in check macro because it can return ""
AC_CHECK_PROG(PCRE_CFLAGS,pcre-config,[yes])
if test "$PCRE_CFLAGS" != yes; then
	AC_MSG_ERROR([Could not find pcre-config script. Make sure the pcre libraries are installed])
else
	PCRE_CFLAGS=`pcre-config --cflags`
fi
AC_SUBST(PCRE_CFLAGS)


# 
# gettext
#
GETTEXT_PACKAGE="mysql-administrator"
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [The gettext package name])


AC_ARG_ENABLE(i18n,
[  --disable-i18n       do not add support for internationalization (requires GNU gettext)],
        enable_i18n=$enableval, enable_i18n=yes)

if test x$enable_i18n = xyes; then
    #
    # Gettext
    #
    GETTEXT_PACKAGE="$PACKAGE_NAME"
    AC_SUBST(GETTEXT_PACKAGE)
    AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[Translation domain used])
    dnl Add the languages which your application supports here.
    ALL_LINGUAS="ja de pt_BR"
    AM_GLIB_GNU_GETTEXT
fi


#
# mysql libraries
#
AC_CHECK_PROG(MYSQL_CFLAGS,mysql_config,`mysql_config --cflags`)
if test -z "$MYSQL_CFLAGS"; then 
        AC_MSG_ERROR([Could not find mysql_config script. Make sure the mysql client libraries are installed])
fi
AC_SUBST(MYSQL_CFLAGS)


AC_CHECK_PROG(MYSQL_LIBS,mysql_config,`mysql_config --libs_r`)
if test -z "$MYSQL_LIBS"; then 
        AC_MSG_ERROR([Could not find mysql_config script. Make sure the mysql client libraries are installed])
fi
AC_SUBST(MYSQL_LIBS)



# 
# gnome libraries
#
PKG_CHECK_MODULES(GLIB, [glib-2.0 libxml-2.0 >= 2.6.2])
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)

PKG_CHECK_MODULES(GNOME, [libglade-2.0
			libxml-2.0 >= 2.6.2
                        gtkmm-2.4])
AC_SUBST(GNOME_CFLAGS)
AC_SUBST(GNOME_LIBS)


#
# check other headers
#

AC_CHECK_HEADERS(sys/statfs.h sys/param.h sys/mount.h)


AC_CHECK_FUNCS(strtoll __strtoll)


# path mangling

commondirname="common"
AC_ARG_WITH(commondirname,
        [  --with-commondirname         sets the common data directory name],
        [commondirname="$withval"])
                                                                                                                        
MG_COMMONDIR=$commondirname
AC_SUBST(MG_COMMONDIR)

DATADIRNAME=`echo $datadir|sed -e "s@${prefix}/@@" -e 's@${prefix}/@@'`
AC_SUBST(DATADIRNAME)


mydatadir='$(datadir)/mysql-gui'
AC_SUBST(mydatadir)
madatadir='$(datadir)/mysql-gui/administrator'
AC_SUBST(madatadir)

AC_CONFIG_FILES([
mysql-administrator.spec
Makefile
res/Makefile
res/linux/Makefile
images/Makefile
images/icons/Makefile
images/icons/png/Makefile
images/icons/png/maintree/Makefile
images/icons/png/sections/Makefile
library/Makefile
library/source/Makefile
source/Makefile
source/linux/Makefile
source/util/Makefile
po/Makefile.in
])

AC_OUTPUT()
