diff --git a/CHANGES b/CHANGES
index b548bd40e2009f83e141b81b8779142418f5eff4..d66143eb79e51e196037e69d29f4d048fd3d80f2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,10 @@
 
                                   Changelog
 
+Daniel (10 November 2004)
+- I installed Heimdal on my Debian box (using the debian package) and noticed
+  that configure --with-gssapi failed to create a nice build. Fixed now.
+
 Daniel (9 November 2004)
 - Gisle Vanem marked all external function calls with CURL_EXTERN so that now
   the Windows, Netware and other builds no longer need libcurl.def or similar
diff --git a/configure.ac b/configure.ac
index 6215495826e50f4c4e8bc96e08c0aadafe95e548..d8aaf023856889738cf4126ca61c962e9aa2a27b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -647,7 +647,7 @@ if test x"$want_gss" = xyes; then
   if test -z "$GSSAPI_INCS"; then
      if test -f "$GSSAPI_ROOT/bin/krb5-config"; then
         GSSAPI_INCS=`$GSSAPI_ROOT/bin/krb5-config --cflags gssapi`
-     else
+     elif test "$GSSAPI_ROOT" != "yes"; then
         GSSAPI_INCS="-I$GSSAPI_ROOT/include"
      fi
   fi
@@ -657,8 +657,10 @@ if test x"$want_gss" = xyes; then
      if test -f "$GSSAPI_ROOT/bin/krb5-config"; then
         gss_ldflags=`$GSSAPI_ROOT/bin/krb5-config --libs gssapi`
 	LDFLAGS="$LDFLAGS $gss_ldflags"
-     else
+     elif test "$GSSAPI_ROOT" != "yes"; then
         LDFLAGS="$LDFLAGS -L$GSSAPI_ROOT/lib$libsuff -lgssapi"
+     else
+        LDFLAGS="$LDFLAGS -lgssapi"
      fi
   else
      LDFLAGS="$LDFLAGS $GSSAPI_LIB_DIR"
@@ -669,17 +671,21 @@ if test x"$want_gss" = xyes; then
 
   curl_gss_msg="enabled"
 
-  if test -n "$GSSAPI_INCS"; then
-    # cut off the preceding -I from the include path
-    GSSAPI_INCS=`echo $GSSAPI_INCS | sed -e s/^-I//g`
-  fi
-
-  if test -f "$GSSAPI_INCS/gssapi.h"; then
+  AC_CHECK_HEADER(gssapi.h,
+    [
+       dnl found in the given dirs
       AC_DEFINE(HAVE_GSSHEIMDAL, 1, [if you have the Heimdal gssapi libraries])
-  else
-      AC_DEFINE(HAVE_GSSMIT, 1, [if you have the MIT gssapi libraries])
-  fi
-  
+    ],
+    [
+      dnl not found, check in gssapi/ subdir 
+      AC_CHECK_HEADER(gssapi/gssapi.h,
+        dnl found 
+        AC_DEFINE(HAVE_GSSMIT, 1, [if you have the MIT gssapi libraries])
+      )
+      
+    ]
+  )
+
 else
   AC_MSG_RESULT(no)
 fi