blob: d1a356e46a24eac90f2c4c9b3cca67d46e864494 [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
8build_dir=.
9install_dir=/usr/local
10build_type=release
Mohammed Hawari7d646312021-05-04 11:34:37 +020011src_dir="$(dirname "$(readlink -f "$0")")"
Damjan Mariona117c012021-10-31 19:47:23 +010012host_arch=$(uname -m)
13arch=${host_arch}
14wipe=no
15args=()
Damjan Marion88b2e362021-04-29 18:47:25 +020016
17help()
18{
19 cat << __EOF__
20VPP Build Configuration Script
21
22USAGE: ${0} [options]
23
24OPTIONS:
25 --help, -h This help
Damjan Mariona117c012021-10-31 19:47:23 +010026 --arch, -a Cross-compile for specified target architecture (aarch64, riscv64, i386, ...)
Damjan Marion88b2e362021-04-29 18:47:25 +020027 --build-dir, -b Build directory
28 --install-dir, -i Install directory
Damjan Marion2e5544f2021-05-04 09:37:56 +020029 --build-type, -t Build type (release, debug, ...)
Damjan Marion88b2e362021-04-29 18:47:25 +020030 --wipe, -w Wipe whole repo (except startup.* files)
31__EOF__
32}
33
34while (( "$#" )); 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 Mariona117c012021-10-31 19:47:23 +010049 -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 Marion88b2e362021-04-29 18:47:25 +020058 -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 Mariona117c012021-10-31 19:47:23 +010077 wipe=yes
78 shift 1
Damjan Marion88b2e362021-04-29 18:47:25 +020079 ;;
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
89done
90
Damjan Mariona117c012021-10-31 19:47:23 +010091if [ "${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")
102fi
Damjan Marion88b2e362021-04-29 18:47:25 +0200103
Damjan Mariona117c012021-10-31 19:47:23 +0100104args+=("-DCMAKE_PREFIX_PATH=/opt/vpp/external/${arch}")
105args+=("-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON")
106args+=("-DCMAKE_INSTALL_PREFIX=${install_dir}")
107args+=("-DCMAKE_BUILD_TYPE:STRING=${build_type}")
108
109[ "${wipe}" == "yes" ] && git clean -fdx --exclude=startup.\*
110
111cmake ${args[@]} -G Ninja -S ${src_dir}/src -B ${build_dir}
112
113cat << __EOF__
Damjan Marion88b2e362021-04-29 18:47:25 +0200114
115 Useful build commands:
116
Damjan Marion3a533cd2021-05-03 12:40:27 +0200117 ninja Build VPP
118 ninja set-build-type-* Change build type to <debug|release|gcov|...>
119 ninja config Start build configuration TUI
Damjan Marion3a533cd2021-05-03 12:40:27 +0200120 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 Marion88b2e362021-04-29 18:47:25 +0200124
125__EOF__