macOS: update README macOS instructions for both Apple silicon and intel

mr#2134
Willi Mutschler 2023-04-25 22:29:23 +02:00 committed by Sébastien Villemot
parent b8352b251d
commit 7ce2c1d5c2
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 107 additions and 56 deletions

163
README.md
View File

@ -397,84 +397,116 @@ adapted to a 32-bit MATLAB with the following modifications:
currently not supported.
## macOS
Dynare supports both Intel and Apple Silicon chips and is compiled from source
using a [Homebrew](https://brew.sh/) toolchain. However, if you have a *M1*,
*M1 PRO*, *M1 MAX*, *M2* or *M2 PRO* processor, you need to make sure that you are not using the ARM
Homebrew packages. This is due to the fact that although MATLAB runs natively on
Intel, it is not yet available in an ARM version and therefore must be run with the
Intel compatibility layer called Rosetta 2. Accordingly, if you are on Apple Silicon
you need to compile Dynare under Rosetta 2 as well and use the Intel packages from
Homebrew. You can check this by e.g. running `which brew` which should point to
`/usr/local/bin/brew` and not to `/opt/homebrew/bin/brew`. In the steps below, we
create a temporary alias to ensure that `brew` points to the Intel packages.
using a [Homebrew](https://brew.sh/) toolchain. If you have an Apple silicon processor
(*M1/M2 PRO/MAX/ULTRA*), you can compile Dynare both for Intel's `x86_64` (using Rosetta 2)
as well as Apple's native `arm64` platform by using the corresponding Homebrew packages.
If you have an Intel chip you can only compile for `x86_64`.
For the following steps open Terminal.app and enter the commands listed below.
You can check the platform of your current Homebrew installation by e.g. running
`which brew` which should point to `/opt/homebrew/bin/brew` for `arm64` and to
`/usr/local/bin/brew` for `x86_64` systems. In the steps below, we
create a temporary environmental variable `BREWDIR` to ensure that the correct packages are used.
The following commands install all requirements and Dynare from source.
They should be entered at the command prompt in Terminal.app.
### Preparatory work
- Install Rosetta 2 (Apple Silicon only):
```sh
softwareupdate --install-rosetta --agree-to-license
```
- Install the Xcode Command Line Tools:
```sh
xcode-select --install
```
- Install [Homebrew](https://brew.sh/):
- Install Rosetta 2 (Apple Silicon only):
```sh
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
softwareupdate --install-rosetta --agree-to-license
```
The prefix `arch -x86_64` makes sure that you are using Rosetta 2 to install Homebrew.
- Apple Silicon only: Make a (temporary) alias to run `brew` under Rosetta 2:
- Install [Homebrew](https://brew.sh/):
Create environmental variables for which platform you want to compile for, i.e. either `arm64` or `x86_64`:
For `arm64` run the following commands:
```sh
alias brew='arch -x86_64 /usr/local/bin/brew'
which brew
#brew: aliased to arch -x86_64 /usr/local/bin/brew
export ARCH=arm64
export BREWDIR=/opt/homebrew
```
For `x86_64` run the following commands:
```sh
export ARCH=x86_64
export BREWDIR=/usr/local
```
Install Homebrew using the environmental variables:
```sh
arch -$ARCH /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
The prefix `arch -arm64` or `arch -x86_64` makes sure that you are installing the correct packages.
Don't forget to run the displayed commands (**Next steps**) in the terminal to add Homebrew to your PATH.
If you have both Homebrew installations installed, make sure that you are accessing the correct packages by temporarily (!) prepending it to the path:
```sh
export PATH="$BREWDIR/bin:$PATH"
```
- Install required Homebrew packages and link sphinx-doc:
```sh
brew install automake bison flex boost gcc gsl libmatio veclibfort octave sphinx-doc wget
brew link --force sphinx-doc
arch -$ARCH $BREWDIR/bin/brew install automake bison flex boost gcc gsl libmatio veclibfort octave sphinx-doc docutils wget
```
- Install [MacTeX](http://www.tug.org/mactex/index.html) using the universal installer. MacTeX runs natively on both ARM and Intel machines. On Apple Silicon, we need to put `pdflatex` and `bibtex` into our path:
If you want to compile the documentation, you need to link sphinx-doc:
```sh
ln -s /Library/TeX/texbin/pdflatex /usr/local/bin/pdflatex
ln -s /Library/TeX/texbin/bibtex /usr/local/bin/bibtex
arch -$ARCH $BREWDIR/bin/brew link --force sphinx-doc
```
Otherwise add `--disable-doc` flag to the `configure` command below, if you want to skip this.
- Install [MacTeX](http://www.tug.org/mactex/index.html) using the universal installer. MacTeX runs natively on both ARM and Intel machines. On Apple Silicon, it is advised to symlink `pdflatex` and `bibtex` into `/usr/local/bin`:
```sh
sudo ln -s /Library/TeX/texbin/pdflatex /usr/local/bin/pdflatex
sudo ln -s /Library/TeX/texbin/bibtex /usr/local/bin/bibtex
```
Alternatively, if you dont want to install MacTeX, you should pass the `--disable-doc` flag to the `configure` command below.
- Install MATLAB and additional toolboxes. We recommend, but don't require, the following: Optimization, Global Optimization, Statistics and Machine Learning, Econometrics, and Control System. As there is no ARM version of MATLAB yet, Rosetta 2 will be used on Apple Silicon machines. Don't forget to run MATLAB at least once to make sure you have a valid license.
- Install MATLAB and additional toolboxes.
We recommend, but don't require, the following: Optimization, Global Optimization, Statistics and Machine Learning, Econometrics, and Control System.
For Apple Silicon: MATLAB offers a native Apple silicon version of R2022b as an open beta. You can sign up and install it (including a suitable Java 8 JRE, e.g. Amazon Corretto 8) using
[the official instructions](https://de.mathworks.com/support/apple-silicon-r2022b-beta.html).
Unfortunately, this version does not support yet the Optimization, Global Optimization and Econometrics toolboxes.
If you need these, please run the Intel version (under Rosetta 2) instead.
Don't forget to run MATLAB at least once to make sure you have a valid license.
- Compile and install SLICOT, needed for the `kalman_steady_state` MEX file.
- Create a folder for Dynare and its dependencies
```sh
mkdir -p $HOME/dynare/slicot
cd $HOME/dynare/slicot
wget https://deb.debian.org/debian/pool/main/s/slicot/slicot_5.0+20101122.orig.tar.gz
export DYNAREDIR=$HOME/dynare
```
- Compile and install SLICOT, needed for e.g. the `kalman_steady_state` MEX file.
```sh
mkdir -p $DYNAREDIR/slicot/lib
cd $DYNAREDIR/slicot
curl -O https://deb.debian.org/debian/pool/main/s/slicot/slicot_5.0+20101122.orig.tar.gz
tar xf slicot_5.0+20101122.orig.tar.gz
cd slicot-5.0+20101122
make -j$(sysctl -n hw.ncpu) FORTRAN=gfortran OPTS="-O2" LOADER=gfortran lib
cp slicot.a /usr/local/lib/libslicot_pic.a
make -j$(sysctl -n hw.ncpu) FORTRAN=$BREWDIR/bin/gfortran OPTS="-O2" LOADER=gfortran lib
cp slicot.a $DYNAREDIR/slicot/lib/libslicot_pic.a
make clean
make -j$(sysctl -n hw.ncpu) FORTRAN=gfortran OPTS="-O2 -fdefault-integer-8" LOADER=gfortran lib
cp slicot.a /usr/local/lib/libslicot64_pic.a
make -j$(sysctl -n hw.ncpu) FORTRAN=$BREWDIR/bin/gfortran OPTS="-O2 -fdefault-integer-8" LOADER=gfortran lib
cp slicot.a $DYNAREDIR/slicot/lib/libslicot64_pic.a
cd $HOME/dynare
```
- Compile and install the X-13ARIMA-SEATS Seasonal Adjustment Program
```sh
mkdir -p $HOME/dynare/x13as
cd $HOME/dynare/x13as
wget https://www2.census.gov/software/x-13arima-seats/x13as/unix-linux/program-archives/x13as_asciisrc-v1-1-b59.tar.gz
mkdir -p $DYNAREDIR/x13as
cd $DYNAREDIR/x13as
curl -O https://www2.census.gov/software/x-13arima-seats/x13as/unix-linux/program-archives/x13as_asciisrc-v1-1-b59.tar.gz
tar xf x13as_asciisrc-v1-1-b59.tar.gz
sed -i '' 's/-static//g' makefile.gf
make -j$(sysctl -n hw.ncpu) -f makefile.gf FC=gfortran LINKER=gfortran FFLAGS="-O2 -std=legacy" PROGRAM=x13as
cp x13as /usr/local/bin/x13as
make -j$(sysctl -n hw.ncpu) -f makefile.gf FC=$BREWDIR/bin/gfortran LINKER=$BREWDIR/bin/gcc-12 FFLAGS="-O2 -std=legacy" LDFLAGS=-static-libgcc LIBS="$BREWDIR/lib/gcc/current/libgfortran.a /$BREWDIR/lib/gcc/current/libquadmath.a" PROGRAM=x13as
mkdir -p $HOME/.local/bin
cp x13as $HOME/.local/bin/x13as
cd ;
x13as
```
@ -482,33 +514,52 @@ x13as
### Compile Dynare from source
The following commands will download the Dynare source code and compile
it. They should be entered at the command prompt in Terminal.app from the
folder where you want Dynare installed. Apple Silicon: make sure `brew`
points towards `/usr/local/bin/brew` (see above).
folder where you want Dynare installed.
- Prepare the Dynare sources for the unstable version:
```sh
mkdir -p $HOME/dynare/unstable
git clone --recurse-submodules https://git.dynare.org/Dynare/dynare.git $HOME/dynare/unstable
cd $HOME/dynare/unstable
arch -x86_64 autoreconf -si
mkdir -p $DYNAREDIR/unstable
git clone --recurse-submodules https://git.dynare.org/Dynare/dynare.git $DYNAREDIR/unstable
cd $DYNAREDIR/unstable
arch -$ARCH autoreconf -si
```
You can also choose a specific version of Dynare by checking out the corresponding branch or a specific tag with git.
- Configure Dynare from the source directory:
```sh
arch -x86_64 ./configure CC=gcc-12 CXX=g++-12 CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib LEX=/usr/local/opt/flex/bin/flex YACC=/usr/local/opt/bison/bin/bison --with-matlab=/Applications/MATLAB_R2021b.app
arch -$ARCH ./configure --prefix=$BREWDIR CC=gcc-12 CXX=g++-12 CPPFLAGS=-I$BREWDIR/include LDFLAGS=-L$BREWDIR/lib LEX=$BREWDIR/opt/flex/bin/flex YACC=$BREWDIR/opt/bison/bin/bison --with-slicot=$DYNAREDIR/slicot --with-matlab=/Applications/MATLAB_R2022b_Beta.app
```
where you need to adapt the path to MATLAB. If you dont have MATLAB, simply replace `--with-matlab=<…>` by `--disable-matlab`. Check the output of the command whether Dynare is configured for building everything except the internal docs of Dynare and M2HTML.
where you need to adapt the path to MATLAB. If you dont have MATLAB, simply replace `--with-matlab=<…>` by `--disable-matlab`.
Similarly, if you don't want to compile for Octave add a `--disable-octave` flag.
Check the output of the command whether Dynare is configured for building everything except the internal docs of Dynare and M2HTML.
- Compile:
```sh
arch -x86_64 make -j$(sysctl -n hw.ncpu)
arch -$ARCH make -j$(sysctl -n hw.ncpu)
```
If no errors occured, you are done. Dynare is now ready to use.
If you additionally want to compile the documentation run:
```sh
arch -$ARCH make pdf
arch -$ARCH make html
```
### Optional: pass the full PATH to MATLAB to run system commands
If you start MATLAB from a terminal, you will get the PATH inherited from the shell. However, when you click on the icon in macOS, you are not running at the terminal: the program is run by launcher, which does not go through a shell login session. You get the system default PATH which includes `/usr/bin:/bin:/usr/sbin:/sbin`, but not `/usr/local/bin` or `$HOME/.local/bin`. So if you want to use system commands like `pdflatex` or `x13as` you should either call them by their full path (e.g `/Library/TeX/texbin/pdflatex`) or append the PATH in MATLAB by running `setenv('PATH', [getenv('PATH') ':/usr/local/bin:$HOME/.local/bin:/Library/TeX/texbin']);`. Alternatively, you can create a `startup.m` file or change the system default PATH in the `/etc/paths` file.
If you start MATLAB from a terminal, you will get the PATH inherited from the shell.
However, when you click on the application icon in macOS, you are not running at the terminal level:
the program is run by launcher, which does not go through a shell login session.
In other words, you get the system default PATH which includes `/usr/bin:/bin:/usr/sbin:/sbin`, but not `/usr/local/bin` or `$HOME/.local/bin`.
So if you want to use system commands like `pdflatex` or `x13as` you should either call them by their full path (e.g `/Library/TeX/texbin/pdflatex`)
or append the PATH in MATLAB by running `setenv('PATH', [getenv('PATH') ':/usr/local/bin:$HOME/.local/bin:/Library/TeX/texbin']);`.
Alternatively, you can create a `startup.m` file or change the system default PATH in the `/etc/paths` file.
Tested on
- macOS Monterey 12.1 (Apple M1 Virtual Machine)
- macOS Monterey 12.1 (MacBook Air Intel)
- macOS Monterey 12.1 (MacBook Air M1)
### Optional: pass the full PATH to MATLAB to run system commands
If you start MATLAB from a terminal, you will get the PATH inherited from the shell.
However, when you click on the application icon in macOS, you are not running at the terminal level:
the program is run by launcher, which does not go through a shell login session.
In other words, you get the system default PATH which includes `/usr/bin:/bin:/usr/sbin:/sbin`, but not `/usr/local/bin` or `$HOME/.local/bin`.
So if you want to use system commands like `pdflatex` or `x13as` you should either call them by their full path (e.g `/Library/TeX/texbin/pdflatex`) or append the PATH in MATLAB by running `setenv('PATH', [getenv('PATH') ':/usr/local/bin:$HOME/.local/bin:/Library/TeX/texbin']);`.
Alternatively, you can create a `startup.m` file or change the system default PATH in the `/etc/paths` file.
Last tested on:
- macOS Ventura 13.3.1 (MacBook Air M1, MacBook Pro M2 MAX, M2 Virtual Machine using Parallels, Intel Virtual Machine using Quickemu)