diff --git a/.gitignore b/.gitignore
index beef27db67eac41d3b84dbc998d78e0ebeaa9488..41c6d3f1fec80268ead040d6d471ad66e381cc55 100644
--- a/.gitignore
+++ b/.gitignore
@@ -124,6 +124,8 @@ doc/internals/ltxpng
 
 # Windows
 /windows/dynare-version.nsi
+!/windows/Makefile
+!/windows/deps/Makefile
 
 # MacOS stuff
 .DS_Store
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3d84be8af21748587cfa95141170730725af2cac..c3b40fd9d3e31899e2a92320972144499e54d7ca 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,6 +2,11 @@ variables:
   GIT_SUBMODULE_STRATEGY: normal
   TERM: linux
 
+stages:
+  - build
+  - test_and_pkg
+  - deploy
+
 build_binaries:
   stage: build
   script:
@@ -36,10 +41,34 @@ build_doc:
   artifacts:
     paths:
       - doc/manual/build/
+      - doc/*.pdf
+      - doc/*/*.pdf
+      - dynare++/doc/*.pdf
+      - preprocessor/doc/*/*.pdf
     expire_in: 1 week
 
+pkg_windows:
+  stage: test_and_pkg
+  script:
+    - ln -s ~/tarballs windows/deps/
+    - make -C windows
+  cache:
+    key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
+    paths:
+      - windows/deps/sources32/
+      - windows/deps/sources64/
+      - windows/deps/lib32/
+      - windows/deps/lib64/
+  artifacts:
+    paths:
+      - windows/exe/*
+      - windows/zip/*
+    expire_in: 1 week
+  dependencies:
+    - build_doc
+
 .test_matlab_template:
-  stage: test
+  stage: test_and_pkg
   artifacts:
     paths:
       - tests/*.m.log
@@ -73,7 +102,7 @@ test_old_matlab:
   when: manual
 
 test_octave:
-  stage: test
+  stage: test_and_pkg
   variables:
     OPENBLAS_NUM_THREADS: 1
   script:
@@ -97,7 +126,7 @@ test_octave:
   when: manual
 
 test_dynare++:
-  stage: test
+  stage: test_and_pkg
   script:
     - autoreconf -si
     - ./configure --disable-matlab --disable-octave
diff --git a/Makefile.am b/Makefile.am
index d4303cfb0ff1ac42ce34605db4868c4bccf97d86..fc165ca0b4c1dc0a0b0023271e6abd5e30838c3d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,16 +33,16 @@ EXTRA_DIST = \
 	scripts \
 	.dir-locals.el
 
-all-local: preprocessor/src/dynare_m
-	if file preprocessor/src/dynare_m | grep -q x86.64; then \
+all-local: preprocessor/src/dynare_m$(EXEEXT)
+	if file preprocessor/src/dynare_m$(EXEEXT) | grep -q x86.64; then \
 	  ARCH="64"; \
 	else \
 	  ARCH="32"; \
 	fi; \
 	mkdir -p $(abs_srcdir)/matlab/preprocessor$$ARCH && \
-	$(LN_S) -f $(abs_srcdir)/preprocessor/src/dynare_m $(abs_srcdir)/matlab/preprocessor$$ARCH && \
+	$(LN_S) -f $(abs_builddir)/preprocessor/src/dynare_m$(EXEEXT) $(abs_srcdir)/matlab/preprocessor$$ARCH && \
 	mkdir -p $(abs_srcdir)/julia/preprocessor$$ARCH && \
-	$(LN_S) -f $(abs_srcdir)/preprocessor/src/dynare_m $(abs_srcdir)/julia/preprocessor$$ARCH
+	$(LN_S) -f $(abs_builddir)/preprocessor/src/dynare_m$(EXEEXT) $(abs_srcdir)/julia/preprocessor$$ARCH
 
 dist-hook:
 	rm -rf `find $(distdir)/matlab $(distdir)/examples -name *~`
diff --git a/configure.ac b/configure.ac
index 140b84feb759ef727f5b88d2c15d87041d905248..57b18274b21f23bdc4ea5fa30db415c409cf7fa4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,7 +119,6 @@ AC_CONFIG_FILES([Makefile
                  doc/dseries-and-reporting/Makefile
                  tests/Makefile
                  matlab/dynare_version.m
-                 windows/dynare-version.nsi
                  dynare++/Makefile
                  dynare++/parser/cc/Makefile
                  dynare++/sylv/Makefile
diff --git a/m4/ax_mexopts.m4 b/m4/ax_mexopts.m4
index e9bda330eb5e2864c4783df360f0636322637bc3..70014d7875f0cbc3b9be0e1be4d6c37fde2d61c8 100644
--- a/m4/ax_mexopts.m4
+++ b/m4/ax_mexopts.m4
@@ -57,7 +57,7 @@ case ${MATLAB_ARCH} in
     # against libwinpthread DLL (which is pulled in by libstdc++, even without
     # using threads, since we are using the POSIX threads version of MinGW)
     MATLAB_LDFLAGS_NOMAP="-static-libgcc -static-libstdc++ -shared -L$MATLAB/bin/${MATLAB_ARCH} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,-Bdynamic,--no-whole-archive"
-    MATLAB_LDFLAGS="$MATLAB_LDFLAGS_NOMAP $(pwd)/$srcdir/mex.def"
+    MATLAB_LDFLAGS="$MATLAB_LDFLAGS_NOMAP \$(abs_top_srcdir)/mex.def"
     MATLAB_LIBS="-lmex -lmx -lmat -lmwlapack -lmwblas"
     ax_mexopts_ok="yes"
     ;;
@@ -68,7 +68,7 @@ case ${MATLAB_ARCH} in
     MATLAB_CXXFLAGS="$MATLAB_CFLAGS"
     MATLAB_FFLAGS="-fexceptions -fbackslash -arch x86_64"
     MATLAB_LDFLAGS_NOMAP="-Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -bundle"
-    MATLAB_LDFLAGS="$MATLAB_LDFLAGS_NOMAP -Wl,-exported_symbols_list,$(pwd)/$srcdir/mexFunction-MacOSX.map"
+    MATLAB_LDFLAGS="$MATLAB_LDFLAGS_NOMAP -Wl,-exported_symbols_list,\$(abs_top_srcdir)/mexFunction-MacOSX.map"
     MATLAB_LIBS="-L$MATLAB/bin/maci64 -lmx -lmex -lmat -lmwlapack -lmwblas"
     ax_mexopts_ok="yes"
     ;;
diff --git a/matlab/add_path_to_mex_files.m b/matlab/add_path_to_mex_files.m
index e218eb7bdf97d8638b82feb7149ba4ec22e01487..95cb70e54c5bedf6ab871fd9a28679a585f2f5db 100644
--- a/matlab/add_path_to_mex_files.m
+++ b/matlab/add_path_to_mex_files.m
@@ -1,6 +1,6 @@
 function mexpath = add_path_to_mex_files(dynareroot, modifypath)
 
-% Copyright (C) 2015-2017 Dynare Team
+% Copyright (C) 2015-2019 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -22,13 +22,34 @@ if nargin<2
 end
 
 if isoctave
-    if ispc() && strcmpi(computer(), 'i686-w64-mingw32')
-        mexpath = {[dynareroot '../mex/octave32/']};
+    % Add specific paths for Dynare Windows package
+    if ispc
+        if strcmpi(computer(), 'i686-w64-mingw32')
+            tmp = [dynareroot '../mex/octave/win32/'];
+            if exist(tmp, 'dir')
+                mexpath = tmp;
+                if modifypath
+                    addpath(mexpath);
+                end
+            end
+        else
+            tmp = [dynareroot '../mex/octave/win64/'];
+            if exist(tmp, 'dir')
+                mexpath = tmp;
+                if modifypath
+                    addpath(mexpath);
+                end
+            end
+        end
+    end
+    % Add generic MATLAB path (with higher priority than the previous ones)
+    if exist('mexpath')
+        mexpath = { mexpath; [dynareroot '../mex/octave/'] };
     else
-        mexpath = {[dynareroot '../mex/octave/']};
+        mexpath = { [dynareroot '../mex/octave/'] };
     end
     if modifypath
-        addpath(mexpath{1});
+        addpath([dynareroot '../mex/octave/']);
     end
 else
     % Add win32 specific paths for Dynare Windows package
diff --git a/mex/build/matlab/mex.am b/mex/build/matlab/mex.am
index d684338d0e8eb48999224805011529c3497d3784..620de3538672233303359625a58da10d27af5cec 100644
--- a/mex/build/matlab/mex.am
+++ b/mex/build/matlab/mex.am
@@ -16,7 +16,7 @@ all-local: $(PROGRAMS)
 	$(MKDIR_P) $(top_srcdir)/../../matlab
 	cd $(top_srcdir)/../../matlab && \
 	for p in $(PROGRAMS); do \
-		$(LN_S) -f $(abs_srcdir)/$$p $$p; \
+		$(LN_S) -f $(abs_builddir)/$$p $$p; \
 	done
 
 clean-local:
diff --git a/mex/build/octave/mex.am b/mex/build/octave/mex.am
index dba1b3944d9492d814d99d006ec806c11f58df88..df5505c270caf0ea1eee30af96e585e584301bb1 100644
--- a/mex/build/octave/mex.am
+++ b/mex/build/octave/mex.am
@@ -23,7 +23,7 @@ all-local: $(PROGRAMS)
 	$(MKDIR_P) $(top_srcdir)/../../octave
 	cd $(top_srcdir)/../../octave && \
 	for p in $(PROGRAMS); do \
-		$(LN_S) -f $(abs_srcdir)/$$p $$p; \
+		$(LN_S) -f $(abs_builddir)/$$p $$p; \
 	done
 
 clean-local:
diff --git a/windows/Makefile b/windows/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..36a9fc1600d888299151f5af6b70e991bb0e3c1c
--- /dev/null
+++ b/windows/Makefile
@@ -0,0 +1,39 @@
+# Copyright © 2017-2019 Dynare Team
+#
+# This file is part of Dynare.
+#
+# Dynare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Dynare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
+
+.PHONY: all deps clean-deps clean clean-all install build
+
+NTHREADS=$(shell nproc)
+
+all: build
+
+deps:
+	make -C deps -j$(NTHREADS)
+
+clean-deps:
+	make -C deps clean-all
+
+clean:
+	rm -rf exe/ zip/
+
+clean-all: clean-deps clean
+
+install:
+	./install-packages.sh
+
+build: deps
+	./build.sh
diff --git a/windows/build.sh b/windows/build.sh
new file mode 100755
index 0000000000000000000000000000000000000000..ac448d6a993110369d8c26d1a1bd5e4801e7d193
--- /dev/null
+++ b/windows/build.sh
@@ -0,0 +1,281 @@
+#!/bin/bash
+
+# Produces Windows packages of Dynare (Windows installer and zip archive).
+#
+# The binaries are cross compiled for Windows (32/64bits), Octave and MATLAB
+# (all supported versions).
+
+# Copyright © 2017-2019 Dynare Team
+#
+# This file is part of Dynare.
+#
+# Dynare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Dynare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
+
+# Exit on first error and print commands as they are executed
+set -ex
+
+# Set root directory
+ROOT_DIRECTORY=$(dirname "$(readlink -f "$0")")
+
+# Create TMP folder and make sure it is deleted upon exit
+TMP_DIRECTORY=$(mktemp -d)
+
+cleanup()
+{
+    [[ -z $TMP_DIRECTORY ]] || rm -rf -- "$TMP_DIRECTORY"
+}
+trap cleanup EXIT
+
+# Set the number of threads
+NTHREADS=$(nproc)
+
+# Set Dynare version
+if [[ -n $CI_COMMIT_TAG ]]; then
+    # Official release tagged through Gitlab
+    VERSION=$CI_COMMIT_TAG
+    VERSION_SHORT=$VERSION
+else
+    VERSION=$(grep '^AC_INIT(' ../configure.ac | sed 's/AC_INIT(\[dynare\], \[\(.*\)\])/\1/')
+    if [[ -n $CI_COMMIT_SHA ]]; then
+        VERSION_SHORT=$VERSION-$CI_COMMIT_SHORT_SHA
+        VERSION=$VERSION-$CI_COMMIT_SHA
+    elif [[ -d ../.git/ ]]; then
+        VERSION_SHORT=$VERSION-$(git rev-parse --short HEAD)
+        VERSION=$VERSION-$(git rev-parse HEAD)
+    else
+        VERSION_SHORT=$VERSION
+    fi
+fi
+
+BASENAME=dynare-$VERSION_SHORT
+
+# Set directories for dependencies
+LIB32="$ROOT_DIRECTORY"/deps/lib32
+LIB64="$ROOT_DIRECTORY"/deps/lib64
+
+# Go to source root directory
+cd ..
+
+# Autoreconf if needed
+[[ -f configure ]] || autoreconf -si
+
+## Compile preprocessor (32-bit), Dynare++ (32-bit) and documentation
+./configure --host=i686-w64-mingw32 \
+	    --with-boost="$LIB32"/Boost \
+	    --with-blas="$LIB32"/OpenBLAS/libopenblas.a \
+	    --with-lapack="$LIB32"/OpenBLAS/libopenblas.a \
+	    --with-matio="$LIB32"/matIO \
+	    --disable-octave \
+	    --disable-matlab \
+	    PACKAGE_VERSION="$VERSION" \
+	    PACKAGE_STRING="dynare $VERSION"
+if [[ -z $CI ]]; then
+    # If not in Gitlab CI, clean the source and build the doc
+    make clean
+    make -j"$NTHREADS" pdf html
+fi
+make -j"$NTHREADS"
+i686-w64-mingw32-strip matlab/preprocessor32/dynare_m.exe
+i686-w64-mingw32-strip dynare++/src/dynare++.exe
+
+## Compile 64-bit preprocessor
+cd preprocessor
+make -C src clean # We don't want to clean the doc
+./configure --host=x86_64-w64-mingw32 \
+	    --with-boost="$LIB64"/Boost \
+	    PACKAGE_VERSION="$VERSION" \
+	    PACKAGE_STRING="dynare $VERSION"
+make -j"$NTHREADS"
+x86_64-w64-mingw32-strip src/dynare_m.exe
+mkdir -p ../matlab/preprocessor64
+mv src/dynare_m.exe ../matlab/preprocessor64
+
+## Define functions for building MEX files
+
+## Note that we do out-of-tree compilation, since we want to do these in
+## parallel
+
+# Create Windows 32-bit DLL binaries for MATLAB ≥ R2009b
+build_windows_matlab_mex_32 ()
+{
+    mkdir -p "$TMP_DIRECTORY"/matlab-win32/
+    cd "$TMP_DIRECTORY"/matlab-win32/
+    "$ROOT_DIRECTORY"/../mex/build/matlab/configure \
+                     --host=i686-w64-mingw32 \
+		     --with-gsl="$LIB32"/Gsl \
+		     --with-matio="$LIB32"/matIO \
+		     --with-slicot="$LIB32"/Slicot/without-underscore \
+		     --with-matlab="$LIB32"/matlab/R2009b \
+		     MATLAB_VERSION=R2009b \
+		     MEXEXT=mexw32 \
+		     PACKAGE_VERSION="$VERSION" \
+		     PACKAGE_STRING="dynare $VERSION"
+    make -j"$NTHREADS" all
+    i686-w64-mingw32-strip -- **/*.mexw32
+    mkdir -p "$ROOT_DIRECTORY"/../mex/matlab/win32-7.9-8.6
+    mv -- **/*.mexw32 "$ROOT_DIRECTORY"/../mex/matlab/win32-7.9-8.6
+}
+
+# Create Windows 64-bit DLL binaries for MATLAB ≥ R2009b and ≤ R2017b
+build_windows_matlab_mex_64_a ()
+{
+    mkdir -p "$TMP_DIRECTORY"/matlab-win64-a/
+    cd "$TMP_DIRECTORY"/matlab-win64-a/
+    "$ROOT_DIRECTORY"/../mex/build/matlab/configure \
+                     --host=x86_64-w64-mingw32 \
+		     --with-gsl="$LIB64"/Gsl \
+		     --with-matio="$LIB64"/matIO \
+		     --with-slicot="$LIB64"/Slicot/without-underscore \
+		     --with-matlab="$LIB64"/matlab/R2009b \
+		     MATLAB_VERSION=R2009b \
+		     MEXEXT=mexw64 \
+		     PACKAGE_VERSION="$VERSION" \
+		     PACKAGE_STRING="dynare $VERSION"
+    make -j"$NTHREADS" all
+    x86_64-w64-mingw32-strip -- **/*.mexw64
+    mkdir -p "$ROOT_DIRECTORY"/../mex/matlab/win64-7.9-9.3
+    mv -- **/*.mexw64 "$ROOT_DIRECTORY"/../mex/matlab/win64-7.9-9.3
+}
+
+# Create Windows 64-bit DLL binaries for MATLAB ≥ R2018a
+build_windows_matlab_mex_64_b ()
+{
+    mkdir -p "$TMP_DIRECTORY"/matlab-win64-b/
+    cd "$TMP_DIRECTORY"/matlab-win64-b/
+    "$ROOT_DIRECTORY"/../mex/build/matlab/configure \
+                     --host=x86_64-w64-mingw32 \
+		     --with-gsl="$LIB64"/Gsl \
+		     --with-matio="$LIB64"/matIO \
+		     --with-slicot="$LIB64"/Slicot/without-underscore \
+		     --with-matlab="$LIB64"/matlab/R2018a \
+		     MATLAB_VERSION=R2018a \
+		     MEXEXT=mexw64 \
+		     PACKAGE_VERSION="$VERSION" \
+		     PACKAGE_STRING="dynare $VERSION"
+    make -j"$NTHREADS" all
+    x86_64-w64-mingw32-strip -- **/*.mexw64
+    mkdir -p "$ROOT_DIRECTORY"/../mex/matlab/win64-9.4-9.6
+    mv -- **/*.mexw64 "$ROOT_DIRECTORY"/../mex/matlab/win64-9.4-9.6
+}
+
+# Create Windows DLL binaries for Octave/MinGW (32bit)
+build_windows_octave_mex_32 ()
+{
+    mkdir -p "$TMP_DIRECTORY"/octave-32/
+    cd "$TMP_DIRECTORY"/octave-32/
+    "$ROOT_DIRECTORY"/../mex/build/octave/configure \
+                     --host=i686-w64-mingw32 \
+                     --with-gsl="$LIB32"/Gsl \
+                     --with-matio="$LIB32"/matIO \
+                     --with-slicot="$LIB32"/Slicot/with-underscore \
+                     MKOCTFILE="$ROOT_DIRECTORY"/deps/mkoctfile32 \
+                     PACKAGE_VERSION="$VERSION" \
+                     PACKAGE_STRING="dynare $VERSION"
+    make -j"$NTHREADS" all
+    i686-w64-mingw32-strip -- **/*.mex
+    mkdir -p "$ROOT_DIRECTORY"/../mex/octave/win32
+    mv -- **/*.mex "$ROOT_DIRECTORY"/../mex/octave/win32
+}
+
+# Create Windows DLL binaries for Octave/MinGW (64bit)
+build_windows_octave_mex_64 ()
+{
+    mkdir -p "$TMP_DIRECTORY"/octave-64/
+    cd "$TMP_DIRECTORY"/octave-64/
+    "$ROOT_DIRECTORY"/../mex/build/octave/configure \
+                     --host=x86_64-w64-mingw32 \
+                     --with-gsl="$LIB64"/Gsl \
+                     --with-matio="$LIB64"/matIO \
+                     --with-slicot="$LIB64"/Slicot/with-underscore \
+                     MKOCTFILE="$ROOT_DIRECTORY"/deps/mkoctfile64 \
+                     PACKAGE_VERSION="$VERSION" \
+                     PACKAGE_STRING="dynare $VERSION"
+    make -j"$NTHREADS" all
+    x86_64-w64-mingw32-strip -- **/*.mex
+    mkdir -p "$ROOT_DIRECTORY"/../mex/octave/win64
+    mv -- **/*.mex "$ROOT_DIRECTORY"/../mex/octave/win64
+}
+
+## Actually build the MEX files
+
+TASKS=(build_windows_matlab_mex_32 build_windows_matlab_mex_64_a build_windows_matlab_mex_64_b build_windows_octave_mex_32 build_windows_octave_mex_64)
+# Reset the number of threads. The mex files for MATLAB/Octave (32-bit and 64-bit) will be built
+# in parallel, so we need to account for the number of tasks and lower the value of NTHREADS.
+NTHREADS=$((NTHREADS/${#TASKS[@]}))
+[[ $NTHREADS -ge 1 ]] || NTHREADS=1 # Ensure that there is at least 1 thread
+# Build all the mex files (parallel).
+# Some variables and functions need to be available in subshells.
+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
+    if [[ "$line" =~ OCTAVE_VERSION[[:space:]]*=[[:space:]]*([^[:space:]]+) ]]; then
+        OCTAVE_VERSION=${BASH_REMATCH[1]}
+        break
+    fi
+done < "$ROOT_DIRECTORY"/deps/versions.mk
+[[ -n $OCTAVE_VERSION ]] || { echo "Can't find OCTAVE_VERSION in versions.mk" >&2; exit 1; }
+# shellcheck disable=SC1117
+echo -e "function v = supported_octave_version\nv=\"${OCTAVE_VERSION}\";\nend" > ../matlab/supported_octave_version.m
+
+## Create Windows installer
+makensis -DVERSION="$VERSION" dynare.nsi
+mkdir -p exe
+mv dynare-"$VERSION"-win.exe "$ROOT_DIRECTORY"/exe/"$BASENAME"-win.exe
+
+## Create .zip file (for those people that are not allowed to download/execute the installer)
+
+# Set name of the root directory in the ZIP archive
+ZIPNAME=dynare-$VERSION
+ZIPDIR="$TMP_DIRECTORY"/"$ZIPNAME"
+mkdir -p "$ZIPDIR"
+
+cd ..
+cp -p NEWS "$ZIPDIR"
+cp -p VERSION "$ZIPDIR"
+cp -p license.txt "$ZIPDIR"
+cp -p windows/README.txt "$ZIPDIR"
+cp -pr windows/deps/mingw32 "$ZIPDIR"
+cp -pr windows/deps/mingw64 "$ZIPDIR"
+mkdir -p "$ZIPDIR"/contrib/ms-sbvar/TZcode
+cp -pr contrib/ms-sbvar/TZcode/MatlabFiles "$ZIPDIR"/contrib/ms-sbvar/TZcode
+mkdir -p "$ZIPDIR"/contrib/jsonlab
+cp -pr contrib/jsonlab/* "$ZIPDIR"/contrib/jsonlab
+mkdir "$ZIPDIR"/mex
+cp -pr mex/octave/ "$ZIPDIR"/mex
+cp -pr mex/matlab/ "$ZIPDIR"/mex
+cp -pr matlab "$ZIPDIR"
+cp -pr examples "$ZIPDIR"
+cp -pr scripts "$ZIPDIR"
+mkdir "$ZIPDIR"/dynare++
+cp -p dynare++/src/dynare++.exe "$ZIPDIR"/dynare++
+mkdir -p "$ZIPDIR"/doc/dynare++
+mkdir -p "$ZIPDIR"/doc/dynare-manual.html
+cp -pr doc/manual/build/html/* "$ZIPDIR"/doc/dynare-manual.html
+cp -p doc/*.pdf "$ZIPDIR"/doc
+cp -p doc/manual/build/latex/dynare-manual.pdf "$ZIPDIR"/doc
+cp -p preprocessor/doc/macroprocessor/macroprocessor.pdf "$ZIPDIR"/doc
+cp -p doc/parallel/parallel.pdf "$ZIPDIR"/doc
+cp -p preprocessor/doc/preprocessor/preprocessor.pdf "$ZIPDIR"/doc
+cp -p doc/gsa/gsa.pdf "$ZIPDIR"/doc
+cp -p dynare++/doc/*.pdf "$ZIPDIR"/doc/dynare++
+
+mkdir -p "$ROOT_DIRECTORY"/zip
+cd "$TMP_DIRECTORY"
+zip -9 -r "$ROOT_DIRECTORY"/zip/"$BASENAME"-win.zip "$ZIPNAME"
diff --git a/windows/deps/Makefile b/windows/deps/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..f296bbeca0a19157430516699efb0462ebc3a843
--- /dev/null
+++ b/windows/deps/Makefile
@@ -0,0 +1,453 @@
+# Copyright © 2017-2019 Dynare Team
+#
+# This file is part of Dynare.
+#
+# Dynare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Dynare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
+
+include versions.mk
+
+ROOT_PATH = $(realpath .)
+
+WGET_OPTIONS := --no-verbose --no-use-server-timestamps --retry-connrefused --retry-on-host-error
+
+.PHONY: clean-openblas-src clean-openblas-tar clean-openblas-all clean-libopenblas \
+	clean-boost-src clean-boost-tar clean-boost-all clean-libboost \
+	clean-gsl-src clean-gsl-tar clean-gsl-all clean-libgsl\
+	clean-slicot-src clean-slicot-tar clean-slicot-all clean-libslicot \
+	clean-matio-src clean-matio-tar clean-matio-all clean-libmatio\
+	clean-zlib-src clean-zlib-tar clean-zlib-src clean-libzlib\
+	clean-src clean-all clean-lib clean-tar \
+	build build-openblas build-slicot build-matio build-boost build-gsl \
+	octave matlab mingw
+
+all: build octave matlab mingw
+
+build: build-openblas build-slicot build-matio build-boost build-gsl
+
+clean-lib: clean-libopenblas clean-libgsl clean-libzlib clean-libmatio clean-libslicot clean-libboost clean-matlab clean-octave clean-mingw
+
+clean-src: clean-openblas-src clean-boost-src clean-gsl-src clean-matio-src clean-slicot-src clean-zlib-src
+
+clean-tar: clean-openblas-tar clean-boost-tar clean-gsl-tar clean-matio-tar clean-slicot-tar clean-zlib-tar
+
+clean-all: clean-lib clean-src clean-tar
+
+#
+# OpenBLAS library
+#
+
+tarballs/openblas-${OPENBLAS_VERSION}.tar.gz:
+	mkdir -p tarballs
+	wget $(WGET_OPTIONS) -O $@ https://github.com/xianyi/OpenBLAS/archive/v${OPENBLAS_VERSION}.tar.gz
+
+sources32/OpenBLAS-${OPENBLAS_VERSION}: tarballs/openblas-${OPENBLAS_VERSION}.tar.gz
+	mkdir -p sources32
+	tar xf $< --directory sources32
+	patch $@/Makefile.rule < patches/openblas-w32.patch
+
+sources64/OpenBLAS-${OPENBLAS_VERSION}: tarballs/openblas-${OPENBLAS_VERSION}.tar.gz
+	mkdir -p sources64
+	tar xf $< --directory sources64
+	patch $@/Makefile.rule < patches/openblas-w64.patch
+
+lib32/OpenBLAS/libopenblas.a: sources32/OpenBLAS-${OPENBLAS_VERSION}
+	make -C $<
+	i686-w64-mingw32-strip --strip-debug $</libopenblasp-r${OPENBLAS_VERSION}.a
+	mkdir -p $(dir $@)
+	cp $</libopenblasp-r${OPENBLAS_VERSION}.a $@
+
+lib64/OpenBLAS/libopenblas.a: sources64/OpenBLAS-${OPENBLAS_VERSION}
+	make -C $<
+	x86_64-w64-mingw32-strip --strip-debug $</libopenblasp-r${OPENBLAS_VERSION}.a
+	mkdir -p $(dir $@)
+	cp $</libopenblasp-r${OPENBLAS_VERSION}.a $@
+
+build-openblas: lib32/OpenBLAS/libopenblas.a lib64/OpenBLAS/libopenblas.a
+
+clean-openblas-tar:
+	rm -f tarballs/openblas-${OPENBLAS_VERSION}.tar.gz
+
+clean-openblas-src:
+	rm -rf sources32/OpenBLAS-${OPENBLAS_VERSION}
+	rm -rf sources64/OpenBLAS-${OPENBLAS_VERSION}
+
+clean-libopenblas:
+	rm -rf lib32/OpenBLAS
+	rm -rf lib64/OpenBLAS
+
+clean-openblas-all: clean-openblas-src clean-openblas-tar clean-libopenblas
+
+#
+# Boost library
+#
+
+tarballs/boost_${BOOST_VERSION}.tar.bz2:
+	mkdir -p tarballs
+	wget $(WGET_OPTIONS) -O $@ https://dl.bintray.com/boostorg/release/$(subst _,.,${BOOST_VERSION})/source/$(notdir $@)
+
+sources32/boost_${BOOST_VERSION}: tarballs/boost_${BOOST_VERSION}.tar.bz2
+	mkdir -p sources32
+	tar xf $< --directory sources32
+	echo "using gcc : mingw : i686-w64-mingw32-g++ ;" > $@/user-config.jam
+
+sources64/boost_${BOOST_VERSION}: tarballs/boost_${BOOST_VERSION}.tar.bz2
+	mkdir -p sources64
+	tar xf $< --directory sources64
+	echo "using gcc : mingw : x86_64-w64-mingw32-g++ ;" > $@/user-config.jam
+
+lib32/Boost: sources32/boost_${BOOST_VERSION}
+	rm -rf lib32/Boost
+	cd $< && ./bootstrap.sh --with-libraries=system,filesystem --prefix=${ROOT_PATH}/lib32/Boost && ./b2 -a -q --user-config=user-config.jam toolset=gcc-mingw target-os=windows address-model=32 variant=release install
+
+lib64/Boost: sources64/boost_${BOOST_VERSION}
+	rm -rf lib64/Boost
+	cd $< && ./bootstrap.sh --with-libraries=system,filesystem --prefix=${ROOT_PATH}/lib64/Boost && ./b2 -a -q --user-config=user-config.jam toolset=gcc-mingw target-os=windows address-model=64 variant=release install
+
+build-boost: lib32/Boost lib64/Boost
+
+clean-boost-tar:
+	rm -f tarballs/boost_${BOOST_VERSION}.tar.bz2
+
+clean-boost-src:
+	rm -rf sources32/boost_${BOOST_VERSION}
+	rm -rf sources64/boost_${BOOST_VERSION}
+
+clean-libboost:
+	rm -rf lib32/Boost
+	rm -rf lib64/Boost
+
+clean-boost-all: clean-boost-src clean-boost-tar clean-libboost
+
+#
+# Gsl
+#
+
+tarballs/gsl-${GSL_VERSION}.tar.gz:
+	mkdir -p tarballs
+	wget $(WGET_OPTIONS) -O $@ https://ftp.gnu.org/gnu/gsl/$(notdir $@)
+
+sources32/gsl-${GSL_VERSION}: tarballs/gsl-${GSL_VERSION}.tar.gz
+	mkdir -p sources32
+	tar xf $< --directory sources32
+
+sources64/gsl-${GSL_VERSION}: tarballs/gsl-${GSL_VERSION}.tar.gz
+	mkdir -p sources64
+	tar xf $< --directory sources64
+
+lib32/Gsl/lib/libgsl.a: sources32/gsl-${GSL_VERSION}
+	rm -rf lib32/Gsl
+	cd $< && ./configure --host=i686-w64-mingw32 --prefix=${ROOT_PATH}/lib32/Gsl --disable-shared --enable-static && make && make install
+
+lib64/Gsl/lib/libgsl.a: sources64/gsl-${GSL_VERSION}
+	rm -rf lib64/Gsl
+	cd $< && ./configure --host=x86_64-w64-mingw32 --prefix=${ROOT_PATH}/lib64/Gsl --disable-shared --enable-static && make && make install
+
+build-gsl: lib32/Gsl/lib/libgsl.a lib64/Gsl/lib/libgsl.a
+
+clean-gsl-tar:
+	rm -f tarballs/gsl-${GSL_VERSION}.tar.gz
+
+clean-gsl-src:
+	rm -rf sources32/gsl-${GSL_VERSION}
+	rm -rf sources64/gsl-${GSL_VERSION}
+
+clean-libgsl:
+	rm -rf lib32/Gsl
+	rm -rf lib64/Gsl
+
+clean-gsl-all: clean-gsl-src clean-gsl-tar clean-libgsl
+
+#
+# matIO
+#
+
+tarballs/matio-${MATIO_VERSION}.tar.gz:
+	mkdir -p tarballs
+	wget $(WGET_OPTIONS) -O $@ https://sourceforge.net/projects/matio/files/matio/${MATIO_VERSION}/$(notdir $@)/download
+
+sources32/matio-${MATIO_VERSION}: tarballs/matio-${MATIO_VERSION}.tar.gz
+	mkdir -p sources32
+	tar xf $< --directory sources32
+	touch $@
+
+sources64/matio-${MATIO_VERSION}: tarballs/matio-${MATIO_VERSION}.tar.gz
+	mkdir -p sources64
+	tar xf $< --directory sources64
+	touch $@
+
+# The "ac_cv_va_copy=C99" argument is a workaround for https://github.com/tbeu/matio/issues/78
+
+lib32/matIO/lib/libmatio.a: sources32/matio-${MATIO_VERSION} lib32/Zlib/lib/libz.a
+	rm -rf lib32/matIO
+	cd $< && ./configure --host=i686-w64-mingw32 --disable-shared --with-zlib=${ROOT_PATH}/lib32/Zlib --prefix=${ROOT_PATH}/lib32/matIO ac_cv_va_copy=C99 && make install
+	ln -sf ${ROOT_PATH}/lib32/Zlib/include/zconf.h ${ROOT_PATH}/lib32/matIO/include/zconf.h
+	ln -sf ${ROOT_PATH}/lib32/Zlib/include/zlib.h ${ROOT_PATH}/lib32/matIO/include/zlib.h
+	ln -sf ${ROOT_PATH}/lib32/Zlib/lib/libz.a ${ROOT_PATH}/lib32/matIO/lib/libz.a
+
+lib64/matIO/lib/libmatio.a: sources64/matio-${MATIO_VERSION} lib64/Zlib/lib/libz.a
+	rm -rf lib64/matIO
+	cd $< && ./configure --host=x86_64-w64-mingw32 --disable-shared --with-zlib=${ROOT_PATH}/lib64/Zlib --prefix=${ROOT_PATH}/lib64/matIO ac_cv_va_copy=C99 && make install
+	ln -sf ${ROOT_PATH}/lib64/Zlib/include/zconf.h ${ROOT_PATH}/lib64/matIO/include/zconf.h
+	ln -sf ${ROOT_PATH}/lib64/Zlib/include/zlib.h ${ROOT_PATH}/lib64/matIO/include/zlib.h
+	ln -sf ${ROOT_PATH}/lib64/Zlib/lib/libz.a ${ROOT_PATH}/lib64/matIO/lib/libz.a
+
+build-matio: build-zlib lib32/matIO/lib/libmatio.a lib64/matIO/lib/libmatio.a
+
+clean-matio-tar:
+	rm -f tarballs/matio-${MATIO_VERSION}.tar.gz
+
+clean-matio-src:
+	rm -rf sources32/matio-${MATIO_VERSION}
+	rm -rf sources64/matio-${MATIO_VERSION}
+
+clean-libmatio:
+	rm -rf lib32/matIO
+	rm -rf lib64/matIO
+
+clean-matio-all: clean-matio-src clean-matio-tar clean-libmatio
+
+#
+# Slicot
+#
+
+tarballs/slicot-$(SLICOT_VERSION).tar.gz:
+	mkdir -p tarballs
+	wget $(WGET_OPTIONS) -O $@ https://deb.debian.org/debian/pool/main/s/slicot/slicot_$(SLICOT_VERSION).orig.tar.gz
+
+sources32/slicot-$(SLICOT_VERSION)-without-underscore: tarballs/slicot-$(SLICOT_VERSION).tar.gz
+	mkdir -p $@
+	tar xf $< --directory $@ --strip-components=1
+	patch $@/make.inc < patches/slicot-32-without-underscore.patch
+
+sources32/slicot-$(SLICOT_VERSION)-with-underscore: tarballs/slicot-$(SLICOT_VERSION).tar.gz
+	mkdir -p $@
+	tar xf $< --directory $@ --strip-components=1
+	patch $@/make.inc < patches/slicot-32-with-underscore.patch
+
+sources64/slicot-$(SLICOT_VERSION)-with-32bit-integer: tarballs/slicot-$(SLICOT_VERSION).tar.gz
+	mkdir -p $@
+	tar xf $< --directory $@ --strip-components=1
+	patch $@/make.inc < patches/slicot-64-with-32bit-integer.patch
+
+sources64/slicot-$(SLICOT_VERSION)-with-64bit-integer: tarballs/slicot-$(SLICOT_VERSION).tar.gz
+	mkdir -p $@
+	tar xf $< --directory $@ --strip-components=1
+	patch $@/make.inc < patches/slicot-64-with-64bit-integer.patch
+
+sources64/slicot-$(SLICOT_VERSION)-with-32bit-integer-and-underscore: tarballs/slicot-$(SLICOT_VERSION).tar.gz
+	mkdir -p $@
+	tar xf $< --directory $@ --strip-components=1
+	patch $@/make.inc < patches/slicot-64-with-32bit-integer-and-underscore.patch
+
+sources64/slicot-$(SLICOT_VERSION)-with-64bit-integer-and-underscore: tarballs/slicot-$(SLICOT_VERSION).tar.gz
+	mkdir -p $@
+	tar xf $< --directory $@ --strip-components=1
+	patch $@/make.inc < patches/slicot-64-with-64bit-integer-and-underscore.patch
+
+lib32/Slicot/without-underscore/lib/libslicot_pic.a: sources32/slicot-$(SLICOT_VERSION)-without-underscore
+	make -C $< lib
+	i686-w64-mingw32-strip --strip-debug $</libslicot_pic.a
+	mkdir -p $(dir $@)
+	cp $</libslicot_pic.a $@
+
+lib32/Slicot/with-underscore/lib/libslicot_pic.a: sources32/slicot-$(SLICOT_VERSION)-with-underscore
+	make -C $< lib
+	i686-w64-mingw32-strip --strip-debug $</libslicot_pic.a
+	mkdir -p $(dir $@)
+	cp $</libslicot_pic.a $@
+
+lib64/Slicot/without-underscore/lib/libslicot_pic.a: sources64/slicot-$(SLICOT_VERSION)-with-32bit-integer
+	make -C $< lib
+	x86_64-w64-mingw32-strip --strip-debug $</libslicot_pic.a
+	mkdir -p $(dir $@)
+	cp $</libslicot_pic.a $@
+
+lib64/Slicot/without-underscore/lib/libslicot64_pic.a: sources64/slicot-$(SLICOT_VERSION)-with-64bit-integer
+	make -C $< lib
+	x86_64-w64-mingw32-strip --strip-debug $</libslicot64_pic.a
+	mkdir -p $(dir $@)
+	cp $</libslicot64_pic.a $@
+
+lib64/Slicot/with-underscore/lib/libslicot_pic.a: sources64/slicot-$(SLICOT_VERSION)-with-32bit-integer-and-underscore
+	make -C $< lib
+	x86_64-w64-mingw32-strip --strip-debug $</libslicot_pic.a
+	mkdir -p $(dir $@)
+	cp $</libslicot_pic.a $@
+
+lib64/Slicot/with-underscore/lib/libslicot64_pic.a: sources64/slicot-$(SLICOT_VERSION)-with-64bit-integer-and-underscore
+	make -C $< lib
+	x86_64-w64-mingw32-strip --strip-debug $</libslicot64_pic.a
+	mkdir -p $(dir $@)
+	cp $</libslicot64_pic.a $@
+
+build-slicot: lib32/Slicot/without-underscore/lib/libslicot_pic.a \
+	lib32/Slicot/with-underscore/lib/libslicot_pic.a \
+	lib64/Slicot/without-underscore/lib/libslicot_pic.a \
+	lib64/Slicot/without-underscore/lib/libslicot64_pic.a \
+	lib64/Slicot/with-underscore/lib/libslicot_pic.a \
+	lib64/Slicot/with-underscore/lib/libslicot64_pic.a
+
+clean-slicot-tar:
+	rm -f tarballs/slicot-$(SLICOT_VERSION).tar.gz
+
+clean-slicot-src:
+	rm -rf sources32/slicot-$(SLICOT_VERSION)-with-underscore
+	rm -rf sources32/slicot-$(SLICOT_VERSION)-without-underscore
+	rm -rf sources64/slicot-$(SLICOT_VERSION)-with-32bit-integer
+	rm -rf sources64/slicot-$(SLICOT_VERSION)-with-64bit-integer
+	rm -rf sources64/slicot-$(SLICOT_VERSION)-with-32bit-integer-and-underscore
+	rm -rf sources64/slicot-$(SLICOT_VERSION)-with-64bit-integer-and-underscore
+
+clean-libslicot:
+	rm -rf lib64/Slicot
+	rm -rf lib32/Slicot
+
+clean-slicot-all: clean-slicot-src clean-slicot-tar clean-libslicot
+
+#
+# Zlib
+#
+
+tarballs/zlib-${ZLIB_VERSION}.tar.xz:
+	mkdir -p tarballs
+	wget $(WGET_OPTIONS) -O $@ https://zlib.net/$(notdir $@)
+
+sources32/zlib-${ZLIB_VERSION}: tarballs/zlib-${ZLIB_VERSION}.tar.xz
+	mkdir -p sources32
+	tar xf $< --directory sources32
+	touch $@
+
+sources64/zlib-${ZLIB_VERSION}: tarballs/zlib-${ZLIB_VERSION}.tar.xz
+	mkdir -p sources64
+	tar xf $< --directory sources64
+	touch $@
+
+lib32/Zlib/lib/libz.a: sources32/zlib-${ZLIB_VERSION}
+	rm -rf lib32/Zlib
+	cd $< && CC=i686-w64-mingw32-gcc ./configure --static --prefix=${ROOT_PATH}/lib32/Zlib && make install
+
+lib64/Zlib/lib/libz.a: sources64/zlib-${ZLIB_VERSION}
+	rm -rf lib64/Zlib
+	cd $< && CC=x86_64-w64-mingw32-gcc ./configure --static --prefix=${ROOT_PATH}/lib64/Zlib && make install
+
+build-zlib: lib32/Zlib/lib/libz.a lib64/Zlib/lib/libz.a
+
+clean-zlib-tar:
+	rm -f tarballs/zlib-${ZLIB_VERSION}.tar.xz
+
+clean-zlib-src:
+	rm -rf sources32/zlib-${ZLIB_VERSION}
+	rm -rf sources64/zlib-${ZLIB_VERSION}
+
+clean-libzlib:
+	rm -rf lib32/Zlib
+	rm -rf lib64/Zlib
+
+clean-zlib-all: clean-zlib-src clean-zlib-tar clean-libzlib
+
+#
+# Octave
+#
+
+tarballs/octave-${OCTAVE_VERSION}-w32${OCTAVE_W32_BUILD}.7z:
+	mkdir -p tarballs
+	wget $(WGET_OPTIONS) -O $@ https://ftp.gnu.org/gnu/octave/windows/$(notdir $@)
+
+tarballs/octave-${OCTAVE_VERSION}-w64${OCTAVE_W64_BUILD}.7z:
+	mkdir -p tarballs
+	wget $(WGET_OPTIONS) -O $@ https://ftp.gnu.org/gnu/octave/windows/$(notdir $@)
+
+lib32/octave/mingw32/octave-cli.exe: tarballs/octave-${OCTAVE_VERSION}-w32${OCTAVE_W32_BUILD}.7z
+	rm -rf lib32/octave
+	7zr x -olib32 $< > /dev/null
+	mv lib32/octave-${OCTAVE_VERSION}-w32 lib32/octave
+	# Clean up MinGW stuff that interferes with our cross-compiler
+	cd lib32/octave/mingw32/lib && rm -f libadvapi32.a libkernel32.a libmingw32.a libmingwex.a libmoldname.a libmsvcrt.a libpthread.dll.a libshell32.a libuser32.a
+	cd lib32/octave/mingw32/include && rm -f $$(grep -l "This file is part of the mingw-w64 runtime package" *.h)
+	touch $@
+
+lib64/octave/mingw64/octave-cli.exe: tarballs/octave-${OCTAVE_VERSION}-w64${OCTAVE_W64_BUILD}.7z
+	rm -rf lib64/octave
+	7zr x -olib64 $< > /dev/null
+	mv lib64/octave-${OCTAVE_VERSION}-w64 lib64/octave
+	# Clean up MinGW stuff that interferes with our cross-compiler
+	cd lib64/octave/mingw64/lib && rm -f libadvapi32.a libkernel32.a libmingw32.a libmingwex.a libmoldname.a libmsvcrt.a libpthread.dll.a libshell32.a libuser32.a
+	cd lib64/octave/mingw64/include && rm -f $$(grep -l "This file is part of the mingw-w64 runtime package" *.h)
+	touch $@
+
+octave: lib32/octave/mingw32/octave-cli.exe lib64/octave/mingw64/octave-cli.exe
+
+clean-octave:
+	rm -rf lib32/octave
+	rm -rf lib64/octave
+	rm -f tarballs/octave-${OCTAVE_VERSION}-w64${OCTAVE_W64_BUILD}.7z
+	rm -f tarballs/octave-${OCTAVE_VERSION}-w32${OCTAVE_W32_BUILD}.7z
+
+#
+# MATLAB
+#
+
+tarballs/matlab%.tar.xz:
+	mkdir -p tarballs
+	wget $(WGET_OPTIONS) -O $@.gpg https://www.dynare.org/windows-pkg-build/$(notdir $@).gpg
+	gpg --output $@ --decrypt $@.gpg
+	rm $@.gpg
+
+lib32/matlab/R2009b/bin/win32/MATLAB.exe: tarballs/matlab32-$(MATLAB32_VERSION).tar.xz
+	rm -rf lib32/matlab
+	mkdir -p lib32/matlab
+	tar xf $< --directory lib32/matlab --strip-components=1
+	touch $@
+
+lib64/matlab/R2009b/bin/win64/MATLAB.exe: tarballs/matlab64-$(MATLAB64_VERSION).tar.xz
+	rm -rf lib64/matlab
+	mkdir -p lib64/matlab
+	tar xf $< --directory lib64/matlab --strip-components=1
+	touch $@
+
+matlab: lib32/matlab/R2009b/bin/win32/MATLAB.exe lib64/matlab/R2009b/bin/win64/MATLAB.exe
+
+clean-matlab:
+	rm -f tarballs/matlab32.tar.xz
+	rm -f tarballs/matlab64.tar.xz
+	rm -rf lib32/matlab
+	rm -rf lib64/matlab
+
+#
+# Embedded MinGW (for use_dll)
+#
+
+mingw: mingw32 mingw64
+
+mingw32: tarballs/mingw-w64-i686-gcc-$(MINGW32_GCC_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-i686-gmp-$(MINGW32_GMP_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-i686-binutils-$(MINGW32_BINUTILS_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-i686-headers-git-$(MINGW32_HEADERS_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-i686-crt-git-$(MINGW32_CRT_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-i686-winpthreads-git-$(MINGW32_WINPTHREADS_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-i686-libwinpthread-git-$(MINGW32_LIBWINPTHREAD_VERSION)-any.pkg.tar.xz
+	rm -rf $@
+	for f in $^; do tar xf $$f; done
+	touch $@
+
+mingw64: tarballs/mingw-w64-x86_64-gcc-$(MINGW64_GCC_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-x86_64-gmp-$(MINGW64_GMP_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-x86_64-binutils-$(MINGW64_BINUTILS_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-x86_64-headers-git-$(MINGW64_HEADERS_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-x86_64-crt-git-$(MINGW64_CRT_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-x86_64-winpthreads-git-$(MINGW64_WINPTHREADS_VERSION)-any.pkg.tar.xz tarballs/mingw-w64-x86_64-libwinpthread-git-$(MINGW64_LIBWINPTHREAD_VERSION)-any.pkg.tar.xz
+	rm -rf $@
+	for f in $^; do tar xf $$f; done
+	touch $@
+
+tarballs/mingw-w64-i686-%-any.pkg.tar.xz:
+	wget $(WGET_OPTIONS) -O $@ http://repo.msys2.org/mingw/i686/$(notdir $@)
+
+tarballs/mingw-w64-x86_64-%-any.pkg.tar.xz:
+	wget $(WGET_OPTIONS) -O $@ http://repo.msys2.org/mingw/x86_64/$(notdir $@)
+
+clean-mingw:
+	rm -rf mingw32
+	rm -rf mingw64
+	rm -f tarballs/mingw-w64-i686-*.tar.xz
+	rm -f tarballs/mingw-w64-x86_64-*.tar.xz
diff --git a/windows/deps/mkoctfile32 b/windows/deps/mkoctfile32
new file mode 100755
index 0000000000000000000000000000000000000000..a8bfe42224e78a529663b8b2effb1e27abab0260
--- /dev/null
+++ b/windows/deps/mkoctfile32
@@ -0,0 +1,541 @@
+#! /bin/sh
+
+## Attention à garder -static-libgcc et -static-libstdc++ dans LDFLAGS et
+## DL_LDFLAGS lors des mises à jour de ce fichier
+## Garder aussi BINDIR dans DEFAULT_LFLAGS (pour UMFPACK)
+
+# Exit immediately on any error.
+set -e
+
+: ${SED="/bin/sed"}
+
+# Get path to the mkoctfile shell script
+MKOCTFILE_PATH=$(dirname $(readlink -f "$0"))
+OCTAVE_PREFIX="$MKOCTFILE_PATH/lib32/octave/mingw32"
+
+# Get Octave version
+current_octave_version=$(grep "^OCTAVE_VERSION" "$MKOCTFILE_PATH/versions.mk")
+eval $(echo "$current_octave_version" | tr -d '[:space:]')
+
+DEFAULT_BINDIR="$OCTAVE_PREFIX/bin"
+DEFAULT_INCLUDEDIR="$OCTAVE_PREFIX/include"
+DEFAULT_LIBDIR="$OCTAVE_PREFIX/lib"
+DEFAULT_OCTINCLUDEDIR="$OCTAVE_PREFIX/include/octave-${OCTAVE_VERSION}/octave"
+DEFAULT_OCTLIBDIR="$OCTAVE_PREFIX/lib/octave/${OCTAVE_VERSION}"
+
+if [ -n "$OCTAVE_HOME" ]; then
+  DEFAULT_BINDIR="`echo $DEFAULT_BINDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
+  DEFAULT_INCLUDEDIR="`echo $DEFAULT_INCLUDEDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
+  DEFAULT_LIBDIR="`echo $DEFAULT_LIBDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
+  DEFAULT_OCTINCLUDEDIR="`echo $DEFAULT_OCTINCLUDEDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
+  DEFAULT_OCTLIBDIR="`echo $DEFAULT_OCTLIBDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
+fi
+
+: ${BINDIR=$DEFAULT_BINDIR}
+: ${INCLUDEDIR=$DEFAULT_INCLUDEDIR}
+: ${LIBDIR=$DEFAULT_LIBDIR}
+: ${OCTINCLUDEDIR=$DEFAULT_OCTINCLUDEDIR}
+: ${OCTLIBDIR=$DEFAULT_OCTLIBDIR}
+
+DEFAULT_INCFLAGS="-I$OCTINCLUDEDIR/.. -I$OCTINCLUDEDIR"
+if [ "$INCLUDEDIR" != /usr/include ]; then
+  DEFAULT_INCFLAGS="$DEFAULT_INCFLAGS -I$INCLUDEDIR"
+fi
+
+DEFAULT_LFLAGS="-L$OCTLIBDIR -L$BINDIR"
+if [ "$LIBDIR" != /usr/lib ]; then
+  DEFAULT_LFLAGS="$DEFAULT_LFLAGS -L$LIBDIR"
+fi
+
+# Default values for these variables are filled in when Octave is
+# compiled.
+
+: ${EXEEXT=""}
+
+: ${CPPFLAGS=""}
+: ${INCFLAGS=$DEFAULT_INCFLAGS}
+: ${F77="i686-w64-mingw32-gfortran"}
+: ${FFLAGS="-O"}
+: ${FPICFLAG=""}
+: ${CC="i686-w64-mingw32-gcc"}
+: ${CFLAGS="-g -O2"}
+: ${CPICFLAG=""}
+: ${CXX="i686-w64-mingw32-g++"}
+: ${CXXFLAGS="-g -O2"}
+: ${CXXPICFLAG=""}
+: ${XTRA_CFLAGS=""}
+: ${XTRA_CXXFLAGS=""}
+
+: ${DEPEND_FLAGS="-M"}
+: ${DEPEND_EXTRA_SED_PATTERN=""}
+
+: ${DL_LD="i686-w64-mingw32-g++"}
+: ${DL_LDFLAGS="-shared -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc -static-libgcc -static-libstdc++"}
+
+: ${RLD_FLAG="-Wl,-rpath -Wl,$OCTAVE_PREFIX/lib/octave/${OCTAVE_VERSION}"}
+: ${RDYNAMIC_FLAG="-rdynamic"}
+: ${LIBOCTAVE=-loctave}
+: ${LIBOCTINTERP=-loctinterp}
+: ${READLINE_LIBS=-lreadline}
+: ${LAPACK_LIBS="-llapack"}
+: ${BLAS_LIBS="-lblas"}
+: ${FFTW3_LDFLAGS=""}
+: ${FFTW3_LIBS="-lfftw3"}
+: ${FFTW3F_LDFLAGS=""}
+: ${FFTW3F_LIBS="-lfftw3f"}
+: ${LIBS="-lm -lgfortran -llapack -lgdi32 -lws2_32 -luser32 -lkernel32"}
+: ${FLIBS="-lm -lgfortran -llapack -lmingw32 -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32"}
+: ${LD_CXX="i686-w64-mingw32-g++"}
+: ${LDFLAGS="-Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc-v2 -Wl,--allow-multiple-definition -static-libgcc -static-libstdc++"}
+: ${LD_STATIC_FLAG=""}
+: ${LFLAGS=$DEFAULT_LFLAGS}
+: ${F77_INTEGER_8_FLAG=""}
+
+: ${ALL_FFLAGS="$FFLAGS $F77_INTEGER_8_FLAG"}
+
+: ${ALL_CFLAGS="$INCFLAGS $XTRA_CFLAGS $CFLAGS"}
+
+: ${ALL_CXXFLAGS="$INCFLAGS $XTRA_CXXFLAGS $CXXFLAGS"}
+
+: ${ALL_LDFLAGS="$LD_STATIC_FLAG $CPICFLAG $LDFLAGS"}
+
+: ${OCTAVE_LIBS="$LIBOCTINTERP $LIBOCTAVE $SPECIAL_MATH_LIB"}
+
+# Local variables.
+
+FFTW_LIBS="$FFTW3_LDFLAGS $FFTW3_LIBS $FFTW3F_LDFLAGS $FFTW3F_LIBS"
+
+usage_msg="usage: mkoctfile [options] file ..."
+
+version_msg="mkoctfile, version $OCTAVE_VERSION"
+
+cfiles=
+ccfiles=
+f77files=
+objfiles=
+libfiles=
+octfiles=
+octfile=
+outputfile=
+incflags=
+defs=
+ldflags=
+dbg=:
+pass_on_options=
+strip=false
+no_oct_file_strip_on_this_platform=false
+link=true
+link_stand_alone=false
+output_ext=".oct"
+depend=false
+compile=true
+
+if [ $# -eq 0 ]; then
+  echo $usage_msg 1>&2
+  exit 1
+fi
+
+if [ $# -eq 1 ]; then
+  case "$1" in
+    -v | -version | --version)
+      echo $version_msg 1>&2
+      exit 0
+    ;;
+  esac
+fi
+
+while [ $# -gt 0 ]; do
+  file=
+  case "$1" in
+    *.c)
+      file=$1
+      cfiles="$cfiles $file"
+    ;;
+    *.cc | *.C | *.cpp)
+      file=$1
+      ccfiles="$ccfiles $file"
+    ;;
+    *.f | *.F | *.f90 | *.F90)
+      file=$1
+      f77files="$f77files $file"
+    ;;
+    *.o)
+      file=$1
+      objfiles="$objfiles $file"
+    ;;
+    *.a)
+      file=$1
+      libfiles="$libfiles $file"
+    ;;
+    -d | -debug | --debug | -v | -verbose | --verbose)
+      dbg=echo
+    ;;
+    -h | -\? | -help | --help)
+      echo $usage_msg 1>&2
+      cat << EOF
+
+Options:
+
+  -h, -?, --help          Print this message.
+
+  -IDIR                   Add -IDIR to compile commands.
+
+  -idirafter DIR          Add -idirafter DIR to compile commands.
+
+  -DDEF                   Add -DDEF to compile commands.
+
+  -lLIB                   Add -lLIB to link command.
+
+  -LDIR                   Add -LDIR to link command.
+
+  -RDIR                   Add -RDIR to link command.
+
+  -g                      Enable debugging option for all compilers.
+
+  -pthread                Add -pthread to link command.
+
+  -W...                   Pass flags to the compiler such as -Wa,OPTION.
+
+  -Wl,...                 Pass flags to the linker such as -Wl,-rpath=...
+
+  -M, --depend            Generate dependency files (.d) for C and C++
+                          source files.
+
+  -c, --compile           Compile, but do not link.
+
+  --link-stand-alone      Link a stand-alone executable file.
+
+  -s, --strip             Strip output file.
+
+  --mex                   Create a MEX file.  
+                          Set the default output extension to ".mex".
+
+  -o FILE, --output FILE  Output file name.  Default extension is .oct
+                          (or .mex if --mex is specified) unless linking
+                          a stand-alone executable.
+
+  -p VAR, --print VAR     Print configuration variable VAR.  Recognized
+                          variables are:
+
+                            ALL_CFLAGS                FFTW3F_LDFLAGS
+                            ALL_CXXFLAGS              FFTW3F_LIBS
+                            ALL_FFLAGS                FLIBS
+                            ALL_LDFLAGS               FPICFLAG
+                            BLAS_LIBS                 INCFLAGS
+                            CC                        LAPACK_LIBS
+                            CFLAGS                    LDFLAGS
+                            CPICFLAG                  LD_CXX
+                            CPPFLAGS                  LD_STATIC_FLAG
+                            CXX                       LFLAGS
+                            CXXFLAGS                  LIBCRUFT
+                            CXXPICFLAG                LIBOCTAVE
+                            DEPEND_EXTRA_SED_PATTERN  LIBOCTINTERP
+                            DEPEND_FLAGS              LIBS
+                            DL_LD                     OCTAVE_LIBS
+                            DL_LDFLAGS                RDYNAMIC_FLAG
+                            EXEEXT                    READLINE_LIBS
+                            F77                       RLD_FLAG
+                            F77_INTEGER_8_FLAG        SED
+                            FFLAGS                    XTRA_CFLAGS
+                            FFTW3_LDFLAGS             XTRA_CXXFLAGS
+                            FFTW3_LIBS
+
+  -v, --verbose           Echo commands as they are executed.
+
+  FILE                    Compile or link FILE.  Recognized file types are:
+
+                            .c    C source
+                            .cc   C++ source
+                            .C    C++ source
+                            .cpp  C++ source
+                            .f    Fortran source (fixed form)
+                            .F    Fortran source (fixed form)
+                            .f90  Fortran source (free form)
+                            .F90  Fortran source (free form)
+                            .o    object file
+                            .a    library file
+
+EOF
+      exit 0
+    ;;
+    -I*)
+      incflags="$incflags $1"
+    ;;
+    -idirafter)
+      shift
+      if [ $# -gt 0 ]; then
+        incflags="$incflags -idirafter $1"
+      else
+        echo "mkoctfile: include directory name missing" 1>&2
+      fi
+    ;;
+    -D*)
+      defs="$defs $1"
+    ;;
+    -[lLR]* | -Wl,*)
+      ldflags="$ldflags $1"
+    ;;
+    -pthread)
+      ldflags="$ldflags $1"
+    ;;
+    -M | -depend | --depend)
+      depend=true
+      compile=false
+    ;;
+    -o | -ouput | --output)
+      shift
+      if [ $# -gt 0 ]; then
+        outputfile="$1"
+      else
+        echo "mkoctfile: output file name missing" 1>&2
+      fi
+    ;;
+    -p | -print | --print)
+      shift
+      if [ $# -gt 0 ]; then
+        eval echo \${$1}
+        exit 0
+      else
+        echo "mkoctfile: --print requires argument" 1>&2
+        exit 1
+      fi
+    ;;
+    -s | -strip | --strip)
+      if $no_oct_file_strip_on_this_platform; then
+        echo "mkoctfile: stripping disabled on this platform" 1>&2
+      else
+        strip=true
+      fi
+    ;;
+    -c | -compile | --compile)
+      link=false
+    ;;
+    -g)
+      ALL_CFLAGS="$ALL_CFLAGS -g"
+      ALL_CXXFLAGS="$ALL_CXXFLAGS -g"
+      ALL_FFLAGS="$ALL_FFLAGS -g"
+    ;;
+    -link-stand-alone | --link-stand-alone)
+      link_stand_alone=true
+    ;;
+    -mex | --mex)
+      incflags="$incflags -I."
+      output_ext=".mex"
+    ;;
+    -W*)
+      pass_on_options="$pass_on_options $1"
+    ;;
+    *)
+      echo "mkoctfile: unrecognized argument $1" 1>&2
+      exit 1
+    ;;
+  esac
+  if [ -n "$file" ]; then
+    if [ -z "$octfile" ]; then
+      octfile="$file"
+    fi
+  fi
+  shift
+done
+
+if $link_stand_alone; then
+  if [ -n "$outputfile" ]; then
+    output_option="-o $outputfile"
+  fi
+else
+  if [ -n "$outputfile" ]; then
+    octfile="$outputfile"
+    case "$octfile" in
+      *$output_ext)
+      ;;
+      *)
+        octfile="$octfile$output_ext"
+      ;;
+    esac
+  else
+    octfile=`basename $octfile`
+    octfile=`echo $octfile | $SED 's,\.[^.]*$,,'`$output_ext
+  fi
+fi
+
+# Generate dependency files for C and C++ files.
+
+if $depend; then
+  if [ -n "$cfiles" ]; then
+    for f in $cfiles; do
+      b=`echo $f | $SED 's,\.c$,,'`
+      d=$b.d
+      cmd="rm -f $d"
+      $dbg $cmd
+      eval $cmd
+      cmd="$CC $DEPEND_FLAGS $CPPFLAGS $ALL_CFLAGS $incflags $def $f | $SED $DEPEND_EXTRA_SED_PATTERN -e 's,^[^:]*/\(.*\.o\):,\1:,' -e 's,$b\.o,pic/& & $d,g' > $d-t && mv $d-t $d"
+      $dbg $cmd
+      eval $cmd
+    done
+  fi
+
+  if [ -n "$ccfiles" ]; then
+    for f in $ccfiles; do
+      case $f in
+        *.cc)
+          b=`echo $f | $SED 's,\.cc$,,'`
+        ;;
+        *.C)
+          b=`echo $f | $SED 's,\.C$,,'`
+        ;;
+        *.cpp)
+          b=`echo $f | $SED 's,\.cpp$,,'`
+        ;;
+      esac
+      d=$b.d
+      cmd="rm -f $d"
+      $dbg $cmd
+      eval $cmd
+      cmd="$CXX $DEPEND_FLAGS $CPPFLAGS $ALL_CXXFLAGS $incflags $defs $f | $SED $DEPEND_EXTRA_SED_PATTERN -e 's,^[^:]*/\(.*\.o\):,\1:,' -e 's,$b\.o,pic/& & $d,g' > $d-t && mv $d-t $d"
+      $dbg $cmd
+      eval $cmd
+    done
+  fi
+  # If generating dependencies, that's all we do.
+  exit 0
+fi
+
+# Compile Fortran, C, and C++ files.  Add the name of each object file
+# that is produced to the overall list of object files.
+
+if [ -n "$f77files" ]; then
+  for f in $f77files; do
+    case $f in
+      *.f)
+        b=`echo $f | $SED 's,.*/,,; s,\.f$,,'`
+      ;;
+      *.F)
+        b=`echo $f | $SED 's,.*/,,; s,\.F$,,'`
+      ;;
+      *.f90)
+        b=`echo $f | $SED 's,.*/,,; s,\.f90$,,'`
+      ;;
+      *.F90)
+        b=`echo $f | $SED 's,.*/,,; s,\.F90$,,'`
+      ;;
+    esac
+    if [ -n "$F77" ]; then
+      if [ -n "$outputfile" ]; then
+        if $link; then
+          o=$b.o
+        else
+          o=$outputfile
+        fi
+      else
+        o=$b.o
+      fi
+      objfiles="$objfiles $o"
+      cmd="$F77 -c $FPICFLAG $ALL_FFLAGS $incflags $defs $pass_on_options $f -o $o"
+      $dbg $cmd
+      eval $cmd
+    else
+      echo "mkoctfile: no way to compile Fortran file $f" 1>&2
+    fi
+  done
+fi
+
+if [ -n "$cfiles" ]; then
+  for f in $cfiles; do
+    if [ -n  "$CC" ]; then
+      b=`echo $f | $SED 's,.*/,,; s,\.c$,,'`
+      if [ -n "$outputfile" ]; then
+        if $link; then
+          o=$b.o
+        else
+          o=$outputfile
+        fi
+      else
+        o=$b.o
+      fi
+      objfiles="$objfiles $o"
+      cmd="$CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $pass_on_options $incflags $defs $f -o $o"
+      $dbg $cmd
+      eval $cmd
+    else
+      echo "mkoctfile: no way to compile C++ file $f" 1>&2
+    fi
+  done
+fi
+
+if [ -n "$ccfiles" ]; then
+  for f in $ccfiles; do
+    if [ -n "$CXX" ]; then
+      case $f in
+        *.cc)
+          b=`echo $f | $SED 's,.*/,,; s,\.cc$,,'`
+        ;;
+        *.C)
+          b=`echo $f | $SED 's,.*/,,; s,\.C$,,'`
+        ;;
+        *.cpp)
+          b=`echo $f | $SED 's,.*/,,; s,\.cpp$,,'`
+        ;;
+      esac
+      if [ -n "$outputfile" ]; then
+        if $link; then
+          o=$b.o
+        else
+          o=$outputfile
+        fi
+      else
+        o=$b.o
+      fi
+      objfiles="$objfiles $o"
+      cmd="$CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $pass_on_options $incflags $defs $f -o $o"
+      $dbg $cmd
+      eval $cmd
+    else
+      echo "mkoctfile: no way to compile C++ file $f" 1>&2
+    fi
+  done
+fi
+
+## Uncomment the following group of lines if you get `Text file busy'
+## errors from ld.  This may happen if the .oct file is currently
+## running while you are trying to recompile it.  We try moving first,
+## since on some systems (HP-UX, maybe others) it is possible to
+## rename running programs but not remove them.
+
+## if [ -f "$octfile" ]; then
+##   cmd="mv $octfile $octfile.bak"
+##   $dbg $cmd
+##   eval $cmd
+##   cmd="rm -f $octfile.bak"
+##   $dbg $cmd
+##   eval $cmd
+## fi
+
+# Link all the object files.
+
+if $link && [ -n "$objfiles" ]; then
+  if $link_stand_alone; then
+    if [ -n "$LD_CXX" ]; then
+      cmd="$LD_CXX $CPPFLAGS $ALL_CXXFLAGS $RDYNAMIC_FLAG $ALL_LDFLAGS $pass_on_options $output_option $objfiles $libfiles $ldflags $LFLAGS $RLD_FLAG $OCTAVE_LIBS $LAPACK_LIBS $BLAS_LIBS $FFTW_LIBS $READLINE_LIBS $LIBS $FLIBS"
+      $dbg $cmd
+      eval $cmd
+    else
+      echo "mkoctfile: no way to link stand-alone executable file" 1>&2
+      exit 1
+    fi
+  else
+    LINK_DEPS="$LFLAGS $OCTAVE_LIBS $LDFLAGS $LAPACK_LIBS $BLAS_LIBS $FFTW_LIBS $LIBS $FLIBS"
+    cmd="$DL_LD $DL_LDFLAGS $pass_on_options -o $octfile $objfiles $libfiles $ldflags $LINK_DEPS"
+    $dbg $cmd
+    eval $cmd
+  fi
+
+# Maybe strip it.
+
+  if $strip; then
+    cmd="strip $octfile"
+    $dbg $cmd
+    eval $cmd
+  fi
+fi
+
+exit 0
diff --git a/windows/deps/mkoctfile64 b/windows/deps/mkoctfile64
new file mode 100755
index 0000000000000000000000000000000000000000..fed395d2ae5ff35c186f0369a947d0a498f003b6
--- /dev/null
+++ b/windows/deps/mkoctfile64
@@ -0,0 +1,541 @@
+#! /bin/sh
+
+## Attention à garder -static-libgcc et -static-libstdc++ dans LDFLAGS et
+## DL_LDFLAGS lors des mises à jour de ce fichier
+## Garder aussi BINDIR dans DEFAULT_LFLAGS (pour UMFPACK)
+
+# Exit immediately on any error.
+set -e
+
+: ${SED="/bin/sed"}
+
+# Get path to the mkoctfile shell script
+MKOCTFILE_PATH=$(dirname $(readlink -f "$0"))
+OCTAVE_PREFIX="$MKOCTFILE_PATH/lib64/octave/mingw64"
+
+# Get Octave version
+current_octave_version=$(grep "^OCTAVE_VERSION" "$MKOCTFILE_PATH/versions.mk")
+eval $(echo "$current_octave_version" | tr -d '[:space:]')
+
+DEFAULT_BINDIR="$OCTAVE_PREFIX/bin"
+DEFAULT_INCLUDEDIR="$OCTAVE_PREFIX/include"
+DEFAULT_LIBDIR="$OCTAVE_PREFIX/lib"
+DEFAULT_OCTINCLUDEDIR="$OCTAVE_PREFIX/include/octave-${OCTAVE_VERSION}/octave"
+DEFAULT_OCTLIBDIR="$OCTAVE_PREFIX/lib/octave/${OCTAVE_VERSION}"
+
+if [ -n "$OCTAVE_HOME" ]; then
+  DEFAULT_BINDIR="`echo $DEFAULT_BINDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
+  DEFAULT_INCLUDEDIR="`echo $DEFAULT_INCLUDEDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
+  DEFAULT_LIBDIR="`echo $DEFAULT_LIBDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
+  DEFAULT_OCTINCLUDEDIR="`echo $DEFAULT_OCTINCLUDEDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
+  DEFAULT_OCTLIBDIR="`echo $DEFAULT_OCTLIBDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
+fi
+
+: ${BINDIR=$DEFAULT_BINDIR}
+: ${INCLUDEDIR=$DEFAULT_INCLUDEDIR}
+: ${LIBDIR=$DEFAULT_LIBDIR}
+: ${OCTINCLUDEDIR=$DEFAULT_OCTINCLUDEDIR}
+: ${OCTLIBDIR=$DEFAULT_OCTLIBDIR}
+
+DEFAULT_INCFLAGS="-I$OCTINCLUDEDIR/.. -I$OCTINCLUDEDIR"
+if [ "$INCLUDEDIR" != /usr/include ]; then
+  DEFAULT_INCFLAGS="$DEFAULT_INCFLAGS -I$INCLUDEDIR"
+fi
+
+DEFAULT_LFLAGS="-L$OCTLIBDIR -L$BINDIR"
+if [ "$LIBDIR" != /usr/lib ]; then
+  DEFAULT_LFLAGS="$DEFAULT_LFLAGS -L$LIBDIR"
+fi
+
+# Default values for these variables are filled in when Octave is
+# compiled.
+
+: ${EXEEXT=""}
+
+: ${CPPFLAGS=""}
+: ${INCFLAGS=$DEFAULT_INCFLAGS}
+: ${F77="x86_64-w64-mingw32-gfortran"}
+: ${FFLAGS="-O"}
+: ${FPICFLAG=""}
+: ${CC="x86_64-w64-mingw32-gcc"}
+: ${CFLAGS="-g -O2"}
+: ${CPICFLAG=""}
+: ${CXX="x86_64-w64-mingw32-g++"}
+: ${CXXFLAGS="-g -O2"}
+: ${CXXPICFLAG=""}
+: ${XTRA_CFLAGS=""}
+: ${XTRA_CXXFLAGS=""}
+
+: ${DEPEND_FLAGS="-M"}
+: ${DEPEND_EXTRA_SED_PATTERN=""}
+
+: ${DL_LD="x86_64-w64-mingw32-g++"}
+: ${DL_LDFLAGS="-shared -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc -static-libgcc -static-libstdc++"}
+
+: ${RLD_FLAG="-Wl,-rpath -Wl,$OCTAVE_PREFIX/lib/octave/${OCTAVE_VERSION}"}
+: ${RDYNAMIC_FLAG="-rdynamic"}
+: ${LIBOCTAVE=-loctave}
+: ${LIBOCTINTERP=-loctinterp}
+: ${READLINE_LIBS=-lreadline}
+: ${LAPACK_LIBS="-llapack"}
+: ${BLAS_LIBS="-lblas"}
+: ${FFTW3_LDFLAGS=""}
+: ${FFTW3_LIBS="-lfftw3"}
+: ${FFTW3F_LDFLAGS=""}
+: ${FFTW3F_LIBS="-lfftw3f"}
+: ${LIBS="-lm -lgfortran -llapack -lgdi32 -lws2_32 -luser32 -lkernel32"}
+: ${FLIBS="-lm -lgfortran -llapack -lmingw32 -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32"}
+: ${LD_CXX="x86_64-w64-mingw32-g++"}
+: ${LDFLAGS="-Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc-v2 -Wl,--allow-multiple-definition -static-libgcc -static-libstdc++"}
+: ${LD_STATIC_FLAG=""}
+: ${LFLAGS=$DEFAULT_LFLAGS}
+: ${F77_INTEGER_8_FLAG=""}
+
+: ${ALL_FFLAGS="$FFLAGS $F77_INTEGER_8_FLAG"}
+
+: ${ALL_CFLAGS="$INCFLAGS $XTRA_CFLAGS $CFLAGS"}
+
+: ${ALL_CXXFLAGS="$INCFLAGS $XTRA_CXXFLAGS $CXXFLAGS"}
+
+: ${ALL_LDFLAGS="$LD_STATIC_FLAG $CPICFLAG $LDFLAGS"}
+
+: ${OCTAVE_LIBS="$LIBOCTINTERP $LIBOCTAVE $SPECIAL_MATH_LIB"}
+
+# Local variables.
+
+FFTW_LIBS="$FFTW3_LDFLAGS $FFTW3_LIBS $FFTW3F_LDFLAGS $FFTW3F_LIBS"
+
+usage_msg="usage: mkoctfile [options] file ..."
+
+version_msg="mkoctfile, version $OCTAVE_VERSION"
+
+cfiles=
+ccfiles=
+f77files=
+objfiles=
+libfiles=
+octfiles=
+octfile=
+outputfile=
+incflags=
+defs=
+ldflags=
+dbg=:
+pass_on_options=
+strip=false
+no_oct_file_strip_on_this_platform=false
+link=true
+link_stand_alone=false
+output_ext=".oct"
+depend=false
+compile=true
+
+if [ $# -eq 0 ]; then
+  echo $usage_msg 1>&2
+  exit 1
+fi
+
+if [ $# -eq 1 ]; then
+  case "$1" in
+    -v | -version | --version)
+      echo $version_msg 1>&2
+      exit 0
+    ;;
+  esac
+fi
+
+while [ $# -gt 0 ]; do
+  file=
+  case "$1" in
+    *.c)
+      file=$1
+      cfiles="$cfiles $file"
+    ;;
+    *.cc | *.C | *.cpp)
+      file=$1
+      ccfiles="$ccfiles $file"
+    ;;
+    *.f | *.F | *.f90 | *.F90)
+      file=$1
+      f77files="$f77files $file"
+    ;;
+    *.o)
+      file=$1
+      objfiles="$objfiles $file"
+    ;;
+    *.a)
+      file=$1
+      libfiles="$libfiles $file"
+    ;;
+    -d | -debug | --debug | -v | -verbose | --verbose)
+      dbg=echo
+    ;;
+    -h | -\? | -help | --help)
+      echo $usage_msg 1>&2
+      cat << EOF
+
+Options:
+
+  -h, -?, --help          Print this message.
+
+  -IDIR                   Add -IDIR to compile commands.
+
+  -idirafter DIR          Add -idirafter DIR to compile commands.
+
+  -DDEF                   Add -DDEF to compile commands.
+
+  -lLIB                   Add -lLIB to link command.
+
+  -LDIR                   Add -LDIR to link command.
+
+  -RDIR                   Add -RDIR to link command.
+
+  -g                      Enable debugging option for all compilers.
+
+  -pthread                Add -pthread to link command.
+
+  -W...                   Pass flags to the compiler such as -Wa,OPTION.
+
+  -Wl,...                 Pass flags to the linker such as -Wl,-rpath=...
+
+  -M, --depend            Generate dependency files (.d) for C and C++
+                          source files.
+
+  -c, --compile           Compile, but do not link.
+
+  --link-stand-alone      Link a stand-alone executable file.
+
+  -s, --strip             Strip output file.
+
+  --mex                   Create a MEX file.  
+                          Set the default output extension to ".mex".
+
+  -o FILE, --output FILE  Output file name.  Default extension is .oct
+                          (or .mex if --mex is specified) unless linking
+                          a stand-alone executable.
+
+  -p VAR, --print VAR     Print configuration variable VAR.  Recognized
+                          variables are:
+
+                            ALL_CFLAGS                FFTW3F_LDFLAGS
+                            ALL_CXXFLAGS              FFTW3F_LIBS
+                            ALL_FFLAGS                FLIBS
+                            ALL_LDFLAGS               FPICFLAG
+                            BLAS_LIBS                 INCFLAGS
+                            CC                        LAPACK_LIBS
+                            CFLAGS                    LDFLAGS
+                            CPICFLAG                  LD_CXX
+                            CPPFLAGS                  LD_STATIC_FLAG
+                            CXX                       LFLAGS
+                            CXXFLAGS                  LIBCRUFT
+                            CXXPICFLAG                LIBOCTAVE
+                            DEPEND_EXTRA_SED_PATTERN  LIBOCTINTERP
+                            DEPEND_FLAGS              LIBS
+                            DL_LD                     OCTAVE_LIBS
+                            DL_LDFLAGS                RDYNAMIC_FLAG
+                            EXEEXT                    READLINE_LIBS
+                            F77                       RLD_FLAG
+                            F77_INTEGER_8_FLAG        SED
+                            FFLAGS                    XTRA_CFLAGS
+                            FFTW3_LDFLAGS             XTRA_CXXFLAGS
+                            FFTW3_LIBS
+
+  -v, --verbose           Echo commands as they are executed.
+
+  FILE                    Compile or link FILE.  Recognized file types are:
+
+                            .c    C source
+                            .cc   C++ source
+                            .C    C++ source
+                            .cpp  C++ source
+                            .f    Fortran source (fixed form)
+                            .F    Fortran source (fixed form)
+                            .f90  Fortran source (free form)
+                            .F90  Fortran source (free form)
+                            .o    object file
+                            .a    library file
+
+EOF
+      exit 0
+    ;;
+    -I*)
+      incflags="$incflags $1"
+    ;;
+    -idirafter)
+      shift
+      if [ $# -gt 0 ]; then
+        incflags="$incflags -idirafter $1"
+      else
+        echo "mkoctfile: include directory name missing" 1>&2
+      fi
+    ;;
+    -D*)
+      defs="$defs $1"
+    ;;
+    -[lLR]* | -Wl,*)
+      ldflags="$ldflags $1"
+    ;;
+    -pthread)
+      ldflags="$ldflags $1"
+    ;;
+    -M | -depend | --depend)
+      depend=true
+      compile=false
+    ;;
+    -o | -ouput | --output)
+      shift
+      if [ $# -gt 0 ]; then
+        outputfile="$1"
+      else
+        echo "mkoctfile: output file name missing" 1>&2
+      fi
+    ;;
+    -p | -print | --print)
+      shift
+      if [ $# -gt 0 ]; then
+        eval echo \${$1}
+        exit 0
+      else
+        echo "mkoctfile: --print requires argument" 1>&2
+        exit 1
+      fi
+    ;;
+    -s | -strip | --strip)
+      if $no_oct_file_strip_on_this_platform; then
+        echo "mkoctfile: stripping disabled on this platform" 1>&2
+      else
+        strip=true
+      fi
+    ;;
+    -c | -compile | --compile)
+      link=false
+    ;;
+    -g)
+      ALL_CFLAGS="$ALL_CFLAGS -g"
+      ALL_CXXFLAGS="$ALL_CXXFLAGS -g"
+      ALL_FFLAGS="$ALL_FFLAGS -g"
+    ;;
+    -link-stand-alone | --link-stand-alone)
+      link_stand_alone=true
+    ;;
+    -mex | --mex)
+      incflags="$incflags -I."
+      output_ext=".mex"
+    ;;
+    -W*)
+      pass_on_options="$pass_on_options $1"
+    ;;
+    *)
+      echo "mkoctfile: unrecognized argument $1" 1>&2
+      exit 1
+    ;;
+  esac
+  if [ -n "$file" ]; then
+    if [ -z "$octfile" ]; then
+      octfile="$file"
+    fi
+  fi
+  shift
+done
+
+if $link_stand_alone; then
+  if [ -n "$outputfile" ]; then
+    output_option="-o $outputfile"
+  fi
+else
+  if [ -n "$outputfile" ]; then
+    octfile="$outputfile"
+    case "$octfile" in
+      *$output_ext)
+      ;;
+      *)
+        octfile="$octfile$output_ext"
+      ;;
+    esac
+  else
+    octfile=`basename $octfile`
+    octfile=`echo $octfile | $SED 's,\.[^.]*$,,'`$output_ext
+  fi
+fi
+
+# Generate dependency files for C and C++ files.
+
+if $depend; then
+  if [ -n "$cfiles" ]; then
+    for f in $cfiles; do
+      b=`echo $f | $SED 's,\.c$,,'`
+      d=$b.d
+      cmd="rm -f $d"
+      $dbg $cmd
+      eval $cmd
+      cmd="$CC $DEPEND_FLAGS $CPPFLAGS $ALL_CFLAGS $incflags $def $f | $SED $DEPEND_EXTRA_SED_PATTERN -e 's,^[^:]*/\(.*\.o\):,\1:,' -e 's,$b\.o,pic/& & $d,g' > $d-t && mv $d-t $d"
+      $dbg $cmd
+      eval $cmd
+    done
+  fi
+
+  if [ -n "$ccfiles" ]; then
+    for f in $ccfiles; do
+      case $f in
+        *.cc)
+          b=`echo $f | $SED 's,\.cc$,,'`
+        ;;
+        *.C)
+          b=`echo $f | $SED 's,\.C$,,'`
+        ;;
+        *.cpp)
+          b=`echo $f | $SED 's,\.cpp$,,'`
+        ;;
+      esac
+      d=$b.d
+      cmd="rm -f $d"
+      $dbg $cmd
+      eval $cmd
+      cmd="$CXX $DEPEND_FLAGS $CPPFLAGS $ALL_CXXFLAGS $incflags $defs $f | $SED $DEPEND_EXTRA_SED_PATTERN -e 's,^[^:]*/\(.*\.o\):,\1:,' -e 's,$b\.o,pic/& & $d,g' > $d-t && mv $d-t $d"
+      $dbg $cmd
+      eval $cmd
+    done
+  fi
+  # If generating dependencies, that's all we do.
+  exit 0
+fi
+
+# Compile Fortran, C, and C++ files.  Add the name of each object file
+# that is produced to the overall list of object files.
+
+if [ -n "$f77files" ]; then
+  for f in $f77files; do
+    case $f in
+      *.f)
+        b=`echo $f | $SED 's,.*/,,; s,\.f$,,'`
+      ;;
+      *.F)
+        b=`echo $f | $SED 's,.*/,,; s,\.F$,,'`
+      ;;
+      *.f90)
+        b=`echo $f | $SED 's,.*/,,; s,\.f90$,,'`
+      ;;
+      *.F90)
+        b=`echo $f | $SED 's,.*/,,; s,\.F90$,,'`
+      ;;
+    esac
+    if [ -n "$F77" ]; then
+      if [ -n "$outputfile" ]; then
+        if $link; then
+          o=$b.o
+        else
+          o=$outputfile
+        fi
+      else
+        o=$b.o
+      fi
+      objfiles="$objfiles $o"
+      cmd="$F77 -c $FPICFLAG $ALL_FFLAGS $incflags $defs $pass_on_options $f -o $o"
+      $dbg $cmd
+      eval $cmd
+    else
+      echo "mkoctfile: no way to compile Fortran file $f" 1>&2
+    fi
+  done
+fi
+
+if [ -n "$cfiles" ]; then
+  for f in $cfiles; do
+    if [ -n  "$CC" ]; then
+      b=`echo $f | $SED 's,.*/,,; s,\.c$,,'`
+      if [ -n "$outputfile" ]; then
+        if $link; then
+          o=$b.o
+        else
+          o=$outputfile
+        fi
+      else
+        o=$b.o
+      fi
+      objfiles="$objfiles $o"
+      cmd="$CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $pass_on_options $incflags $defs $f -o $o"
+      $dbg $cmd
+      eval $cmd
+    else
+      echo "mkoctfile: no way to compile C++ file $f" 1>&2
+    fi
+  done
+fi
+
+if [ -n "$ccfiles" ]; then
+  for f in $ccfiles; do
+    if [ -n "$CXX" ]; then
+      case $f in
+        *.cc)
+          b=`echo $f | $SED 's,.*/,,; s,\.cc$,,'`
+        ;;
+        *.C)
+          b=`echo $f | $SED 's,.*/,,; s,\.C$,,'`
+        ;;
+        *.cpp)
+          b=`echo $f | $SED 's,.*/,,; s,\.cpp$,,'`
+        ;;
+      esac
+      if [ -n "$outputfile" ]; then
+        if $link; then
+          o=$b.o
+        else
+          o=$outputfile
+        fi
+      else
+        o=$b.o
+      fi
+      objfiles="$objfiles $o"
+      cmd="$CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $pass_on_options $incflags $defs $f -o $o"
+      $dbg $cmd
+      eval $cmd
+    else
+      echo "mkoctfile: no way to compile C++ file $f" 1>&2
+    fi
+  done
+fi
+
+## Uncomment the following group of lines if you get `Text file busy'
+## errors from ld.  This may happen if the .oct file is currently
+## running while you are trying to recompile it.  We try moving first,
+## since on some systems (HP-UX, maybe others) it is possible to
+## rename running programs but not remove them.
+
+## if [ -f "$octfile" ]; then
+##   cmd="mv $octfile $octfile.bak"
+##   $dbg $cmd
+##   eval $cmd
+##   cmd="rm -f $octfile.bak"
+##   $dbg $cmd
+##   eval $cmd
+## fi
+
+# Link all the object files.
+
+if $link && [ -n "$objfiles" ]; then
+  if $link_stand_alone; then
+    if [ -n "$LD_CXX" ]; then
+      cmd="$LD_CXX $CPPFLAGS $ALL_CXXFLAGS $RDYNAMIC_FLAG $ALL_LDFLAGS $pass_on_options $output_option $objfiles $libfiles $ldflags $LFLAGS $RLD_FLAG $OCTAVE_LIBS $LAPACK_LIBS $BLAS_LIBS $FFTW_LIBS $READLINE_LIBS $LIBS $FLIBS"
+      $dbg $cmd
+      eval $cmd
+    else
+      echo "mkoctfile: no way to link stand-alone executable file" 1>&2
+      exit 1
+    fi
+  else
+    LINK_DEPS="$LFLAGS $OCTAVE_LIBS $LDFLAGS $LAPACK_LIBS $BLAS_LIBS $FFTW_LIBS $LIBS $FLIBS"
+    cmd="$DL_LD $DL_LDFLAGS $pass_on_options -o $octfile $objfiles $libfiles $ldflags $LINK_DEPS"
+    $dbg $cmd
+    eval $cmd
+  fi
+
+# Maybe strip it.
+
+  if $strip; then
+    cmd="strip $octfile"
+    $dbg $cmd
+    eval $cmd
+  fi
+fi
+
+exit 0
diff --git a/windows/deps/patches/openblas-w32.patch b/windows/deps/patches/openblas-w32.patch
new file mode 100644
index 0000000000000000000000000000000000000000..c5bd6f16040e045be1924f461347a79417e3a187
--- /dev/null
+++ b/windows/deps/patches/openblas-w32.patch
@@ -0,0 +1,69 @@
+--- OpenBLAS-0.3.6/Makefile.rule	2019-04-29 19:22:19.000000000 +0200
++++ OpenBLAS-0.3.6-w32/Makefile.rule	2019-06-13 11:02:50.665872965 +0200
+@@ -15,7 +15,7 @@
+ # TARGET = PENRYN
+ 
+ # If you want to support multiple architecture in one binary
+-# DYNAMIC_ARCH = 1
++DYNAMIC_ARCH = 1
+ 
+ # If you want the full list of x86_64 architectures supported in DYNAMIC_ARCH
+ # mode (including individual optimizied codes for PENRYN, DUNNINGTON, OPTERON,
+@@ -24,10 +24,10 @@
+ 
+ # C compiler including binary type(32bit / 64bit). Default is gcc.
+ # Don't use Intel Compiler or PGI, it won't generate right codes as I expect.
+-# CC = gcc
++CC = i686-w64-mingw32-gcc
+ 
+ # Fortran compiler. Default is g77.
+-# FC = gfortran
++FC = i686-w64-mingw32-gfortran
+ 
+ # Even you can specify cross compiler. Meanwhile, please set HOSTCC.
+ 
+@@ -45,7 +45,7 @@
+ 
+ 
+ # If you use the cross compiler, please set this host compiler.
+-# HOSTCC = gcc
++HOSTCC = gcc
+ 
+ # If you need 32bit binary, define BINARY=32, otherwise define BINARY=64
+ # Please note that AVX is not available on 32-bit.
+@@ -56,7 +56,7 @@
+ # specify it.
+ # For force setting for single threaded, specify USE_THREAD = 0
+ # For force setting for multi  threaded, specify USE_THREAD = 1
+-# USE_THREAD = 0
++USE_THREAD = 1
+ 
+ # If you're going to use this library with OpenMP, please comment it in.
+ # This flag is always set for POWER8. Don't set USE_OPENMP = 0 if you're targeting POWER8.
+@@ -82,7 +82,7 @@
+ # value (eg. 32-256) if you expect your users to use that many threads. Due to the way
+ # some internal structures are allocated, using a large NUM_THREADS value has a RAM
+ # footprint penalty, even if users reduce the actual number of threads at runtime.
+-# NUM_THREADS = 24
++NUM_THREADS = 2
+ 
+ # If you have enabled USE_OPENMP and your application would call
+ # OpenBLAS's calculation API from multiple threads, please comment this in.
+@@ -95,7 +95,7 @@
+ # NO_STATIC = 1
+ 
+ # If you don't need to generate the shared library, please comment this in.
+-# NO_SHARED = 1
++NO_SHARED = 1
+ 
+ # If you don't need the CBLAS interface, please comment this in.
+ # NO_CBLAS = 1
+@@ -109,7 +109,7 @@
+ # NO_LAPACK = 1
+ 
+ # If you don't need LAPACKE (C Interface to LAPACK), please comment this in.
+-# NO_LAPACKE = 1
++NO_LAPACKE = 1
+ 
+ # Build LAPACK Deprecated functions since LAPACK 3.6.0
+ BUILD_LAPACK_DEPRECATED = 1
diff --git a/windows/deps/patches/openblas-w64.patch b/windows/deps/patches/openblas-w64.patch
new file mode 100644
index 0000000000000000000000000000000000000000..84910149d58ec4c61cef426463483868c30a7e32
--- /dev/null
+++ b/windows/deps/patches/openblas-w64.patch
@@ -0,0 +1,77 @@
+--- OpenBLAS-0.3.6/Makefile.rule	2019-04-29 19:22:19.000000000 +0200
++++ OpenBLAS-0.3.6-w64/Makefile.rule	2019-06-13 11:04:44.433315864 +0200
+@@ -15,7 +15,7 @@
+ # TARGET = PENRYN
+ 
+ # If you want to support multiple architecture in one binary
+-# DYNAMIC_ARCH = 1
++DYNAMIC_ARCH = 1
+ 
+ # If you want the full list of x86_64 architectures supported in DYNAMIC_ARCH
+ # mode (including individual optimizied codes for PENRYN, DUNNINGTON, OPTERON,
+@@ -24,10 +24,10 @@
+ 
+ # C compiler including binary type(32bit / 64bit). Default is gcc.
+ # Don't use Intel Compiler or PGI, it won't generate right codes as I expect.
+-# CC = gcc
++CC = x86_64-w64-mingw32-gcc
+ 
+ # Fortran compiler. Default is g77.
+-# FC = gfortran
++FC = x86_64-w64-mingw32-gfortran
+ 
+ # Even you can specify cross compiler. Meanwhile, please set HOSTCC.
+ 
+@@ -45,7 +45,7 @@
+ 
+ 
+ # If you use the cross compiler, please set this host compiler.
+-# HOSTCC = gcc
++HOSTCC = gcc
+ 
+ # If you need 32bit binary, define BINARY=32, otherwise define BINARY=64
+ # Please note that AVX is not available on 32-bit.
+@@ -56,7 +56,7 @@
+ # specify it.
+ # For force setting for single threaded, specify USE_THREAD = 0
+ # For force setting for multi  threaded, specify USE_THREAD = 1
+-# USE_THREAD = 0
++USE_THREAD = 1
+ 
+ # If you're going to use this library with OpenMP, please comment it in.
+ # This flag is always set for POWER8. Don't set USE_OPENMP = 0 if you're targeting POWER8.
+@@ -82,7 +82,7 @@
+ # value (eg. 32-256) if you expect your users to use that many threads. Due to the way
+ # some internal structures are allocated, using a large NUM_THREADS value has a RAM
+ # footprint penalty, even if users reduce the actual number of threads at runtime.
+-# NUM_THREADS = 24
++NUM_THREADS = 2
+ 
+ # If you have enabled USE_OPENMP and your application would call
+ # OpenBLAS's calculation API from multiple threads, please comment this in.
+@@ -95,7 +95,7 @@
+ # NO_STATIC = 1
+ 
+ # If you don't need to generate the shared library, please comment this in.
+-# NO_SHARED = 1
++NO_SHARED = 1
+ 
+ # If you don't need the CBLAS interface, please comment this in.
+ # NO_CBLAS = 1
+@@ -109,7 +109,7 @@
+ # NO_LAPACK = 1
+ 
+ # If you don't need LAPACKE (C Interface to LAPACK), please comment this in.
+-# NO_LAPACKE = 1
++NO_LAPACKE = 1
+ 
+ # Build LAPACK Deprecated functions since LAPACK 3.6.0
+ BUILD_LAPACK_DEPRECATED = 1
+@@ -242,3 +242,7 @@
+ #
+ #  End of user configuration
+ #
++
++# Workaround for apparent MinGW bug with -march=skylake-avx512
++# See https://sourceforge.net/p/mingw-w64/bugs/681/
++NO_AVX512 = 1
diff --git a/windows/deps/patches/slicot-32-with-underscore.patch b/windows/deps/patches/slicot-32-with-underscore.patch
new file mode 100644
index 0000000000000000000000000000000000000000..827c49fb11481a67f4a33ae682a1a388baf60df1
--- /dev/null
+++ b/windows/deps/patches/slicot-32-with-underscore.patch
@@ -0,0 +1,30 @@
+--- make.inc	2012-01-19 20:51:25.000000000 +0100
++++ slicot-32-with-underscore.inc	2016-09-18 15:39:53.403237169 +0200
+@@ -16,16 +16,16 @@
+ #  selected.  Define LOADER and LOADOPTS to refer to the loader and 
+ #  desired load options for your machine.
+ #
+-FORTRAN  = f77
+-OPTS     = -O4 -native -u
++FORTRAN  = i686-w64-mingw32-gfortran
++OPTS     = -O2 -g
+ NOOPT    = -u
+-LOADER   = f77
++LOADER   = i686-w64-mingw32-gfortran
+ LOADOPTS = $(SLICOTLIB) $(LPKAUXLIB) $(LAPACKLIB)
+ #
+ #  The archiver and the flag(s) to use when building archive (library)
+ #  If your system has no ranlib, set RANLIB = echo.
+ #
+-ARCH     = ar
++ARCH     = i686-w64-mingw32-ar
+ ARCHFLAGS= r
+ # ARCHFLAGS= cr
+ # RANLIB   = ranlib
+@@ -36,5 +36,5 @@
+ #
+ #BLASLIB     = -L/software/lib
+ LAPACKLIB    = -L/software/lib -llapack -lblas
+-SLICOTLIB    = ../slicot.a
++SLICOTLIB    = ../libslicot_pic.a
+ LPKAUXLIB    = ../lpkaux.a
diff --git a/windows/deps/patches/slicot-32-without-underscore.patch b/windows/deps/patches/slicot-32-without-underscore.patch
new file mode 100644
index 0000000000000000000000000000000000000000..391ba967feb8542f4f80a593d851edf832c3ff13
--- /dev/null
+++ b/windows/deps/patches/slicot-32-without-underscore.patch
@@ -0,0 +1,30 @@
+--- make.inc	2012-01-19 20:51:25.000000000 +0100
++++ slicot-32-without-underscore.inc	2016-09-18 15:32:26.784187836 +0200
+@@ -16,16 +16,16 @@
+ #  selected.  Define LOADER and LOADOPTS to refer to the loader and 
+ #  desired load options for your machine.
+ #
+-FORTRAN  = f77
+-OPTS     = -O4 -native -u
++FORTRAN  = i686-w64-mingw32-gfortran
++OPTS     = -O2 -g -fno-underscoring
+ NOOPT    = -u
+-LOADER   = f77
++LOADER   = i686-w64-mingw32-gfortran
+ LOADOPTS = $(SLICOTLIB) $(LPKAUXLIB) $(LAPACKLIB)
+ #
+ #  The archiver and the flag(s) to use when building archive (library)
+ #  If your system has no ranlib, set RANLIB = echo.
+ #
+-ARCH     = ar
++ARCH     = i686-w64-mingw32-ar
+ ARCHFLAGS= r
+ # ARCHFLAGS= cr
+ # RANLIB   = ranlib
+@@ -36,5 +36,5 @@
+ #
+ #BLASLIB     = -L/software/lib
+ LAPACKLIB    = -L/software/lib -llapack -lblas
+-SLICOTLIB    = ../slicot.a
++SLICOTLIB    = ../libslicot_pic.a
+ LPKAUXLIB    = ../lpkaux.a
diff --git a/windows/deps/patches/slicot-64-with-32bit-integer-and-underscore.patch b/windows/deps/patches/slicot-64-with-32bit-integer-and-underscore.patch
new file mode 100644
index 0000000000000000000000000000000000000000..2aadf8b9b09b6a1b253e13f3671fe5afe0d13ef8
--- /dev/null
+++ b/windows/deps/patches/slicot-64-with-32bit-integer-and-underscore.patch
@@ -0,0 +1,30 @@
+--- make.inc	2012-01-19 20:51:25.000000000 +0100
++++ slicot-64-with-32bit-integer.inc	2016-09-18 15:39:22.022804314 +0200
+@@ -16,16 +16,16 @@
+ #  selected.  Define LOADER and LOADOPTS to refer to the loader and 
+ #  desired load options for your machine.
+ #
+-FORTRAN  = f77
+-OPTS     = -O4 -native -u
++FORTRAN  = x86_64-w64-mingw32-gfortran
++OPTS     = -O2 -g
+ NOOPT    = -u
+-LOADER   = f77
++LOADER   = x86_64-w64-mingw32-gfortran
+ LOADOPTS = $(SLICOTLIB) $(LPKAUXLIB) $(LAPACKLIB)
+ #
+ #  The archiver and the flag(s) to use when building archive (library)
+ #  If your system has no ranlib, set RANLIB = echo.
+ #
+-ARCH     = ar
++ARCH     = x86_64-w64-mingw32-ar
+ ARCHFLAGS= r
+ # ARCHFLAGS= cr
+ # RANLIB   = ranlib
+@@ -36,5 +36,5 @@
+ #
+ #BLASLIB     = -L/software/lib
+ LAPACKLIB    = -L/software/lib -llapack -lblas
+-SLICOTLIB    = ../slicot.a
++SLICOTLIB    = ../libslicot_pic.a
+ LPKAUXLIB    = ../lpkaux.a
diff --git a/windows/deps/patches/slicot-64-with-32bit-integer.patch b/windows/deps/patches/slicot-64-with-32bit-integer.patch
new file mode 100644
index 0000000000000000000000000000000000000000..a069e16ca97d10aae607bc6ec855c616df0db922
--- /dev/null
+++ b/windows/deps/patches/slicot-64-with-32bit-integer.patch
@@ -0,0 +1,30 @@
+--- make.inc	2012-01-19 20:51:25.000000000 +0100
++++ slicot-64-with-32bit-integer.inc	2016-09-18 15:39:22.022804314 +0200
+@@ -16,16 +16,16 @@
+ #  selected.  Define LOADER and LOADOPTS to refer to the loader and 
+ #  desired load options for your machine.
+ #
+-FORTRAN  = f77
+-OPTS     = -O4 -native -u
++FORTRAN  = x86_64-w64-mingw32-gfortran
++OPTS     = -O2 -g -fno-underscoring
+ NOOPT    = -u
+-LOADER   = f77
++LOADER   = x86_64-w64-mingw32-gfortran
+ LOADOPTS = $(SLICOTLIB) $(LPKAUXLIB) $(LAPACKLIB)
+ #
+ #  The archiver and the flag(s) to use when building archive (library)
+ #  If your system has no ranlib, set RANLIB = echo.
+ #
+-ARCH     = ar
++ARCH     = x86_64-w64-mingw32-ar
+ ARCHFLAGS= r
+ # ARCHFLAGS= cr
+ # RANLIB   = ranlib
+@@ -36,5 +36,5 @@
+ #
+ #BLASLIB     = -L/software/lib
+ LAPACKLIB    = -L/software/lib -llapack -lblas
+-SLICOTLIB    = ../slicot.a
++SLICOTLIB    = ../libslicot_pic.a
+ LPKAUXLIB    = ../lpkaux.a
diff --git a/windows/deps/patches/slicot-64-with-64bit-integer-and-underscore.patch b/windows/deps/patches/slicot-64-with-64bit-integer-and-underscore.patch
new file mode 100644
index 0000000000000000000000000000000000000000..b1c7bc6257446faf876f1a70fb0e2496c9c941a7
--- /dev/null
+++ b/windows/deps/patches/slicot-64-with-64bit-integer-and-underscore.patch
@@ -0,0 +1,30 @@
+--- make.inc	2012-01-19 20:51:25.000000000 +0100
++++ slicot-64-with-64bit-integer.inc	2016-09-18 15:39:09.142623934 +0200
+@@ -16,16 +16,16 @@
+ #  selected.  Define LOADER and LOADOPTS to refer to the loader and 
+ #  desired load options for your machine.
+ #
+-FORTRAN  = f77
+-OPTS     = -O4 -native -u
++FORTRAN  = x86_64-w64-mingw32-gfortran
++OPTS     = -O2 -g -fdefault-integer-8
+ NOOPT    = -u
+-LOADER   = f77
++LOADER   = x86_64-w64-mingw32-gfortran
+ LOADOPTS = $(SLICOTLIB) $(LPKAUXLIB) $(LAPACKLIB)
+ #
+ #  The archiver and the flag(s) to use when building archive (library)
+ #  If your system has no ranlib, set RANLIB = echo.
+ #
+-ARCH     = ar
++ARCH     = x86_64-w64-mingw32-ar
+ ARCHFLAGS= r
+ # ARCHFLAGS= cr
+ # RANLIB   = ranlib
+@@ -36,5 +36,5 @@
+ #
+ #BLASLIB     = -L/software/lib
+ LAPACKLIB    = -L/software/lib -llapack -lblas
+-SLICOTLIB    = ../slicot.a
++SLICOTLIB    = ../libslicot64_pic.a
+ LPKAUXLIB    = ../lpkaux.a
diff --git a/windows/deps/patches/slicot-64-with-64bit-integer.patch b/windows/deps/patches/slicot-64-with-64bit-integer.patch
new file mode 100644
index 0000000000000000000000000000000000000000..d5597176bb18cb9cf439f56ca4ecdf6edfd41055
--- /dev/null
+++ b/windows/deps/patches/slicot-64-with-64bit-integer.patch
@@ -0,0 +1,30 @@
+--- make.inc	2012-01-19 20:51:25.000000000 +0100
++++ slicot-64-with-64bit-integer.inc	2016-09-18 15:39:09.142623934 +0200
+@@ -16,16 +16,16 @@
+ #  selected.  Define LOADER and LOADOPTS to refer to the loader and 
+ #  desired load options for your machine.
+ #
+-FORTRAN  = f77
+-OPTS     = -O4 -native -u
++FORTRAN  = x86_64-w64-mingw32-gfortran
++OPTS     = -O2 -g -fno-underscoring -fdefault-integer-8
+ NOOPT    = -u
+-LOADER   = f77
++LOADER   = x86_64-w64-mingw32-gfortran
+ LOADOPTS = $(SLICOTLIB) $(LPKAUXLIB) $(LAPACKLIB)
+ #
+ #  The archiver and the flag(s) to use when building archive (library)
+ #  If your system has no ranlib, set RANLIB = echo.
+ #
+-ARCH     = ar
++ARCH     = x86_64-w64-mingw32-ar
+ ARCHFLAGS= r
+ # ARCHFLAGS= cr
+ # RANLIB   = ranlib
+@@ -36,5 +36,5 @@
+ #
+ #BLASLIB     = -L/software/lib
+ LAPACKLIB    = -L/software/lib -llapack -lblas
+-SLICOTLIB    = ../slicot.a
++SLICOTLIB    = ../libslicot64_pic.a
+ LPKAUXLIB    = ../lpkaux.a
diff --git a/windows/deps/versions.mk b/windows/deps/versions.mk
new file mode 100644
index 0000000000000000000000000000000000000000..b88e702aa81c1392f81165c96e85f2fb22d12007
--- /dev/null
+++ b/windows/deps/versions.mk
@@ -0,0 +1,47 @@
+BOOST_VERSION = 1_70_0
+GSL_VERSION = 2.5
+MATIO_VERSION = 1.5.15
+OPENBLAS_VERSION = 0.3.6
+SLICOT_VERSION = 5.0+20101122
+ZLIB_VERSION = 1.2.11
+
+OCTAVE_VERSION = 5.1.0
+OCTAVE_W32_BUILD =
+OCTAVE_W64_BUILD =
+
+MATLAB32_VERSION = 20181204
+MATLAB64_VERSION = 20181204
+
+## MinGW packages
+# Determine the versions by:
+# - first running: pacman -Sy
+# - and then with appropriate queries using: pacman -Ss <regex>
+
+# pacman -Ss mingw-w64-.*-gcc$
+MINGW32_GCC_VERSION = 9.1.0-2
+MINGW64_GCC_VERSION = 9.1.0-2
+
+# pacman -Ss mingw-w64-.*-gmp$
+MINGW32_GMP_VERSION = 6.1.2-1
+MINGW64_GMP_VERSION = 6.1.2-1
+
+# pacman -Ss mingw-w64-.*-binutils
+MINGW32_BINUTILS_VERSION = 2.30-6
+MINGW64_BINUTILS_VERSION = 2.30-6
+
+# pacman -Ss mingw-w64-.*-headers-git
+MINGW32_HEADERS_VERSION = 7.0.0.5449.a0647123-1
+MINGW64_HEADERS_VERSION = 7.0.0.5449.a0647123-1
+
+# pacman -Ss mingw-w64-.*-crt-git
+MINGW32_CRT_VERSION = 7.0.0.5449.a0647123-1
+MINGW64_CRT_VERSION = 7.0.0.5449.a0647123-1
+
+# pacman -Ss mingw-w64-.*-winpthreads-git
+MINGW32_WINPTHREADS_VERSION = 7.0.0.5447.a2d94c81-1
+MINGW64_WINPTHREADS_VERSION = 7.0.0.5447.a2d94c81-1
+
+# pacman -Ss mingw-w64-.*-libwinpthread-git
+# NB: "thread" is singular here
+MINGW32_LIBWINPTHREAD_VERSION = 7.0.0.5447.a2d94c81-1
+MINGW64_LIBWINPTHREAD_VERSION = 7.0.0.5447.a2d94c81-1
diff --git a/windows/dynare-version.nsi.in b/windows/dynare-version.nsi.in
deleted file mode 100644
index ed5252ccbfa44b8d164099bb4ab710fa57ca97a1..0000000000000000000000000000000000000000
--- a/windows/dynare-version.nsi.in
+++ /dev/null
@@ -1,3 +0,0 @@
-# This file is processed by the configure script to create dynare-version.nsi
-
-!define VERSION "@PACKAGE_VERSION@"
diff --git a/windows/dynare.nsi b/windows/dynare.nsi
index d6e815a8338591026ae2b805804b05489cb60d27..0b1d246bdd1fd1d3bc04f4aadb371de12735be5b 100644
--- a/windows/dynare.nsi
+++ b/windows/dynare.nsi
@@ -2,13 +2,6 @@
 # Uses "NullSoft Scriptable Installer System", aka NSIS (see http://nsis.sourceforge.net)
 # NSIS can be run from both Windows and Linux (see "nsis" package in Debian)
 
-# How to build the installer:
-# - build: the preprocessor, the MEX binaries (for MATLAB and for Octave), and the documentation (PDF files + HTML manual)
-# - run "makensis dynare.nsi" to create the installer
-# - if there is no failure, this will create a file "dynare-VERSION-win.exe" in the current directory
-
-!include dynare-version.nsi
-
 SetCompressor /SOLID lzma
 
 Name "Dynare ${VERSION}"
@@ -25,7 +18,7 @@ InstallDir "c:\dynare\${VERSION}"
 !insertmacro MUI_PAGE_COMPONENTS
 !insertmacro MUI_PAGE_DIRECTORY
 !insertmacro MUI_PAGE_INSTFILES
-!define MUI_FINISHPAGE_LINK_LOCATION http://www.dynare.org
+!define MUI_FINISHPAGE_LINK_LOCATION https://www.dynare.org
 !define MUI_FINISHPAGE_LINK "Go to Dynare homepage"
 !define MUI_FINISHPAGE_SHOWREADME $INSTDIR\README.txt
 !insertmacro MUI_PAGE_FINISH
@@ -108,13 +101,13 @@ SectionGroupEnd
 SectionGroup "MEX files for Octave"
 
 Section "MEX files for Octave 5.1.0 (MinGW, 64bit)"
- SetOutPath $INSTDIR\mex\octave
- File ..\mex\octave\*
+ SetOutPath $INSTDIR\mex\octave\win64
+ File ..\mex\octave\win64\*
 SectionEnd
 
 Section "MEX files for Octave 5.1.0 (MinGW, 32bit)"
- SetOutPath $INSTDIR\mex\octave32
- File ..\mex\octave32\*
+ SetOutPath $INSTDIR\mex\octave\win32
+ File ..\mex\octave\win32\*
 SectionEnd
 
 SectionGroupEnd
@@ -123,12 +116,12 @@ SectionGroup "MinGW compiler (needed for use_dll option under MATLAB)"
 
 Section "MinGW for 32-bit MATLAB"
  SetOutPath $INSTDIR\mingw32
- File /r mingw32\*
+ File /r deps\mingw32\*
 SectionEnd
 
 Section "MinGW for 64-bit MATLAB"
  SetOutPath $INSTDIR\mingw64
- File /r mingw64\*
+ File /r deps\mingw64\*
 SectionEnd
 
 SectionGroupEnd
@@ -140,7 +133,7 @@ SectionEnd
 
 Section "Documentation and examples (Dynare and Dynare++)"
  SetOutPath $INSTDIR\doc
- File ..\doc\manual\build\latex\dynare-manual.pdf ..\doc\guide.pdf ..\doc\bvar-a-la-sims.pdf ..\doc\dr.pdf ..\doc\macroprocessor\macroprocessor.pdf ..\doc\preprocessor\preprocessor.pdf ..\doc\parallel\parallel.pdf ..\doc\gsa\gsa.pdf ..\doc\dseries-and-reporting\dseriesReporting.pdf
+ File ..\doc\manual\build\latex\dynare-manual.pdf ..\doc\guide.pdf ..\doc\bvar-a-la-sims.pdf ..\doc\dr.pdf ..\preprocessor\doc\macroprocessor\macroprocessor.pdf ..\preprocessor\doc\preprocessor\preprocessor.pdf ..\doc\parallel\parallel.pdf ..\doc\gsa\gsa.pdf ..\doc\dseries-and-reporting\dseriesReporting.pdf
 
  SetOutPath $INSTDIR\doc\dynare-manual.html
  File /r ..\doc\manual\build\html\*
diff --git a/windows/install-packages.sh b/windows/install-packages.sh
new file mode 100755
index 0000000000000000000000000000000000000000..2fbd2f7888e8c7b37a723b48c8244e15ec21dd55
--- /dev/null
+++ b/windows/install-packages.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+# On a Debian system, install the packages needed for Windows
+# cross-compilation, and also setup the cross-compiler alternatives.
+
+# Copyright © 2017-2019 Dynare Team
+#
+# This file is part of Dynare.
+#
+# Dynare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Dynare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
+
+[[ $(id -u) == 0 ]] || { echo "You must be root" >&2; exit 1; }
+
+PACKAGES=(make xz-utils p7zip bzip2 zip patch wget autoconf automake libtool
+          mingw-w64 gfortran-mingw-w64 parallel flex bison texlive
+          texlive-publishers texlive-latex-extra texlive-math-extra
+          texlive-fonts-extra lmodern python3-sphinx nsis)
+
+apt install "${PACKAGES[@]}"
+
+# Configure MinGW to use the POSIX threading model (needed for C++11 threads in
+# Dynare++, see /usr/share/doc/gcc-mingw-w64-base/README.Debian)
+update-alternatives --set x86_64-w64-mingw32-gfortran /usr/bin/x86_64-w64-mingw32-gfortran-posix
+update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
+update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
+update-alternatives --set i686-w64-mingw32-gfortran /usr/bin/i686-w64-mingw32-gfortran-posix
+update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix
+update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix