diff --git a/.gitignore b/.gitignore index a5a9becfc..cee39574d 100644 --- a/.gitignore +++ b/.gitignore @@ -130,9 +130,13 @@ windows/zip/ # MacOS stuff .DS_Store macOS/pkg/ -macOS/deps/sources64/ macOS/deps/tarballs/ +macOS/deps/sources64/ +macOS/deps/sources64/arm64/ +macOS/deps/sources64/x86_64/ macOS/deps/lib64/ +macOS/deps/lib64/arm64/ +macOS/deps/lib64/x86_64/ # Emacs stuff scripts/dynare.elc diff --git a/macOS/Makefile b/macOS/Makefile index 3a51bd58a..56d6e2180 100644 --- a/macOS/Makefile +++ b/macOS/Makefile @@ -15,22 +15,38 @@ # You should have received a copy of the GNU General Public License # along with Dynare. If not, see . -.PHONY: all deps clean-deps clean clean-all build +.PHONY: all clean-all clean-pkg clean-mex-matlab\ + deps-arm64 deps-x86_64 \ + clean-arm64-deps clean-x86_64-deps \ + build-arm64 build-x86_64 -NTHREADS=$(shell sysctl -n hw.ncpu) +NTHREADS=$(shell sysctl -n hw.physicalcpu) -all: build +all: build-arm64 build-x86_64 -deps: - make -C deps -j$(NTHREADS) +deps-arm64: + make -C deps -j$(NTHREADS) build-arm64 -clean-deps: - make -C deps clean-all +deps-x86_64: + make -C deps -j$(NTHREADS) build-x86_64 -clean: +clean-arm64-deps: + make -C deps clean-arm64-all + +clean-x86_64-deps: + make -C deps clean-x86_64-all + +clean-pkg: rm -rf pkg -clean-all: clean-deps clean +clean-mex-matlab: + # make sure there are no symbolic links left to possibly missing mexmaca64 or mexmaci64 files + rm -rf ../mex/matlab -build: deps - ./build.sh +clean-all: clean-arm64-deps clean-x86_64-deps clean-pkg clean-mex-matlab + +build-arm64: deps-arm64 + ./build.sh arm64 + +build-x86_64: deps-x86_64 + ./build.sh x86_64 diff --git a/macOS/build.sh b/macOS/build.sh index 76b34808f..a31a1306f 100755 --- a/macOS/build.sh +++ b/macOS/build.sh @@ -21,6 +21,24 @@ set -ex ROOTDIR=$(pwd)/.. +# Set arch, base dir of homebrew, and versions of MATLAB to be used +ARCH=$1 +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}"; } +if [ $ARCH == arm64 ]; then + 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_VERSION_0=MATLAB_R2022a_Beta +else + BREWDIR=/usr/local + # remove /opt/homebrew/bin from PATH, so it does not intervene with the x86_64 compilations below + path_remove PATH /opt/homebrew/bin + # on x86_64 we need to differentiate between MATLAB < 2018a and MATLAB ≥ 2018a + MATLAB_VERSION_0=MATLAB_R2016b + MATLAB_VERSION_1=MATLAB_R2019b +fi + # Set the GCC version GCC_VERSION=12 @@ -29,10 +47,10 @@ CC=gcc-$GCC_VERSION CXX=g++-$GCC_VERSION # Set the number of threads -NTHREADS=$(sysctl -n hw.ncpu) +NTHREADS=$(sysctl -n hw.physicalcpu) # Set dependency directory -LIB64="$ROOTDIR"/macOS/deps/lib64 +LIB64="$ROOTDIR"/macOS/deps/lib64/"$ARCH" ## @@ -64,6 +82,10 @@ else LOCATION=$(echo "$VERSION" | cut -f1 -d"-" | cut -c 1-5)-"$DATE" fi +# Make sure arch is appended to LOCATION and VERSION +VERSION="$VERSION"-"$ARCH" +LOCATION="$LOCATION"-"$ARCH" + ## 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). @@ -73,36 +95,36 @@ fi ## - 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. QUADMATH_DIR=$(mktemp -d) -ln -s /usr/local/opt/gcc/lib/gcc/$GCC_VERSION/libquadmath.a $QUADMATH_DIR +ln -s "$BREWDIR"/opt/gcc/lib/gcc/$GCC_VERSION/libquadmath.a $QUADMATH_DIR ## -## Compile Dynare doc, preprocessor, mex for MATLAB < 2018a +## Compile Dynare doc, dynare++, preprocessor, mex using MATLAB_VERSION_0 ## ## NB: In Homebrew, -static-libgfortran is implied by -static-libgcc (see “gfortran -dumpspecs”) ## NB2: We use the hack for libquadmath in LDFLAGS cd "$ROOTDIR" -[[ -f configure ]] || autoreconf -si -./configure \ +arch -$ARCH autoreconf -si +arch -$ARCH ./configure \ PACKAGE_VERSION="$VERSION" \ PACKAGE_STRING="dynare $VERSION" \ CC=$CC \ CXX=$CXX \ - CPPFLAGS=-I/usr/local/include \ + CPPFLAGS=-I"$BREWDIR"/include \ LDFLAGS="-static-libgcc -L$QUADMATH_DIR" \ - LEX=/usr/local/opt/flex/bin/flex \ - YACC=/usr/local/opt/bison/bin/bison \ + LEX="$BREWDIR"/opt/flex/bin/flex \ + YACC="$BREWDIR"/opt/bison/bin/bison \ + --prefix="$BREWDIR" \ --with-gsl="$LIB64"/gsl \ --with-matio="$LIB64"/matio \ --with-slicot="$LIB64"/Slicot/with-underscore \ --disable-octave \ - --with-matlab=/Applications/MATLAB_R2016b.app + --with-matlab=/Applications/"$MATLAB_VERSION_0".app if [[ -z $CI ]]; then # If not in Gitlab CI, clean the source and build the doc - make clean - make -j"$NTHREADS" pdf html + arch -$ARCH make clean + arch -$ARCH make pdf html fi -make -j"$NTHREADS" - +arch -$ARCH make -j"$NTHREADS" ## ## Create package @@ -111,11 +133,16 @@ NAME=dynare-"$VERSION" PKGFILES="$ROOTDIR"/macOS/pkg/"$NAME" mkdir -p \ "$PKGFILES"/preprocessor \ - "$PKGFILES"/mex/matlab/maci64-8.3-9.3 \ - "$PKGFILES"/mex/matlab/maci64-9.4-9.14 \ - "$PKGFILES"/doc \ + "$PKGFILES"/doc/dynare++ \ + "$PKGFILES"/dynare++ \ "$PKGFILES"/scripts \ "$PKGFILES"/contrib/ms-sbvar/TZcode +if [ $ARCH == arm64 ]; then + mkdir -p "$PKGFILES"/mex/matlab/maca64-9.12 +else + mkdir -p "$PKGFILES"/mex/matlab/maci64-8.3-9.3 + mkdir -p "$PKGFILES"/mex/matlab/maci64-9.4-9.12 +fi if [[ $VERSION == *-unstable* ]]; then echo "$SHA" > "$PKGFILES"/sha.txt @@ -134,7 +161,11 @@ cp -p "$ROOTDIR"/preprocessor/src/dynare-preprocessor "$PKGFILES" rm -f "$ROOTDIR"/matlab/preprocessor64/dynare_m ln -sf ../../preprocessor/dynare-preprocessor "$PKGFILES"/matlab/preprocessor64/dynare_m -cp -L "$ROOTDIR"/mex/matlab/* "$PKGFILES"/mex/matlab/maci64-8.3-9.3 +if [ $ARCH == arm64 ]; then + cp -L "$ROOTDIR"/mex/matlab/*.mexmaca64 "$PKGFILES"/mex/matlab/maca64-9.12 +else + cp -L "$ROOTDIR"/mex/matlab/**.mexmaci64 "$PKGFILES"/mex/matlab/maci64-8.3-9.3 +fi cp -p "$ROOTDIR"/scripts/dynare.el "$PKGFILES"/scripts cp -pr "$ROOTDIR"/contrib/ms-sbvar/TZcode/MatlabFiles "$PKGFILES"/contrib/ms-sbvar/TZcode @@ -150,28 +181,29 @@ cp "$ROOTDIR"/doc/manual/build/latex/dynare-manual.pdf "$PKGFILES" cp -r "$ROOTDIR"/doc/manual/build/html "$PKGFILES"/doc/dynare-manual.html mkdir -p "$PKGFILES"/matlab/modules/dseries/externals/x13/macOS/64 -cp -p "$ROOTDIR"/macOS/deps/lib64/x13as/x13as "$PKGFILES"/matlab/modules/dseries/externals/x13/macOS/64 - - -## -## Create mex for MATLAB ≥ 2018a -## -cd "$ROOTDIR"/mex/build/matlab -make clean -./configure \ - PACKAGE_VERSION="$VERSION" \ - PACKAGE_STRING="dynare $VERSION" \ - CC=$CC \ - CXX=$CXX \ - CPPFLAGS=-I/usr/local/include \ - LDFLAGS="-static-libgcc -L$QUADMATH_DIR" \ - --with-gsl="$LIB64"/gsl \ - --with-matio="$LIB64"/matio \ - --with-slicot="$LIB64"/Slicot/with-underscore \ - --with-matlab=/Applications/MATLAB_R2022b.app -make -j"$NTHREADS" -cp -L "$ROOTDIR"/mex/matlab/* "$PKGFILES"/mex/matlab/maci64-9.4-9.14 +cp -p "$ROOTDIR"/macOS/deps/lib64/"$ARCH"/x13as/x13as "$PKGFILES"/matlab/modules/dseries/externals/x13/macOS/64 +if [ $ARCH == x86_64 ]; then + ## + ## Create mex using MATLAB_VERSION_1 + ## + cd "$ROOTDIR"/mex/build/matlab + arch -$ARCH make clean + arch -$ARCH ./configure \ + PACKAGE_VERSION="$VERSION" \ + PACKAGE_STRING="dynare $VERSION" \ + CC=$CC \ + CXX=$CXX \ + CPPFLAGS=-I/usr/local/include \ + LDFLAGS="-static-libgcc -L$QUADMATH_DIR" \ + --prefix=/usr/local \ + --with-gsl="$LIB64"/gsl \ + --with-matio="$LIB64"/matio \ + --with-slicot="$LIB64"/Slicot/with-underscore \ + --with-matlab=/Applications/"$MATLAB_VERSION_1".app + arch -$ARCH make -j"$NTHREADS" + cp -L "$ROOTDIR"/mex/matlab/*.mexmaci64 "$PKGFILES"/mex/matlab/maci64-9.4-9.12 +fi ## ## Make package @@ -179,12 +211,12 @@ cp -L "$ROOTDIR"/mex/matlab/* "$PKGFILES" cd "$ROOTDIR"/macOS/pkg # Dynare option -pkgbuild --root "$PKGFILES" --identifier org.dynare --version "$VERSION" --install-location /Applications/Dynare/"$LOCATION" "$NAME".pkg +arch -$ARCH pkgbuild --root "$PKGFILES" --identifier org.dynare --version "$VERSION" --install-location /Applications/Dynare/"$LOCATION" "$NAME".pkg # GCC option # Create dummy payload for GCC package; otherwise the size is displayed as 0 bytes in the installer dd if=/dev/zero of="$ROOTDIR"/macOS/brewfiles/dummy bs=1m count=800 -pkgbuild --root "$ROOTDIR"/macOS/brewfiles --identifier org.dynare.gcc --version "$VERSION" --scripts "$ROOTDIR"/macOS/scripts --install-location /Applications/Dynare/"$LOCATION" "$NAME"-gcc.pkg +arch -$ARCH pkgbuild --root "$ROOTDIR"/macOS/brewfiles --identifier org.dynare.gcc --version "$VERSION" --scripts "$ROOTDIR"/macOS/scripts/"$ARCH" --install-location /Applications/Dynare/"$LOCATION" "$NAME"-gcc.pkg # Replace variables in displayed files sed "s/VERSION_READ/$VERSION/g" "$ROOTDIR"/macOS/distribution_template.xml > distribution_tmp.xml @@ -194,7 +226,7 @@ sed "s/VERSION_NO_SPACE/$VERSION/g" "$ROOTDIR"/macOS/welcome.html > "$ROOTDIR"/m sed "s/DATE/$DATELONG/g" "$ROOTDIR"/macOS/welcome_tmp.html > "$ROOTDIR"/macOS/welcome.html # Create installer -productbuild --distribution distribution.xml --resources "$ROOTDIR"/macOS --package-path ./"$NAME".pkg "$NAME"-new.pkg +arch -$ARCH productbuild --distribution distribution.xml --resources "$ROOTDIR"/macOS --package-path ./"$NAME".pkg "$NAME"-new.pkg # cleanup rm -f ./*.xml diff --git a/macOS/deps/Makefile b/macOS/deps/Makefile index 42f511c93..df15c68a2 100644 --- a/macOS/deps/Makefile +++ b/macOS/deps/Makefile @@ -22,66 +22,118 @@ ROOT_PATH = $(realpath .) WGET_OPTIONS := --no-verbose --no-use-server-timestamps --retry-connrefused --retry-on-host-error -.PHONY: all build build-slicot build-x13as \ - clean-lib clean-libslicot clean-x13as-bin \ - clean-src clean-slicot-src clean-x13as-src \ +.PHONY: all clean_all\ + build-x86_64 build-x86_64-slicot build-x86_64-x13as \ + build-arm64 build-arm64-slicot build-arm64-x13as \ + clean-x86_64-lib clean-x86_64-libslicot clean-x86_64-x13as-bin \ + clean-arm64-lib clean-arm64-libslicot clean-arm64-x13as-bin \ + clean-x86_64-src clean-x86_64-slicot-src clean-x86_64-x13as-src \ + clean-arm64-src clean-arm64-slicot-src clean-arm64-x13as-src \ clean-tar clean-slicot-tar clean-x13as-tar \ - clean-all clean-lib clean-src clean-tar + clean-x86_64-all clean-x86_64-lib clean-x86_64-src \ + clean-arm64-all clean-arm64-lib clean-arm64-src \ + ln-x86_64-matio ln-x86_64-gsl \ + ln-arm64-matio ln-arm64-gsl -all: build +all: build-x86_64 build-arm64 -build: build-slicot build-x13as ln-matio ln-gsl +clean_all: clean-x86_64-all clean-arm64-all -clean-lib: clean-libslicot clean-x13as-bin +build-x86_64: build-x86_64-slicot build-x86_64-x13as ln-x86_64-matio ln-x86_64-gsl -clean-src: clean-slicot-src clean-x13as-src +build-arm64: build-arm64-slicot build-arm64-x13as ln-arm64-matio ln-arm64-gsl + +clean-x86_64-lib: clean-x86_64-libslicot clean-x86_64-x13as-bin + +clean-arm64-lib: clean-arm64-libslicot clean-arm64-x13as-bin + +clean-x86_64-src: clean-x86_64-slicot-src clean-x86_64-x13as-src + +clean-arm64-src: clean-arm64-slicot-src clean-arm64-x13as-src clean-tar: clean-slicot-tar clean-x13as-tar -clean-all: clean-lib clean-src clean-tar +clean-x86_64-all: clean-x86_64-lib clean-x86_64-src clean-tar +clean-arm64-all: clean-arm64-lib clean-arm64-src clean-tar # # Matio & GSL # (done to link only to static Matio and GSL libraries) # Matio -lib64/matio/lib/libmatio.a: /usr/local/lib/libmatio.a +lib64/x86_64/matio/lib/libmatio.a: /usr/local/lib/libmatio.a mkdir -p $(dir $@) && ln -sf $< $@ -lib64/matio/lib/libhdf5.a: /usr/local/lib/libhdf5.a +lib64/arm64/matio/lib/libmatio.a: /opt/homebrew/lib/libmatio.a mkdir -p $(dir $@) && ln -sf $< $@ -lib64/matio/lib/libsz.a: /usr/local/lib/libsz.a +lib64/x86_64/matio/lib/libhdf5.a: /usr/local/lib/libhdf5.a mkdir -p $(dir $@) && ln -sf $< $@ -lib64/matio/include/matio.h: /usr/local/include/matio.h +lib64/arm64/matio/lib/libhdf5.a: /opt/homebrew/lib/libhdf5.a + mkdir -p $(dir $@) && ln -sf $< $@ + +lib64/x86_64/matio/lib/libsz.a: /usr/local/lib/libsz.a + mkdir -p $(dir $@) && ln -sf $< $@ + +lib64/arm64/matio/lib/libsz.a: /opt/homebrew/lib/libsz.a + mkdir -p $(dir $@) && ln -sf $< $@ + +lib64/x86_64/matio/include/matio.h: /usr/local/include/matio.h mkdir -p $(dir $@) && cd $(dir $@).. && rm -rf include && ln -sf $(dir $<) . -ln-matio: lib64/matio/lib/libmatio.a \ - lib64/matio/lib/libhdf5.a \ - lib64/matio/lib/libsz.a \ - lib64/matio/include/matio.h +lib64/arm64/matio/include/matio.h: /opt/homebrew/include/matio.h + mkdir -p $(dir $@) && cd $(dir $@).. && rm -rf include && ln -sf $(dir $<) . -clean-matio: - rm -rf lib64/matio +ln-x86_64-matio: lib64/x86_64/matio/lib/libmatio.a \ + lib64/x86_64/matio/lib/libhdf5.a \ + lib64/x86_64/matio/lib/libsz.a \ + lib64/x86_64/matio/include/matio.h + +ln-arm64-matio: lib64/arm64/matio/lib/libmatio.a \ + lib64/arm64/matio/lib/libhdf5.a \ + lib64/arm64/matio/lib/libsz.a \ + lib64/arm64/matio/include/matio.h + +clean-x86_64-matio: + rm -rf lib64/x86_64/matio + +clean-arm64-matio: + rm -rf lib64/arm64/matio # GSL -lib64/gsl/lib/libgsl.a: /usr/local/lib/libgsl.a +lib64/x86_64/gsl/lib/libgsl.a: /usr/local/lib/libgsl.a mkdir -p $(dir $@) && ln -sf $< $@ -lib64/gsl/lib/libgslcblas.a: /usr/local/lib/libgslcblas.a +lib64/arm64/gsl/lib/libgsl.a: /opt/homebrew/lib/libgsl.a mkdir -p $(dir $@) && ln -sf $< $@ -lib64/gsl/include/gsl/gsl_blas.h: /usr/local/include/gsl/gsl_blas.h +lib64/x86_64/gsl/lib/libgslcblas.a: /usr/local/lib/libgslcblas.a + mkdir -p $(dir $@) && ln -sf $< $@ + +lib64/arm64/gsl/lib/libgslcblas.a: /opt/homebrew/lib/libgslcblas.a + mkdir -p $(dir $@) && ln -sf $< $@ + +lib64/x86_64/gsl/include/gsl/gsl_blas.h: /usr/local/include/gsl/gsl_blas.h mkdir -p $(dir $@) && cd $(dir $@).. && rm -rf gsl && ln -sf $(dir $<) . -ln-gsl: lib64/gsl/lib/libgsl.a \ - lib64/gsl/lib/libgslcblas.a \ - lib64/gsl/include/gsl/gsl_blas.h +lib64/arm64/gsl/include/gsl/gsl_blas.h: /opt/homebrew/include/gsl/gsl_blas.h + mkdir -p $(dir $@) && cd $(dir $@).. && rm -rf gsl && ln -sf $(dir $<) . -clean-gsl: - rm -rf lib64/gsl +ln-x86_64-gsl: lib64/x86_64/gsl/lib/libgsl.a \ + lib64/x86_64/gsl/lib/libgslcblas.a \ + lib64/x86_64/gsl/include/gsl/gsl_blas.h + +ln-arm64-gsl: lib64/arm64/gsl/lib/libgsl.a \ + lib64/arm64/gsl/lib/libgslcblas.a \ + lib64/arm64/gsl/include/gsl/gsl_blas.h + +clean-x86_64-gsl: + rm -rf lib64/x86_64/gsl + +clean-arm64-gsl: + rm -rf lib64/arm64/gsl # # Slicot @@ -90,43 +142,78 @@ tarballs/slicot-$(SLICOT_VERSION).tar.gz: mkdir -p tarballs wget $(WGET_OPTIONS) -O $@ https://deb.debian.org/debian/pool/main/s/slicot/slicot_$(SLICOT_VERSION).orig.tar.gz -sources64/slicot-$(SLICOT_VERSION)-with-32bit-integer-and-underscore: tarballs/slicot-$(SLICOT_VERSION).tar.gz - rm -rf sources64/slicot-*-with-32bit-integer-and-underscore +sources64/x86_64/slicot-$(SLICOT_VERSION)-with-32bit-integer-and-underscore: tarballs/slicot-$(SLICOT_VERSION).tar.gz + rm -rf sources64/x86_64/slicot-*-with-32bit-integer-and-underscore mkdir -p $@ tar xf $< --directory $@ --strip-components=1 touch $@ -sources64/slicot-$(SLICOT_VERSION)-with-64bit-integer-and-underscore: tarballs/slicot-$(SLICOT_VERSION).tar.gz - rm -rf sources64/slicot-*-with-64bit-integer-and-underscore +sources64/arm64/slicot-$(SLICOT_VERSION)-with-32bit-integer-and-underscore: tarballs/slicot-$(SLICOT_VERSION).tar.gz + rm -rf sources64/arm64/slicot-*-with-32bit-integer-and-underscore mkdir -p $@ tar xf $< --directory $@ --strip-components=1 touch $@ -lib64/Slicot/with-underscore/lib/libslicot_pic.a: sources64/slicot-$(SLICOT_VERSION)-with-32bit-integer-and-underscore - make -C $< FORTRAN=gfortran LOADER=gfortran SLICOTLIB=../libslicot_pic.a OPTS="-O2 -g" lib +sources64/x86_64/slicot-$(SLICOT_VERSION)-with-64bit-integer-and-underscore: tarballs/slicot-$(SLICOT_VERSION).tar.gz + rm -rf sources64/x86_64/slicot-*-with-64bit-integer-and-underscore + mkdir -p $@ + tar xf $< --directory $@ --strip-components=1 + touch $@ + +sources64/arm64/slicot-$(SLICOT_VERSION)-with-64bit-integer-and-underscore: tarballs/slicot-$(SLICOT_VERSION).tar.gz + rm -rf sources64/arm64/slicot-*-with-64bit-integer-and-underscore + mkdir -p $@ + tar xf $< --directory $@ --strip-components=1 + touch $@ + +lib64/x86_64/Slicot/with-underscore/lib/libslicot_pic.a: sources64/x86_64/slicot-$(SLICOT_VERSION)-with-32bit-integer-and-underscore + make -C $< FORTRAN=/usr/local/bin/gfortran LOADER=/usr/local/bin/gfortran SLICOTLIB=../libslicot_pic.a OPTS="-O2 -g" lib strip -S $. + +set -ex + +set -o errexit +readonly LOG_FILE="$2"/install.log +sudo touch "$LOG_FILE" +exec 1>"$LOG_FILE" +exec 2>&1 + +# Remove dummy payload +rm -f "$2"/dummy + +# Test for Internet connection +if ! curl -s -m 4 https://github.com >/dev/null; then + osascript -e 'display alert "Dynare Installation Error" message "Not able to connect to github.com. Either you are not connected to the internet or github.com is blocked where you are.\n\nAccess to GitHub is necessary to make Dynare work with the `use_dll` option on macOS.\n\nIf you cannot establish this connection or do not want to use the `use_dll` option of Dynare, please run the installer again and choose \"Customize\" from the \"Installation Type\" screen and uncheck the `GCC` option." as critical' + echo "No internet connection to github.com" + exit 1 +fi + +# Install Command Line Tools +# Checking that “xcode-select -print-path” returns a valid path is not enough, because +# the contents of that directory might have been removed (this is the official way of +# uninstalling CLT, see https://developer.apple.com/library/archive/technotes/tn2339/_index.html#//apple_ref/doc/uid/DTS40014588-CH1-HOW_CAN_I_UNINSTALL_THE_COMMAND_LINE_TOOLS_) +# Hence we also check that the directory contains the git binary. +if ! xcpath=$(/usr/bin/xcode-select -print-path) || [[ ! -x "$xcpath"/usr/bin/git ]]; then + touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress + SUC=$(softwareupdate -l | + grep "\*.*Command Line" | + grep -m1 "" | + awk -F"*" '{print $2}' | + sed -e 's/^ *//' | + tr -d '\n') + # On macOS 10.15 softwareupdate output is preceded by "Label: " + [[ $SUC == Label:* ]] && SUC=${SUC#"Label: "} + softwareupdate -i "$SUC" --verbose + rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress + softwareupdate -l +fi + +# If CLT installation didn't work, exit +if ! xcpath=$(/usr/bin/xcode-select -print-path) || [[ ! -x "$xcpath"/usr/bin/git ]]; then + osascript -e 'display alert "Dynare Installation Error" message "Not able to find Command Line Tools.\n\nCommand Line Tools is necessary to make Dynare work with the `use_dll` option on macOS.\n\nIf you cannot establish this connection or do not want to use the `use_dll` option of Dynare, please run the installer again and choose \"Customize\" from the \"Installation Type\" screen and uncheck the `GCC` option." as critical' + echo "Command Line Tools not installed" + exit 1 +fi + +# Ensure git is in the path +if ! which git >/dev/null; then + osascript -e 'display alert "Dynare Installation Error" message "Not able to find Git even though the Command Line Tools have already been installed. This is likely a problem with your PATH environment variable.\n\nGit is necessary to make Dynare work with the `use_dll` option on macOS.\n\nIf you cannot establish this connection or do not want to use the `use_dll` option of Dynare, please run the installer again and choose \"Customize\" from the \"Installation Type\" screen and uncheck the `GCC` option." as critical' + echo $PATH + echo "Git not found in PATH" + exit 1 +fi + +# Install Homebrew +BREWDIR="$2"/.brew +[ -d "$BREWDIR" ] || mkdir -p "$BREWDIR" + +BREW_URL="https://github.com/Homebrew/brew" +BREW_BRANCH="master" + +curl -\# -L "$BREW_URL"/tarball/"$BREW_BRANCH" | tar xz -m --strip 1 -C "$BREWDIR" + +# Change ownership of Dynare directory +chown -R "$USER":staff "$2" + +sudo -u "$USER" arch -x86_64 "$BREWDIR"/bin/brew tap homebrew/core +HOMEBREW_CACHE="$HOME"/Library/Caches/Homebrew-Dynare +HOMEBREW_NO_AUTO_UPDATE=1 +[[ -z "${HOMEBREW_NO_ANALYTICS}" ]] && HOMEBREW_NO_ANALYTICS=1 + +# Move modified formulas to Homebrew Formula directory +mv "$2"/*.rb "$BREWDIR"/Library/Taps/homebrew/homebrew-core/Formula + +# Install GCC & deps +sudo -u "$USER" arch -x86_64 "$BREWDIR"/bin/brew install gcc -v --force-bottle + +exit 0