Skip to content

Commit

Permalink
improved bootstrap.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Dodd committed Nov 6, 2023
1 parent 61990d2 commit ba69163
Showing 1 changed file with 89 additions and 8 deletions.
97 changes: 89 additions & 8 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# Copyright 2013-present Barefoot Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,12 +13,93 @@
# See the License for the specific language governing permissions and
# limitations under the License.


set -e # exit on error

mkdir -p extensions # place where additional back-ends are expected
mkdir -p build # recommended folder for build
cd build
# Configure for a debug build
cmake .. -DCMAKE_BUILD_TYPE=DEBUG $*
echo "### Configured for building in 'build' folder"
mydir=`dirname $0`
mydir=`realpath $mydir`
cd $mydir

BuildType=Debug
BuildDir=""
EXTRA=""
FORCE=false

while [ $# -gt 0 ]; do
case ${1,,} in
--build-dir)
BuildDir="$2"
shift
;;
--build-type)
BuildType="$2"
shift
;;
--distcc)
export CC="distcc gcc"
export CXX="distcc g++"
;;
--disable-unified)
EXTRA="$EXTRA -DENABLE_UNIFIED_COMPILATION=OFF"
;;
--force)
FORCE=true
;;
debug|release|relwithdebinfo)
BuildType="$1"
;;
build*)
if [ -n "$BuildDir" ]; then
echo >&2 "mulitple build directories not supported"
exit 2
elif [ -e "$1" ]; then
if $FORCE; then
rm -f "$1"/CMakeCache.txt
else
echo >&2 "$1 already exists, use --force to replace"
exit 2
fi
fi
BuildDir="$1"
;;
-D*)
EXTRA="$EXTRA $1"
;;
*)
echo >&2 "Invalid argument $1"
exit 2
;;
esac
shift
done

if [ -z "$BuildDir" ]; then
BuildDir=build # default (recommended) folder for build
if [ -e "$BuildDir" ]; then
if $FORCE; then
rm -f "$BuildDir"/CMakeCache.txt
else
echo >&2 "$BuildDir already exists, use --force to replace"
exit 2
fi
fi
fi

mkdir -p p4c/extensions
mkdir -p "$BuildDir"
cd "$BuildDir"
cmake .. -DCMAKE_BUILD_TYPE=$BuildType $EXTRA
echo "### Configured for building in '$BuildDir' folder"

make_relative_link ()
{
local target="${1:?make_relative_link: Argument 1 should be the target.}"
local link_name="${2:?make_relative_link: Argument 2 should be the link name.}"
local link_name_dir="$(dirname "${link_name}")"
mkdir -p "${link_name_dir}/"
ln -sf "$(realpath --relative-to "${link_name_dir}/" "${target}")" "${link_name}"
}

make_relative_link "${mydir}/.gdbinit" "backends/bmv2/p4c-bm2-psa-gdb.gdb"
make_relative_link "${mydir}/.gdbinit" "backends/bmv2/p4c-bm2-ss-gdb.gdb"
make_relative_link "${mydir}/.gdbinit" "backends/dpdk/p4c-dpdk-gdb.gdb"
make_relative_link "${mydir}/.gdbinit" "backends/dpdk/p4test-gdb.gdb"

0 comments on commit ba69163

Please sign in to comment.