Add the ability to automatically detect MATLAB version at configure time

It is thus no longer needed to pass the MATLAB_VERSION option to the configure
script when compiling from source.
parent fa12e5ab
Pipeline #4236 passed with stages
in 233 minutes and 7 seconds
......@@ -27,7 +27,7 @@ build_binaries:
stage: build
script:
- autoreconf -si
- ./configure --with-matlab=/usr/local/MATLAB/$MATLAB_VERSION MATLAB_VERSION=$MATLAB_VERSION PACKAGE_VERSION=$VERSION PACKAGE_STRING="dynare $VERSION"
- ./configure --with-matlab=/usr/local/MATLAB/$MATLAB_VERSION PACKAGE_VERSION=$VERSION PACKAGE_STRING="dynare $VERSION"
- make -j $(nproc) LN_S="cp -p"
artifacts:
paths:
......@@ -69,7 +69,7 @@ pkg_source:
- rm doc/manual/source/_static/mathjax && sed -i "/^mathjax_path *=/d" doc/manual/source/conf.py
- 'for f in configure.ac preprocessor/configure.ac mex/build/matlab/configure.ac mex/build/octave/configure.ac; do sed -i "s/^AC_INIT(\[\(.*\)\],\s*\[\(.*\)\])/AC_INIT([\1], [$VERSION])/" $f; done'
- autoreconf -si
- ./configure --with-matlab=/usr/local/MATLAB/$MATLAB_VERSION MATLAB_VERSION=$MATLAB_VERSION
- ./configure --with-matlab=/usr/local/MATLAB/$MATLAB_VERSION
- make dist
artifacts:
paths:
......@@ -139,14 +139,14 @@ test_matlab:
extends: .test_matlab_template
script:
- autoreconf -si
- ./configure --disable-octave --with-matlab=/usr/local/MATLAB/$MATLAB_VERSION MATLAB_VERSION=$MATLAB_VERSION
- ./configure --disable-octave --with-matlab=/usr/local/MATLAB/$MATLAB_VERSION
- make -j $(($(nproc) * 3 / 4)) -C tests check-matlab
test_old_matlab:
extends: .test_matlab_template
script:
- autoreconf -si
- ./configure --disable-octave --with-matlab=/usr/local/MATLAB/$OLD_MATLAB_VERSION MATLAB_VERSION=$OLD_MATLAB_VERSION
- ./configure --disable-octave --with-matlab=/usr/local/MATLAB/$OLD_MATLAB_VERSION
- make -C mex/build/matlab clean
- make -j $(nproc) -C mex/build/matlab
- make -j $(($(nproc) * 3 / 4)) -C tests check-matlab
......
......@@ -106,11 +106,10 @@ Simply launch the configure script from a terminal:
```
./configure
```
If you have MATLAB, you need to indicate both the MATLAB location and version. For example, on GNU/Linux:
If you have MATLAB, you need to indicate both the MATLAB location. For example, on GNU/Linux:
```
./configure --with-matlab=/usr/local/MATLAB/R2019a MATLAB_VERSION=9.6
./configure --with-matlab=/usr/local/MATLAB/R2019a
```
Note that the MATLAB version can also be specified via the MATLAB family product release (R2019a, R2018b, …).
Alternatively, you can disable the compilation of MEX files for MATLAB with the `--disable-matlab` flag, and MEX files for Octave with `--disable-octave`.
......@@ -280,9 +279,9 @@ autoreconf -si
```
- Configure Dynare from the source directory:
```
./configure --with-slicot=/usr/local --with-matlab=<…> MATLAB_VERSION=<…> --disable-octave --disable-doc
./configure --with-slicot=/usr/local --with-matlab=<…> --disable-octave --disable-doc
```
where the path and version of MATLAB are specified. Note that you should use
where the path of MATLAB is specified. Note that you should use
the MSYS2 notation and not put spaces in the MATLAB path, so you probably want
to use something like `/c/Progra~1/MATLAB/…`. Alternatively, if your filesystem
does not have short filenames (8dot3), then you can run `mkdir -p
......@@ -344,7 +343,7 @@ folder where you want Dynare installed.
- `cd dynare`
- `PATH="/usr/local/opt/bison/bin:/usr/local/opt/flex/bin:$PATH"`
- `autoreconf -si`
- `CC=gcc-9 CXX=g++-9 ./configure --disable-octave --with-matlab=/Applications/MATLAB_R2019a.app MATLAB_VERSION=R2019a --with-matio=/usr/local --with-gsl=/usr/local --with-slicot=/usr/local`, adjusting the MATLAB path and version to accord with your local installation. If you don't have MATLAB, simply remove `--with-matlab=/Applications/MATLAB_R2019a.app MATLAB_VERSION=R2019a` from the above command
- `CC=gcc-9 CXX=g++-9 ./configure --disable-octave --with-matlab=/Applications/MATLAB_R2019a.app --with-matio=/usr/local --with-gsl=/usr/local --with-slicot=/usr/local`, adjusting the MATLAB path to accord with your local installation. If you don't have MATLAB, simply remove `--with-matlab=/Applications/MATLAB_R2019a.app` from the above command
- `make -j`
- **(Optional)** To then build mex files for Octave, run
- `cd mex/build/octave`
......
......@@ -20,7 +20,29 @@ AC_DEFUN([AX_MATLAB_VERSION],
AC_REQUIRE([AX_MATLAB])
AC_MSG_CHECKING([for MATLAB version])
if test -n "$MATLAB"; then
dnl Try to autodetect MATLAB version
if test -f "${MATLAB}/VersionInfo.xml"; then
dnl The VersionInfo.xml file is present on all versions since R2017a, on all platforms.
dnl Extract the version number as x.y, since it is our preferred form, and is
dnl more robust to future versions.
dnl NB: brackets in regular expressions are enclosed in other brackets, because this is m4
MATLAB_VERSION=$(sed -En '/<version>/s/.*>([[0-9]]+\.[[0-9]]+).*/\1/p' "${MATLAB}/VersionInfo.xml")
elif test -f "${MATLAB}/bin/util/mex/version.txt"; then
dnl The bin/util/mex/version.txt file is present on Windows and macOS, at least
dnl since R2009b. It contains the release number (Rnnnnx).
MATLAB_VERSION=$(cat "${MATLAB}/bin/util/mex/version.txt")
elif test -f "${MATLAB}/bin/mex" || test -f "${MATLAB}/bin/mexsh"; then
dnl Works on Linux and macOS until R2018a included. Returns the release number (Rnnnnx).
dnl Older MATLABs have the version in bin/mex, more recent in bin/mexsh
dnl NB: brackets in regular expressions are enclosed in other brackets, because this is m4
MATLAB_VERSION=$(sed -En "/^.*full_ver=/s/^.*full_ver='(R[[^']]+)'.*/\1/p" "${MATLAB}"/bin/mex*)
fi
fi
if test -n "$MATLAB_VERSION"; then
dnl Convert a release number (Rnnnnx) into a version number (x.y)
case $MATLAB_VERSION in
*2020b | *2020B)
MATLAB_VERSION="9.9"
......@@ -125,6 +147,7 @@ if test -n "$MATLAB_VERSION"; then
MATLAB_VERSION="7.0.0"
;;
esac
dnl Check that we have an x.y version number
if ! echo "${MATLAB_VERSION}" | grep -qE '^[[0-9.]]+$'; then
AC_MSG_ERROR([unknown MATLAB version ${MATLAB_VERSION}])
fi
......@@ -134,6 +157,5 @@ else
AC_MSG_RESULT([unknown])
ax_matlab_version_ok="no"
fi
AC_ARG_VAR([MATLAB_VERSION], [MATLAB version])
AC_SUBST([MATLAB_VERSION])
])
......@@ -73,7 +73,7 @@ CC=$CC CXX=$CXX ./configure \
--with-matio="$LIB64"/matio \
--with-slicot="$LIB64"/Slicot/with-underscore \
--disable-octave \
--with-matlab=/Applications/MATLAB_R2016b.app MATLAB_VERSION=R2016b
--with-matlab=/Applications/MATLAB_R2016b.app
if [[ -z $CI ]]; then
# If not in Gitlab CI, clean the source and build the doc
make clean
......@@ -144,7 +144,7 @@ CC=$CC CXX=$CXX ./configure \
--with-gsl="$LIB64"/gsl \
--with-matio="$LIB64"/matio \
--with-slicot="$LIB64"/Slicot/with-underscore \
--with-matlab=/Applications/MATLAB_R2019b.app MATLAB_VERSION=R2019b
--with-matlab=/Applications/MATLAB_R2019b.app
make -j"$NTHREADS"
cp -L "$ROOTDIR"/mex/matlab/* "$PKGFILES"/mex/matlab/maci64-9.4-9.9
......
......@@ -95,7 +95,6 @@ build_windows_matlab_mex_64_a ()
--with-matio="$LIB64_MSYS2" \
--with-slicot="$LIB64"/Slicot/without-underscore \
--with-matlab="$ROOT_DIRECTORY"/deps/matlab64/R2014a \
MATLAB_VERSION=R2014a \
MEXEXT=mexw64 \
PACKAGE_VERSION="$VERSION" \
PACKAGE_STRING="dynare $VERSION"
......@@ -116,7 +115,6 @@ build_windows_matlab_mex_64_b ()
--with-matio="$LIB64_MSYS2" \
--with-slicot="$LIB64"/Slicot/without-underscore \
--with-matlab="$ROOT_DIRECTORY"/deps/matlab64/R2018a \
MATLAB_VERSION=R2018a \
MEXEXT=mexw64 \
PACKAGE_VERSION="$VERSION" \
PACKAGE_STRING="dynare $VERSION"
......
......@@ -4,7 +4,7 @@ X13AS_VERSION = 1.1_B39
OCTAVE_VERSION = 5.2.0
OCTAVE_W64_BUILD = _1
MATLAB64_VERSION = 20200407
MATLAB64_VERSION = 20200930
### MSYS2 packages
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment