-
Notifications
You must be signed in to change notification settings - Fork 443
/
bootstrap.sh
executable file
·119 lines (110 loc) · 3.12 KB
/
bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# Copyright 2013-present Barefoot Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e # exit on error
if type -p grealpath >/dev/null 2>/dev/null; then
realpath=grealpath
else
realpath=realpath
fi
mydir=`dirname $0`
mydir=`$realpath $mydir`
cd $mydir
BuildType=Debug
BuildDir=""
BuildGenerator="Unix Makefiles"
EXTRA=""
FORCE=false
while [ $# -gt 0 ]; do
case "$1" in
--build-dir)
BuildDir="$2"
shift
;;
--build-type)
BuildType="$2"
shift
;;
--build-generator)
BuildGenerator="$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"
;;
-DCMAKE_BUILD_TYPE=*)
BuildType="${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 -G "$BuildGenerator" $EXTRA
echo "### Configured for building with '$BuildGenerator' 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/p4test/p4test-gdb.gdb"