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