diff --git a/mex/build/matlab/mex.am b/mex/build/matlab/mex.am
index 620de3538672233303359625a58da10d27af5cec..7a91726c4198279b034663377bda37f5ab0cf6e1 100644
--- a/mex/build/matlab/mex.am
+++ b/mex/build/matlab/mex.am
@@ -13,11 +13,15 @@ LIBS += $(MATLAB_LIBS)
 mexdir = $(libdir)/dynare/mex/matlab
 
 all-local: $(PROGRAMS)
-	$(MKDIR_P) $(top_srcdir)/../../matlab
-	cd $(top_srcdir)/../../matlab && \
-	for p in $(PROGRAMS); do \
-		$(LN_S) -f $(abs_builddir)/$$p $$p; \
-	done
+## Create symlinks in mex/matlab/, but only if the build is not
+## out-of-tree (because of the Windows installer)
+	if [ "$(abs_srcdir)" = "$(abs_builddir)" ]; then \
+		$(MKDIR_P) $(top_srcdir)/../../matlab && \
+		cd $(top_srcdir)/../../matlab && \
+		for p in $(PROGRAMS); do \
+			$(LN_S) -f $(abs_builddir)/$$p $$p; \
+		done; \
+	fi
 
 clean-local:
 	if test -d $(top_srcdir)/../../matlab; then \
diff --git a/mex/build/octave/mex.am b/mex/build/octave/mex.am
index df5505c270caf0ea1eee30af96e585e584301bb1..f0da052beec5b86b93014806821871c652559451 100644
--- a/mex/build/octave/mex.am
+++ b/mex/build/octave/mex.am
@@ -20,11 +20,15 @@ LIBS += $(shell $(MKOCTFILE) -p FLIBS)
 mexdir = $(libdir)/dynare/mex/octave
 
 all-local: $(PROGRAMS)
-	$(MKDIR_P) $(top_srcdir)/../../octave
-	cd $(top_srcdir)/../../octave && \
-	for p in $(PROGRAMS); do \
-		$(LN_S) -f $(abs_builddir)/$$p $$p; \
-	done
+## Create symlinks in mex/octave/, but only if the build is not
+## out-of-tree (because of the Windows installer)
+	if [ "$(abs_srcdir)" = "$(abs_builddir)" ]; then \
+		$(MKDIR_P) $(top_srcdir)/../../octave && \
+		cd $(top_srcdir)/../../octave && \
+		for p in $(PROGRAMS); do \
+			$(LN_S) -f $(abs_builddir)/$$p $$p; \
+		done; \
+	fi
 
 clean-local:
 	if test -d $(top_srcdir)/../../octave; then \
diff --git a/windows/build.sh b/windows/build.sh
index 36d8e00c5ffac7587ac0ae4fdbf6ff31ccfbd636..dd31a80fe6069c4a86159d24d03af3b9b193b495 100755
--- a/windows/build.sh
+++ b/windows/build.sh
@@ -220,8 +220,7 @@ cd "$ROOT_DIRECTORY"
 export TMP_DIRECTORY ROOT_DIRECTORY LIB32 LIB64 VERSION NTHREADS
 export -f "${TASKS[@]}"
 parallel "set -ex;shopt -s globstar;" ::: "${TASKS[@]}"
-# Clean up bogus symlinks left by parallel builds of MEX
-rm -f ../mex/matlab/*.mexw32 ../mex/matlab/*.mexw64 ../mex/octave/*.mex
+
 # Add supported_octave_version.m (see matlab/dynare.m)
 while read -r line
 do