blob: 29f7dbd32581b660347095551d2c25f0d7948970 [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}
Damjan Marion45e05392022-04-25 12:38:40 +020014native_only=no
Damjan Mariona117c012021-10-31 19:47:23 +010015wipe=no
16args=()
Damjan Marion88b2e362021-04-29 18:47:25 +020017
18help()
19{
20 cat << __EOF__
21VPP Build Configuration Script
22
23USAGE: ${0} [options]
24
25OPTIONS:
26 --help, -h This help
Damjan Mariona117c012021-10-31 19:47:23 +010027 --arch, -a Cross-compile for specified target architecture (aarch64, riscv64, i386, ...)
Damjan Marion88b2e362021-04-29 18:47:25 +020028 --build-dir, -b Build directory
29 --install-dir, -i Install directory
Damjan Marion2e5544f2021-05-04 09:37:56 +020030 --build-type, -t Build type (release, debug, ...)
Damjan Marion45e05392022-04-25 12:38:40 +020031 --native-only, -n Only compile for Native CPU (no multiarch)
Damjan Marion88b2e362021-04-29 18:47:25 +020032 --wipe, -w Wipe whole repo (except startup.* files)
33__EOF__
34}
35
36while (( "$#" )); do
37 case "$1" in
38 -h|--help)
39 help
40 exit 1
41 ;;
42 -b|--build-dir)
43 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
44 build_dir=$2
45 shift 2
46 else
47 echo "Error: Argument for $1 is missing" >&2
48 exit 1
49 fi
50 ;;
Damjan Mariona117c012021-10-31 19:47:23 +010051 -a|--arch)
52 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
53 arch=$2
54 shift 2
55 else
56 echo "Error: Argument for $1 is missing" >&2
57 exit 1
58 fi
59 ;;
Damjan Marion88b2e362021-04-29 18:47:25 +020060 -i|--install-dir)
61 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
62 install_dir=$2
63 shift 2
64 else
65 echo "Error: Argument for $1 is missing" >&2
66 exit 1
67 fi
68 ;;
69 -t|--build-type)
70 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
71 build_type=$2
72 shift 2
73 else
74 echo "Error: Argument for $1 is missing" >&2
75 exit 1
76 fi
77 ;;
Damjan Marion45e05392022-04-25 12:38:40 +020078 -n|--native-only)
79 native_only=yes
80 shift 1
81 ;;
Damjan Marion88b2e362021-04-29 18:47:25 +020082 -w|--wipe)
Damjan Mariona117c012021-10-31 19:47:23 +010083 wipe=yes
84 shift 1
Damjan Marion88b2e362021-04-29 18:47:25 +020085 ;;
86 -*|--*=) # unsupported flags
87 echo "Error: Unsupported flag $1" >&2
88 exit 1
89 ;;
90 *) # preserve positional arguments
91 PARAMS="$PARAMS $1"
92 shift
93 ;;
94 esac
95done
96
Damjan Mariona117c012021-10-31 19:47:23 +010097if [ "${arch}" != "${host_arch}" ] ; then
98 args+=("-DCMAKE_SYSTEM_NAME=Linux")
99 args+=("-DCMAKE_SYSTEM_PROCESSOR=${arch}")
100 args+=("-DCMAKE_C_COMPILER=clang")
101 args+=("-DCMAKE_C_COMPILER_TARGET=${arch}-linux-gnu")
102 args+=("-DCMAKE_ASM_COMPILER_TARGET=${arch}-linux-gnu")
103 args+=("-DCMAKE_FIND_ROOT_PATH=/usr/${arch}-linux-gnu")
104 args+=("-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER")
105 args+=("-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH")
106 args+=("-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH")
107 args+=("-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY")
108fi
Damjan Marion88b2e362021-04-29 18:47:25 +0200109
Damjan Mariona117c012021-10-31 19:47:23 +0100110args+=("-DCMAKE_PREFIX_PATH=/opt/vpp/external/${arch}")
111args+=("-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON")
112args+=("-DCMAKE_INSTALL_PREFIX=${install_dir}")
113args+=("-DCMAKE_BUILD_TYPE:STRING=${build_type}")
Damjan Marion45e05392022-04-25 12:38:40 +0200114[ "${native_only}" == "yes" ] && args+=("-DVPP_BUILD_NATIVE_ONLY:BOOL=ON")
Damjan Mariona117c012021-10-31 19:47:23 +0100115
116[ "${wipe}" == "yes" ] && git clean -fdx --exclude=startup.\*
117
118cmake ${args[@]} -G Ninja -S ${src_dir}/src -B ${build_dir}
119
120cat << __EOF__
Damjan Marion88b2e362021-04-29 18:47:25 +0200121
122 Useful build commands:
123
Damjan Marion3a533cd2021-05-03 12:40:27 +0200124 ninja Build VPP
125 ninja set-build-type-* Change build type to <debug|release|gcov|...>
126 ninja config Start build configuration TUI
Damjan Marion3a533cd2021-05-03 12:40:27 +0200127 ninja run Runs VPP using startup.conf in the build directory
128 ninja debug Runs VPP inside GDB using startup.conf in the build directory
129 ninja pkg-deb Create .deb packages
130 ninja install Install VPP to $install_dir
Damjan Marion88b2e362021-04-29 18:47:25 +0200131
132__EOF__