diff --git a/Makefile.am.template b/Makefile.am.template
index c455633d8e493240e3fb9294f05da900f1e40078..d77a9eb52d0bd1509f9cf09ef5a2bb5acd4b37c6 100644
--- a/Makefile.am.template
+++ b/Makefile.am.template
@@ -3,35 +3,88 @@
 ## DO NOT EDIT, this file is automatically generated by
 ## ${top_srcdir}/generate-alberta-automakefiles.sh
 
-DIM_OF_WORLD = %DIM_OF_WORLD%
-ALBERTA_DEBUG = %ALBERTA_DEBUG%
+%NO_MULTI_DIM%lib_LTLIBRARIES =
+%NO_MULTI_DIM%noinst_LTLIBRARIES =
 
-lib_LTLIBRARIES = libalberta%LIBCODE%.la
+assemble%LIBCODE%_libs = libSS_assemble%LIBCODE%.la
+if VECTOR_BASIS_FUNCTIONS
+assemble%LIBCODE%_libs += libVV_assemble%LIBCODE%.la\
+ libVC_assemble%LIBCODE%.la libCV_assemble%LIBCODE%.la\
+ libVS_assemble%LIBCODE%.la libSV_assemble%LIBCODE%.la
+endif
+
+lib_LTLIBRARIES += libalberta%LIBCODE%.la
+noinst_LTLIBRARIES += $(assemble%LIBCODE%_libs)
 
-include $(srcdir)/../Common/Makefile.am.include
+%NO_MULTI_DIM%include $(srcdir)/../Common/Makefile.am.include
 
 AM_CFLAGS   = $(ALBERTA_%EFLAGS%_CFLAGS)
 AM_CXXFLAGS = $(ALBERTA_%EFLAGS%_CXXFLAGS)
 
 nodist_libalberta%LIBCODE%_la_SOURCES = $(sources)
+libalberta%LIBCODE%_la_LIBADD = $(assemble%LIBCODE%_libs)
 libalberta%LIBCODE%_la_CPPFLAGS = \
- $(CPPFLAGS) -DDIM_OF_WORLD=$(DIM_OF_WORLD) -DALBERTA_DEBUG=$(ALBERTA_DEBUG)
-libalberta%LIBCODE%_la_LDFLAGS = -version-info 3:0:0
+ $(CPPFLAGS) -DDIM_OF_WORLD=%DIM_OF_WORLD% -DALBERTA_DEBUG=%ALBERTA_DEBUG%
+libalberta%LIBCODE%_la_LDFLAGS = -version-info 4:0:0
+
+# Various flavours of block-matrix assembly
+
+# scalar-scalar or Cartesian/Cartesian
+libSS_assemble%LIBCODE%_la_SOURCES = $(assemble_sources)
+libSS_assemble%LIBCODE%_la_CPPFLAGS = \
+ $(libalberta%LIBCODE%_la_CPPFLAGS)\
+ -DHAVE_PSI_V_TYPE=0 -DHAVE_PHI_V_TYPE=0\
+ -DHAVE_PSI_C_TYPE=0 -DHAVE_PHI_C_TYPE=0
+
+# vector-vector
+libVV_assemble%LIBCODE%_la_SOURCES = $(assemble_sources)
+libVV_assemble%LIBCODE%_la_CPPFLAGS = \
+ $(libalberta%LIBCODE%_la_CPPFLAGS)\
+ -DHAVE_PSI_V_TYPE=1 -DHAVE_PHI_V_TYPE=1\
+ -DHAVE_PSI_C_TYPE=0 -DHAVE_PHI_C_TYPE=0
+
+# vector-Cartesian
+libVC_assemble%LIBCODE%_la_SOURCES = $(assemble_sources)
+libVC_assemble%LIBCODE%_la_CPPFLAGS = \
+ $(libalberta%LIBCODE%_la_CPPFLAGS)\
+ -DHAVE_PSI_V_TYPE=1 -DHAVE_PHI_V_TYPE=0\
+ -DHAVE_PSI_C_TYPE=0 -DHAVE_PHI_C_TYPE=1
+
+# Cartesian-vector
+libCV_assemble%LIBCODE%_la_SOURCES = $(assemble_sources)
+libCV_assemble%LIBCODE%_la_CPPFLAGS = \
+ $(libalberta%LIBCODE%_la_CPPFLAGS)\
+ -DHAVE_PSI_V_TYPE=0 -DHAVE_PHI_V_TYPE=1\
+ -DHAVE_PSI_C_TYPE=1 -DHAVE_PHI_C_TYPE=0
+
+# vector-scalar
+libVS_assemble%LIBCODE%_la_SOURCES = $(VSSV_assemble_sources)
+libVS_assemble%LIBCODE%_la_CPPFLAGS = \
+ $(libalberta%LIBCODE%_la_CPPFLAGS)\
+ -DHAVE_PSI_V_TYPE=1 -DHAVE_PHI_V_TYPE=0\
+ -DHAVE_PSI_C_TYPE=0 -DHAVE_PHI_C_TYPE=0
+
+# scalar-vector
+libSV_assemble%LIBCODE%_la_SOURCES = $(VSSV_assemble_sources)
+libSV_assemble%LIBCODE%_la_CPPFLAGS = \
+ $(libalberta%LIBCODE%_la_CPPFLAGS)\
+ -DHAVE_PSI_V_TYPE=0 -DHAVE_PHI_V_TYPE=1\
+ -DHAVE_PSI_C_TYPE=0 -DHAVE_PHI_C_TYPE=0
 
 if ALBERTA_USE_GRAPHICS
 lib_LTLIBRARIES += libalberta_gfx%LIBCODE%.la
 
 nodist_libalberta_gfx%LIBCODE%_la_SOURCES = $(gfxsources)
 libalberta_gfx%LIBCODE%_la_CPPFLAGS = \
- $(CPPFLAGS) -DDIM_OF_WORLD=$(DIM_OF_WORLD) -DALBERTA_DEBUG=$(ALBERTA_DEBUG)
+ $(CPPFLAGS) -DDIM_OF_WORLD=%DIM_OF_WORLD% -DALBERTA_DEBUG=%ALBERTA_DEBUG%
 #libalberta_gfx%LIBCODE%_la_LIBADD = @GLTOOLS_ALL_LIBS@ @OPENDX_ALL_LIBS@ @OPENGL_ALL_LIBS@
-libalberta_gfx%LIBCODE%_la_LDFLAGS = -version-info 3:0:0
+libalberta_gfx%LIBCODE%_la_LDFLAGS = -version-info 4:0:0
 
 endif
 
-if MAINTAINER_MODE
-$(srcdir)/Makefile.am: \
- $(top_srcdir)/Makefile.am.template \
- $(top_srcdir)/generate-alberta-automakefiles.sh
-	cd $(top_srcdir) && sh generate-alberta-automakefiles.sh
-endif
+%NO_MULTI_DIM%if MAINTAINER_MODE
+%NO_MULTI_DIM%$(srcdir)/Makefile.am: \
+%NO_MULTI_DIM% $(top_srcdir)/Makefile.am.template \
+%NO_MULTI_DIM% $(top_srcdir)/generate-alberta-automakefiles.sh
+%NO_MULTI_DIM%	cd $(top_srcdir) && sh generate-alberta-automakefiles.sh
+%NO_MULTI_DIM%endif
diff --git a/configure.ac b/configure.ac
index edb886a1066df191b4a9cbec6b4069456db479d3..b9d8c4c381cfeb38927287d788872f825a9754c3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,6 +24,8 @@ AC_CONFIG_FILES([Makefile gnu-compat/Makefile
                  alberta_util/Makefile alberta_util/src/Makefile
                  alberta_util/src/alberta_util_inlines.h.in
 		 add_ons/Makefile
+		 add_ons/libalbas/Makefile
+		 add_ons/libalbas/src/Makefile
 		 add_ons/geomview/Makefile
 		 add_ons/grape/Makefile
 		 add_ons/grape/mesh/Makefile
@@ -70,18 +72,18 @@ else
 fi],
 [BITS=$(( ${ac_cv_sizeof_long} * 8 ))])
 
-AC_CONFIG_COMMANDS([dof_stride_free_bit.h],
-[: ${TMPDIR=/tmp}
-TARGET_NEW=${TMPDIR}/dof_stride_free_bit.h
-TARGET=alberta/src/Common/dof_stride_free_bit.h
-${SHELL} ${srcdir}/mkdoffreemasks.sh ${BITS} ${BITS} > ${TARGET_NEW}
-if test -f ${TARGET} && cmp ${TARGET} ${TARGET_NEW} > /dev/null 2>&1 ; then
-    AC_MSG_NOTICE([${TARGET} is unchanged])
-else
-    AC_MSG_NOTICE([Creating ${TARGET}])
-    mv -f ${TARGET_NEW} ${TARGET}
-fi],
-[BITS=$(( ${ac_cv_sizeof_long} * 8 ))])
+dnl AC_CONFIG_COMMANDS([dof_stride_free_bit.h],
+dnl [: ${TMPDIR=/tmp}
+dnl TARGET_NEW=${TMPDIR}/dof_stride_free_bit.h
+dnl TARGET=alberta/src/Common/dof_stride_free_bit.h
+dnl ${SHELL} ${srcdir}/mkdoffreemasks.sh ${BITS} ${BITS} > ${TARGET_NEW}
+dnl if test -f ${TARGET} && cmp ${TARGET} ${TARGET_NEW} > /dev/null 2>&1 ; then
+dnl     AC_MSG_NOTICE([${TARGET} is unchanged])
+dnl else
+dnl     AC_MSG_NOTICE([Creating ${TARGET}])
+dnl     mv -f ${TARGET_NEW} ${TARGET}
+dnl fi],
+dnl [BITS=$(( ${ac_cv_sizeof_long} * 8 ))])
 
 # Collect the demo programs
 DEMOSOURCES=
@@ -114,11 +116,7 @@ else
 		alberta_util/src/alberta_util_inlines.h
 fi])
 
-# change the installation directory. This could surely be done more elegantly...
-#
-# cH: hey, boys and girls, why do we do that?
-#
-# AC_PREFIX_DEFAULT([`pwd`])
+# Control of features which may be disabled/enabled as needed
 
 AC_ARG_ENABLE([dim-of-world],
 [AC_HELP_STRING([--enable-dim-of-world="DIM1 ... DIMk"],
@@ -142,28 +140,34 @@ AC_ARG_ENABLE([dim-of-world],
       ;;
 esac])
 
-ASSEMBLE_TYPES="
- M_M_M_M
- M_M_DM_DM
- M_M_SCM_SCM
- DM_DM_DM_DM
- DM_DM_SCM_SCM
- SCM_SCM_SCM_SCM"
-ASSEMBLE_FCTS_BASE=assemble_fcts.c
-ASSEMBLE_FCTS=""
-for variant in ${ASSEMBLE_TYPES}; do
-  ASSEMBLE_FCTS="${ASSEMBLE_FCTS} ${variant}_${ASSEMBLE_FCTS_BASE}"
-done
-AC_SUBST(ASSEMBLE_FCTS)
+ALBERTA_ENABLE_FLAG([vector-basis-functions],
+  [Disable support for vector-valued basis functions. If you leave this enabled
+  ALBERTA supports DIM_OF_WORLD-valued basis functions and scalar basis
+  functions. If you disable this feature ALBERTA only supports scalar valued
+  basis functions. DIM_OF_WORLD-valued
+  basis functions play an important role, e.g. for the discretisation of
+  problems involving H(div) (Maxwell equations ...) and, e.g., for stable
+  mixed discretisations for the Stokes-problem. Building ALBERTA with
+  support for vector valued basis functions increases the compile-time,
+  otherwise it should not have any measureable performance impact, therefore
+  this feature is normally ENABLED. Disable it to reduce the compile time
+  if you do not need this feature.],
+  [enabled],
+  [VECTOR_BASIS_FUNCTIONS],
+  [DEFINE SUBST COND])
+
+ALBERTA_ENABLE_FLAG([chained-basis-functions],
+  [Disable support for chains of basis-functions. ALBERTA has support for
+  forming direct sums of FE-spaces. This is useful, e.g., to
+  implement certain stable mixed discretisations for the Stokes-problem
+  (P1+Bubble = Mini, P1+FaceBubble = Bernardi-Raugel, weak slip b.c.).
+  Keeping this feature enabled will have a slight performance impact,
+  you may disable it if you do not need this feature.],
+  [enabled],
+  [CHAINED_BASIS_FUNCTIONS],
+  [DEFINE SUBST COND])
 
-ASSEMBLE_BNDRY_TYPES="M_M M_DM M_SCM DM_DM DM_SCM SCM_SCM"
-ASSEMBLE_BNDRY_FCTS_BASE=assemble_bndry_fcts.c
-ASS_BNDRY_FCTS=""
-for variant in ${ASSEMBLE_BNDRY_TYPES}; do
-  ASS_BNDRY_FCTS="${ASS_BNDRY_FCTS} ${variant}_${ASSEMBLE_BNDRY_FCTS_BASE}"
-done
-ASSEMBLE_BNDRY_FCTS="${ASS_BNDRY_FCTS}"
-AC_SUBST(ASSEMBLE_BNDRY_FCTS)
+################################################################################
 
 # Checks for programs.
 AC_PROG_INSTALL
@@ -178,6 +182,17 @@ AC_ARG_VAR([TAR_PROGRAM],[name of tar program (need _not_ be GNU-tar)])
 #
 # now check for compilers
 #
+ALBERTA_ENABLE_FLAG([gcc-attribute-flatten],
+  [The GNU C-compiler gcc knows about a special function attribute which
+  forces the compiler to "flatten" a specific function, i.e. to forcibly
+  inline all functions called from the function which carries the "flatten"
+  attribute. ALBERTA can use this feature on selected functions to produce
+  faster code at the expense of compile time. The extra time needed to compile
+  the library is quite large, so use of the "flatten" attribute is normally
+  disabled.],
+  [disabled],
+  [GCC_ATTRIBUTE_FLATTEN],
+  [DEFINE SUBST COND])
 
 #
 # remember the user override, if any.
@@ -346,6 +361,7 @@ AC_PROG_LIBTOOL
 
 # Checks for libraries, headers, functions, declarations ...
 AC_FUNC_OBSTACK
+AM_CONDITIONAL(NEED_OBSTACK, [test ! "x${ac_cv_func_obstack}" = "xyes"])
 
 # Check for libraries
 AC_CHECK_LIB([m],[main],,
@@ -411,8 +427,10 @@ AC_CHECK_FUNCS([unsetenv])
 AC_CHECK_FUNCS([getopt_long],[],
 	[AC_LIBOBJ([getopt])
 	AC_LIBOBJ([getopt1])
+	NEED_GETOPT=1
 	GNUCOMPAT_INCLUDE_PATH='$(top_srcdir)/gnu-compat/'])
 AC_SUBST([GNUCOMPAT_INCLUDE_PATH])
+AM_CONDITIONAL(NEED_GETOPT, [test "x${NEED_GETOPT}" = "x1"])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
diff --git a/gen-assemble-fcts.sh b/gen-assemble-fcts.sh
index 2a854a54493764adf2198a1673433ee3af238fa5..e9b1eecbce55d53ee8638897071a550857ee7867 100755
--- a/gen-assemble-fcts.sh
+++ b/gen-assemble-fcts.sh
@@ -1,5 +1,14 @@
 #! /bin/sh
 
+# A script to generate the various assemble function flavours from the
+# template files alberta/src/Common/assemble_fcts.c.in and
+# alberta/src/Common/assemble_bndry_fcts.c.in
+#
+# The idea is to generate specializations for the various block-matrix
+# variants while still only consuming a moderate amount of compilation
+# time. So we generate different files for different flavours of
+# block-matrices.
+
 if test "$#" -eq 4
 then
     DST_DOWB_ST=$1
diff --git a/generate-alberta-automakefiles.sh b/generate-alberta-automakefiles.sh
index ed7ea8a986d7c9e2a0685e514c18815d942b0e28..8eb71c00c06310c4f3f28ddd87cad574741ecceb 100755
--- a/generate-alberta-automakefiles.sh
+++ b/generate-alberta-automakefiles.sh
@@ -14,8 +14,40 @@ for ALBERTA_DEBUG in 0 1; do
 	    LIBCODE=_${DIM_OF_WORLD}d_debug
 	    EFLAGS=DEBUG 
 	fi
-
-        mkdir -p alberta/src/alberta$LIBCODE
-	sed -e "s/%DIM_OF_WORLD%/$DIM_OF_WORLD/g" Makefile.am.template -e "s/%DEBUG%/$DEBUG/g" -e "s/%ALBERTA_DEBUG%/$ALBERTA_DEBUG/g" -e "s/%LIBCODE%/$LIBCODE/g" -e "s/%EFLAGS%/$EFLAGS/g" > alberta/src/alberta$LIBCODE/Makefile.am
+	DIRECTORY="alberta/src/alberta${LIBCODE}"
+        mkdir -p ${DIRECTORY}
+	sed \
+	    -e "s/%DIM_OF_WORLD%/$DIM_OF_WORLD/g" \
+	    -e "s/%DEBUG%/$DEBUG/g" \
+	    -e "s/%ALBERTA_DEBUG%/$ALBERTA_DEBUG/g" \
+	    -e "s/%LIBCODE%/$LIBCODE/g" \
+	    -e "s/%EFLAGS%/$EFLAGS/g" \
+	    -e "s/%NO_MULTI_DIM%//g" \
+	    -e "s/%MULTI_DIM%/#/g" \
+	    Makefile.am.template > ${DIRECTORY}/Makefile.am
+    done
+    if test $ALBERTA_DEBUG -eq 0; then
+	DIRECTORY="alberta/src/alberta_Nd"
+    else
+	DIRECTORY="alberta/src/alberta_Nd_debug"
+    fi
+    mkdir -p ${DIRECTORY}
+    for DIM_OF_WORLD in 4 5 6 7 8 9; do
+	if test $ALBERTA_DEBUG -eq 0; then
+	    LIBCODE=_${DIM_OF_WORLD}d
+	    EFLAGS=OPTIMIZE 
+	else
+	    LIBCODE=_${DIM_OF_WORLD}d_debug
+	    EFLAGS=DEBUG 
+	fi
+	sed \
+	    -e "s/%DIM_OF_WORLD%/$DIM_OF_WORLD/g" \
+	    -e "s/%DEBUG%/$DEBUG/g" \
+	    -e "s/%ALBERTA_DEBUG%/$ALBERTA_DEBUG/g" \
+	    -e "s/%LIBCODE%/$LIBCODE/g" \
+	    -e "s/%EFLAGS%/$EFLAGS/g" \
+	    -e "s/%NO_MULTI_DIM%/#/g" \
+	    -e "s/%MULTI_DIM%//g" \
+	    Makefile.am.template > ${DIRECTORY}/Makefile-${DIM_OF_WORLD}d.am
     done
 done
diff --git a/gnu-compat/Makefile.am b/gnu-compat/Makefile.am
index 8446bc2773efc190d3bc244e68a8fe78f5c07e73..e5db1239767285b74fbd29be98f5e62f1fa166fc 100644
--- a/gnu-compat/Makefile.am
+++ b/gnu-compat/Makefile.am
@@ -1,7 +1,14 @@
 EXTRADIST = README COPYING
 
 noinst_LTLIBRARIES = libalbertagnucompat.la
-noinst_HEADERS = getopt.h obstack.h
+
+pkginclude_HEADERS =
+if NEED_GETOPT
+pkginclude_HEADERS += getopt.h
+endif
+if NEED_OBSTACK
+pkginclude_HEADERS += obstack.h
+endif
 
 libalbertagnucompat_la_SOURCES = getopt.h dummy.c
 libalbertagnucompat_la_LIBADD  = @LTLIBOBJS@
diff --git a/m4/check-iso-c99.m4 b/m4/check-iso-c99.m4
index 142c3fb8861e7fade3a91fbfd28a1e6f0e739c91..f5c7f30ae7bf1c217d3bbcfa9f95d82dc671f437 100644
--- a/m4/check-iso-c99.m4
+++ b/m4/check-iso-c99.m4
@@ -20,11 +20,20 @@ AC_COMPILE_IFELSE(
 	[AC_LANG_PROGRAM(
 [[extern void exit(int status);
 #define FOO(a, ...)  (a, __VA_ARGS__)
+#include <stdarg.h>
+void va_copy_test(va_list ap)
+{
+  va_list ap2;
+  va_copy(ap2, ap);
+  va_end(ap2);
+}
 extern int foo(int a, int b, int c);]],
 [[int bar[foo FOO(3, 4, 5)];
 exit(bar[0]);]])],
-[AC_MSG_RESULT([variadic macros and variable length arrays available])],
-[AC_MSG_FAILURE([variadic macros and/or vairable length arrays NOT available])])
+[AC_MSG_RESULT(
+  [variadic macros, va_copy() and variable length arrays are available])],
+[AC_MSG_FAILURE(
+ [variadic macros, va_copy() and/or vairable length arrays are NOT available])])
 AC_LANG_POP([C])
 CFLAGS="${_alberta_save_cflags}"
 ])
diff --git a/m4/check-package.m4 b/m4/check-package.m4
index 46ca1294f86bb724129d9c346080f649696c59a3..3e888631545ea4180176218c698436a1fa4d265a 100644
--- a/m4/check-package.m4
+++ b/m4/check-package.m4
@@ -290,6 +290,11 @@ UPNAME[_AUXLIBS]="alb_ac_AUXLIBS"
 dnl
 dnl now check if the library and header files exist
 dnl
+AC_CACHE_CHECK([for libraries for package alb_ac_PKGNAME],
+  [alb_ac_cv_]UPNAME[_libs],[
+dnl
+dnl Cache check start
+dnl
 m4_if(OPTIONAL,[optional],
   [AC_CHECK_LIB(${UPNAME[_LINK_NAMES]}, main,
     [UPNAME[_LIBS]="${UPNAME[_LIB_PATHS]} -l${UPNAME[_LINK_NAMES]}"
@@ -384,6 +389,25 @@ else
      UPNAME[_INCLUDE_PATH]=""])
   LIBS="${alb_ac_save_LIBS}"
 fi])
+if test "x${UPNAME[_LIBS]}" = "x" ; then
+  [alb_ac_cv_]UPNAME[_libs]="notfound"
+else
+  [alb_ac_cv_]UPNAME[_libs]="${UPNAME[_LIBS]}"
+fi
+]) dnl Cache check end
+
+if test "x${[alb_ac_cv_]UPNAME[_libs]}" = "xnotfound"; then
+  m4_if(OPTIONAL,[optional],
+    [UPNAME[_LIBS]=""
+    UPNAME[_ALL_LIBS]=""
+    UPNAME[_LIB_PATHS]=""
+    UPNAME[_INCLUDES]=""
+    UPNAME[_INCLUDE_PATH]=""],
+    [AC_MSG_ERROR([Failed to find libraries for alb_ac_PKGNAME])])
+else
+  UPNAME[_LIBS]="${[alb_ac_cv_]UPNAME[_libs]}"
+  UPNAME[_ALL_LIBS]="${[alb_ac_cv_]UPNAME[_libs]} ${UPNAME[_AUXLIBS]}"
+fi
 
 dnl
 dnl restore default linker
@@ -397,32 +421,40 @@ else
     dnl
     dnl  check for the header file(s)
     dnl
-    [gv_ac_]UPNAME[_save_CPPFLAGS]="$CPPFLAGS"
-    for alb_ac_incdir in ${UPNAME[_INCLUDE_PATH]} ""; do
-      unset alb_ac_header_status
-      unset alb_ac_unset_names
-      alb_ac_incdir_exp="`eval eval eval echo ${alb_ac_incdir}`"
-      if test -n "${alb_ac_incdir_exp}"; then
-	CPPFLAGS="-I${alb_ac_incdir_exp} alb_ac_EXTRA_INC ${[gv_ac_]UPNAME[_save_CPPFLAGS]}"
-        AC_MSG_CHECKING([for header(s) \"alb_ac_HEADERS\" in \"${alb_ac_incdir_exp}\" and system include path])
-        AC_MSG_RESULT([])
-      else
-        AC_MSG_CHECKING([for header(s) \"alb_ac_HEADERS\" in system include path])
-        AC_MSG_RESULT([])
-      fi
-      AC_CHECK_HEADERS(alb_ac_HEADERS,
-                       [alb_ac_unset_names="${alb_ac_unset_names} $as_ac_Header"],
-                       [alb_ac_unset_names="${alb_ac_unset_names} $as_ac_Header"
-                       alb_ac_header_status=notfound])
+    AC_CACHE_CHECK(
+      [for include-files for package alb_ac_PKGNAME],
+      [alb_ac_cv_]UPNAME[_incdir],[
+      [alb_ac_]UPNAME[_save_CPPFLAGS]="$CPPFLAGS"
+      for [alb_ac_cv_]UPNAME[_incdir] in ${UPNAME[_INCLUDE_PATH]} ""; do
+        unset alb_ac_header_status
+        unset alb_ac_unset_names
+        alb_ac_incdir_exp="`eval eval eval echo ${[alb_ac_cv_]UPNAME[_incdir]}`"
+        if test -n "${alb_ac_incdir_exp}"; then
+  	  CPPFLAGS="-I${alb_ac_incdir_exp} alb_ac_EXTRA_INC ${[alb_ac_]UPNAME[_save_CPPFLAGS]}"
+          AC_MSG_CHECKING([for header(s) \"alb_ac_HEADERS\" in \"${alb_ac_incdir_exp}\" and system include path])
+          AC_MSG_RESULT([])
+        else
+          AC_MSG_CHECKING([for header(s) \"alb_ac_HEADERS\" in system include path])
+          AC_MSG_RESULT([])
+        fi
+        AC_CHECK_HEADERS(alb_ac_HEADERS,
+          [alb_ac_unset_names="${alb_ac_unset_names} $as_ac_Header"],
+          [alb_ac_unset_names="${alb_ac_unset_names} $as_ac_Header"
+          alb_ac_header_status=notfound])
+        if test "x${alb_ac_header_status}" = "xnotfound"; then
+	  for name in ${alb_ac_unset_names}; do
+            eval "unset ${name}"
+	  done
+        else
+     	  break
+        fi
+      done
+      CPPFLAGS="${[alb_ac_]UPNAME[_save_CPPFLAGS]}"
       if test "x${alb_ac_header_status}" = "xnotfound"; then
-	for name in ${alb_ac_unset_names}; do
-          eval "unset ${name}"
-	done
-      else
-     	break
+	[alb_ac_cv_]UPNAME[_incdir]="notfound"
       fi
-    done
-    if test "x${alb_ac_header_status}" = "xnotfound"; then
+    ])
+    if test "x${[alb_ac_cv_]UPNAME[_incdir]}" = "xnotfound"; then
       m4_if(OPTIONAL,[optional],
         [UPNAME[_LIBS]=""
 	UPNAME[_ALL_LIBS]=""
@@ -431,11 +463,10 @@ else
 	UPNAME[_INCLUDE_PATH]=""],
         [AC_MSG_ERROR([Header file(s) \"alb_ac_HEADERS\" were not found])])
     else
-      UPNAME[_ALL_INCLUDES]="-I${alb_ac_incdir} alb_ac_EXTRA_INC"
-      UPNAME[_INCLUDES]="-I${alb_ac_incdir}"
-      UPNAME[_INCLUDE_PATH]="${incdir}"
+      UPNAME[_ALL_INCLUDES]="-I${[alb_ac_cv_]UPNAME[_incdir]} alb_ac_EXTRA_INC"
+      UPNAME[_INCLUDES]="-I${[alb_ac_cv_]UPNAME[_incdir]}"
+      UPNAME[_INCLUDE_PATH]="${[alb_ac_cv_]UPNAME[_incdir]}"
     fi
-    CPPFLAGS="${[gv_ac_]UPNAME[_save_CPPFLAGS]}"
   ])
   dnl
   dnl define makefile substitutions and config.h macros
diff --git a/m4/simple-enable-flag.m4 b/m4/simple-enable-flag.m4
index f031de9e09599ea6b06c9eb03cfe7d1ef549994f..0db3fe543a5da106b5d9a39f23b85b6dfdd3d6ba 100644
--- a/m4/simple-enable-flag.m4
+++ b/m4/simple-enable-flag.m4
@@ -24,15 +24,19 @@ AC_DEFUN([ALBERTA_ENABLE_FLAG],
        [m4_define([FLAGNAME], [m4_bpatsubst(m4_toupper([$4]),-,_)])])
 m4_define([NEGDEFAULT],[enable])
 m4_define([DEFAULT],[disabled])
+m4_define([VALUE],[0])
 m4_if([$3],[1],
       [m4_define([NEGDEFAULT],[disable])
-       m4_define([DEFAULT],[enabled])])
+       m4_define([DEFAULT],[enabled])
+       m4_define([VALUE],[1])])
 m4_if([$3],[yes],
       [m4_define([NEGDEFAULT],[disable])
-       m4_define([DEFAULT],[enabled])])
+       m4_define([DEFAULT],[enabled])
+       m4_define([VALUE],[1])])
 m4_if([$3],[enabled],
       [m4_define([NEGDEFAULT],[disable])
-       m4_define([DEFAULT],[enabled])])
+       m4_define([DEFAULT],[enabled])
+       m4_define([VALUE],[1])])
 AC_ARG_ENABLE($1,
 	AC_HELP_STRING(--[]NEGDEFAULT[]-$1,
 			[$2 (default: DEFAULT)]),
@@ -47,7 +51,7 @@ AC_ARG_ENABLE($1,
 			AC_MSG_ERROR(["--[]NEGDEFAULT[]-$1" does not take an argument.])
 			;;
 	esac],
-	[FLAGNAME=$3])
+	[FLAGNAME=VALUE])
 m4_if($#,5,
 [for i in m4_toupper([$5]); do
     case $i in