diff --git a/Makefile.am b/Makefile.am
index 8bec9664ed99f25fbb3a5cbdbc23e06ab221f6c7..d8ee03694344c839ee04cc97f6c27e8d65c48f64 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,4 +32,4 @@ dist-hook: clean-local
 	rm -rf `find $(distdir) -name .svn`
 	rm -rf `find $(distdir)/mex/sources -name *.o`
 	rm -f $(distdir)/matlab/dynare_m$(EXEEXT)
-	$(MKDIR_P) $(distdir)/mex/2007a $(distdir)/mex/2007b $(distdir)/mex/2009a-64bit $(distdir)/mex/octave
+	$(MKDIR_P) $(distdir)/mex/matlab $(distdir)/mex/octave
diff --git a/configure.ac b/configure.ac
index 127489b31da1d73546f1efe6a7213693f56f9c81..e856ec97ac6f93e6d1deb07c5a94981494ff4ae1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,13 @@ AM_INIT_AUTOMAKE([-Wall -Werror foreign])
 AC_PROG_CC
 AC_PROG_CXX
 
+AC_CANONICAL_HOST
+case ${host_os} in
+  *mingw32*)
+    LDFLAGS="$LDFLAGS -static-libgcc" # On mingw32, we don't want dynamic libgcc
+    ;;
+esac
+
 # Use C++ for testing headers
 AC_LANG([C++])
 
diff --git a/m4/ax_mexopts.m4 b/m4/ax_mexopts.m4
index eb31b0968579a69201f0314dcbe43e0ef182d6ed..f8f043283cd493eee7ed23fee51990e7534055c9 100644
--- a/m4/ax_mexopts.m4
+++ b/m4/ax_mexopts.m4
@@ -50,7 +50,7 @@ case ${MATLAB_ARCH} in
     MATLAB_CFLAGS="-fexceptions -g -O2"
     MATLAB_CXXFLAGS="-g -O2"
     LIBLOC="$MATLAB/extern/lib/${MATLAB_ARCH}/microsoft"
-    MATLAB_LDFLAGS="-shared \$(top_srcdir)/mex.def"
+    MATLAB_LDFLAGS="-static-libgcc -shared \$(top_srcdir)/mex.def"
     MATLAB_LIBS="$LIBLOC/libmex.lib $LIBLOC/libmx.lib $LIBLOC/libmwlapack.lib -lstdc++"
     # Starting from MATLAB 7.5, BLAS and LAPACK are in distinct libraries
     AX_COMPARE_VERSION([$MATLAB_VERSION], [ge], [7.5], [MATLAB_LIBS="${MATLAB_LIBS} $LIBLOC/libmwblas.lib"])