Skip to content

Commit

Permalink
Fun with GPTs.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Feb 28, 2024
1 parent df541a3 commit 173ce55
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions tools/install_mac_deps.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,64 @@
#! /bin/bash

# Script for building P4C on MacOS.
# Script to install P4C dependencies on MacOS.

set -e # Exit on error.
set -x # Make command execution verbose

# Installation helper.
brew_install() {
echo "\nInstalling $1"
if brew list $1 &>/dev/null; then
echo "${1} is already installed"
else
brew install $1 && echo "$1 is installed"
fi
}

# Set up Homebrew differently for arm64.
if [[ $(uname -m) == 'arm64' ]]; then
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
else
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> ~/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
# Check if brew shellenv command is already in zprofile
if ! grep -q 'brew shellenv' ~/.zprofile; then
# Set up Homebrew differently for arm64.
if [[ $(uname -m) == 'arm64' ]]; then
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
else
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> ~/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
fi
fi
# Source zprofile.
source ~/.zprofile

if [[ ! -x brew ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Check if Homebrew is already installed
if ! which brew > /dev/null 2>&1; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
HOMEBREW_PREFIX=$(brew --prefix)

# Install some custom requirements on OS X using brew

BOOST_LIB="boost@1.84"
brew install autoconf automake bdw-gc ccache cmake \
libtool openssl pkg-config coreutils bison grep \
${BOOST_LIB}

# We need to link boost and openssl.
brew link ${BOOST_LIB} openssl
# Prefer Homebrew's bison and grep over the macOS-provided version.
# For Bison only `$(brew --prefix bison)/bin` seems to work...
echo 'export PATH="$(brew --prefix bison)/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="$HOMEBREW_PREFIX/opt/grep/libexec/gnubin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
REQUIRED_PACKAGES=(
autoconf automake bdw-gc ccache cmake libtool
openssl pkg-config coreutils bison grep
${BOOST_LIB}
)
for package in "${REQUIRED_PACKAGES[@]}"; do
brew_install ${package}
done

# Check if linking is needed
if ! brew ls --linked --formula ${BOOST_LIB} > /dev/null 2>&1; then
brew link ${BOOST_LIB}
fi

# Check if PATH modification is needed
if ! grep -q "$(brew --prefix bison)/bin" ~/.bash_profile; then
echo 'export PATH="$(brew --prefix bison)/bin:$PATH"' >> ~/.bash_profile
fi
if ! grep -q "$HOMEBREW_PREFIX/opt/grep/libexec/gnubin" ~/.bash_profile; then
echo 'export PATH="$HOMEBREW_PREFIX/opt/grep/libexec/gnubin:$PATH"' >> ~/.bash_profile
fi
source ~/.bash_profile

# Fixes for stuck grpcio installation.
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
Expand Down

0 comments on commit 173ce55

Please sign in to comment.