From a0fdc09c752f10de1be52c1f0d97383c55d7cf7b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 14 May 2018 14:35:12 +0200
Subject: [PATCH] Provisions for MATLAB 9.4 (R2018a)

Take into account the API break in the MEX interface (new interleaved complex API).
But do not split MEX directories on MacOS X for the time being.

(cherry picked from commit 473b2f59ef5a6bb7be2cd4391b1c29f8455ee7b8)
---
 m4/ax_matlab_version.m4        |  3 +++
 matlab/add_path_to_mex_files.m | 10 +++++++++-
 windows/dynare.nsi             |  5 +++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/m4/ax_matlab_version.m4 b/m4/ax_matlab_version.m4
index 603b29945..1004b91b9 100644
--- a/m4/ax_matlab_version.m4
+++ b/m4/ax_matlab_version.m4
@@ -22,6 +22,9 @@ AC_REQUIRE([AX_MATLAB])
 AC_MSG_CHECKING([for MATLAB version])
 if test "x$MATLAB_VERSION" != "x"; then
   case $MATLAB_VERSION in
+    *2018a | *2018A)
+      MATLAB_VERSION="9.4"
+      ;;
     *2017b | *2017B)
       MATLAB_VERSION="9.3"
       ;;
diff --git a/matlab/add_path_to_mex_files.m b/matlab/add_path_to_mex_files.m
index 0e5ddc5ed..e7f5967b3 100644
--- a/matlab/add_path_to_mex_files.m
+++ b/matlab/add_path_to_mex_files.m
@@ -51,7 +51,7 @@ else
                     addpath(mexpath);
                 end
             end
-        else
+        elseif matlab_ver_less_than('9.4')
             tmp = [dynareroot '../mex/matlab/win64-7.8-9.3/'];
             if exist(tmp, 'dir')
                 mexpath = tmp;
@@ -59,6 +59,14 @@ else
                     addpath(mexpath);
                 end
             end
+        else
+            tmp = [dynareroot '../mex/matlab/win64-9.4/'];
+            if exist(tmp, 'dir')
+                mexpath = tmp;
+                if modifypath
+                    addpath(mexpath);
+                end
+            end
         end
     end
     % Add OS X 64bits specific paths for Dynare Mac package
diff --git a/windows/dynare.nsi b/windows/dynare.nsi
index cf4b39491..6d7ffbee2 100644
--- a/windows/dynare.nsi
+++ b/windows/dynare.nsi
@@ -103,6 +103,11 @@ Section "MEX files for MATLAB 64-bit, version 7.8 to 9.3 (R2009a to R2017b)"
  File ..\mex\matlab\win64-7.8-9.3\*.mexw64
 SectionEnd
 
+Section "MEX files for MATLAB 64-bit, version 9.4 (R2018a)"
+ SetOutPath $INSTDIR\mex\matlab\win64-9.4
+ File ..\mex\matlab\win64-9.4\*.mexw64
+SectionEnd
+
 SectionGroupEnd
 
 SectionGroup "MEX files for OCTAVE"
-- 
GitLab