From 4516e906b37d831b3373d4ef2fecb91f7588c84b Mon Sep 17 00:00:00 2001 From: Tynan McAuley Date: Tue, 21 Sep 2021 17:57:02 -0700 Subject: [PATCH] Use GNU readlink on macOS BSD readlink is quite different from GNU readlink, so DIR was not being filled in with the absolute path to the 'scripts' directory on macOS. --- scripts/build-toolchains.sh | 9 ++++++++- scripts/init-submodules-no-riscv-tools-nolog.sh | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/build-toolchains.sh b/scripts/build-toolchains.sh index 536a2e57..f11a3cbd 100755 --- a/scripts/build-toolchains.sh +++ b/scripts/build-toolchains.sh @@ -6,9 +6,16 @@ set -e set -o pipefail +# On macOS, use GNU readlink from 'coreutils' package in Homebrew/MacPorts +if [ "$(uname -s)" = "Darwin" ] ; then + READLINK=greadlink +else + READLINK=readlink +fi + # If BASH_SOURCE is undefined, we may be running under zsh, in that case # provide a zsh-compatible alternative -DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]:-${(%):-%x}}")")" +DIR="$(dirname "$($READLINK -f "${BASH_SOURCE[0]:-${(%):-%x}}")")" CHIPYARD_DIR="$(dirname "$DIR")" usage() { diff --git a/scripts/init-submodules-no-riscv-tools-nolog.sh b/scripts/init-submodules-no-riscv-tools-nolog.sh index 0d47dd03..743ea198 100755 --- a/scripts/init-submodules-no-riscv-tools-nolog.sh +++ b/scripts/init-submodules-no-riscv-tools-nolog.sh @@ -17,9 +17,16 @@ if [ "$MINGIT" != "$(echo -e "$MINGIT\n$MYGIT" | sort -V | head -n1)" ]; then false fi +# On macOS, use GNU readlink from 'coreutils' package in Homebrew/MacPorts +if [ "$(uname -s)" = "Darwin" ] ; then + READLINK=greadlink +else + READLINK=readlink +fi + # If BASH_SOURCE is undefined we may be running under zsh, in that case # provide a zsh-compatible alternative -DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]:-${(%):-%x}}")")" +DIR="$(dirname "$($READLINK -f "${BASH_SOURCE[0]:-${(%):-%x}}")")" CHIPYARD_DIR="$(dirname "$DIR")" cd "$CHIPYARD_DIR"