-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|