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