Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Damjan Marion | d63360c | 2021-05-28 17:32:58 +0200 | [diff] [blame] | 2 | set -o pipefail -o errtrace -o nounset -o errexit |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 3 | |
| 4 | # Experimental script, please consult with dmarion@me.com before |
| 5 | # submitting any changes |
| 6 | |
| 7 | # defaults |
Damjan Marion | 01fe7ab | 2023-10-23 18:36:18 +0200 | [diff] [blame] | 8 | platform=default |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 9 | build_dir=. |
| 10 | install_dir=/usr/local |
| 11 | build_type=release |
Mohammed Hawari | 7d64631 | 2021-05-04 11:34:37 +0200 | [diff] [blame] | 12 | src_dir="$(dirname "$(readlink -f "$0")")" |
Damjan Marion | a117c01 | 2021-10-31 19:47:23 +0100 | [diff] [blame] | 13 | host_arch=$(uname -m) |
| 14 | arch=${host_arch} |
Damjan Marion | 45e0539 | 2022-04-25 12:38:40 +0200 | [diff] [blame] | 15 | native_only=no |
Damjan Marion | a117c01 | 2021-10-31 19:47:23 +0100 | [diff] [blame] | 16 | wipe=no |
| 17 | args=() |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 18 | |
| 19 | help() |
| 20 | { |
| 21 | cat << __EOF__ |
| 22 | VPP Build Configuration Script |
| 23 | |
| 24 | USAGE: ${0} [options] |
| 25 | |
| 26 | OPTIONS: |
| 27 | --help, -h This help |
Damjan Marion | a117c01 | 2021-10-31 19:47:23 +0100 | [diff] [blame] | 28 | --arch, -a Cross-compile for specified target architecture (aarch64, riscv64, i386, ...) |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 29 | --build-dir, -b Build directory |
| 30 | --install-dir, -i Install directory |
Damjan Marion | 2e5544f | 2021-05-04 09:37:56 +0200 | [diff] [blame] | 31 | --build-type, -t Build type (release, debug, ...) |
Damjan Marion | 45e0539 | 2022-04-25 12:38:40 +0200 | [diff] [blame] | 32 | --native-only, -n Only compile for Native CPU (no multiarch) |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 33 | --wipe, -w Wipe whole repo (except startup.* files) |
Benoît Ganne | 634873c | 2022-10-11 10:09:55 +0200 | [diff] [blame] | 34 | --sanitize, -s Enable sanitizer (mem) |
Damjan Marion | 01fe7ab | 2023-10-23 18:36:18 +0200 | [diff] [blame] | 35 | --platform, -p Specify target platform |
Benoît Ganne | a421d56 | 2024-02-08 17:06:22 +0100 | [diff] [blame] | 36 | --option, -o Enable specific VPP options (fib8, fib16) |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 37 | __EOF__ |
| 38 | } |
| 39 | |
| 40 | while (( "$#" )); do |
| 41 | case "$1" in |
| 42 | -h|--help) |
| 43 | help |
| 44 | exit 1 |
| 45 | ;; |
| 46 | -b|--build-dir) |
| 47 | if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then |
| 48 | build_dir=$2 |
| 49 | shift 2 |
| 50 | else |
| 51 | echo "Error: Argument for $1 is missing" >&2 |
| 52 | exit 1 |
| 53 | fi |
| 54 | ;; |
Damjan Marion | a117c01 | 2021-10-31 19:47:23 +0100 | [diff] [blame] | 55 | -a|--arch) |
| 56 | if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then |
| 57 | arch=$2 |
| 58 | shift 2 |
| 59 | else |
| 60 | echo "Error: Argument for $1 is missing" >&2 |
| 61 | exit 1 |
| 62 | fi |
| 63 | ;; |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 64 | -i|--install-dir) |
| 65 | if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then |
| 66 | install_dir=$2 |
| 67 | shift 2 |
| 68 | else |
| 69 | echo "Error: Argument for $1 is missing" >&2 |
| 70 | exit 1 |
| 71 | fi |
| 72 | ;; |
| 73 | -t|--build-type) |
| 74 | if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then |
| 75 | build_type=$2 |
| 76 | shift 2 |
| 77 | else |
| 78 | echo "Error: Argument for $1 is missing" >&2 |
| 79 | exit 1 |
| 80 | fi |
| 81 | ;; |
Damjan Marion | 01fe7ab | 2023-10-23 18:36:18 +0200 | [diff] [blame] | 82 | -p|--platform) |
| 83 | if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then |
| 84 | platform=$2 |
| 85 | shift 2 |
| 86 | else |
| 87 | echo "Error: Argument for $1 is missing" >&2 |
| 88 | exit 1 |
| 89 | fi |
| 90 | ;; |
Damjan Marion | 45e0539 | 2022-04-25 12:38:40 +0200 | [diff] [blame] | 91 | -n|--native-only) |
| 92 | native_only=yes |
| 93 | shift 1 |
| 94 | ;; |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 95 | -w|--wipe) |
Damjan Marion | a117c01 | 2021-10-31 19:47:23 +0100 | [diff] [blame] | 96 | wipe=yes |
| 97 | shift 1 |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 98 | ;; |
Benoît Ganne | 634873c | 2022-10-11 10:09:55 +0200 | [diff] [blame] | 99 | -s|--sanitize) |
| 100 | shift 1 |
| 101 | case "$1" in |
| 102 | mem) |
| 103 | shift 1 |
| 104 | args+=("-DVPP_ENABLE_SANITIZE_ADDR=ON") |
| 105 | ;; |
| 106 | esac |
| 107 | ;; |
Benoît Ganne | a421d56 | 2024-02-08 17:06:22 +0100 | [diff] [blame] | 108 | -o|--option) |
| 109 | shift 1 |
| 110 | case "$1" in |
| 111 | fib8) |
| 112 | shift 1 |
| 113 | args+=("-DVPP_IP_FIB_MTRIE_16=OFF") |
| 114 | ;; |
| 115 | fib16) |
| 116 | shift 1 |
| 117 | args+=("-DVPP_IP_FIB_MTRIE_16=ON") |
| 118 | ;; |
| 119 | esac |
| 120 | ;; |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 121 | -*|--*=) # unsupported flags |
| 122 | echo "Error: Unsupported flag $1" >&2 |
| 123 | exit 1 |
| 124 | ;; |
| 125 | *) # preserve positional arguments |
| 126 | PARAMS="$PARAMS $1" |
| 127 | shift |
| 128 | ;; |
| 129 | esac |
| 130 | done |
| 131 | |
Damjan Marion | a117c01 | 2021-10-31 19:47:23 +0100 | [diff] [blame] | 132 | if [ "${arch}" != "${host_arch}" ] ; then |
| 133 | args+=("-DCMAKE_SYSTEM_NAME=Linux") |
| 134 | args+=("-DCMAKE_SYSTEM_PROCESSOR=${arch}") |
| 135 | args+=("-DCMAKE_C_COMPILER=clang") |
| 136 | args+=("-DCMAKE_C_COMPILER_TARGET=${arch}-linux-gnu") |
| 137 | args+=("-DCMAKE_ASM_COMPILER_TARGET=${arch}-linux-gnu") |
| 138 | args+=("-DCMAKE_FIND_ROOT_PATH=/usr/${arch}-linux-gnu") |
| 139 | args+=("-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER") |
| 140 | args+=("-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH") |
| 141 | args+=("-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH") |
| 142 | args+=("-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY") |
| 143 | fi |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 144 | |
Damjan Marion | a117c01 | 2021-10-31 19:47:23 +0100 | [diff] [blame] | 145 | args+=("-DCMAKE_PREFIX_PATH=/opt/vpp/external/${arch}") |
| 146 | args+=("-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON") |
| 147 | args+=("-DCMAKE_INSTALL_PREFIX=${install_dir}") |
| 148 | args+=("-DCMAKE_BUILD_TYPE:STRING=${build_type}") |
Damjan Marion | 01fe7ab | 2023-10-23 18:36:18 +0200 | [diff] [blame] | 149 | args+=("-DVPP_PLATFORM=${platform}") |
Damjan Marion | 45e0539 | 2022-04-25 12:38:40 +0200 | [diff] [blame] | 150 | [ "${native_only}" == "yes" ] && args+=("-DVPP_BUILD_NATIVE_ONLY:BOOL=ON") |
Damjan Marion | a117c01 | 2021-10-31 19:47:23 +0100 | [diff] [blame] | 151 | |
| 152 | [ "${wipe}" == "yes" ] && git clean -fdx --exclude=startup.\* |
| 153 | |
| 154 | cmake ${args[@]} -G Ninja -S ${src_dir}/src -B ${build_dir} |
| 155 | |
| 156 | cat << __EOF__ |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 157 | |
| 158 | Useful build commands: |
| 159 | |
Damjan Marion | 3a533cd | 2021-05-03 12:40:27 +0200 | [diff] [blame] | 160 | ninja Build VPP |
| 161 | ninja set-build-type-* Change build type to <debug|release|gcov|...> |
| 162 | ninja config Start build configuration TUI |
Damjan Marion | 3a533cd | 2021-05-03 12:40:27 +0200 | [diff] [blame] | 163 | ninja run Runs VPP using startup.conf in the build directory |
| 164 | ninja debug Runs VPP inside GDB using startup.conf in the build directory |
| 165 | ninja pkg-deb Create .deb packages |
| 166 | ninja install Install VPP to $install_dir |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 167 | |
| 168 | __EOF__ |