Debian Codegraph @

windows/build.sh

raw
1 #!/bin/bash
2
3 # Produces Windows packages of Dynare (executable installer and 7z archives).
4 #
5 # The binaries are cross compiled for Windows (64-bit), Octave and MATLAB
6 # (all supported versions).
7
8 # Copyright © 2017-2026 Dynare Team
9 #
10 # This file is part of Dynare.
11 #
12 # Dynare is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
16 #
17 # Dynare is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with Dynare. If not, see <https://www.gnu.org/licenses/>.
24
25 # Exit on first error and print commands as they are executed
26 set -ex
27
28 # Set root directory
29 ROOT_DIRECTORY=$(dirname "$(readlink -f "$0")")
30
31 # Check that build directories do not already exist
32 [[ -d /tmp/windeps ]] && { echo "Please remove the /tmp/windeps directory" 2>&1; exit 1; }
33 [[ -d "$ROOT_DIRECTORY"/../build-win-matlab ]] && { echo "Please remove the build-win-matlab directory" 2>&1; exit 1; }
34 [[ -d "$ROOT_DIRECTORY"/../build-win-octave ]] && { echo "Please remove the build-win-octave directory" 2>&1; exit 1; }
35 [[ -z $CI ]] && [[ -d "$ROOT_DIRECTORY"/../build-doc ]] && { echo "Please remove the build-doc directory" 2>&1; exit 1; }
36
37 # Create temporary folder and make sure it is deleted upon exit (along with /tmp/windeps)
38 TMP_DIRECTORY=$(mktemp -d)
39 cleanup()
40 {
41 [[ -z $TMP_DIRECTORY ]] || rm -rf -- "$TMP_DIRECTORY"
42 rm -rf /tmp/windeps "$ROOT_DIRECTORY"/../build-win-matlab "$ROOT_DIRECTORY"/../build-win-octave
43 [[ -n $CI ]] || rm -rf "$ROOT_DIRECTORY"/../build-doc
44 }
45 trap cleanup EXIT
46
47 # Create a directory for dependencies under /tmp.
48 # Meson does not like when dependencies are under the source tree.
49 # We use a fixed name to avoid having to regenerate the cross files.
50 mkdir /tmp/windeps
51 ln -s "$ROOT_DIRECTORY"/deps/sysroot-matlab /tmp/windeps/
52 ln -s "$ROOT_DIRECTORY"/deps/sysroot-octave /tmp/windeps/
53 ln -s "$ROOT_DIRECTORY"/deps/mkoctfile /tmp/windeps/
54 ln -s "$ROOT_DIRECTORY"/deps/src /tmp/windeps/
55
56 # Go to source root directory
57 cd ..
58
59 common_meson_opts=(--buildtype=release -Db_lto=true --cross-file windows/mingw-cross.ini)
60
61 # Create Windows 64-bit DLL binaries for MATLAB ≥ R2020a
62 meson setup --cross-file windows/mingw-cross-matlab.ini -Dmatlab_path=/tmp/windeps/sysroot-matlab/MATLAB/R2020a \
63 "${common_meson_opts[@]}" build-win-matlab
64 meson compile -v -C build-win-matlab
65
66 # Create Windows DLL binaries for Octave/MinGW (64bit)
67 meson setup --cross-file windows/mingw-cross-octave.ini \
68 "${common_meson_opts[@]}" build-win-octave
69 meson compile -v -C build-win-octave
70
71 # If not in CI, build the docs
72 if [[ -z $CI ]]; then
73 meson compile -v -C build-win-matlab doc
74 ln -sf build-win-matlab build-doc
75 fi
76
77 # Determine Dynare version if not passed by an environment variable as in the CI
78 if [[ -z $VERSION ]]; then
79 cd build-win-matlab
80 VERSION=$(meson introspect --projectinfo | sed -En 's/^.*"version": "([^"]*)".*$/\1/p')
81 cd ..
82 fi
83
84 # Strip binaries
85 x86_64-w64-mingw32ucrt-strip build-win-matlab/preprocessor/src/dynare-preprocessor.exe
86 x86_64-w64-mingw32ucrt-strip -- build-win-matlab/*.mexw64
87 x86_64-w64-mingw32ucrt-strip -- build-win-octave/*.mex
88
89 # Add a preprocessor copy for backward compatibility
90 mkdir -p matlab/preprocessor64/
91 cp build-win-matlab/preprocessor/src/dynare-preprocessor.exe matlab/preprocessor64/dynare_m.exe
92
93 # Add supported_octave_version.m (see matlab/dynare.m)
94 while read -r line
95 do
96 if [[ "$line" =~ OCTAVE_VERSION[[:space:]]*=[[:space:]]*([^[:space:]]+) ]]; then
97 OCTAVE_VERSION=${BASH_REMATCH[1]}
98 break
99 fi
100 done < "$ROOT_DIRECTORY"/deps/versions.mk
101 [[ -n $OCTAVE_VERSION ]] || { echo "Can't find OCTAVE_VERSION in versions.mk" >&2; exit 1; }
102 # shellcheck disable=SC1117
103 echo -e "function v = supported_octave_version\nv=\"${OCTAVE_VERSION}\";\nend" > matlab/supported_octave_version.m
104
105 ## Create Windows installer
106 cd windows
107 makensis -DVERSION="$VERSION" dynare.nsi
108 mkdir -p exe
109 BASENAME=dynare-$VERSION
110 mv dynare-"$VERSION"-win.exe "$ROOT_DIRECTORY"/exe/"$BASENAME"-win.exe
111
112 ## Create 7z archive (for people not allowed to download/execute the installer)
113
114 # Set name of the root directory in the 7z archive
115 ZIPDIR="$TMP_DIRECTORY"/"$BASENAME"
116 mkdir -p "$ZIPDIR"
117
118 cd ..
119 cp -p NEWS.md "$ZIPDIR"
120 cp -p license.txt "$ZIPDIR"
121 cp -p windows/README.txt "$ZIPDIR"
122 cp -pr windows/deps/gcc/ucrt64 "$ZIPDIR"
123 mkdir -p "$ZIPDIR"/contrib/ms-sbvar/TZcode
124 cp -pr contrib/ms-sbvar/TZcode/MatlabFiles "$ZIPDIR"/contrib/ms-sbvar/TZcode
125 mkdir -p "$ZIPDIR"/mex/matlab/win64-9.8-26.1
126 cp -p build-win-matlab/*.mexw64 "$ZIPDIR"/mex/matlab/win64-9.8-26.1
127 mkdir -p "$ZIPDIR"/mex/octave/win64
128 cp -p build-win-octave/*.mex "$ZIPDIR"/mex/octave/win64
129 mkdir "$ZIPDIR"/preprocessor
130 cp -p build-win-matlab/preprocessor/src/dynare-preprocessor.exe "$ZIPDIR"/preprocessor
131 cp -pr matlab "$ZIPDIR"
132 cp -p build-win-matlab/dynare_version.m "$ZIPDIR"/matlab
133 mkdir -p "$ZIPDIR"/matlab/dseries/externals/x13/windows/64
134 cp -p windows/deps/x13as/x13as.exe "$ZIPDIR"/matlab/dseries/externals/x13/windows/64
135 cp -pr examples "$ZIPDIR"
136 mkdir -p "$ZIPDIR"/scripts
137 cp -p scripts/dynare.el "$ZIPDIR"/scripts
138 mkdir -p "$ZIPDIR"/doc
139 cp -p build-doc/*.pdf "$ZIPDIR"/doc
140 cp -p build-doc/preprocessor/doc/*.pdf "$ZIPDIR"/doc
141 cp -pr build-doc/dynare-manual.html "$ZIPDIR"/doc
142
143 cd "$TMP_DIRECTORY"
144
145 mkdir -p "$ROOT_DIRECTORY"/7z
146 7zr a -mx=9 "$ROOT_DIRECTORY"/7z/"$BASENAME"-win.7z "$BASENAME"