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 |
| 11 | prefix_path=/opt/vpp/external/$(uname -m)/ |
Mohammed Hawari | 7d64631 | 2021-05-04 11:34:37 +0200 | [diff] [blame] | 12 | src_dir="$(dirname "$(readlink -f "$0")")" |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 13 | |
| 14 | help() |
| 15 | { |
| 16 | cat << __EOF__ |
| 17 | VPP Build Configuration Script |
| 18 | |
| 19 | USAGE: ${0} [options] |
| 20 | |
| 21 | OPTIONS: |
| 22 | --help, -h This help |
| 23 | --build-dir, -b Build directory |
| 24 | --install-dir, -i Install directory |
Damjan Marion | 2e5544f | 2021-05-04 09:37:56 +0200 | [diff] [blame] | 25 | --build-type, -t Build type (release, debug, ...) |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 26 | --wipe, -w Wipe whole repo (except startup.* files) |
| 27 | __EOF__ |
| 28 | } |
| 29 | |
| 30 | while (( "$#" )); do |
| 31 | case "$1" in |
| 32 | -h|--help) |
| 33 | help |
| 34 | exit 1 |
| 35 | ;; |
| 36 | -b|--build-dir) |
| 37 | if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then |
| 38 | build_dir=$2 |
| 39 | shift 2 |
| 40 | else |
| 41 | echo "Error: Argument for $1 is missing" >&2 |
| 42 | exit 1 |
| 43 | fi |
| 44 | ;; |
| 45 | -i|--install-dir) |
| 46 | if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then |
| 47 | install_dir=$2 |
| 48 | shift 2 |
| 49 | else |
| 50 | echo "Error: Argument for $1 is missing" >&2 |
| 51 | exit 1 |
| 52 | fi |
| 53 | ;; |
| 54 | -t|--build-type) |
| 55 | if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then |
| 56 | build_type=$2 |
| 57 | shift 2 |
| 58 | else |
| 59 | echo "Error: Argument for $1 is missing" >&2 |
| 60 | exit 1 |
| 61 | fi |
| 62 | ;; |
| 63 | -w|--wipe) |
| 64 | git clean -fdx --exclude=startup.\* |
| 65 | exit 1 |
| 66 | ;; |
| 67 | -*|--*=) # unsupported flags |
| 68 | echo "Error: Unsupported flag $1" >&2 |
| 69 | exit 1 |
| 70 | ;; |
| 71 | *) # preserve positional arguments |
| 72 | PARAMS="$PARAMS $1" |
| 73 | shift |
| 74 | ;; |
| 75 | esac |
| 76 | done |
| 77 | |
| 78 | cmake \ |
| 79 | -G Ninja \ |
Mohammed Hawari | 7d64631 | 2021-05-04 11:34:37 +0200 | [diff] [blame] | 80 | -S ${src_dir}/src \ |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 81 | -B ${build_dir} \ |
| 82 | -DCMAKE_PREFIX_PATH=${prefix_path} \ |
| 83 | -DCMAKE_INSTALL_PREFIX=${install_dir} \ |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 84 | -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON \ |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 85 | -DCMAKE_BUILD_TYPE:STRING=${build_type} |
| 86 | |
| 87 | cat << __EOF__ |
| 88 | |
| 89 | Useful build commands: |
| 90 | |
Damjan Marion | 3a533cd | 2021-05-03 12:40:27 +0200 | [diff] [blame] | 91 | ninja Build VPP |
| 92 | ninja set-build-type-* Change build type to <debug|release|gcov|...> |
| 93 | ninja config Start build configuration TUI |
Damjan Marion | 3a533cd | 2021-05-03 12:40:27 +0200 | [diff] [blame] | 94 | ninja run Runs VPP using startup.conf in the build directory |
| 95 | ninja debug Runs VPP inside GDB using startup.conf in the build directory |
| 96 | ninja pkg-deb Create .deb packages |
| 97 | ninja install Install VPP to $install_dir |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 98 | |
| 99 | __EOF__ |