Nathan Skrzypczak | 66f2a88 | 2019-07-31 17:57:58 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | VPP_DIR=$(dirname ${BASH_SOURCE[0]})/../.. |
| 4 | VPP_TOOLCHAIN_FILE=$VPP_DIR/extras/scripts/.config/macos.toolchain |
| 5 | BUILD_PATCH=$VPP_DIR/extras/scripts/patches/macos_build_externals.patch |
| 6 | VPP_EXPORT_CC="" |
| 7 | |
| 8 | function help() { |
| 9 | cat << __EOF__ |
| 10 | Usage: $0 [COMMAND] |
| 11 | conf <dir> create the configuration file |
| 12 | with the give cross-toolchain directory |
| 13 | build run Macos <make build> |
| 14 | build-release run Macos <make build-release> |
| 15 | compile_commands Generate compile_commands.json |
| 16 | __EOF__ |
| 17 | } |
| 18 | |
| 19 | function 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 " |
| 28 | SET(CMAKE_SYSTEM_NAME Linux) |
| 29 | SET(CMAKE_SYSTEM_VERSION 1) |
| 30 | |
| 31 | # specify the cross compiler |
| 32 | SET(CMAKE_C_COMPILER $XCHAIN/x86_64-ubuntu16.04-linux-gnu/bin/x86_64-ubuntu16.04-linux-gnu-gcc) |
| 33 | SET(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 |
| 36 | SET(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 | |
| 38 | SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) |
| 39 | SET(CMAKE_SYSTEM_PROCESSOR x86_64) |
| 40 | # This is needed to build vpp-papi |
| 41 | SET(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 | |
| 50 | function 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 | |
| 56 | case $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 | ;; |
| 74 | esac |