blob: 7db7726ddc68f2fc03922f336d9560bad0b863d1 [file] [log] [blame]
Damjan Marion88b2e362021-04-29 18:47:25 +02001#!/usr/bin/env bash
Damjan Mariond63360c2021-05-28 17:32:58 +02002set -o pipefail -o errtrace -o nounset -o errexit
Damjan Marion88b2e362021-04-29 18:47:25 +02003
4# Experimental script, please consult with dmarion@me.com before
5# submitting any changes
6
7# defaults
Damjan Marion01fe7ab2023-10-23 18:36:18 +02008platform=default
Damjan Marion88b2e362021-04-29 18:47:25 +02009build_dir=.
10install_dir=/usr/local
11build_type=release
Mohammed Hawari7d646312021-05-04 11:34:37 +020012src_dir="$(dirname "$(readlink -f "$0")")"
Damjan Mariona117c012021-10-31 19:47:23 +010013host_arch=$(uname -m)
14arch=${host_arch}
Damjan Marion45e05392022-04-25 12:38:40 +020015native_only=no
Damjan Mariona117c012021-10-31 19:47:23 +010016wipe=no
17args=()
Damjan Marion88b2e362021-04-29 18:47:25 +020018
19help()
20{
21 cat << __EOF__
22VPP Build Configuration Script
23
24USAGE: ${0} [options]
25
26OPTIONS:
27 --help, -h This help
Damjan Mariona117c012021-10-31 19:47:23 +010028 --arch, -a Cross-compile for specified target architecture (aarch64, riscv64, i386, ...)
Damjan Marion88b2e362021-04-29 18:47:25 +020029 --build-dir, -b Build directory
30 --install-dir, -i Install directory
Damjan Marion2e5544f2021-05-04 09:37:56 +020031 --build-type, -t Build type (release, debug, ...)
Damjan Marion45e05392022-04-25 12:38:40 +020032 --native-only, -n Only compile for Native CPU (no multiarch)
Damjan Marion88b2e362021-04-29 18:47:25 +020033 --wipe, -w Wipe whole repo (except startup.* files)
Benoît Ganne634873c2022-10-11 10:09:55 +020034 --sanitize, -s Enable sanitizer (mem)
Damjan Marion01fe7ab2023-10-23 18:36:18 +020035 --platform, -p Specify target platform
Damjan Marion88b2e362021-04-29 18:47:25 +020036__EOF__
37}
38
39while (( "$#" )); do
40 case "$1" in
41 -h|--help)
42 help
43 exit 1
44 ;;
45 -b|--build-dir)
46 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
47 build_dir=$2
48 shift 2
49 else
50 echo "Error: Argument for $1 is missing" >&2
51 exit 1
52 fi
53 ;;
Damjan Mariona117c012021-10-31 19:47:23 +010054 -a|--arch)
55 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
56 arch=$2
57 shift 2
58 else
59 echo "Error: Argument for $1 is missing" >&2
60 exit 1
61 fi
62 ;;
Damjan Marion88b2e362021-04-29 18:47:25 +020063 -i|--install-dir)
64 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
65 install_dir=$2
66 shift 2
67 else
68 echo "Error: Argument for $1 is missing" >&2
69 exit 1
70 fi
71 ;;
72 -t|--build-type)
73 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
74 build_type=$2
75 shift 2
76 else
77 echo "Error: Argument for $1 is missing" >&2
78 exit 1
79 fi
80 ;;
Damjan Marion01fe7ab2023-10-23 18:36:18 +020081 -p|--platform)
82 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
83 platform=$2
84 shift 2
85 else
86 echo "Error: Argument for $1 is missing" >&2
87 exit 1
88 fi
89 ;;
Damjan Marion45e05392022-04-25 12:38:40 +020090 -n|--native-only)
91 native_only=yes
92 shift 1
93 ;;
Damjan Marion88b2e362021-04-29 18:47:25 +020094 -w|--wipe)
Damjan Mariona117c012021-10-31 19:47:23 +010095 wipe=yes
96 shift 1
Damjan Marion88b2e362021-04-29 18:47:25 +020097 ;;
Benoît Ganne634873c2022-10-11 10:09:55 +020098 -s|--sanitize)
99 shift 1
100 case "$1" in
101 mem)
102 shift 1
103 args+=("-DVPP_ENABLE_SANITIZE_ADDR=ON")
104 ;;
105 esac
106 ;;
Damjan Marion88b2e362021-04-29 18:47:25 +0200107 -*|--*=) # unsupported flags
108 echo "Error: Unsupported flag $1" >&2
109 exit 1
110 ;;
111 *) # preserve positional arguments
112 PARAMS="$PARAMS $1"
113 shift
114 ;;
115 esac
116done
117
Damjan Mariona117c012021-10-31 19:47:23 +0100118if [ "${arch}" != "${host_arch}" ] ; then
119 args+=("-DCMAKE_SYSTEM_NAME=Linux")
120 args+=("-DCMAKE_SYSTEM_PROCESSOR=${arch}")
121 args+=("-DCMAKE_C_COMPILER=clang")
122 args+=("-DCMAKE_C_COMPILER_TARGET=${arch}-linux-gnu")
123 args+=("-DCMAKE_ASM_COMPILER_TARGET=${arch}-linux-gnu")
124 args+=("-DCMAKE_FIND_ROOT_PATH=/usr/${arch}-linux-gnu")
125 args+=("-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER")
126 args+=("-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH")
127 args+=("-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH")
128 args+=("-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY")
129fi
Damjan Marion88b2e362021-04-29 18:47:25 +0200130
Damjan Mariona117c012021-10-31 19:47:23 +0100131args+=("-DCMAKE_PREFIX_PATH=/opt/vpp/external/${arch}")
132args+=("-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON")
133args+=("-DCMAKE_INSTALL_PREFIX=${install_dir}")
134args+=("-DCMAKE_BUILD_TYPE:STRING=${build_type}")
Damjan Marion01fe7ab2023-10-23 18:36:18 +0200135args+=("-DVPP_PLATFORM=${platform}")
Damjan Marion45e05392022-04-25 12:38:40 +0200136[ "${native_only}" == "yes" ] && args+=("-DVPP_BUILD_NATIVE_ONLY:BOOL=ON")
Damjan Mariona117c012021-10-31 19:47:23 +0100137
138[ "${wipe}" == "yes" ] && git clean -fdx --exclude=startup.\*
139
140cmake ${args[@]} -G Ninja -S ${src_dir}/src -B ${build_dir}
141
142cat << __EOF__
Damjan Marion88b2e362021-04-29 18:47:25 +0200143
144 Useful build commands:
145
Damjan Marion3a533cd2021-05-03 12:40:27 +0200146 ninja Build VPP
147 ninja set-build-type-* Change build type to <debug|release|gcov|...>
148 ninja config Start build configuration TUI
Damjan Marion3a533cd2021-05-03 12:40:27 +0200149 ninja run Runs VPP using startup.conf in the build directory
150 ninja debug Runs VPP inside GDB using startup.conf in the build directory
151 ninja pkg-deb Create .deb packages
152 ninja install Install VPP to $install_dir
Damjan Marion88b2e362021-04-29 18:47:25 +0200153
154__EOF__