2019-09-16 18:28:34 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-01-03 14:05:37 +01:00
|
|
|
# Copyright © 2019-2023 Dynare Team
|
2019-09-30 16:46:02 +02:00
|
|
|
#
|
|
|
|
# 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
|
2021-06-09 17:33:48 +02:00
|
|
|
# along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2019-09-30 16:46:02 +02:00
|
|
|
|
2019-09-16 18:28:34 +02:00
|
|
|
set -ex
|
2023-09-27 12:15:11 +02:00
|
|
|
#exec > >(tee build-logfile.log) 2>&1 # uncomment for debugging
|
2019-09-16 18:28:34 +02:00
|
|
|
|
2019-11-04 17:10:33 +01:00
|
|
|
ROOTDIR=$(pwd)/..
|
2023-10-11 17:27:14 +02:00
|
|
|
##
|
|
|
|
## Set settings based on architecture
|
|
|
|
##
|
2023-09-27 12:16:53 +02:00
|
|
|
path_remove () { export "$1"="$(echo -n "${!1}" | awk -v RS=: -v ORS=: '$1 != "'"$2"'"' | sed 's/:$//')"; }
|
|
|
|
path_prepend () { path_remove "$1" "$2"; export "$1"="$2:${!1}"; }
|
|
|
|
PKG_ARCH=${1:-x86_64} # default to x86_64
|
|
|
|
if [[ "$PKG_ARCH" == arm64 ]]; then
|
2023-10-11 17:27:14 +02:00
|
|
|
BREWDIR=/opt/homebrew
|
|
|
|
# Make sure /opt/homebrew/bin is set first in PATH (as it might come last)
|
|
|
|
path_prepend PATH /opt/homebrew/bin
|
|
|
|
MATLAB_ARCH=maca64
|
|
|
|
else
|
|
|
|
BREWDIR=/usr/local
|
|
|
|
# Remove /opt/homebrew/bin from PATH, so it does not intervene with the x86_64 compilations
|
|
|
|
path_remove PATH /opt/homebrew/bin
|
|
|
|
MATLAB_ARCH=maci64
|
|
|
|
# On x86_64 we need to differentiate between older and newer MATLAB versions
|
2023-09-27 12:15:11 +02:00
|
|
|
OLD_MATLAB_PATH=/Applications/MATLAB_R2016b.app
|
2023-10-11 17:27:14 +02:00
|
|
|
fi
|
2023-09-27 12:15:11 +02:00
|
|
|
MATLAB_PATH=/Applications/"$PKG_ARCH"/MATLAB_R2023b.app
|
2023-10-11 17:27:14 +02:00
|
|
|
|
|
|
|
# Append texbin to PATH to access latexmk and friends
|
|
|
|
path_prepend PATH /Library/TeX/texbin
|
2019-11-04 17:10:33 +01:00
|
|
|
|
|
|
|
# Set dependency directory
|
2023-10-11 17:27:14 +02:00
|
|
|
LIB64="$ROOTDIR"/macOS/deps/"$PKG_ARCH"/lib64
|
2019-11-04 17:10:33 +01:00
|
|
|
|
2021-06-21 17:37:49 +02:00
|
|
|
## Hack for statically linking libquadmath, similar to the one used in
|
|
|
|
## deps/Makefile for several libraries (there is no -static-libquadmath flag,
|
|
|
|
## see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539).
|
|
|
|
##
|
2023-09-18 16:31:15 +02:00
|
|
|
## NB: The hack done for Windows does not work for two reasons:
|
2021-06-21 17:37:49 +02:00
|
|
|
## - the macOS linker is different from GNU ld and does not have the equivalent of -Bstatic/-Bdynamic
|
|
|
|
## - libgfortran.spec does not include --as-needed on macOS, hence it will link the library anyways
|
|
|
|
## Also, it does not seem possible to override libgfortran.spec with the --specs option.
|
2023-09-27 12:13:26 +02:00
|
|
|
GCC_VERSION=$(sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" "$ROOTDIR"/scripts/homebrew-native-"$PKG_ARCH".ini)
|
2023-10-11 17:27:14 +02:00
|
|
|
|
2021-06-21 17:37:49 +02:00
|
|
|
QUADMATH_DIR=$(mktemp -d)
|
2023-09-27 12:16:53 +02:00
|
|
|
ln -s "$BREWDIR"/opt/gcc/lib/gcc/"$GCC_VERSION"/libquadmath.a "$QUADMATH_DIR"
|
2021-06-21 17:37:49 +02:00
|
|
|
|
2019-09-16 18:28:34 +02:00
|
|
|
##
|
2023-09-18 16:31:15 +02:00
|
|
|
## Compile Dynare
|
2019-09-16 18:28:34 +02:00
|
|
|
##
|
|
|
|
cd "$ROOTDIR"
|
|
|
|
|
2023-10-11 17:09:07 +02:00
|
|
|
# NB: the addition of -Wl,-ld_classic is a workaround for https://github.com/mesonbuild/meson/issues/12282 (see also the native file)
|
2023-09-18 16:31:15 +02:00
|
|
|
common_meson_opts=(-Dbuild_for=matlab -Dbuildtype=release -Dprefer_static=true -Dfortran_args="[ '-B', '$LIB64/Slicot/' ]" \
|
2023-10-11 17:09:07 +02:00
|
|
|
-Dc_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" -Dcpp_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" -Dfortran_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" \
|
2023-10-11 17:27:14 +02:00
|
|
|
--native-file scripts/homebrew-native-$PKG_ARCH.ini)
|
2023-09-18 16:31:15 +02:00
|
|
|
|
2023-10-11 17:27:14 +02:00
|
|
|
# Build for MATLAB ⩾ R2018a (x86_64) and MATLAB ⩾ R2023b (arm64)
|
2023-09-27 12:15:11 +02:00
|
|
|
arch -"$PKG_ARCH" meson setup "${common_meson_opts[@]}" -Dmatlab_path="$MATLAB_PATH" build-matlab --wipe
|
2023-09-27 12:16:53 +02:00
|
|
|
arch -"$PKG_ARCH" meson compile -v -C build-matlab
|
2023-09-18 16:31:15 +02:00
|
|
|
|
2023-09-27 12:16:53 +02:00
|
|
|
if [[ "$PKG_ARCH" == x86_64 ]]; then
|
2023-10-11 17:27:14 +02:00
|
|
|
# Build for MATLAB < R2018a
|
2023-09-27 12:15:11 +02:00
|
|
|
arch -"$PKG_ARCH" meson setup "${common_meson_opts[@]}" -Dmatlab_path="$OLD_MATLAB_PATH" build-old-matlab --wipe
|
2023-09-27 12:16:53 +02:00
|
|
|
arch -"$PKG_ARCH" meson compile -v -C build-old-matlab
|
2023-10-11 17:27:14 +02:00
|
|
|
fi
|
2023-09-18 16:31:15 +02:00
|
|
|
|
|
|
|
# If not in CI, build the docs
|
2023-09-18 14:52:55 +02:00
|
|
|
if [[ -z $CI ]]; then
|
2023-09-27 12:16:53 +02:00
|
|
|
arch -"$PKG_ARCH" meson compile -v -C build-matlab doc
|
2023-09-18 16:31:15 +02:00
|
|
|
ln -s build-matlab build-doc
|
2023-09-18 14:52:55 +02:00
|
|
|
fi
|
2019-09-16 18:28:34 +02:00
|
|
|
|
|
|
|
##
|
|
|
|
## Create package
|
|
|
|
##
|
2023-09-18 16:31:15 +02:00
|
|
|
|
|
|
|
# Determine Dynare version if not passed by an environment variable as in the CI
|
|
|
|
if [[ -z $VERSION ]]; then
|
|
|
|
cd build-matlab
|
|
|
|
VERSION=$(meson introspect --projectinfo | sed -En 's/^.*"version": "([^"]*)".*$/\1/p')
|
|
|
|
cd ..
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Other useful variables
|
|
|
|
DATE=$(date +%Y-%m-%d-%H%M)
|
|
|
|
DATELONG=$(date '+%d %B %Y')
|
|
|
|
|
|
|
|
# Install location must not be too long for gcc.
|
|
|
|
# Otherwise, the headers of the compiled libraries cannot be modified
|
|
|
|
# obliging recompilation on the user's system.
|
|
|
|
# If VERSION is not a official release number, then do some magic
|
|
|
|
# to get something not too long, still more or less unique.
|
|
|
|
if [[ "$VERSION" =~ ^[0-9\.]+$ ]]; then
|
|
|
|
LOCATION=$VERSION
|
|
|
|
else
|
|
|
|
# Get the first component, truncate it to 5 characters, and add the date
|
|
|
|
LOCATION=$(echo "$VERSION" | cut -f1 -d"-" | cut -c 1-5)-"$DATE"
|
|
|
|
fi
|
2023-10-11 17:27:14 +02:00
|
|
|
# Add architecture to LOCATION and VERSION
|
|
|
|
VERSION="$VERSION"-"$PKG_ARCH"
|
|
|
|
LOCATION="$LOCATION"-"$PKG_ARCH"
|
2023-09-18 16:31:15 +02:00
|
|
|
|
2019-09-16 18:28:34 +02:00
|
|
|
NAME=dynare-"$VERSION"
|
|
|
|
PKGFILES="$ROOTDIR"/macOS/pkg/"$NAME"
|
2019-11-04 17:10:33 +01:00
|
|
|
mkdir -p \
|
2021-01-06 17:25:33 +01:00
|
|
|
"$PKGFILES"/preprocessor \
|
2023-01-03 14:05:37 +01:00
|
|
|
"$PKGFILES"/doc \
|
2019-11-04 17:10:33 +01:00
|
|
|
"$PKGFILES"/scripts \
|
|
|
|
"$PKGFILES"/contrib/ms-sbvar/TZcode
|
2023-09-27 12:16:53 +02:00
|
|
|
if [[ "$PKG_ARCH" == x86_64 ]]; then
|
2023-10-11 17:27:14 +02:00
|
|
|
mkdir -p "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-8.3-9.3 \
|
|
|
|
"$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-9.4-23.2
|
|
|
|
else
|
|
|
|
mkdir -p "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-23.2
|
|
|
|
fi
|
2019-11-04 17:10:33 +01:00
|
|
|
|
2020-02-17 23:12:12 +01:00
|
|
|
cp -p "$ROOTDIR"/NEWS.md "$PKGFILES"
|
2019-09-16 18:28:34 +02:00
|
|
|
cp -p "$ROOTDIR"/COPYING "$PKGFILES"
|
|
|
|
cp -p "$ROOTDIR"/license.txt "$PKGFILES"
|
|
|
|
|
|
|
|
cp -pr "$ROOTDIR"/matlab "$PKGFILES"
|
2023-09-20 10:53:10 +02:00
|
|
|
cp -p "$ROOTDIR"/build-matlab/dynare_version.m "$PKGFILES"/matlab
|
|
|
|
|
2019-09-16 18:28:34 +02:00
|
|
|
cp -pr "$ROOTDIR"/examples "$PKGFILES"
|
|
|
|
|
2023-09-18 16:31:15 +02:00
|
|
|
cp -p "$ROOTDIR"/build-matlab/preprocessor/src/dynare-preprocessor "$PKGFILES"/preprocessor
|
2021-01-06 17:25:33 +01:00
|
|
|
|
2023-09-18 16:31:15 +02:00
|
|
|
# Create backward-compatibility symlink
|
|
|
|
mkdir -p "$PKGFILES"/matlab/preprocessor64
|
2021-01-06 17:25:33 +01:00
|
|
|
ln -sf ../../preprocessor/dynare-preprocessor "$PKGFILES"/matlab/preprocessor64/dynare_m
|
|
|
|
|
2023-09-27 12:16:53 +02:00
|
|
|
if [[ "$PKG_ARCH" == x86_64 ]]; then
|
2023-10-11 17:27:14 +02:00
|
|
|
cp -L "$ROOTDIR"/build-matlab/*.mex"$MATLAB_ARCH" "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-9.4-23.2
|
|
|
|
cp -L "$ROOTDIR"/build-old-matlab/*.mex"$MATLAB_ARCH" "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-8.3-9.3
|
|
|
|
else
|
|
|
|
cp -L "$ROOTDIR"/build-matlab/*.mex"$MATLAB_ARCH" "$PKGFILES"/mex/matlab/"$MATLAB_ARCH"-23.2
|
|
|
|
fi
|
2019-09-16 18:28:34 +02:00
|
|
|
|
|
|
|
cp -p "$ROOTDIR"/scripts/dynare.el "$PKGFILES"/scripts
|
2019-10-04 09:50:50 +02:00
|
|
|
cp -pr "$ROOTDIR"/contrib/ms-sbvar/TZcode/MatlabFiles "$PKGFILES"/contrib/ms-sbvar/TZcode
|
2019-09-16 18:28:34 +02:00
|
|
|
cp -pr "$ROOTDIR"/contrib/jsonlab "$PKGFILES"/contrib
|
|
|
|
|
2023-09-18 14:52:55 +02:00
|
|
|
cp "$ROOTDIR"/build-doc/*.pdf "$PKGFILES"/doc
|
|
|
|
cp "$ROOTDIR"/build-doc/preprocessor/doc/*.pdf "$PKGFILES"/doc
|
|
|
|
cp -r "$ROOTDIR"/build-doc/dynare-manual.html "$PKGFILES"/doc
|
2019-09-16 18:28:34 +02:00
|
|
|
|
2019-10-03 18:06:37 +02:00
|
|
|
mkdir -p "$PKGFILES"/matlab/modules/dseries/externals/x13/macOS/64
|
2023-09-27 12:16:53 +02:00
|
|
|
cp -p "$ROOTDIR"/macOS/deps/"$PKG_ARCH"/lib64/x13as/x13as "$PKGFILES"/matlab/modules/dseries/externals/x13/macOS/64
|
2019-09-30 16:45:36 +02:00
|
|
|
|
2019-09-16 18:28:34 +02:00
|
|
|
|
|
|
|
cd "$ROOTDIR"/macOS/pkg
|
2019-11-04 17:10:33 +01:00
|
|
|
|
|
|
|
# Dynare option
|
2023-09-27 12:16:53 +02:00
|
|
|
arch -"$PKG_ARCH" pkgbuild --root "$PKGFILES" --identifier org.dynare."$VERSION" --version "$VERSION" --install-location /Applications/Dynare/"$LOCATION" "$NAME".pkg
|
2019-11-04 17:10:33 +01:00
|
|
|
|
2023-10-11 17:23:42 +02:00
|
|
|
# Create distribution.xml by replacing variables in distribution_template.xml
|
|
|
|
sed -e "s/VERSION_NO_SPACE/$VERSION/g" \
|
2023-09-26 12:23:31 +02:00
|
|
|
-e "s/LOCATION/$LOCATION/g" \
|
2023-10-11 17:23:42 +02:00
|
|
|
"$ROOTDIR"/macOS/distribution_template.xml > distribution.xml
|
|
|
|
|
|
|
|
# Create welcome.html by replacing variables in welcome_template.html
|
|
|
|
sed -e "s/VERSION_NO_SPACE/$VERSION/g" \
|
|
|
|
-e "s/DATE/$DATELONG/g" \
|
|
|
|
"$ROOTDIR"/macOS/welcome_template.html > "$ROOTDIR"/macOS/welcome.html
|
|
|
|
|
|
|
|
# Create conclusion.html by replacing variables in conclusion_template.html
|
|
|
|
sed -e "s/GCC_VERSION/$GCC_VERSION/g" \
|
|
|
|
"$ROOTDIR"/macOS/conclusion_template.html > "$ROOTDIR"/macOS/conclusion.html
|
2019-11-04 17:10:33 +01:00
|
|
|
|
|
|
|
# Create installer
|
2023-09-27 12:16:53 +02:00
|
|
|
arch -"$PKG_ARCH" productbuild --distribution distribution.xml --resources "$ROOTDIR"/macOS --package-path ./"$NAME".pkg "$NAME"-productbuild.pkg
|
2019-11-04 17:10:33 +01:00
|
|
|
|
2023-09-26 12:23:31 +02:00
|
|
|
# Cleanup
|
2023-10-11 17:23:42 +02:00
|
|
|
rm -f ./distribution.xml
|
2019-09-16 18:28:34 +02:00
|
|
|
rm -rf "$PKGFILES"
|
2019-11-04 17:10:33 +01:00
|
|
|
rm -f "$ROOTDIR"/macOS/welcome.html
|
2023-10-11 17:23:42 +02:00
|
|
|
rm -f "$ROOTDIR"/macOS/conclusion.html
|
2019-11-04 17:10:33 +01:00
|
|
|
|
|
|
|
# Final pkg
|
2023-09-26 12:23:31 +02:00
|
|
|
mv "$NAME"-productbuild.pkg "$NAME".pkg
|