Updated build-system. Does this help you khz?
[pinentry.git] / admin / acinclude.m4.in
index 74162c9..a953be7 100644 (file)
@@ -33,10 +33,133 @@ dnl Forward compatibility macros (make autoconf 2.13 look like 2.50),
 dnl thanks to Raja R Harinath.
 dnl ------------------------------------------------------------------------
 dnl
-ifdef([_AC_PATH_X_DIRECT],[],
-   [AC_DEFUN([_AC_PATH_X_DIRECT],[AC_PATH_X_DIRECT])])
 ifdef([_AC_PATH_X_XMKMF],[],
    [AC_DEFUN([_AC_PATH_X_XMKMF],[AC_PATH_X_XMKMF])])
+ifdef([AC_OUTPUT_SUBDIRS],[],
+   [AC_DEFUN([AC_OUTPUT_SUBDIRS],[subdirs=$1; _AC_OUTPUT_SUBDIRS])])
+
+# KDE_PATH_X_DIRECT
+dnl Internal subroutine of AC_PATH_X.
+dnl Set ac_x_includes and/or ac_x_libraries.
+AC_DEFUN(KDE_PATH_X_DIRECT,
+[if test "$ac_x_includes" = NO; then
+  # Guess where to find include files, by looking for this one X11 .h file.
+  test -z "$x_direct_test_include" && x_direct_test_include=X11/Intrinsic.h
+
+  # First, try using that file with no special directory specified.
+AC_TRY_CPP([#include <$x_direct_test_include>],
+[# We can compile using X headers with no special include directory.
+ac_x_includes=],
+[# Look for the header file in a standard set of common directories.
+# Check X11 before X11Rn because it is often a symlink to the current release.
+  for ac_dir in               \
+    /usr/X11/include          \
+    /usr/X11R6/include        \
+    /usr/X11R5/include        \
+    /usr/X11R4/include        \
+                              \
+    /usr/include/X11          \
+    /usr/include/X11R6        \
+    /usr/include/X11R5        \
+    /usr/include/X11R4        \
+                              \
+    /usr/local/X11/include    \
+    /usr/local/X11R6/include  \
+    /usr/local/X11R5/include  \
+    /usr/local/X11R4/include  \
+                              \
+    /usr/local/include/X11    \
+    /usr/local/include/X11R6  \
+    /usr/local/include/X11R5  \
+    /usr/local/include/X11R4  \
+                              \
+    /usr/X386/include         \
+    /usr/x386/include         \
+    /usr/XFree86/include/X11  \
+                              \
+    /usr/include              \
+    /usr/local/include        \
+    /usr/unsupported/include  \
+    /usr/athena/include       \
+    /usr/local/x11r5/include  \
+    /usr/lpp/Xamples/include  \
+                              \
+    /usr/openwin/include      \
+    /usr/openwin/share/include \
+    ; \
+  do
+    if test -r "$ac_dir/$x_direct_test_include"; then
+      ac_x_includes=$ac_dir
+      break
+    fi
+  done])
+fi # $ac_x_includes = NO
+
+if test "$ac_x_libraries" = NO; then
+  # Check for the libraries.
+
+  test -z "$x_direct_test_library" && x_direct_test_library=Xt
+  test -z "$x_direct_test_function" && x_direct_test_function=XtMalloc
+
+  # See if we find them without any special options.
+  # Don't add to $LIBS permanently.
+  ac_save_LIBS="$LIBS"
+  LIBS="-l$x_direct_test_library $LIBS"
+AC_TRY_LINK(, [${x_direct_test_function}()],
+[LIBS="$ac_save_LIBS"
+# We can link X programs with no special library path.
+ac_x_libraries=],
+[LIBS="$ac_save_LIBS"
+# First see if replacing the include by lib works.
+# Check X11 before X11Rn because it is often a symlink to the current release.
+for ac_dir in `echo "$ac_x_includes" | sed s/include/lib/` \
+    /usr/X11/lib          \
+    /usr/X11R6/lib        \
+    /usr/X11R5/lib        \
+    /usr/X11R4/lib        \
+                          \
+    /usr/lib/X11          \
+    /usr/lib/X11R6        \
+    /usr/lib/X11R5        \
+    /usr/lib/X11R4        \
+                          \
+    /usr/local/X11/lib    \
+    /usr/local/X11R6/lib  \
+    /usr/local/X11R5/lib  \
+    /usr/local/X11R4/lib  \
+                          \
+    /usr/local/lib/X11    \
+    /usr/local/lib/X11R6  \
+    /usr/local/lib/X11R5  \
+    /usr/local/lib/X11R4  \
+                          \
+    /usr/X386/lib         \
+    /usr/x386/lib         \
+    /usr/XFree86/lib/X11  \
+                          \
+    /usr/lib              \
+    /usr/local/lib        \
+    /usr/unsupported/lib  \
+    /usr/athena/lib       \
+    /usr/local/x11r5/lib  \
+    /usr/lpp/Xamples/lib  \
+    /lib/usr/lib/X11     \
+                          \
+    /usr/openwin/lib      \
+    /usr/openwin/share/lib \
+    ; \
+do
+dnl Don't even attempt the hair of trying to link an X program!
+  for ac_extension in a so sl; do
+    if test -r $ac_dir/lib${x_direct_test_library}.$ac_extension; then
+      ac_x_libraries=$ac_dir
+      break 2
+    fi
+  done
+done])
+fi # $ac_x_libraries = NO
+])
+
 
 dnl ------------------------------------------------------------------------
 dnl Find a file (or one of more files in a list of dirs)
@@ -49,7 +172,9 @@ for i in $2;
 do
   for j in $1;
   do
+    echo "configure: __oline__: $i/$j" >&AC_FD_CC
     if test -r "$i/$j"; then
+      echo "taking that" >&AC_FD_CC
       $3=$i
       break 2
     fi
@@ -165,6 +290,13 @@ AC_DEFUN(AC_PATH_QT_MOC_UIC,
 
    AC_SUBST(MOC)
    AC_SUBST(UIC)
+
+   UIC_TR="i18n"
+   if test $kde_qtver = 3; then
+     UIC_TR="tr2i18n"
+   fi
+
+   AC_SUBST(UIC_TR)
 ])
 
 AC_DEFUN(KDE_1_CHECK_PATHS,
@@ -234,6 +366,8 @@ AC_DEFUN(KDE_SET_PATHS,
        kde_servicesdir=\"$kde_servicesdir\" \
        kde_servicetypesdir=\"$kde_servicetypesdir\" \
        kde_moduledir=\"$kde_moduledir\" \
+   kde_styledir=\"$kde_styledir\" \
+       kde_widgetdir=\"$kde_widgetdir\" \
        kde_result=$1"
 ])
 
@@ -287,7 +421,17 @@ if test "$1" = "default"; then
     kde_servicetypesdir='\${prefix}/share/servicetypes'
   fi
   if test -z "$kde_moduledir"; then
-    kde_moduledir='\${exec_prefix}/lib/kde2'
+    if test "$kde_qtver" = "2"; then
+      kde_moduledir='\${exec_prefix}/lib/kde2'
+    else
+      kde_moduledir='\${exec_prefix}/lib/kde3'
+    fi
+  fi
+  if test -z "$kde_styledir"; then
+    kde_styledir='\${exec_prefix}/lib/kde3/plugins/styles'
+  fi
+  if test -z "$kde_widgetdir"; then
+    kde_widgetdir='\${exec_prefix}/lib/kde3/plugins/designer'
   fi
 
   KDE_SET_PATHS(defaults)
@@ -313,7 +457,8 @@ AC_DEFUN(KDE_CHECK_PATHS_FOR_COMPLETENESS,
    test -z "$kde_wallpaperdir" || test -z "$kde_templatesdir" ||
    test -z "$kde_bindir" || test -z "$kde_servicesdir" ||
    test -z "$kde_servicetypesdir" || test -z "$kde_moduledir" ||
-   test "$kde_have_all_paths" != "yes"; then
+   test -z "$kde_styledir" || test -z "kde_widgetdir" 
+   test "x$kde_have_all_paths" != "xyes"; then
      kde_have_all_paths=no
   fi
 ])
@@ -328,7 +473,7 @@ Please check whether you installed KDE correctly.
 AC_DEFUN(KDE_SUBST_PROGRAMS,
 [
 
-        kde_default_bindirs="/usr/bin /usr/local/bin /opt/local/bin /usr/X11R6/bin /opt/kde/bin /opt/kde2/bin /usr/kde/bin /usr/local/kde/bin"
+        kde_default_bindirs="/usr/bin /usr/local/bin /opt/local/bin /usr/X11R6/bin /opt/kde/bin /opt/kde3/bin /usr/kde/bin /usr/local/kde/bin"
         if test -n "$KDEDIRS"; then
            kde_save_IFS=$IFS
            IFS=:
@@ -343,6 +488,18 @@ AC_DEFUN(KDE_SUBST_PROGRAMS,
         KDE_FIND_PATH(mcopidl, MCOPIDL, [$kde_default_bindirs], [KDE_MISSING_PROG_ERROR(mcopidl)])
         KDE_FIND_PATH(artsc-config, ARTSCCONFIG, [$kde_default_bindirs], [KDE_MISSING_PROG_ERROR(artsc-config)])
         KDE_FIND_PATH(kde-config, KDECONFIG, [$kde_default_bindirs])
+        KDE_FIND_PATH(meinproc, MEINPROC, [$kde_default_bindirs])
+      
+        if test -n "$MEINPROC" && test ! "$MEINPROC" = "compiled"; then  
+           kde_sharedirs="/usr/share/kde /usr/local/share /usr/share /opt/kde3/share /opt/kde/share $prefix/share"
+            test -n "$KDEDIR" && kde_sharedirs="$KDEDIR/share $kde_sharedirs"
+            AC_FIND_FILE(apps/ksgmltools2/customization/kde-chunk.xsl, $kde_sharedirs, KDE_XSL_STYLESHEET)
+           if test "$KDE_XSL_STYLESHEET" = "NO"; then
+               KDE_XSL_STYLESHEET=""
+           else
+                KDE_XSL_STYLESHEET="$KDE_XSL_STYLESHEET/apps/ksgmltools2/customization/kde-chunk.xsl"
+           fi
+        fi
 
         DCOP_DEPENDENCIES='$(DCOPIDL)'
         AC_SUBST(DCOPIDL)
@@ -351,6 +508,8 @@ AC_DEFUN(KDE_SUBST_PROGRAMS,
         AC_SUBST(MCOPIDL)
         AC_SUBST(ARTSCCONFIG)
         AC_SUBST(KDECONFIG)
+       AC_SUBST(MEINPROC)
+       AC_SUBST(KDE_XSL_STYLESHEET)
 
         if test -x "$KDECONFIG"; then # it can be "compiled"
           kde_libs_prefix=`$KDECONFIG --prefix`
@@ -391,6 +550,8 @@ if test "$kde_have_all_paths" = "no" && test "$kde_cached_paths" = "yes"; then
   kde_mimedir= kde_toolbardir= kde_wallpaperdir= kde_templatesdir=
   kde_bindir= kde_servicesdir= kde_servicetypesdir= kde_moduledir=
   kde_have_all_paths=
+  kde_styledir=
+  kde_widgetdir=
   KDE_SET_DEFAULT_PATHS($1)
   eval "$kde_cv_all_paths"
   KDE_CHECK_PATHS_FOR_COMPLETENESS
@@ -431,6 +592,8 @@ AC_SUBST(kde_templatesdir)
 AC_SUBST(kde_servicesdir)
 AC_SUBST(kde_servicetypesdir)
 AC_SUBST(kde_moduledir)
+AC_SUBST(kde_styledir)
+AC_SUBST(kde_widgetdir)
 if test "$kde_qtver" = 1; then
   kde_minidir="$kde_icondir/mini"
 else
@@ -447,7 +610,9 @@ AC_DEFUN(KDE_MISC_TESTS,
 [
    AC_LANG_C
    dnl Checks for libraries.
-   AC_CHECK_LIB(compat, main, [LIBCOMPAT="-lcompat"]) dnl for FreeBSD
+   AC_CHECK_LIB(util, main, [LIBUTIL="-lutil"]) dnl for *BSD 
+   AC_SUBST(LIBUTIL)
+   AC_CHECK_LIB(compat, main, [LIBCOMPAT="-lcompat"]) dnl for *BSD
    AC_SUBST(LIBCOMPAT)
    kde_have_crypt=
    AC_CHECK_LIB(crypt, crypt, [LIBCRYPT="-lcrypt"; kde_have_crypt=yes],
@@ -487,12 +652,27 @@ support])
    AC_CHECK_FUNC(shmat, ,
      AC_CHECK_LIB(ipc, shmat, X_EXTRA_LIBS="$X_EXTRA_LIBS -lipc"))
    
-   # Solaris 2.6 needs -lresolv for res_init
-   AC_CHECK_FUNC(res_init, ,
-     AC_CHECK_LIB(resolv, res_init, X_EXTRA_LIBS="$X_EXTRA_LIBS -lresolv"))
+   # Solaris 2.6 and others need -lresolv for res_init
+   AC_CHECK_FUNCS(res_init, , [
+     kde_libs_safe="$LIBS"
+     LIBS="$LIBS $X_EXTRA_LIBS -lresolv"
+     AC_TRY_LINK(
+[
+#include <resolv.h>
+],
+[ 
+res_init(); 
+],
+        LIBRESOLV="-lresolv"
+        X_EXTRA_LIBS="$X_EXTRA_LIBS $LIBRESOLV"
+        AC_DEFINE(HAVE_RES_INIT, 1, [Define if you have the res_init function])
+     )
+     LIBS=$kde_libs_safe
+   ])
 
    LIBSOCKET="$X_EXTRA_LIBS"
    AC_SUBST(LIBSOCKET)
+   AC_SUBST(LIBRESOLV)
    AC_SUBST(X_EXTRA_LIBS)
    AC_CHECK_LIB(ucb, killpg, [LIBUCB="-lucb"]) dnl for Solaris2.4
    AC_SUBST(LIBUCB)
@@ -517,8 +697,24 @@ dnl ------------------------------------------------------------------------
 dnl
 AC_DEFUN(K_PATH_X,
 [
-AC_REQUIRE([AC_PROG_CPP])dnl
 AC_REQUIRE([KDE_MISC_TESTS])dnl
+
+AC_ARG_ENABLE(
+  embedded,
+  [  --enable-embedded       link to Qt-embedded, don't use X],
+  kde_use_qt_emb=$enableval,
+  kde_use_qt_emb=no
+)
+
+AC_ARG_ENABLE(
+  palmtop,
+  [  --enable-palmtop       link to Qt-embedded, don't use X and link to the Qt Palmtop Environment],
+  kde_use_qt_emb_palm=$enableval,
+  kde_use_qt_emb_palm=no
+)
+
+if test "$kde_use_qt_emb" = "no"; then
+
 AC_MSG_CHECKING(for X)
 AC_LANG_SAVE
 AC_LANG_C
@@ -539,7 +735,7 @@ fi
 ac_x_libraries=$kde_x_libraries
 ac_x_includes=$kde_x_includes
 
-_AC_PATH_X_DIRECT
+KDE_PATH_X_DIRECT
 dnl AC_PATH_X_XMKMF picks /usr/lib as the path for the X libraries.
 dnl Unfortunately, if compiling with the N32 ABI, this is not the correct
 dnl location. The correct location is /usr/lib32 or an undefined value
@@ -676,7 +872,7 @@ fi
 AC_MSG_CHECKING(for Xinerama)
 
  AC_ARG_WITH(xinerama,
-  [  --with-xinerama        enable support for Xinerama ],
+  [  --with-xinerama         enable support for Xinerama ],
   [
     no_xinerama=no
   ], [
@@ -720,6 +916,35 @@ LDFLAGS="$kde_save_LDFLAGS"
 CFLAGS="$kde_save_CFLAGS"
 LIBS="$kde_save_LIBS"
 
+LIB_XEXT="-lXext"
+QTE_NORTTI=""
+
+else
+  dnl We're using QT Embedded
+  CXXFLAGS="$CXXFLAGS -fno-rtti -DQWS"
+  CFLAGS="$CFLAGS -DQWS"
+  LDFLAGS="$LDFLAGS -DQWS"
+  QTE_NORTTI="-fno-rtti -DQWS"
+  X_PRE_LIBS=""
+  LIB_X11=""
+  LIB_XEXT=""
+  LIBSM=""
+  X_INCLUDES=""
+  X_LDFLAGS=""
+  x_includes=""
+  x_libraries=""
+  AC_SUBST(X_PRE_LIBS)
+  AC_SUBST(LIB_X11)
+  AC_SUBST(LIBSM)
+  AC_SUBST(X_INCLUDES)
+  AC_SUBST(X_LDFLAGS)
+  AC_SUBST(x_includes)
+  AC_SUBST(x_libraries)
+fi
+AC_SUBST(QTE_NORTTI)
+AC_SUBST(LIB_XEXT)
+
+
 AC_LANG_RESTORE
 
 ])
@@ -744,7 +969,14 @@ cat >> conftest.$ac_ext <<EOF
 #include <qiconview.h>
 EOF
 fi
+fi
 
+if test "$kde_qtver" = "3"; then
+cat >> conftest.$ac_ext <<EOF
+#include <qcursor.h>
+#include <qstylefactory.h>
+#include <private/qucomextra_p.h>
+EOF
 fi
 
 echo "#if ! ($kde_qt_verstring)" >> conftest.$ac_ext
@@ -757,6 +989,7 @@ EOF
 if test "$kde_qtver" = "2"; then
 cat >> conftest.$ac_ext <<EOF
     QStringList *t = new QStringList();
+    Q_UNUSED(t);
 EOF
 if test $kde_qtsubver -gt 0; then
 cat >> conftest.$ac_ext <<EOF
@@ -764,10 +997,15 @@ cat >> conftest.$ac_ext <<EOF
     iv.setWordWrapIconText(false);
     QString s;
     s.setLatin1("Elvis is alive", 14);
-    int magnolia = QEvent::Speech; /* new in 2.2 beta2 */
 EOF
 fi
 fi
+if test "$kde_qtver" = "3"; then
+cat >> conftest.$ac_ext <<EOF
+    (void)QStyleFactory::create(QString::null);
+    QCursor c(Qt::WhatsThisCursor);
+EOF
+fi
 cat >> conftest.$ac_ext <<EOF
     return 0;
 }
@@ -778,34 +1016,32 @@ AC_DEFUN(KDE_USE_QT,
 [
 
 if test -z "$1"; then
-  kde_qtver=2
+  kde_qtver=3
   kde_qtsubver=1
 else
-  kde_qtsubver=`echo "$1" | sed -e 's#[0-9]\+\.\([0-9]\+\).*#\1#'`
+  kde_qtsubver=`echo "$1" | sed -e 's#[0-9][0-9]*\.\([0-9][0-9]*\).*#\1#'`
   # following is the check if subversion isnĀ“t found in passed argument
   if test "$kde_qtsubver" = "$1"; then
     kde_qtsubver=1
   fi
-  kde_qtver=`echo "$1" | sed -e 's#^\([0-9]\+\)\..*#\1#'`
+  kde_qtver=`echo "$1" | sed -e 's#^\([0-9][0-9]*\)\..*#\1#'`
   if test "$kde_qtver" = "1"; then
     kde_qtsubver=42
-  else
-   # this is the version number fallback to 2.1, unless major version is 1 or 2
-   if test "$kde_qtver" != "2"; then
-    kde_qtver=2
-    kde_qtsubver=1
-   fi
   fi
 fi
 
 if test -z "$2"; then
-  if test $kde_qtver = 2; then
+  if test "$kde_qtver" = "2"; then
     if test $kde_qtsubver -gt 0; then
       kde_qt_minversion=">= Qt 2.2.2"
     else
       kde_qt_minversion=">= Qt 2.0.2"
     fi
-  else
+  fi
+  if test "$kde_qtver" = "3"; then
+    kde_qt_minversion=">= Qt 3.0.1"
+  fi
+  if test "$kde_qtver" = "1"; then
     kde_qt_minversion=">= 1.42 and < 2.0"
   fi
 else
@@ -813,22 +1049,30 @@ else
 fi
 
 if test -z "$3"; then
+   if test $kde_qtver = 3; then
+     kde_qt_verstring="QT_VERSION >= 301"
+   fi
    if test $kde_qtver = 2; then
-    if test $kde_qtsubver -gt 0; then
-      kde_qt_verstring="QT_VERSION >= 222"
-    else
-      kde_qt_verstring="QT_VERSION >= 200"
-    fi
-   else
+     if test $kde_qtsubver -gt 0; then
+       kde_qt_verstring="QT_VERSION >= 222"
+     else
+       kde_qt_verstring="QT_VERSION >= 200"
+     fi
+   fi
+   if test $kde_qtver = 1; then
     kde_qt_verstring="QT_VERSION >= 142 && QT_VERSION < 200"
-  fi
+   fi
 else
    kde_qt_verstring=$3
 fi
 
+if test $kde_qtver = 3; then
+  kde_qt_dirs="$QTDIR /usr/lib/qt3 /usr/lib/qt"
+fi
 if test $kde_qtver = 2; then
    kde_qt_dirs="$QTDIR /usr/lib/qt2 /usr/lib/qt"
-else
+fi
+if test $kde_qtver = 1; then
    kde_qt_dirs="$QTDIR /usr/lib/qt"
 fi
 ])
@@ -849,7 +1093,11 @@ ac_libs_safe="$LIBS"
 
 CXXFLAGS="$CXXFLAGS -I$qt_includes"
 LDFLAGS="$LDFLAGS $X_LDFLAGS"
+if test "x$kde_use_qt_emb" != "xyes"; then
 LIBS="$LIBQT -lXext -lX11 $LIBSOCKET"
+else
+LIBS="$LIBQT $LIBSOCKET"
+fi
 LD_LIBRARY_PATH=
 export LD_LIBRARY_PATH
 LIBRARY_PATH=
@@ -903,77 +1151,101 @@ dnl ------------------------------------------------------------------------
 
 AC_ARG_ENABLE(
   mt,
-  [  --enable-mt             link to threaded Qt (experimental)],
+  [  --disable-mt            link to non-threaded Qt (deprecated)],
   kde_use_qt_mt=$enableval,
-  kde_use_qt_mt=no
+  [
+    if test $kde_qtver = 3; then
+      kde_use_qt_mt=yes
+    else
+      kde_use_qt_mt=no
+    fi
+  ]
 )
 
 USING_QT_MT=""
 
 dnl ------------------------------------------------------------------------
-dnl If we got --enable-qt-mt then adjust some vars for the host.
+dnl If we not get --disable-qt-mt then adjust some vars for the host.
 dnl ------------------------------------------------------------------------
 
+KDE_MT_LDFLAGS=
+KDE_MT_LIBS=
 if test "x$kde_use_qt_mt" = "xyes"; then
-
-  case $host in
-  *-*-linux-*)
-    if test "x$GCC" = "xyes"; then
-      CPPFLAGS="$CPPFLAGS -DQT_THREAD_SUPPORT -pthread"
-      X_EXTRA_LIBS="$X_EXTRA_LIBS -pthread"
-    else
-      AC_MSG_WARN([Compiler is not gcc. MT support disabled.])
-    fi
-    ;;
-  *)
-    AC_MSG_WARN([MT not yet supported on $host - disabled.])
-    ;;
-  esac
-
+  KDE_CHECK_THREADING
+  if test "x$kde_use_threading" = "xyes"; then
+    CPPFLAGS="$USE_THREADS -DQT_THREAD_SUPPORT $CPPFLAGS"
+    KDE_MT_LDFLAGS="$USE_THREADS"
+    KDE_MT_LIBS="$LIBPTHREAD"
+  else
+    kde_use_qt_mt=no
+  fi
 fi
+AC_SUBST(KDE_MT_LDFLAGS)
+AC_SUBST(KDE_MT_LIBS)
 
 kde_qt_was_given=yes
 
 dnl ------------------------------------------------------------------------
 dnl If we haven't been told how to link to Qt, we work it out for ourselves.
 dnl ------------------------------------------------------------------------
-
 if test -z "$LIBQT_GLOB"; then
-
-  LIBQT_GLOB="libqt.*"
-
+  if test "x$kde_use_qt_emb" = "xyes"; then
+    LIBQT_GLOB="libqte.*"
+  else
+    LIBQT_GLOB="libqt.*"
+  fi
 fi
 
 if test -z "$LIBQT"; then
+dnl ------------------------------------------------------------
+dnl If we got --enable-embedded then adjust the Qt library name.
+dnl ------------------------------------------------------------
+  if test "x$kde_use_qt_emb" = "xyes"; then
+    qtlib="qte"
+  else
+    qtlib="qt"
+  fi
 
-  LIBQT="-lqt"
-  kde_int_qt="-lqt"
+  kde_int_qt="-l$qtlib"
+else
+  kde_int_qt="$LIBQT"
+  kde_lib_qt_set=yes
+fi
+
+if test -z "$LIBQPE"; then
+dnl ------------------------------------------------------------
+dnl If we got --enable-palmtop then add -lqpe to the link line
+dnl ------------------------------------------------------------
+  if test "x$kde_use_qt_emb" = "xyes"; then
+    if test "x$kde_use_qt_emb_palm" = "xyes"; then
+      LIB_QPE="-lqpe"
+    else
+      LIB_QPE=""
+    fi
+  else
+    LIB_QPE=""
+  fi
+fi
 
 dnl ------------------------------------------------------------------------
 dnl If we got --enable-qt-mt then adjust the Qt library name for the host.
 dnl ------------------------------------------------------------------------
 
-  if test "x$kde_use_qt_mt" = "xyes"; then
-
-      case $host in
-      *-*-linux-*)
-        if test "x$GCC" = "xyes"; then
-          LIBQT="-lqt-mt"
-          kde_int_qt="-lqt-mt"
-          LIBQT_GLOB="libqt-mt.*"
-          USING_QT_MT="using -mt"
-        fi
-      ;;
-      esac
+if test "x$kde_use_qt_mt" = "xyes"; then
+  if test -z "$LIBQT"; then
+    LIBQT="-l$qtlib-mt"
+    kde_int_qt="-l$qtlib-mt"
+  else
+    LIBQT="$qtlib-mt"
+    kde_int_qt="$qtlib-mt"
   fi
-
-  kde_qt_was_given=no
-
+  LIBQT_GLOB="lib$qtlib-mt.*"
+  USING_QT_MT="using -mt"
 else
-  kde_int_qt="$LIBQT"
+  LIBQT="-l$qtlib"
 fi
 
-if test $kde_qtver = 2; then
+if test $kde_qtver != 1; then
 
   AC_REQUIRE([AC_FIND_PNG])
   AC_REQUIRE([AC_FIND_JPEG])
@@ -982,7 +1254,9 @@ fi
 
 AC_MSG_CHECKING([for Qt])
 
+if test "x$kde_use_qt_emb" != "xyes"; then
 LIBQT="$LIBQT $X_PRE_LIBS -lXext -lX11 $LIBSM $LIBSOCKET"
+fi
 ac_qt_includes=NO ac_qt_libraries=NO ac_qt_bindir=NO
 qt_libraries=""
 qt_includes=""
@@ -1019,7 +1293,7 @@ if test ! "$ac_qt_includes" = "NO"; then
    qt_incdirs="$ac_qt_includes $qt_incdirs"
 fi
 
-if test "$kde_qtver" = "2"; then
+if test "$kde_qtver" != "1"; then
   kde_qt_header=qstyle.h
 else
   kde_qt_header=qglobal.h
@@ -1055,8 +1329,8 @@ ac_ldflags_safe="$LDFLAGS"
 ac_libs_safe="$LIBS"
 
 CXXFLAGS="$CXXFLAGS -I$qt_incdir $all_includes"
-LDFLAGS="$LDFLAGS -L$qt_libdir $all_libraries $USER_LDFLAGS"
-LIBS="$LIBS $LIBQT"
+LDFLAGS="$LDFLAGS -L$qt_libdir $all_libraries $USER_LDFLAGS $KDE_MT_LDFLAGS"
+LIBS="$LIBS $LIBQT $KDE_MT_LIBS"
 
 KDE_PRINT_QT_PROGRAM
 
@@ -1076,6 +1350,7 @@ AC_LANG_RESTORE
 if test "$ac_qt_includes" = NO || test "$ac_qt_libraries" = NO; then
   ac_cv_have_qt="have_qt=no"
   ac_qt_notfound=""
+  missing_qt_mt=""
   if test "$ac_qt_includes" = NO; then
     if test "$ac_qt_libraries" = NO; then
       ac_qt_notfound="(headers and libraries)";
@@ -1083,11 +1358,17 @@ if test "$ac_qt_includes" = NO || test "$ac_qt_libraries" = NO; then
       ac_qt_notfound="(headers)";
     fi
   else
-    ac_qt_notfound="(libraries)";
+    if test "x$kde_use_qt_mt" = "xyes"; then
+       missing_qt_mt="
+Make sure that you have compiled Qt with thread support!"
+       ac_qt_notfound="(library $qtlib-mt)";
+    else
+       ac_qt_notfound="(library $qtlib)";
+    fi
   fi
 
   AC_MSG_ERROR([Qt ($kde_qt_minversion) $ac_qt_notfound not found. Please check your installation!
-For more details about this problem, look at the end of config.log.])
+For more details about this problem, look at the end of config.log.$missing_qt_mt])
 else
   have_qt="yes"
 fi
@@ -1114,7 +1395,7 @@ AC_SUBST(qt_libraries)
 AC_SUBST(qt_includes)
 
 if test "$qt_includes" = "$x_includes" || test -z "$qt_includes"; then
- QT_INCLUDES="";
+ QT_INCLUDES=""
 else
  QT_INCLUDES="-I$qt_includes"
  all_includes="$QT_INCLUDES $all_includes"
@@ -1126,14 +1407,23 @@ else
  QT_LDFLAGS="-L$qt_libraries"
  all_libraries="$all_libraries $QT_LDFLAGS"
 fi
+test -z "$KDE_MT_LDFLAGS" || all_libraries="$all_libraries $KDE_MT_LDFLAGS"
 
 AC_SUBST(QT_INCLUDES)
 AC_SUBST(QT_LDFLAGS)
 AC_PATH_QT_MOC_UIC
 
+if test "x$kde_use_qt_emb" != "xyes"; then
 LIB_QT="$kde_int_qt "'$(LIBPNG) $(LIBJPEG) -lXext $(LIB_X11) $(LIBSM)'
+else
+LIB_QT="$kde_int_qt "'$(LIBPNG) $(LIBJPEG)'
+fi
+test -z "$KDE_MT_LIBS" || LIB_QT="$LIB_QT $KDE_MT_LIBS"
+
 AC_SUBST(LIB_QT)
+AC_SUBST(LIB_QPE)
 
+AC_SUBST(kde_qtver)
 ])
 
 AC_DEFUN(AC_PATH_QT,
@@ -1216,7 +1506,7 @@ fi
 
 if test -z "$1"; then
 
-kde_incdirs="/usr/lib/kde/include /usr/local/kde/include /usr/local/include /usr/kde/include /usr/include/kde /usr/include /opt/kde2/include /opt/kde/include $x_includes $qt_includes"
+kde_incdirs="/usr/lib/kde/include /usr/local/kde/include /usr/local/include /usr/kde/include /usr/include/kde /usr/include /opt/kde3/include /opt/kde/include $x_includes $qt_includes"
 test -n "$KDEDIR" && kde_incdirs="$KDEDIR/include $KDEDIR/include/kde $KDEDIR $kde_incdirs"
 kde_incdirs="$ac_kde_includes $kde_incdirs"
 AC_FIND_FILE($kde_check_header, $kde_incdirs, kde_incdir)
@@ -1228,7 +1518,7 @@ in the prefix, you've chosen, are no KDE headers installed. This will fail.
 So, check this please and use another prefix!])
 fi
 
-kde_libdirs="/usr/lib/kde/lib /usr/local/kde/lib /usr/kde/lib /usr/lib/kde /usr/lib /usr/X11R6/lib /usr/local/lib /opt/kde2/lib /opt/kde/lib /usr/X11R6/kde/lib"
+kde_libdirs="/usr/lib/kde/lib /usr/local/kde/lib /usr/kde/lib /usr/lib/kde /usr/lib/kde3 /usr/lib /usr/X11R6/lib /usr/local/lib /opt/kde3/lib /opt/kde/lib /usr/X11R6/kde/lib"
 test -n "$KDEDIR" && kde_libdirs="$KDEDIR/lib $KDEDIR $kde_libdirs"
 kde_libdirs="$ac_kde_libraries $kde_libdirs"
 AC_FIND_FILE($kde_check_lib, $kde_libdirs, kde_libdir)
@@ -1285,7 +1575,7 @@ fi
 AC_SUBST(kde_libraries)
 AC_SUBST(kde_includes)
 
-if test "$kde_includes" = "$x_includes" || test "$kde_includes" = "$qt_includes" ; then
+if test "$kde_includes" = "$x_includes" || test "$kde_includes" = "$qt_includes"  || test "$kde_includes" = "/usr/include"; then
  KDE_INCLUDES=""
 else
  KDE_INCLUDES="-I$kde_includes"
@@ -1396,6 +1686,8 @@ int main() {
     printf("kde_servicesdir=\\"/tmp/dummy\\"\n");
     printf("kde_servicetypesdir=\\"/tmp/dummy\\"\n");
     printf("kde_moduledir=\\"/tmp/dummy\\"\n");
+    printf("kde_styledir=\\"/tmp/dummy\\"\n");
+    printf("kde_widgetdir=\\"/tmp/dummy\\"\n");
     return 0;
     }
 EOF
@@ -1464,10 +1756,10 @@ AC_DEFUN(KDE_CHECK_KIMGIO,
      LIBS="$LIBS $all_libraries $LIBJPEG $LIBTIFF $LIBPNG $LIBQT -lm"
      AC_CHECK_LIB(kimgio, kimgioRegister, [
       LIBKIMGIO_EXISTS=yes],LIBKIMGIO_EXISTS=no)
-      LIBS="$kde_save_LIBS"
-      AC_LANG_RESTORE
+     LIBS="$kde_save_LIBS"
+     AC_LANG_RESTORE
    else
-      LIBKIMGIO_EXISTS=yes
+     LIBKIMGIO_EXISTS=yes
    fi
 
    if test "$LIBKIMGIO_EXISTS" = "yes"; then
@@ -1484,13 +1776,11 @@ AC_DEFUN(KDE_CREATE_LIBS_ALIASES,
    AC_REQUIRE([KDE_CHECK_LIBDL])
    AC_REQUIRE([K_PATH_X])
 
-if test $kde_qtver = 2; then
+if test $kde_qtver != 1; then
    LIB_KDECORE='-lkdecore'
    AC_SUBST(LIB_KDECORE)
    LIB_KDEUI='-lkdeui'
    AC_SUBST(LIB_KDEUI)
-   LIB_KFORMULA='-lkformula'
-   AC_SUBST(LIB_KFORMULA)
    LIB_KIO='-lkio'
    AC_SUBST(LIB_KIO)
    LIB_KSYCOCA='-lksycoca'
@@ -1507,8 +1797,8 @@ if test $kde_qtver = 2; then
    AC_SUBST(LIB_KSPELL)
    LIB_KPARTS='-lkparts'
    AC_SUBST(LIB_KPARTS)
-   LIB_KWRITE='-lkwrite'
-   AC_SUBST(LIB_KWRITE)
+   LIB_KDEPRINT='-lkdeprint'
+   AC_SUBST(LIB_KDEPRINT)
 else
    LIB_KDECORE='-lkdecore -lXext $(LIB_QT)'
    AC_SUBST(LIB_KDECORE)
@@ -1743,7 +2033,11 @@ AC_DEFUN(AC_FIND_GIF,
    [AC_MSG_CHECKING([for giflib])
 AC_CACHE_VAL(ac_cv_lib_gif,
 [ac_save_LIBS="$LIBS"
+if test "x$kde_use_qt_emb" != "xyes"; then
 LIBS="$all_libraries -lgif -lX11 $LIBSOCKET"
+else
+LIBS="$all_libraries -lgif"
+fi
 AC_TRY_LINK(dnl
 [
 #ifdef __cplusplus
@@ -1818,24 +2112,10 @@ dnl first look for libraries
 KDE_FIND_JPEG_HELPER(6b, 6b,
    KDE_FIND_JPEG_HELPER(normal, [],
     [
-dnl what to do, if the normal way fails:
-       if test -f "$kde_libraries/libjpeg.so"; then
-          test -f ./libjpegkde.so || $LN_S $kde_libraries/libjpeg.so ./libjpegkde.so
-          ac_cv_lib_jpeg="-L\${topdir} -ljpegkde"
-       else if test -f "$kde_libraries/libjpeg.sl"; then
-          test -f ./libjpegkde.sl ||$LN_S $kde_libraries/libjpeg.sl ./libjpegkde.sl
-          ac_cv_lib_jpeg="-L\${topdir} -ljpegkde"      
-       else if test -f "$kde_libraries/libjpeg.a"; then
-          test -f ./libjpegkde.a || $LN_S $kde_libraries/libjpeg.a ./libjpegkde.a
-          ac_cv_lib_jpeg="-L\${topdir} -ljpegkde"
-        else
-         ac_cv_lib_jpeg=
-       fi
-      fi
-   fi
-
-   LIBJPEG=$ac_cv_lib_jpeg
-]))
+       LIBJPEG=
+    ]
+   )
+)
 
 dnl then search the headers (can't use simply AC_TRY_xxx, as jpeglib.h
 dnl requires system dependent includes loaded before it)
@@ -1910,7 +2190,11 @@ AC_CACHE_VAL(kde_cv_libtiff_$1,
 AC_LANG_SAVE
 AC_LANG_CPLUSPLUS
 kde_save_LIBS="$LIBS"
+if test "x$kde_use_qt_emb" != "xyes"; then
 LIBS="$all_libraries $USER_LDFLAGS -l$1 $LIBJPEG $LIBZ -lX11 $LIBSOCKET -lm"
+else
+LIBS="$all_libraries $USER_LDFLAGS -l$1 $LIBJPEG $LIBZ -lm"
+fi
 kde_save_CXXFLAGS="$CXXFLAGS"
 CXXFLAGS="$CXXFLAGS $all_includes $USER_INCLUDES"
 
@@ -1965,7 +2249,11 @@ AC_MSG_CHECKING([for libpng])
 AC_CACHE_VAL(ac_cv_lib_png,
 [
 kde_save_LIBS="$LIBS"
+if test "x$kde_use_qt_emb" != "xyes"; then
 LIBS="$LIBS $all_libraries $USER_LDFLAGS -lpng $LIBZ -lm -lX11 $LIBSOCKET"
+else
+LIBS="$LIBS $all_libraries $USER_LDFLAGS -lpng $LIBZ -lm"
+fi
 kde_save_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS $all_includes $USER_INCLUDES"
 AC_LANG_C
@@ -2031,19 +2319,17 @@ fi
 
 AC_DEFUN(KDE_CHECK_COMPILER_FLAG,
 [
-dnl AC_REQUIRE([AC_CHECK_COMPILERS]) <- breaks with autoconf 2.50
 AC_MSG_CHECKING(whether $CXX supports -$1)
-kde_cache=`echo $1 | sed 'y%.=/+-%___p_%'`
+kde_cache=`echo $1 | sed 'y% .=/+-%____p_%'`
 AC_CACHE_VAL(kde_cv_prog_cxx_$kde_cache,
 [
-echo 'int main() { return 0; }' >conftest.cc
-eval "kde_cv_prog_cxx_$kde_cache=no"
-if test -z "`$CXX -$1 -c conftest.cc 2>&1`"; then
-  if test -z "`$CXX -$1 -o conftest conftest.o 2>&1`"; then
-    eval "kde_cv_prog_cxx_$kde_cache=yes"
-  fi
-fi
-rm -f conftest*
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -$1"
+  AC_TRY_LINK([],[ return 0; ], [eval "kde_cv_prog_cxx_$kde_cache=yes"], [])
+  CXXFLAGS="$save_CXXFLAGS"
+  AC_LANG_RESTORE
 ])
 if eval "test \"`echo '$kde_cv_prog_cxx_'$kde_cache`\" = yes"; then
  AC_MSG_RESULT(yes)
@@ -2082,22 +2368,33 @@ AC_DEFUN(AC_REMOVE_FORBIDDEN,
 dnl AC_VALIDIFY_CXXFLAGS checks for forbidden flags the user may have given
 AC_DEFUN(AC_VALIDIFY_CXXFLAGS,
 [dnl
+if test "x$kde_use_qt_emb" != "xyes"; then
  AC_REMOVE_FORBIDDEN(CXX, [-fno-rtti -rpath])
  AC_REMOVE_FORBIDDEN(CXXFLAGS, [-fno-rtti -rpath])
+else
+ AC_REMOVE_FORBIDDEN(CXX, [-rpath])
+ AC_REMOVE_FORBIDDEN(CXXFLAGS, [-rpath])
+fi
 ])
 
 AC_DEFUN(AC_CHECK_COMPILERS,
 [
-  AC_ARG_ENABLE(debug,[  --enable-debug          enables debug symbols [default=no]],
+  AC_ARG_ENABLE(debug,[  --enable-debug[=ARG]    enables debug symbols (yes|no|full) [default=no]],
   [
-   if test $enableval = "no"; dnl
-     then
-       kde_use_debug_code="no"
-       kde_use_debug_define=yes
-     else
-       kde_use_debug_code="yes"
-       kde_use_debug_define=no
-   fi
+    case $enableval in
+      yes)
+        kde_use_debug_code="yes"
+        kde_use_debug_define=no
+        ;;
+      full)
+        kde_use_debug_code="full"
+        kde_use_debug_define=no
+        ;;
+      *)
+        kde_use_debug_code="no"
+        kde_use_debug_define=yes
+        ;;
+    esac
   ], 
     [kde_use_debug_code="no"
       kde_use_debug_define=no
@@ -2125,9 +2422,15 @@ AC_DEFUN(AC_CHECK_COMPILERS,
 
   AC_PROG_CC 
 
+  AC_PROG_CPP
+
   if test "$GCC" = "yes"; then
-    if test "$kde_use_debug_code" = "yes"; then
-      CFLAGS="-g -O2 $CFLAGS"
+    if test "$kde_use_debug_code" != "no"; then
+      if test $kde_use_debug_code = "full"; then
+        CFLAGS="-g3 $CFLAGS"
+      else
+        CFLAGS="-g -O2 $CFLAGS"
+      fi
       case $host in
         *-*-linux-gnu) 
           CFLAGS="-ansi -W -Wall -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -D_XOPEN_SOURCE=500 -D_BSD_SOURCE $CFLAGS"
@@ -2155,10 +2458,17 @@ AC_DEFUN(AC_CHECK_COMPILERS,
 
   AC_PROG_CXX
 
-  if test "$GXX" = "yes"; then
-    if test "$kde_use_debug_code" = "yes"; then
-      CXXFLAGS="-g -O2 -Wall -pedantic -W -Wpointer-arith -Wmissing-prototypes -Wwrite-strings $CXXFLAGS"
-
+  if test "$GXX" = "yes" || test "$CXX" = "KCC"; then
+    if test "$kde_use_debug_code" != "no"; then
+      if test "$CXX" = "KCC"; then
+        CXXFLAGS="+K0 -Wall -pedantic -W -Wpointer-arith -Wmissing-prototypes -Wwrite-strings $CXXFLAGS"
+      else
+        if test $kde_use_debug_code = "full"; then
+          CXXFLAGS="-g3 -Wall -pedantic -W -Wpointer-arith -Wmissing-prototypes -Wwrite-strings $CXXFLAGS"
+        else
+          CXXFLAGS="-g -O2 -Wall -pedantic -W -Wpointer-arith -Wmissing-prototypes -Wwrite-strings $CXXFLAGS"
+        fi
+      fi
       KDE_CHECK_COMPILER_FLAG(Wno-long-long,[CXXFLAGS="-Wno-long-long $CXXFLAGS"])
       KDE_CHECK_COMPILER_FLAG(Wnon-virtual-dtor,[CXXFLAGS="-Wnon-virtual-dtor $CXXFLAGS"])
       KDE_CHECK_COMPILER_FLAG(fno-builtin,[CXXFLAGS="-fno-builtin $CXXFLAGS"])
@@ -2177,12 +2487,16 @@ AC_DEFUN(AC_CHECK_COMPILERS,
         CXXFLAGS="-Wold-style-cast -Wredundant-decls -Wconversion $CXXFLAGS"
       fi
     else
-      CXXFLAGS="-O2 $CXXFLAGS"
+      if test "$CXX" = "KCC"; then
+        CXXFLAGS="+K3 $CXXFLAGS"
+      else
+        CXXFLAGS="-O2 $CXXFLAGS"
+      fi  
     fi
   fi
 
   if test "$kde_use_debug_define" = "yes"; then
-    CXXFLAGS="-DNDEBUG $CXXFLAGS"
+    CXXFLAGS="-DNDEBUG -DNO_DEBUG $CXXFLAGS"
   fi  
 
   if test "$kde_use_profiling" = "yes"; then
@@ -2193,9 +2507,48 @@ AC_DEFUN(AC_CHECK_COMPILERS,
     ])
   fi
     
-  KDE_CHECK_COMPILER_FLAG(fno-exceptions,[CXXFLAGS="$CXXFLAGS -fno-exceptions"])
-  KDE_CHECK_COMPILER_FLAG(fno-check-new, [CXXFLAGS="$CXXFLAGS -fno-check-new"])
-  KDE_CHECK_COMPILER_FLAG(fexceptions, [USE_EXCEPTIONS="-fexceptions"], USE_EXCEPTIONS=        )
+  if test "$GXX" = "yes"; then
+    KDE_CHECK_COMPILER_FLAG(fno-exceptions,[CXXFLAGS="$CXXFLAGS -fno-exceptions"])
+    KDE_CHECK_COMPILER_FLAG(fno-check-new, [CXXFLAGS="$CXXFLAGS -fno-check-new"])
+    KDE_CHECK_COMPILER_FLAG(fexceptions, [USE_EXCEPTIONS="-fexceptions"], USE_EXCEPTIONS=      )
+  fi
+  if test "$CXX" = "KCC"; then
+    dnl unfortunately we currently cannot disable exception support in KCC
+    dnl because doing so is binary incompatible and Qt by default links with exceptions :-(
+    dnl KDE_CHECK_COMPILER_FLAG(-no_exceptions,[CXXFLAGS="$CXXFLAGS --no_exceptions"])
+    dnl KDE_CHECK_COMPILER_FLAG(-exceptions, [USE_EXCEPTIONS="--exceptions"], USE_EXCEPTIONS=  )
+
+    AC_ARG_ENABLE(pch,[  --enable-pch            enables precompiled header support (currently only KCC) [default=no]],
+    [
+      kde_use_pch=$enableval
+    ],[kde_use_pch=no])
+    if test "$kde_use_pch" = "yes"; then
+      dnl TODO: support --pch-dir!
+      KDE_CHECK_COMPILER_FLAG(-pch,[CXXFLAGS="$CXXFLAGS --pch"])
+      dnl the below works (but the dir must exist), but it's
+      dnl useless for a whole package.
+      dnl The are precompiled headers for each source file, so when compiling
+      dnl from scratch, it doesn't make a difference, and they take up
+      dnl around ~5Mb _per_ sourcefile.
+      dnl KDE_CHECK_COMPILER_FLAG(-pch_dir /tmp,
+      dnl   [CXXFLAGS="$CXXFLAGS --pch_dir `pwd`/pcheaders"])
+    fi
+    dnl this flag controls inlining. by default KCC inlines in optimisation mode
+    dnl all implementations that are defined inside the class {} declaration. 
+    dnl because of templates-compatibility with broken gcc compilers, this
+    dnl can cause excessive inlining. This flag limits it to a sane level
+    KDE_CHECK_COMPILER_FLAG(-inline_keyword_space_time=6,[CXXFLAGS="$CXXFLAGS --inline_keyword_space_time=6"])
+    KDE_CHECK_COMPILER_FLAG(-inline_auto_space_time=2,[CXXFLAGS="$CXXFLAGS --inline_auto_space_time=2"])
+    KDE_CHECK_COMPILER_FLAG(-inline_implicit_space_time=2.0,[CXXFLAGS="$CXXFLAGS --inline_implicit_space_time=2.0"])
+    KDE_CHECK_COMPILER_FLAG(-inline_generated_space_time=2.0,[CXXFLAGS="$CXXFLAGS --inline_generated_space_time=2.0"])
+    dnl Some source files are shared between multiple executables
+    dnl (or libraries) and some of those need template instantiations.
+    dnl In that case KCC needs to compile those sources with
+    dnl --one_instantiation_per_object.  To make it easy for us we compile
+    dnl _all_ objects with that flag (--one_per is a shorthand).
+    KDE_CHECK_COMPILER_FLAG(-one_per, [CXXFLAGS="$CXXFLAGS --one_per"])
+  fi
   AC_SUBST(USE_EXCEPTIONS)
   dnl obsolete macro - provided to keep things going
   USE_RTTI=
@@ -2237,6 +2590,10 @@ AC_DEFUN(AC_CHECK_COMPILERS,
       IFS=$kde_safe_IFS
   fi
 
+  if test "x$kde_use_qt_emb" = "xyes"; then
+    NOOPT_CXXFLAGS="$NOOPT_CXXFLAGS -fno-rtti -DQWS"
+  fi
+
   AC_SUBST(NOOPT_CXXFLAGS)
 
   KDE_CHECK_FINAL
@@ -2273,7 +2630,7 @@ AC_LIBTOOL_CXX
 
 LIBTOOL_SHELL="/bin/sh ./libtool"
 #  LIBTOOL="$LIBTOOL --silent"
-KDE_PLUGIN="-avoid-version -module -no-undefined \$(KDE_RPATH)"
+KDE_PLUGIN="-avoid-version -module -no-undefined \$(KDE_RPATH) \$(KDE_MT_LDFLAGS)"
 AC_SUBST(KDE_PLUGIN)
 ])
 
@@ -2475,7 +2832,7 @@ AC_DEFUN(AM_LC_MESSAGES,
 dnl From Jim Meyering.
 dnl FIXME: migrate into libit.
 
-AC_DEFUN(AM_FUNC_OBSTACK,
+AC_DEFUN([AM_FUNC_OBSTACK],
 [AC_CACHE_CHECK([for obstacks], am_cv_func_obstack,
  [AC_TRY_LINK([#include "obstack.h"],
              [struct obstack *mem;obstack_free(mem,(char *) 0)],
@@ -2491,7 +2848,7 @@ AC_DEFUN(AM_FUNC_OBSTACK,
 dnl From Jim Meyering.  Use this if you use the GNU error.[ch].
 dnl FIXME: Migrate into libit
 
-AC_DEFUN(AM_FUNC_ERROR_AT_LINE,
+AC_DEFUN([AM_FUNC_ERROR_AT_LINE],
 [AC_CACHE_CHECK([for error_at_line], am_cv_lib_error_at_line,
  [AC_TRY_LINK([],[error_at_line(0, 0, "", 0, "");],
               am_cv_lib_error_at_line=yes,
@@ -2588,7 +2945,11 @@ AC_DEFUN(AC_HAVE_XPM,
     AC_LANG_C
     ac_save_ldflags="$LDFLAGS"
     ac_save_cflags="$CFLAGS"
-    LDFLAGS="$LDFLAGS $X_LDFLAGS $USER_LDFLAGS $LDFLAGS $XPM_LDFLAGS $all_libraries -lXpm -lX11 -lXext $LIBZ $LIBSOCKET"
+    if test "x$kde_use_qt_emb" != "xyes"; then
+      LDFLAGS="$LDFLAGS $X_LDFLAGS $USER_LDFLAGS $LDFLAGS $XPM_LDFLAGS $all_libraries -lXpm -lX11 -lXext $LIBZ $LIBSOCKET"
+    else
+      LDFLAGS="$LDFLAGS $X_LDFLAGS $USER_LDFLAGS $LDFLAGS $XPM_LDFLAGS $all_libraries -lXpm $LIBZ $LIBSOCKET"
+    fi
     CFLAGS="$CFLAGS $X_INCLUDES $USER_INCLUDES"
     test -n "$XPM_INCLUDE" && CFLAGS="-I$XPM_INCLUDE $CFLAGS"
     AC_TRY_LINK([#include <X11/xpm.h>],[],
@@ -2640,41 +3001,46 @@ AC_DEFUN(AC_HAVE_DPMS,
    dnl 'yes' means DPMS_LIB="", '-lXdpms' means DPMS_LIB="-lXdpms".
    AC_CACHE_VAL(ac_cv_have_dpms,
    [
-    AC_LANG_C
-    ac_save_ldflags="$LDFLAGS"
-    ac_save_cflags="$CFLAGS"
-    ac_save_libs="$LIBS"
-    LDFLAGS="$LDFLAGS $DPMS_LDFLAGS $all_libraries -lX11 -lXext $LIBSOCKET"
-    CFLAGS="$CFLAGS $X_INCLUDES"
-    test -n "$DPMS_INCLUDE" && CFLAGS="-I$DPMS_INCLUDE $CFLAGS"
-    AC_TRY_LINK([
-       #include <X11/Xproto.h>
-       #include <X11/X.h>
-       #include <X11/Xlib.h>
-       #include <X11/extensions/dpms.h>
-       int foo_test_dpms()
-       { return DPMSSetTimeouts( 0, 0, 0, 0 ); }],[],
-       ac_cv_have_dpms="yes", [
-            LDFLAGS="$ac_save_ldflags"
-            CFLAGS="$ac_save_cflags"
-            LDFLAGS="$LDFLAGS $DPMS_LDFLAGS $all_libraries -lX11 -lXext $LIBSOCKET"
-            LIBS="$LIBS -lXdpms"
-            CFLAGS="$CFLAGS $X_INCLUDES"
-            test -n "$DPMS_INCLUDE" && CFLAGS="-I$DPMS_INCLUDE $CFLAGS"
-            AC_TRY_LINK([
-               #include <X11/Xproto.h>
-               #include <X11/X.h>
-               #include <X11/Xlib.h>
-               #include <X11/extensions/dpms.h>
-               int foo_test_dpms()
-               { return DPMSSetTimeouts( 0, 0, 0, 0 ); }],[],
-               [
-                ac_cv_have_dpms="-lXdpms"
-                ],ac_cv_have_dpms="no")
-            ])
-    LDFLAGS="$ac_save_ldflags"
-    CFLAGS="$ac_save_cflags"
-    LIBS="$ac_save_libs"
+    if test "x$kde_use_qt_emb" = "xyes"; then
+      AC_MSG_RESULT(no)
+      ac_cv_have_dpms="no"
+    else
+      AC_LANG_C
+      ac_save_ldflags="$LDFLAGS"
+      ac_save_cflags="$CFLAGS"
+      ac_save_libs="$LIBS"
+      LDFLAGS="$LDFLAGS $DPMS_LDFLAGS $all_libraries -lX11 -lXext $LIBSOCKET"
+      CFLAGS="$CFLAGS $X_INCLUDES"
+      test -n "$DPMS_INCLUDE" && CFLAGS="-I$DPMS_INCLUDE $CFLAGS"
+      AC_TRY_LINK([
+         #include <X11/Xproto.h>
+         #include <X11/X.h>
+         #include <X11/Xlib.h>
+         #include <X11/extensions/dpms.h>
+         int foo_test_dpms()
+         { return DPMSSetTimeouts( 0, 0, 0, 0 ); }],[],
+         ac_cv_have_dpms="yes", [
+              LDFLAGS="$ac_save_ldflags"
+              CFLAGS="$ac_save_cflags"
+              LDFLAGS="$LDFLAGS $DPMS_LDFLAGS $all_libraries -lX11 -lXext $LIBSOCKET"
+              LIBS="$LIBS -lXdpms"
+              CFLAGS="$CFLAGS $X_INCLUDES"
+              test -n "$DPMS_INCLUDE" && CFLAGS="-I$DPMS_INCLUDE $CFLAGS"
+              AC_TRY_LINK([
+                 #include <X11/Xproto.h>
+                 #include <X11/X.h>
+                 #include <X11/Xlib.h>
+                 #include <X11/extensions/dpms.h>
+                 int foo_test_dpms()
+                 { return DPMSSetTimeouts( 0, 0, 0, 0 ); }],[],
+                 [
+                  ac_cv_have_dpms="-lXdpms"
+                  ],ac_cv_have_dpms="no")
+              ])
+      LDFLAGS="$ac_save_ldflags"
+      CFLAGS="$ac_save_cflags"
+      LIBS="$ac_save_libs"
+    fi
    ])dnl
 
   if test "$ac_cv_have_dpms" = no; then
@@ -2714,7 +3080,10 @@ AC_DEFUN(AC_HAVE_GL,
 
  AC_ARG_WITH(gl, [  --without-gl            disable 3D GL modes],
        gl_test=$withval, gl_test="yes")
- if test "x$gl_test" = xno; then
+ if test "x$kde_use_qt_emb" = "xyes"; then
+   # GL and Qt Embedded is a no-go for now.
+   ac_cv_have_gl=no
+ elif test "x$gl_test" = xno; then
    ac_cv_have_gl=no
  else
    AC_MSG_CHECKING(for GL)
@@ -2723,15 +3092,19 @@ AC_DEFUN(AC_HAVE_GL,
     AC_LANG_C
     ac_save_ldflags="$LDFLAGS"
     ac_save_cflags="$CFLAGS"
-    LDFLAGS="$LDFLAGS $GL_LDFLAGS $X_LDFLAGS $all_libraries -lMesaGL -lMesaGLU -lX11 -lXext -lm $LIBSOCKET"
+    LDFLAGS="$LDFLAGS $GL_LDFLAGS $X_LDFLAGS $all_libraries -lMesaGL -lMesaGLU"
+    test "x$kde_use_qt_emb" != xyes && LDFLAGS="$LDFLAGS -lX11"
+    LDFLAGS="$LDFLAGS $LIB_XEXT -lm $LIBSOCKET"
     CFLAGS="$CFLAGS $X_INCLUDES"
     test -n "$GL_INCLUDE" && CFLAGS="-I$GL_INCLUDE $CFLAGS"
     AC_TRY_LINK([#include <GL/gl.h>
-#include <GL/glu.h>           
+#include <GL/glu.h>
 ], [],
        ac_cv_have_gl="mesa", ac_cv_have_gl="no")
     if test "x$ac_cv_have_gl" = "xno"; then
-      LDFLAGS="$ac_save_ldflags $X_LDFLAGS $GL_LDFLAGS $all_libraries -lGL -lGLU -lX11 -lXext -lm $LIBSOCKET"
+      LDFLAGS="$ac_save_ldflags $X_LDFLAGS $GL_LDFLAGS $all_libraries -lGL -lGLU"
+      test "x$kde_use_qt_emb" != xyes && LDFLAGS="$LDFLAGS -lX11"
+      LDFLAGS="$LDFLAGS $LIB_XEXT -lm $LIBSOCKET"
       CFLAGS="$ac_save_cflags $X_INCLUDES"
       test -n "$GL_INCLUDE" && CFLAGS="-I$GL_INCLUDE $CFLAGS"
       AC_TRY_LINK([#include <GL/gl.h>
@@ -2786,20 +3159,24 @@ AC_DEFUN(KDE_PAM, [
     [  --with-pam[=ARG]        enable support for PAM: ARG=[yes|no|service name]],
     [ if test "x$withval" = "xyes"; then
         use_pam=yes
+        pam_service=kde
       elif test "x$withval" = "xno"; then
         use_pam=no
       else
         use_pam=yes
-        pam_service="$withval"
+        pam_service=$withval
       fi
       ac_cv_path_pam="use_pam=$use_pam pam_service=$pam_service"
     ], [
       AC_CACHE_VAL(ac_cv_path_pam,
         [ use_pam=no
           AC_CHECK_LIB(pam, pam_start,
-            [ AC_CHECK_HEADER(security/pam_appl.h, use_pam=yes) ], , $LIBDL)
-         ac_cv_path_pam="use_pam=$use_pam pam_service="
-       ])
+            [ AC_CHECK_HEADER(security/pam_appl.h,
+                [ use_pam=yes
+                  pam_service=kde ]) 
+            ], , $LIBDL)
+          ac_cv_path_pam="use_pam=$use_pam pam_service=$pam_service"
+        ])
     ])
   eval "$ac_cv_path_pam"
 
@@ -2809,7 +3186,7 @@ AC_DEFUN(KDE_PAM, [
     PAMLIBS=""
   else
     AC_MSG_RESULT(yes)
-    AC_DEFINE(HAVE_PAM, 1, [Defines if you have PAM (Pluggable Authentication Modules); Redhat-Users!])
+    AC_DEFINE(HAVE_PAM, 1, [Defines if you have PAM (Pluggable Authentication Modules)])
     PAMLIBS="$PAM_MISC_LIB -lpam $LIBDL"
 
     dnl test whether struct pam_message is const (Linux) or not (Sun)
@@ -2821,18 +3198,33 @@ AC_DEFUN(KDE_PAM, [
                         AC_DEFINE(PAM_MESSAGE_NONCONST, 1, [Define if your PAM support takes non-const arguments (Solaris)])]
                         )],
       [AC_MSG_RESULT([not found - assume const, Linux-type PAM])])
-
-    if test "x$pam_service" = x; then
-      AC_MSG_RESULT(["Default PAM service name will be used."])
-    else
-      AC_DEFINE_UNQUOTED(KDE_PAM_SERVICE, "$pam_service", [Define to change the default name of the PAM service used by KDE])
-      AC_MSG_RESULT([PAM service name will be: $pam_service])
-    fi
   fi
 
   AC_SUBST(PAMLIBS)
 ])
 
+dnl DEF_PAM_SERVICE(arg name, full name, define name)
+AC_DEFUN(DEF_PAM_SERVICE, [
+  AC_ARG_WITH($1-pam,
+    [  --with-$1-pam=[val]    override PAM service from --with-pam for $2],
+    [ if test "x$use_pam" = xyes; then
+        $3_PAM_SERVICE="$withval"
+      else
+        AC_MSG_ERROR([Cannot use use --with-$1-pam, as no PAM was detected.
+You may want to enforce it by using --with-pam.])
+      fi
+    ], 
+    [ if test "x$use_pam" = xyes; then
+        $3_PAM_SERVICE="$pam_service"
+      fi
+    ])
+    if test -n "$$3_PAM_SERVICE"; then
+      AC_MSG_RESULT([The PAM service used by $2 will be $$3_PAM_SERVICE])
+      AC_DEFINE_UNQUOTED($3_PAM_SERVICE, "$$3_PAM_SERVICE", [The PAM service to be used by $2])
+    fi
+    AC_SUBST($3_PAM_SERVICE)
+])
+
 AC_DEFUN(KDE_SHADOWPASSWD, [
   AC_REQUIRE([KDE_PAM])
 
@@ -3204,21 +3596,20 @@ AC_DEFUN(KDE_CHECK_PTHREAD_OPTION,
     case $host_os in
        solaris*)
                KDE_CHECK_COMPILER_FLAG(mt, [USE_THREADS="-mt"])
-                CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -DUSE_SOLARIS"
-                echo "Setting Solaris pthread compilation options"
+                CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -DUSE_SOLARIS -DSVR4"
                ;;
         freebsd*)
                 CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE"
-                echo "Setting FreeBSD pthread compilation options"
                 ;;
         aix*)
                 CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE"
                 LIBPTHREAD="$LIBPTHREAD -lc_r"
-                echo "Setting AIX pthread compilation options"
                 ;;
         linux*) CPPFLAGS="$CPPFLAGS -D_REENTRANT"
-                USE_THREADS="$USE_THREADS -DPIC -fPIC"
-                echo "Setting Linux pthread compilation options"
+                if test "$CXX" = "KCC"; then
+                  CXXFLAGS="$CXXFLAGS --thread_safe"
+                 NOOPT_CXXFLAGS="$NOOPT_CXXFLAGS --thread_safe"
+                fi
                 ;;
        *)
                ;;
@@ -3233,13 +3624,16 @@ AC_DEFUN(KDE_CHECK_THREADING,
   AC_REQUIRE([KDE_CHECK_PTHREAD_OPTION])
   dnl default is yes if libpthread is found and no if no libpthread is available
   if test -z "$LIBPTHREAD"; then
-    kde_check_threading_default=no
+    if test -z "$USE_THREADS"; then
+      kde_check_threading_default=no
+    else
+      kde_check_threading_default=yes
+    fi
   else
     kde_check_threading_default=yes
   fi
   AC_ARG_ENABLE(threading, [  --disable-threading     disables threading even if libpthread found ],
    kde_use_threading=$enableval, kde_use_threading=$kde_check_threading_default)
-
   if test "x$kde_use_threading" = "xyes"; then
     AC_DEFINE(HAVE_LIBPTHREAD, 1, [Define if you have a working libpthread (will enable threaded code)])
   fi
@@ -3385,6 +3779,7 @@ else
   KDE_TRY_LINK_PYTHON(m, -lm)
   KDE_TRY_LINK_PYTHON(pthread, $LIBPTHREAD)
   KDE_TRY_LINK_PYTHON(tcl, -ltcl)
+  KDE_TRY_LINK_PYTHON(db2, -ldb2)
   KDE_TRY_LINK_PYTHON(m_and_thread, [$LIBPTHREAD -lm])
   KDE_TRY_LINK_PYTHON(m_and_thread_and_util, [$LIBPTHREAD -lm -lutil])
   KDE_TRY_LINK_PYTHON(m_and_thread_and_db3, [$LIBPTHREAD -lm -ldb-3 -lutil])
@@ -3766,16 +4161,6 @@ AC_DEFUN(KDE_CHECK_HEADER,
    AC_LANG_RESTORE
 ])
 
-AC_DEFUN(KDE_CHECK_QWSPRITEFIELD,
-[
-  KDE_CHECK_HEADER(QwSpriteField.h, ,
-  [
-    AC_MSG_WARN([you don't have QwSpriteField.h somewhere. Please install
-       QwSpriteField out of kdesupport.])
-      $1
-  ])
-])
-
 AC_DEFUN(KDE_FAST_CONFIGURE,
 [
   dnl makes configure fast (needs perl)
@@ -3901,6 +4286,7 @@ AC_CACHE_VAL(kde_cv_c_long_long,
   foo = foo+1;
   ],
   kde_cv_c_long_long=yes, kde_cv_c_long_long=no)
+  AC_LANG_RESTORE
 ])
 AC_MSG_RESULT($kde_cv_c_long_long)
 if test "$kde_cv_c_long_long" = yes; then
@@ -3978,8 +4364,8 @@ dnl at this point ac_java_dir is either a dir, 'no' to disable, or '' to say loo
 if test "x$ac_java_dir" = xno; then
    kde_cv_java_bindir=no
    kde_cv_java_includedir=no
-   kde_cv_java_libjvmdir=no
-   kde_cv_java_libhpidir=no
+   kde_java_libjvmdir=no
+   kde_java_libhpidir=no
 else
   if test "x$ac_java_dir" = x; then
     dnl No option set -> look in $PATH
@@ -4002,14 +4388,14 @@ else
   fi
 fi
 
-dnl Look for libjvm.so
-kde_cv_java_libjvmdir=`find $kde_cv_java_bindir/.. -name libjvm.so | sed 's,libjvm.so,,'|head -n 1`
-dnl Look for libhpi.so and avoid green threads
-kde_cv_java_libhpidir=`find $kde_cv_java_bindir/.. -name libhpi.so | grep -v green | sed 's,libhpi.so,,'`
-
 dnl At this point kde_cv_java_bindir and kde_cv_java_includedir are either set or "no"
 if test ! "x$kde_cv_java_bindir" = xno; then
 
+  dnl Look for libjvm.so
+  kde_java_libjvmdir=`find $kde_cv_java_bindir/.. -name libjvm.so | sed 's,libjvm.so,,'|head -n 1`
+  dnl Look for libhpi.so and avoid green threads
+  kde_java_libhpidir=`find $kde_cv_java_bindir/.. -name libhpi.so | grep -v green | sed 's,libhpi.so,,'`
+
   dnl Now check everything's fine under there
 
   if test ! -x "$kde_cv_java_bindir/javac"; then
@@ -4024,11 +4410,11 @@ if test ! "x$kde_cv_java_bindir" = xno; then
   if test ! -r "$kde_cv_java_includedir/jni.h"; then
     AC_MSG_ERROR([jni.h not found under $kde_cv_java_includedir. Use --with-java or --without-java.])
   fi
-  if test ! -r "$kde_cv_java_libjvmdir/libjvm.so"; then
-    AC_MSG_ERROR([libjvm.so not found under $kde_cv_java_libjvmdir. Use --without-java.])
+  if test ! -r "$kde_java_libjvmdir/libjvm.so"; then
+    AC_MSG_ERROR([libjvm.so not found under $kde_java_libjvmdir. Use --without-java.])
   fi
-  if test ! -r "$kde_cv_java_libhpidir/libhpi.so"; then
-    AC_MSG_ERROR([libhpi.so not found under $kde_cv_java_libhpidir. Use --without-java.])
+  if test ! -r "$kde_java_libhpidir/libhpi.so"; then
+    AC_MSG_ERROR([libhpi.so not found under $kde_java_libhpidir. Use --without-java.])
   fi
 
   jni_includes="-I$kde_cv_java_includedir"
@@ -4050,15 +4436,18 @@ if test ! "x$kde_cv_java_bindir" = xno; then
 #ifndef JNI_VERSION_1_2
 Syntax Error
 #endif
-           ],[ 
-           ],[ AC_MSG_ERROR([Incorrect version of $kde_cv_java_includedir/jni.h.
+           ],[ kde_jni_works=yes ],
+            [ kde_jni_works=no ])
+
+  if test $kde_jni_works = no; then
+    AC_MSG_ERROR([Incorrect version of $kde_cv_java_includedir/jni.h.
                  You need to have Java Development Kit (JDK) version 1.2. 
        
                  Use --with-java to specify another location.
                  Use --without-java to configure without java support.
                  Or download a newer JDK and try again. 
                  See e.g. http://java.sun.com/products/jdk/1.2 ])
-           ])
+  fi
 
   CXXFLAGS="$ac_cxxflags_safe"    
   AC_LANG_RESTORE
@@ -4073,7 +4462,136 @@ Syntax Error
   JAR=$kde_cv_java_bindir/jar
   AC_SUBST(JAR)
   AC_SUBST(jni_includes)
-  JVMLIBS="-L$kde_cv_java_libjvmdir -ljvm -L$kde_cv_java_libhpidir -lhpi"
+  JVMLIBS="-L$kde_java_libjvmdir -ljvm -L$kde_cv_java_libhpidir -lhpi"
   AC_SUBST(JVMLIBS)
 fi
 ])
+
+dnl this is a redefinition of autoconf 2.5x's AC_FOREACH.
+dnl When the argument list becomes big, as in KDE for AC_OUTPUT in
+dnl big packages, m4_foreach is dog-slow.  So use our own version of
+dnl it.  (matz@kde.org)
+m4_define([mm_foreach],
+[m4_pushdef([$1])_mm_foreach($@)m4_popdef([$1])])
+m4_define([mm_car], [[$1]])
+m4_define([mm_car2], [[$@]])
+m4_define([_mm_foreach],
+[m4_if(m4_quote($2), [], [],
+       [m4_define([$1], [mm_car($2)])$3[]_mm_foreach([$1],
+                                                     mm_car2(m4_shift($2)),
+                                                     [$3])])])
+m4_define([AC_FOREACH],
+[mm_foreach([$1], m4_split(m4_normalize([$2])), [$3])])
+
+AC_DEFUN(KDE_NEED_FLEX,
+[
+AC_REQUIRE([AM_PROG_LEX])
+if test -z "$LEXLIB"; then
+    AC_MSG_ERROR([You need to have flex installed.])
+fi
+AC_SUBST(LEXLIB)
+])
+
+AC_DEFUN(AC_PATH_QTOPIA,
+[
+  dnl TODO: use AC_CACHE_VAL
+
+  if test -z "$1"; then
+    qtopia_minver_maj=1
+    qtopia_minver_min=5
+    qtopia_minver_pat=0
+  else
+    qtopia_minver_maj=`echo "$1" | sed -e "s/^\(.*\)\..*\..*$/\1/"`
+    qtopia_minver_min=`echo "$1" | sed -e "s/^.*\.\(.*\)\..*$/\1/"`
+    qtopia_minver_pat=`echo "$1" | sed -e "s/^.*\..*\.\(.*\)$/\1/"`
+  fi
+
+  qtopia_minver="$qtopia_minver_maj$qtopia_minver_min$qtopia_minver_pat"
+  qtopia_minverstr="$qtopia_minver_maj.$qtopia_minver_min.$qtopia_minver_pat"
+
+  AC_REQUIRE([AC_PATH_QT])
+
+  AC_MSG_CHECKING([for Qtopia])
+
+  LIB_QTOPIA="-lqpe"
+  AC_SUBST(LIB_QTOPIA)
+
+  kde_qtopia_dirs="$QPEDIR /opt/Qtopia"
+
+  ac_qtopia_incdir=NO
+
+  AC_ARG_WITH(qtopia-dir,
+              [  --with-qtopia-dir=DIR   where the root of Qtopia is installed ],
+              [  ac_qtopia_incdir="$withval"/include] ) 
+  
+  qtopia_incdirs=""
+  for dir in $kde_qtopia_dirs; do
+    qtopia_incdirs="$qtopia_incdirs $dir/include"
+  done
+
+  if test ! "$ac_qtopia_incdir" = "NO"; then
+    qtopia_incdirs="$ac_qtopia_incdir $qtopia_incdirs"
+  fi
+
+  qtopia_incdir=""
+  AC_FIND_FILE(qpe/qpeapplication.h, $qtopia_incdirs, qtopia_incdir)
+  ac_qtopia_incdir="$qtopia_incdir"
+
+  if test -z "$qtopia_incdir"; then
+    AC_MSG_ERROR([Cannot find Qtopia headers. Please check your installation.])
+  fi
+
+  qtopia_ver_maj=`cat $qtopia_incdir/qpe/version.h | sed -n -e 's,.*QPE_VERSION "\(.*\)\..*\..*".*,\1,p'`;
+  qtopia_ver_min=`cat $qtopia_incdir/qpe/version.h | sed -n -e 's,.*QPE_VERSION ".*\.\(.*\)\..*".*,\1,p'`;
+  qtopia_ver_pat=`cat $qtopia_incdir/qpe/version.h | sed -n -e 's,.*QPE_VERSION ".*\..*\.\(.*\)".*,\1,p'`;
+
+  qtopia_ver="$qtopia_ver_maj$qtopia_ver_min$qtopia_ver_pat"
+  qtopia_verstr="$qtopia_ver_maj.$qtopia_ver_min.$qtopia_ver_pat"
+  if test "$qtopia_ver" -lt "$qtopia_minver"; then
+    AC_MSG_ERROR([found Qtopia version $qtopia_verstr but version $qtopia_minverstr
+is required.])
+  fi
+
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+
+  ac_cxxflags_safe="$CXXFLAGS"
+  ac_ldflags_safe="$LDFLAGS"
+  ac_libs_safe="$LIBS"
+
+  CXXFLAGS="$CXXFLAGS -I$qtopia_incdir $all_includes"
+  LDFLAGS="$LDFLAGS $QT_LDFLAGS $all_libraries $USER_LDFLAGS $KDE_MT_LDFLAGS"
+  LIBS="$LIBS $LIB_QTOPIA $LIBQT"
+
+  cat > conftest.$ac_ext <<EOF
+#include "confdefs.h"
+#include <qpe/qpeapplication.h>
+#include <qpe/version.h>
+
+int main( int argc, char **argv )
+{
+    QPEApplication app( argc, argv );
+    return 0;
+}
+EOF
+
+  if AC_TRY_EVAL(ac_link) && test -s conftest; then
+    rm -f conftest*
+  else
+    rm -f conftest*
+    AC_MSG_ERROR([Cannot link small Qtopia Application. For more details look at
+the end of config.log])
+  fi
+
+  CXXFLAGS="$ac_cxxflags_safe"
+  LDFLAGS="$ac_ldflags_safe"
+  LIBS="$ac_libs_safe"
+
+  AC_LANG_RESTORE
+
+  QTOPIA_INCLUDES="-I$qtopia_incdir"
+  AC_SUBST(QTOPIA_INCLUDES)
+
+  AC_MSG_RESULT([found version $qtopia_verstr with headers at $qtopia_incdir])
+])
+