-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmake-all.sh
executable file
·301 lines (273 loc) · 7.58 KB
/
make-all.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/bin/bash
#
# Copyright 2022-2023 Intel Corporation
# SPDX-License-Identifier: Apache 2.0
#
# Sample script to configure and build P4 Control Plane.
#
# Abort on error.
set -e
##################
# Default values #
##################
_DEPS_DIR=${DEPEND_INSTALL}
_HOST_DIR=${HOST_INSTALL}
_NJOBS=8
_OVS_DIR="${OVS_INSTALL:-ovs/install}"
_PREFIX="install"
_RPATH=OFF
_SDE_DIR=${SDE_INSTALL}
_TGT_TYPE="DPDK"
_TOOLFILE=${CMAKE_TOOLCHAIN_FILE}
_BLD_DIR=build
_DO_BUILD=1
_DRY_RUN=0
_OVS_BLD="ovs/build"
_WITH_OVS=1
##############
# print_help #
##############
print_help() {
echo ""
echo "Configure and build P4 Control Plane"
echo ""
echo "General:"
echo " --dry-run -n Display cmake parameters and exit"
echo " --help -h Display help text and exit"
echo ""
echo "Paths:"
echo " --deps=DIR -D Target dependencies directory [${_DEPS_DIR}]"
echo " --host=DIR -H Host dependencies directory [${_HOST_DIR}]"
echo " --ovs=DIR -O OVS install directory [${_OVS_DIR}]"
echo " --prefix=DIR -P Install directory prefix [${_PREFIX}]"
echo " --sde=DIR -S SDE install directory [${_SDE_DIR}]"
# echo " --staging=DIR Staging directory prefix [${_STAGING}]"
echo " --toolchain=FILE -T CMake toolchain file"
echo ""
echo "Options:"
echo " --coverage Instrument build to measure code coverage"
echo " --cxx-std=STD C++ standard (11|14|17) [$_CXX_STD])"
echo " --jobs=NJOBS -j Number of build threads [${_NJOBS}]"
echo " --no-build Configure without building"
echo " --no-krnlmon Exclude Kernel Monitor"
echo " --no-ovs Exclude OVS support"
echo " --target=TARGET Target to build (dpdk|es2k|tofino) [${_TGT_TYPE}]"
echo ""
echo "Configurations:"
echo " --debug Debug configuration"
echo " --minsize MinSizeRel configuration"
echo " --reldeb RelWithDebInfo configuration"
echo " --release Release configuration"
echo ""
echo "Environment variables:"
echo " CMAKE_TOOLCHAIN_FILE - Default toolchain file"
echo " DEPEND_INSTALL - Default target dependencies directory"
echo " HOST_INSTALL - Default host dependencies directory"
echo " OVS_INSTALL - Default OVS install directory"
echo " SDE_INSTALL - Default SDE install directory"
echo ""
}
######################
# print_cmake_params #
######################
print_cmake_params() {
echo ""
[ -n "${_GENERATOR}" ] && echo "${_GENERATOR}"
[ -n "${_BUILD_TYPE}" ] && echo "${_BUILD_TYPE:2}"
echo "CMAKE_INSTALL_PREFIX=${_PREFIX}"
[ -n "${_STAGING_PREFIX}" ] && echo "${_STAGING_PREFIX:2}"
[ -n "${_TOOLCHAIN_FILE}" ] && echo "${_TOOLCHAIN_FILE:2}"
[ -n "${_CXX_STD}" ] && echo "CMAKE_CXX_STANDARD=${_CXX_STD}"
echo "DEPEND_INSTALL_DIR=${_DEPS_DIR}"
[ -n "${_HOST_DEPEND_DIR}" ] && echo "${_HOST_DEPEND_DIR:2}"
echo "OVS_INSTALL_DIR=${_OVS_DIR}"
echo "SDE_INSTALL_DIR=${_SDE_DIR}"
[ -n "${_WITH_KRNLMON}" ] && echo "${_WITH_KRNLMON:2}"
[ -n "${_WITH_OVSP4RT}" ] && echo "${_WITH_OVSP4RT:2}"
[ -n "${_COVERAGE}" ] && echo "${_COVERAGE:2}"
echo "${_SET_RPATH:2}"
echo "${_TARGET_TYPE:2}"
if [ ${_DO_BUILD} -eq 0 ]; then
echo ""
echo "Configure without building"
echo ""
return
fi
echo "JOBS=${_NJOBS}"
echo ""
}
##############
# config_ovs #
##############
config_ovs() {
# shellcheck disable=SC2086
cmake -S ovs -B ${_OVS_BLD} \
${_BUILD_TYPE} \
-DCMAKE_INSTALL_PREFIX="${_OVS_DIR}" \
${_TOOLCHAIN_FILE} \
-DP4OVS=ON
}
#############
# build_ovs #
#############
build_ovs() {
cmake --build ${_OVS_BLD} -j6 -- V=0
}
#################
# config_recipe #
#################
config_recipe() {
# shellcheck disable=SC2086
cmake -S . -B ${_BLD_DIR} \
${_GENERATOR} \
${_BUILD_TYPE} \
-DCMAKE_INSTALL_PREFIX="${_PREFIX}" \
${_STAGING_PREFIX} \
${_TOOLCHAIN_FILE} \
${_CXX_STANDARD} \
-DDEPEND_INSTALL_DIR="${_DEPS_DIR}" \
${_HOST_DEPEND_DIR} \
-DOVS_INSTALL_DIR="${_OVS_DIR}" \
-DSDE_INSTALL_DIR="${_SDE_DIR}" \
${_WITH_KRNLMON} \
${_WITH_OVSP4RT} \
${_COVERAGE} \
${_SET_RPATH} \
${_TARGET_TYPE}
}
################
# build_recipe #
################
build_recipe() {
cmake --build ${_BLD_DIR} "-j${_NJOBS}" --target install
}
######################
# Parse command line #
######################
SHORTOPTS=D:H:O:P:S:T:
SHORTOPTS=${SHORTOPTS}hj:n
LONGOPTS=deps:,hostdeps:,ovs:,prefix:,sde:,toolchain:
LONGOPTS=${LONGOPTS},cxx-std:,jobs:,staging:,target:
LONGOPTS=${LONGOPTS},debug,release,minsize,reldeb
LONGOPTS=${LONGOPTS},dry-run,help
LONGOPTS=${LONGOPTS},coverage,ninja,rpath
LONGOPTS=${LONGOPTS},no-build,no-krnlmon,no-ovs,no-rpath
GETOPTS=$(getopt -o ${SHORTOPTS} --long ${LONGOPTS} -- "$@")
eval set -- "${GETOPTS}"
while true ; do
case "$1" in
# Paths
--deps|-D)
_DEPS_DIR=$2
shift 2 ;;
--hostdeps|-H)
_HOST_DIR=$2
shift 2 ;;
--ovs|-O)
_OVS_DIR=$2
shift 2 ;;
--prefix|-P)
_PREFIX=$2
shift 2 ;;
--sde|-S)
_SDE_DIR=$2
shift 2 ;;
--staging)
_STAGING=$2
shift 2 ;;
--toolchain|-T)
_TOOLFILE=$2
shift 2 ;;
# Configurations
--debug)
_BLD_TYPE="Debug"
shift ;;
--minsize)
_BLD_TYPE="MinSizeRel"
shift ;;
--reldeb)
_BLD_TYPE="RelWithDebInfo"
shift ;;
--release)
_BLD_TYPE="Release"
shift ;;
# Options
--coverage)
_COVERAGE="-DTEST_COVERAGE=ON"
shift ;;
--cxx-std)
_CXX_STD=$2
shift 2;;
--dry-run|-n)
_DRY_RUN=1
shift ;;
--help|-h)
print_help
exit 99 ;;
--jobs|-j)
_NJOBS=$2
shift 2 ;;
--ninja)
_GENERATOR="-G Ninja"
shift 1 ;;
--no-build)
_DO_BUILD=0
shift ;;
--no-krnlmon)
_WITH_KRNLMON=FALSE
shift ;;
--no-ovs)
_WITH_OVS=0
_WITH_OVSP4RT=FALSE
shift ;;
--no-rpath)
_RPATH=OFF
shift ;;
--rpath)
_RPATH=ON
shift ;;
--target)
# convert to uppercase
_TGT_TYPE=${2^^}
shift 2 ;;
--)
shift
break ;;
*)
echo "Invalid parameter: $1"
exit 1 ;;
esac
done
######################
# Process parameters #
######################
if [ -z "${_SDE_DIR}" ]; then
echo "ERROR: SDE_INSTALL not defined!"
exit 1
fi
[ -n "${_BLD_TYPE}" ] && _BUILD_TYPE="-DCMAKE_BUILD_TYPE=${_BLD_TYPE}"
[ -n "${_CXX_STD}" ] && _CXX_STANDARD="-DCMAKE_CXX_STANDARD=${_CXX_STD}"
[ -n "${_HOST_DIR}" ] && _HOST_DEPEND_DIR="-DHOST_DEPEND_DIR=${_HOST_DIR}"
[ -n "${_RPATH}" ] && _SET_RPATH="-DSET_RPATH=${_RPATH}"
[ -n "${_STAGING}" ] && _STAGING_PREFIX="-DCMAKE_STAGING_PREFIX=${_STAGING}"
[ -n "${_TGT_TYPE}" ] && _TARGET_TYPE="-DTDI_TARGET=${_TGT_TYPE}"
[ -n "${_TOOLFILE}" ] && _TOOLCHAIN_FILE="-DCMAKE_TOOLCHAIN_FILE=${_TOOLFILE}"
[ -n "${_WITH_KRNLMON}" ] && _WITH_KRNLMON="-DWITH_KRNLMON=${_WITH_KRNLMON}"
[ -n "${_WITH_OVSP4RT}" ] && _WITH_OVSP4RT="-DWITH_OVSP4RT=${_WITH_OVSP4RT}"
# Show parameters if this is a dry run
if [ ${_DRY_RUN} -ne 0 ]; then
print_cmake_params
exit 0
fi
################
# Do the build #
################
# First build OVS
if [ ${_WITH_OVS} -ne 0 ]; then
config_ovs
build_ovs
fi
config_recipe
if [ ${_DO_BUILD} -ne 0 ]; then
build_recipe
fi