diff --git a/Makefile.am b/Makefile.am
index a784de57b0f21d0096f53d8420386beda614b2bd..8bec9664ed99f25fbb3a5cbdbc23e06ab221f6c7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,12 @@ endif
 endif
 
 # MEX must be built after dynare++ (because of kordepert)
-SUBDIRS += mex/build/octave mex/build/matlab
+if ENABLE_MATLAB
+SUBDIRS += mex/build/matlab
+endif
+if ENABLE_OCTAVE
+SUBDIRS += mex/build/octave
+endif
 
 ACLOCAL_AMFLAGS = -I m4
 
diff --git a/configure.ac b/configure.ac
index 5769badf19d1569760bfc2f372923d7fbed06059..127489b31da1d73546f1efe6a7213693f56f9c81 100644
--- a/configure.ac
+++ b/configure.ac
@@ -159,7 +159,17 @@ AC_CONFIG_FILES([Makefile
                  dynare++/src/Makefile
 ])
 
-AC_CONFIG_SUBDIRS([mex/build/matlab mex/build/octave])
+AC_ARG_ENABLE([matlab], AS_HELP_STRING([--disable-matlab], [disable compilation of MEX files for MATLAB]), [], [enable_matlab=yes])
+if test "x$enable_matlab" = "xyes"; then
+  AC_CONFIG_SUBDIRS([mex/build/matlab])
+fi
+AM_CONDITIONAL([ENABLE_MATLAB], [test "x$enable_matlab" = "xyes"])
+
+AC_ARG_ENABLE([octave], AS_HELP_STRING([--disable-octave], [disable compilation of MEX files for Octave]), [], [enable_octave=yes])
+if test "x$enable_octave" = "xyes"; then
+  AC_CONFIG_SUBDIRS([mex/build/octave])
+fi
+AM_CONDITIONAL([ENABLE_OCTAVE], [test "x$enable_octave" = "xyes"])
 
 # Construct final output message
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8cd47eec6f10a2cdf8155ae6af1578027045efd5..b2e6d1f14fdded6adba2e6b24281611f579b558a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,7 +22,8 @@ OCTAVE_MODS = \
 	AIM/fs2000x10L9_L.mod \
 	AIM/fs2000x10L9_L_AIM.mod \
 	AIM/fs2000x10_L9_L.mod \
-	AIM/fs2000x10_L9_L_AIM.mod
+	AIM/fs2000x10_L9_L_AIM.mod \
+	conditional_variance_decomposition/example1.mod
 
 MODS = $(OCTAVE_MODS) \
 	arima/mod1b.mod \