#MIN_CONFIG
KDE_ENABLE_HIDDEN_VISIBILITY
KDE_INIT_DOXYGEN([KDE Utils API Reference], [Version $VERSION])

# Check for ECMA-335 image loader.

AC_DEFUN([KDE_CHECK_CLI],[
	AC_ARG_WITH(cli, [  --with-cli=FILE         ECMA 335 PE image loader is FILE ],
	[
		AC_MSG_CHECKING(for CLI image loader)

		if test -x "$with_cli"
		then
			CLI="$with_cli"
			AC_MSG_RESULT($CLI)
		fi
	],
	[
		AC_PATH_PROG(CLI, mono, [], $PATH:/usr/local/bin)

		if test -z "$CLI"
		then
			AC_PATH_PROG(CLI, ilrun, [], $PATH:/usr/local/bin)
		fi

		if test -z "$CLI"
		then
			AC_PATH_PROG(CLI, clix, [], $PATH:/usr/local/bin)
		fi
	])

	AC_SUBST(CLI)
])

# Pick a C# compiler.

# Check for Portable.NET's C# compiler

AC_DEFUN([KDE_CHECK_CSCC],[
	AC_ARG_WITH(cscc, [  --with-cscc=FILE        cscc executable is FILE ],
	[
		AC_MSG_CHECKING(for $with_cscc)

		if test -x $with_cscc
		then
			AC_MSG_RESULT(found)
			cscc="$with_cscc"
		else
			AC_MSG_RESULT(no)
		fi
	],
	[
		AC_PATH_PROG(cscc, cscc, [], $PATH:/usr/local/bin)
	])
])

# Check for Microsoft's C# compiler

AC_DEFUN([KDE_CHECK_CSC],[
	AC_ARG_WITH(csc, [  --with-csc=FILE         csc executable is FILE ],
	[
		AC_MSG_CHECKING(for $with_csc)

		if test -x $with_csc
		then
			AC_MSG_RESULT(found)
			csc="$with_csc"
		else
			AC_MSG_RESULT(no)
		fi
	],
	[
		AC_PATH_PROG(csc, csc.exe, [], $PATH:/usr/local/bin)

		if test -z "$csc"
		then
			AC_PATH_PROG(csc, csc, [], $PATH:/usr/local/bin)
		fi
	])
])

# Check for Mono's C# compiler

AC_DEFUN([KDE_CHECK_MCS],[
	dnl AC_REQUIRE(KDE_CHECK_CLI)
	AC_ARG_WITH(mcs, [  --with-mcs=FILE         mcs executable is FILE ],
	[
		AC_MSG_CHECKING(for $with_mcs)

		if test -f $with_mcs
		then
			AC_MSG_RESULT(found)
			mcs="$with_mcs"
		else
			AC_MSG_RESULT(no)
		fi
	],
	[
		AC_PATH_PROG(mcs, mcs, [], $PATH:/usr/local/bin)

		if test -z "$mcs"
		then
			AC_PATH_PROG(mcs, mcs.exe, [], $PATH:/usr/local/bin)
		fi
	])

])

AM_PATH_GLIB([1.2.6])
AM_PATH_GTK([1.2.6])

# check for CSANT compiler

AC_DEFUN([KDE_CHECK_CSANT],[
])

# Pick one of the available C# compilers.

AC_DEFUN([KDE_CHECK_CS_COMPILER],[
	KDE_CHECK_CSANT
	KDE_CHECK_CSCC
	KDE_CHECK_CSC
	KDE_CHECK_MCS

	AC_MSG_CHECKING(for c-sharp compiler)

	AC_ARG_WITH(cs-compiler, [  --with-cs-compiler=NAME mcs, cscc, or csc ],
	[
		if test "$with_cs_compiler" = "cscc"
		then
			CSC="$cscc"
			CSC_NAME="cscc"
		fi

		if test "$with_cs_compiler" = "csc"
		then
			CSC="$csc"
			CSC_NAME="csc"
		fi

		if test "$with_cs_compiler" = "mcs"
		then
			CSC="$mono"
			CSC_NAME="mcs"
		fi

		if test -z "$CSC_NAME"
		then
			AC_MSG_RESULT(no)
			echo "ERROR: Unknown C# compiler: $with_cs_compiler"
			exit
		else
			AC_MSG_RESULT($CSC_NAME)
		fi
	],
	[
		if test -n "$mcs"
		then
			CSC="$mcs"
			CSC_NAME="mcs"
			AC_MSG_RESULT(mcs)
		else
			if test -n "$cscc"
			then
				CSC="$cscc"
				CSC_NAME="cscc"
				AC_MSG_RESULT(cscc)
			else
				if test -n "$csc"
				then
					CSC="$csc"
					CSC_NAME="csc"
					AC_MSG_RESULT(csc)
				fi
			fi
		fi

		if test -z "$CSC_NAME"
		then
			AC_MSG_RESULT(no)
    			DO_NOT_COMPILE="$DO_NOT_COMPILE qtsharp"
		fi
	])

	AC_SUBST(CSC)
	AC_SUBST(CSC_NAME)
])

dnl
dnl Java checks
dnl

AC_DEFUN([KDE_CHECK_JAVA],
[
 AC_REQUIRE([KDE_CHECK_JAVA_DIR])
 if test "$kde_java_bindir" = "no"; then
   DO_NOT_COMPILE="$DO_NOT_COMPILE $1";
   BUILD_$1=false
 else
   BUILD_$1=true
 fi
 AM_CONDITIONAL(BUILD_$1, ${BUILD_$1})
]
)

dnl
dnl Check Perl
dnl

AC_DEFUN([KDE_CHECK_PERL],
[
  AC_ARG_VAR(PERL, full path to the perl program)
  AC_PATH_PROG(PERL, perl, "perl")
  AC_MSG_CHECKING([for Perl >= $1])
  has_wanted_perl="not found"
  if test -e "$PERL" && $PERL -e "require $1"; then
      has_wanted_perl=yes
  else
      DO_NOT_COMPILE="$DO_NOT_COMPILE $2"
  fi
  AC_MSG_RESULT($has_wanted_perl)
])

dnl  **********
dnl  check whether we need the qextmdi lib
dnl  (Shamlesly stolen from gideon souorces and
dnl  modified for quanta by fredi)
dnl  ..and borrowed again for a tdebindings test by rdale
dnl  **********

AC_DEFUN([KDE_CHECK_MDI],
[
  AC_MSG_CHECKING(whether to use tdemdi lib from tdelibs)
  AC_CACHE_VAL(ac_cv_mdi_setup,
  [
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
    save_CXXFLAGS="$CXXFLAGS"
    CXXFLAGS="$KDE_INCLUDES $TQT_INCLUDES $all_includes"

    AC_TRY_COMPILE([
      #include <tdeversion.h>
    ],
    [
      #if TDE_VERSION < ((3<<16) | (2<<8) | (0))
         KDE_choke me
      #endif
    ],
      ac_cv_mdi_setup=yes,
      ac_cv_mdi_setup=no
    )
    CXXFLAGS="$save_CXXFLAGS"
    AC_LANG_RESTORE
   ])

  if test "$ac_cv_mdi_setup" = "yes"; then
    LIB_KMDI="-ltdemdi"
    AC_MSG_RESULT(yes)
  else
    LIB_KMDI=''
    AC_MSG_RESULT(no)
  fi

  AC_SUBST(LIB_KMDI)
])

dnl Check if tdemdi is present, if not don't bother..
KDE_CHECK_MDI


AC_DEFUN([KDE_CHECK_KNS],
[
  AC_MSG_CHECKING(whether to use the tdenewstuff lib from tdelibs)
  AC_CACHE_VAL(ac_cv_kns_setup,
  [
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
    save_CXXFLAGS="$CXXFLAGS"
    CXXFLAGS="$KDE_INCLUDES $TQT_INCLUDES $all_includes"

    AC_TRY_COMPILE([
      #include <tdeversion.h>
    ],
    [
      #if TDE_VERSION < ((3<<16) | (3<<8) | (92))
         KDE_choke me
      #endif
    ],
      ac_cv_kns_setup=yes,
      ac_cv_kns_setup=no
    )
    CXXFLAGS="$save_CXXFLAGS"
    AC_LANG_RESTORE
   ])

  if test "$ac_cv_kns_setup" = "yes"; then
    LIB_KNS="-ltdenewstuff"
    AC_MSG_RESULT(yes)
  else
    LIB_KNS=''
    AC_MSG_RESULT(no)
  fi

  AC_SUBST(LIB_KNS)
])

dnl Check if tdenewstuff is present, if not don't bother..
KDE_CHECK_KNS

dnl remove when fixed
DO_NOT_COMPILE="$DO_NOT_COMPILE qtsharp"