build.sh 4.0 KB
Newer Older
xiaonuo911teamo's avatar
xiaonuo911teamo 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#!/bin/bash

set -e
# cross-compile tools dependence
# sudo apt install gcc-aarch64-linux-gnu
# sudo apt install g++-aarch64-linux-gnu

# settings
current_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
function print_help() {
    echo "Usage:
    -b  build and install to [output]
    -c  clean all [build] & [output]
    -n  cross-compile option: linux/x86_64,  n = native
example:
    ./build.sh -ncb    // clean & local-native compile & install
    "
}

function create_dir() {
        mkdir -p $1
}

function get_cpu_num(){
        return `cat /proc/cpuinfo | grep processor | wc -l`
}

# 用于前置下载依赖项,一般将项目需要用到的三方库,放在ftp上使用integration.py进行下载
function download_deps() {
        $current_dir/integration.py -c d -$TYPE_CHAR
}

function upload() {
        echo $1
        if [ "$1" == "loc" ]; then
                cd output
                if [ ! -d "./output" ]; then
                        ln -s ../output output
                fi
                cp ../integration.py integration.py
                cp ../scripts/version_depend_loc.json version_depend.json
                ./integration.py -c u -$TYPE_CHAR
        elif [ "$1" == "thd" ]; then
44
                cd inner-depend/3rdParty
xiaonuo911teamo's avatar
xiaonuo911teamo 已提交
45
                if [ ! -d "./output" ]; then
46
                        ln -s ../3rdParty output
xiaonuo911teamo's avatar
xiaonuo911teamo 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
                fi
                cp $current_dir/integration.py integration.py
                cp $current_dir/scripts/version_depend_thd.json version_depend.json
                ./integration.py -c u -$TYPE_CHAR
        else
                echo "unknown option: "$1
        fi
}

function set_debug() {
        export CMAKE_BUILD_TYPE="-DCMAKE_BUILD_TYPE=DEBUG"
}

function native_x86() {
        #source /opt/ros/kinetic/setup.bash
        export CMAKE_TOOLCHAIN=""
        export CMAKE_OPTIONS=$CMAKE_TOOLCHAIN
        export BUILD_TYPE=linux-x86_64
        export TYPE_CHAR=$TYPE_CHAR'n'
}

function set_release(){
        export CMAKE_BUILD_TYPE="-DCMAKE_BUILD_TYPE=MinSizeRel"
}

function  build_clean() {
        rm -rf $current_dir/build/$BUILD_TYPE
        rm -rf $current_dir/opt/$BUILD_TYPE/{bin,lib}
        rm -rf $current_dir/output/$BUILD_TYPE
}

function build_all() {
        create_dir $current_dir/build/$BUILD_TYPE
        cd $current_dir/build/$BUILD_TYPE ; cmake ../../code $CMAKE_OPTIONS $CMAKE_BUILD_TYPE -DBUILD_TYPE=$BUILD_TYPE ;make $JOBS
        if [ $BUILD_TYPE == "qnx-aarch64" ]; then
        cd -
        ./cmake/cmaketool
        fi
}

function gen_proto() {
88
        protoc=$current_dir/inner-depend/3rdParty/linux-x86_64/protobuf/bin/protoc
xiaonuo911teamo's avatar
xiaonuo911teamo 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
        protofile=`ls $current_dir/src/proto_data/proto/*.proto`
        input=" -I=$current_dir/src/proto_data/proto "
        output="--cpp_out=$current_dir/src/proto_data/data"
        $protoc $input $protofile $output
}

# 拷贝输出和依赖项到output
function install_all() {
        mkdir -p $current_dir/output
        mkdir -p $current_dir/output/$BUILD_TYPE/config
        cp -a $current_dir/opt/config/* $current_dir/output/$BUILD_TYPE/config
        cp -a $current_dir/opt/$BUILD_TYPE/* $current_dir/output/$BUILD_TYPE
        cp -a $current_dir/opt/run.sh $current_dir/output/$BUILD_TYPE
        cp $current_dir/version_depend.json $current_dir/output/$BUILD_TYPE
        mkdir -p $current_dir/output/$BUILD_TYPE/lib/3rdlib

}

if [ $# == 0 ]; then
   print_help
   exit -1
fi

while getopts "dibcgnrPj:" arg
do
        case $arg in
        b)
                build_all
                ;;
        c)
                build_clean
                ;;
        n)
                native_x86
                ;;
        d)
                download_deps
                exit
                ;;
        i)
                install_all
                ;;
        g)
                set_debug
                ;;
        r)
                set_release
                ;;
        j)
                export JOBS="-j$OPTARG"
                ;;
        P)
                gen_proto
                ;;
        esac
done