blob: 998d914cf8860a54057714faab0a0cce721d6a0d [file] [log] [blame]
Nathan Skrzypczak66f2a882019-07-31 17:57:58 +02001#!/bin/bash
2
3VPP_DIR=$(dirname ${BASH_SOURCE[0]})/../..
4VPP_TOOLCHAIN_FILE=$VPP_DIR/extras/scripts/.config/macos.toolchain
5BUILD_PATCH=$VPP_DIR/extras/scripts/patches/macos_build_externals.patch
6VPP_EXPORT_CC=""
7
8function help() {
9cat << __EOF__
10Usage: $0 [COMMAND]
11conf <dir> create the configuration file
12 with the give cross-toolchain directory
13build run Macos <make build>
14build-release run Macos <make build-release>
15compile_commands Generate compile_commands.json
16__EOF__
17}
18
19function create_toolchain_file () {
20 if [ x$1 = x ]; then
21 echo "Please specify the cross toolchain directory"
22 exit 1
23 fi
24 XCHAIN=$1
25 if [ ! -e ]; then
26 mkdir -p $VPP_DIR/extras/scripts/.config
27 echo "
28SET(CMAKE_SYSTEM_NAME Linux)
29SET(CMAKE_SYSTEM_VERSION 1)
30
31# specify the cross compiler
32SET(CMAKE_C_COMPILER $XCHAIN/x86_64-ubuntu16.04-linux-gnu/bin/x86_64-ubuntu16.04-linux-gnu-gcc)
33SET(CMAKE_CXX_COMPILER $XCHAIN/x86_64-ubuntu16.04-linux-gnu/bin/x86_64-ubuntu16.04-linux-gnu-g++)
34
35# where is the target environment
36SET(CMAKE_FIND_ROOT_PATH $XCHAIN/x86_64-ubuntu16.04-linux-gnu $XCHAIN/x86_64-ubuntu16.04-linux-gnu/x86_64-ubuntu16.04-linux-gnu/sysroot/)
37
38SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
39SET(CMAKE_SYSTEM_PROCESSOR x86_64)
40# This is needed to build vpp-papi
41SET(PYTHON_EXECUTABLE /usr/local/bin/python)" | tee $VPP_TOOLCHAIN_FILE > /dev/null
42 echo "Configration file created"
43 echo "please edit $VPP_TOOLCHAIN_FILE"
44 else
45 echo "configuration file already exists"
46 echo "please edit $VPP_TOOLCHAIN_FILE"
47 fi
48}
49
50function vpp_make () {
51 cd $VPP_DIR ; git apply $BUILD_PATCH
52 trap "cd $VPP_DIR ; git apply -R $BUILD_PATCH" EXIT
53 export VPP_EXTRA_CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=${VPP_TOOLCHAIN_FILE} -DCMAKE_EXPORT_COMPILE_COMMANDS=${VPP_EXPORT_CC}" ; make -C $VPP_DIR $1
54}
55
56case $1 in
57 conf)
58 create_toolchain_file $2
59 ;;
60 build)
61 vpp_make build
62 ;;
63 build-release)
64 vpp_make build-release
65 ;;
66 compile_commands)
67 VPP_EXPORT_CC=ON vpp_make build
68 echo "compile_commands.json should be generated"
69 echo "check $VPP_DIR/build-root/build-vpp_debug-native/vpp/compile_commands.json"
70 ;;
71 *)
72 help
73 ;;
74esac