dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.13)
AC_INIT(lf-test)
AM_INIT_AUTOMAKE(lf-test,0.0.1)

dnl ========================================================================
dnl needed for cross-compiling
AC_CONFIG_SRCDIR([src/test_window.c])
dnl AC_CONFIG_HEADERS([config.h])

dnl ========================================================================
dnl Checks for programs.
AC_PROG_MAKE_SET
AC_PROG_CC

# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([strcspn strspn])


dnl ========================================================================
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE

dnl ========================================================================
dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
AC_CHECK_HEADERS(sys/time.h unistd.h)
AC_CHECK_HEADERS([stdlib.h string.h])

dnl ========================================================================
dnl check for libminigui
have_libminigui="no"
AC_CHECK_HEADERS(minigui/common.h, have_libminigui=yes, foo=bar)

dnl ========================================================================
dnl check for non-UNIX system
unix="yes"
AC_CHECK_DECLS(__NOUNIX__, unix="no", foo=bar)

dnl ========================================================================
dnl check for run-time mode of MiniGUI
dnl ========================================================================
threads_version="no"
AC_CHECK_DECLS(_MGRM_THREADS, threads_version="yes", foo=bar, [#include <minigui/common.h>])

procs_version="no"
AC_CHECK_DECLS(_MGRM_PROCESSES, procs_version="yes", foo=bar, [#include <minigui/common.h>])

standalone_version="no"
AC_CHECK_DECLS(_MGRM_STANDALONE, standalone_version="yes", foo=bar, [#include <minigui/common.h>])

dnl ========================================================================
dnl check for newgal or oldgal interface.
use_newgal="no"
AC_CHECK_DECLS(_USE_NEWGAL, use_newgal="yes", foo=bar, [#include <minigui/common.h>])

AC_ARG_WITH(lang,
        [  --with-lang=[en/zhcn/zhtw]])

case "$with_lang" in
  zhcn)
    AC_DEFINE(_LANG_ZHCN, 1, 
            [Use text strings for locale zh_CN in GB2312])
    ;;
  zhtw)
    AC_DEFINE(_LANG_ZHTW, 1, 
            [Use text strings for locale zh_TW in BIG5])
    ;;
  *)
    AC_DEFINE(_LANG_EN, 1, 
            [Use text strings for locale en_US in ISO8859-1])
    ;;
esac

dnl ========================================================================
dnl Write Output

if test "$ac_cv_prog_gcc" = "yes"; then
    CFLAGS="$CFLAGS -Wall -Wstrict-prototypes -pipe"
fi


if test "x$threads_version" = "xyes"; then
    LIBS="$LIBS -lminigui_ths"
else
if test "x$standalone_version" = "xyes"; then
    CFLAGS="$CFLAGS -D_REENTRANT"
    LIBS="$LIBS -lminigui_sa"
else
    LIBS="$LIBS -lminigui_procs"
fi  
fi
LIBS="$LIBS -lpthread"

AC_CHECK_DECLS(_HAVE_MATH_LIB, LIBS="$LIBS -lm", foo=bar, [#include <minigui/common.h>])
AC_CHECK_DECLS(_MGIMAGE_PNG, LIBS="$LIBS -lpng", foo=bar, [#include <minigui/common.h>])
AC_CHECK_DECLS(_MGIMAGE_JPG, LIBS="$LIBS -ljpeg", foo=bar, [#include <minigui/common.h>])
AC_CHECK_DECLS(_MGFONT_TYPE1, LIBS="$LIBS -lt1", foo=bar, [#include <minigui/common.h>])
AC_CHECK_DECLS(_MGFONT_TTF, LIBS="$LIBS -lttf", foo=bar, [#include <minigui/common.h>])
AC_CHECK_DECLS(_MGFONT_FT2, LIBS="$LIBS -lfreetype", foo=bar, [#include <minigui/common.h>])
AC_CHECK_DECLS(_MGLF_RDR_FASHION, LIBS="$LIBS -lmgplus", foo=bar,
        [#include <minigui/mgplus.h>])

AM_CONDITIONAL(NOUNIX, test "x$unix" = "xno")
AM_CONDITIONAL(MGRM_THREADS, test "x$threads_version" = "xyes")
AM_CONDITIONAL(MGRM_PROCESSES, test "x$procs_version" = "xyes")
AM_CONDITIONAL(MGRM_STANDALONE, test "x$standalone_version" = "xyes")

AC_OUTPUT(
Makefile
src/Makefile
src/res/Makefile
)

if test "x$have_libminigui" != "xyes"; then
    AC_MSG_WARN([
		MiniGUI is not properly installed on the system. You need 
        MiniGUI Ver 2.2 or later for building this package. 
        Please configure and install MiniGUI Ver 2.2 first.
    ])
fi

