linux-cp: fix setting mtu on hardware interfaces
[vpp.git] / configure
1 #!/usr/bin/env bash
2 set -o pipefail -o errtrace -o nounset -o errexit
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 src_dir="$(dirname "$(readlink -f "$0")")"
12 host_arch=$(uname -m)
13 arch=${host_arch}
14 wipe=no
15 args=()
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
26   --arch, -a              Cross-compile for specified target architecture (aarch64, riscv64, i386, ...)
27   --build-dir, -b         Build directory
28   --install-dir, -i       Install directory
29   --build-type, -t        Build type (release, debug, ...)
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       ;;
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       ;;
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)
77       wipe=yes
78       shift 1
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
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
103
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__
114
115   Useful build commands:
116
117   ninja                   Build VPP
118   ninja set-build-type-*  Change build type to <debug|release|gcov|...>
119   ninja config            Start build configuration TUI
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
124
125 __EOF__