diff --git a/m4/ug.m4 b/m4/ug.m4
index 8f221d1357e245524eddd548b2594f50fe12ef3c..b29899606276e923d2261e228abdef874dd8da9c 100644
--- a/m4/ug.m4
+++ b/m4/ug.m4
@@ -136,6 +136,12 @@ AC_DEFUN([DUNE_PATH_UG],[
       AC_LANG_POP([C++])
       
       # did it work?
+      if test x$HAVE_UG = x0 ; then
+	  # reset flags, so they do not appear in makefiles
+	  UG_LDFLAGS=""
+	  UG_LIBS=""
+	  UG_CPPFLAGS=""
+      fi
       if test x$HAVE_UG = x1 ; then
 	  AC_SUBST(UG_LDFLAGS, $UG_LDFLAGS)
 	  AC_SUBST(UG_LIBS, $UG_LIBS)