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 4430de0
Showing 1 changed file with 45 additions and 21 deletions.
66 changes: 45 additions & 21 deletions tools/install_mac_deps.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,63 @@
#! /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


# Set up Homebrew differently for arm64.
if [[ $(uname -m) == 'arm64' ]]; then
# 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
else
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> ~/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
fi
fi

# 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

if [[ ! -x brew ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Source zprofile only if necessary
if ! source ~/.zprofile &> /dev/null; then
echo "Warning: Failed to source ~/.zprofile."
fi

HOMEBREW_PREFIX=$(brew --prefix)

# Install some custom requirements on OS X using brew
BOOST_LIB="[email protected]"
brew install autoconf automake bdw-gc ccache cmake \
libtool openssl pkg-config coreutils bison grep \
${BOOST_LIB}
# Check if any packages need installation.
REQUIRED_PACKAGES=(autoconf automake bdw-gc ccache cmake libtool openssl pkg-config coreutils bison grep)
MISSING_PACKAGES=()
for package in "${REQUIRED_PACKAGES[@]}"; do
if ! brew list -q "$package"; then
MISSING_PACKAGES+=("$package")
fi
done

# 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
# Install missing packages.
if [[ ${#MISSING_PACKAGES[@]} -gt 0 ]]; then
brew install "${MISSING_PACKAGES[@]}"
fi

# Check if linking is needed
if ! brew ls --linked --formula ${BOOST_LIB} > /dev/null 2>&1; then
brew link ${BOOST_LIB} openssl
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 only if necessary
if ! source ~/.bash_profile &> /dev/null; then
echo "Warning: Failed to source ~/.bash_profile."
fi

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

0 comments on commit 4430de0

Please sign in to comment.