utils.sh 2.3 KB
Newer Older
1 2 3 4
#!/usr/bin/env bash
set -e

OS=$(uname -s)
5 6
NINJA_CMD=""
NINJA_BASE="ninja"
7 8 9

if [[ $OS =~ "NT" ]]; then
    echo "BUILD in NT ..."
10
    NINJA_BASE="Ninja"
11 12
fi

13 14 15 16 17 18 19 20 21 22 23 24
READLINK=readlink
if [ $OS = "Darwin" ];then
    READLINK=greadlink
fi

function cd_real_build_dir() {
    REAL_DIR=$($READLINK -f $1)
    echo "may alias dir: $1"
    echo "cd real build dir: ${REAL_DIR}"
    cd ${REAL_DIR}
}

25 26 27
function build_flatc() {
    BUILD_DIR=$1/build_dir/host_flatc/build
    INSTALL_DIR=$BUILD_DIR/../install
28 29 30
    REMOVE_OLD_BUILD=$2

    if [ $REMOVE_OLD_BUILD = "true" ]; then
31 32 33
        echo "remove old build/install dir"
        rm -rf $INSTALL_DIR
        rm -rf $BUILD_DIR
34 35 36 37
    else
        echo "strip remove old build"
    fi

38 39
    mkdir -p $BUILD_DIR
    mkdir -p $INSTALL_DIR
40

41
    cd_real_build_dir $BUILD_DIR
42
    cmake -G Ninja \
43 44 45 46 47 48 49 50
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
        -DFLATBUFFERS_BUILD_TESTS=OFF \
        -DFLATBUFFERS_BUILD_FLATHASH=OFF \
        -DFLATBUFFERS_BUILD_FLATLIB=OFF \
        -DFLATBUFFERS_LIBCXX_WITH_CLANG=OFF \
        $SRC_DIR/third_party/flatbuffers

51 52
    ${NINJA_BASE} all
    ${NINJA_BASE} install/strip
53
}
54 55 56 57 58 59 60 61

function try_remove_old_build() {
    REMOVE_OLD_BUILD=$1
    echo $REMOVE_OLD_BUILD
    BUILD_DIR=$2
    INSTALL_DIR=$3

    if [ $REMOVE_OLD_BUILD = "true" ]; then
62 63 64
        echo "remove old build/install dir"
        rm -rf ${BUILD_DIR}
        rm -rf ${INSTALL_DIR}
65 66 67 68
    else
        echo "strip remove old build"
    fi
}
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

function config_ninja_target_cmd() {
    NINJA_CMD="${NINJA_BASE} all"
    if [ $# -eq 4 ]; then
        _NINJA_VERBOSE=$1
        _BUILD_DEVELOP=$2
        _INSTALL_ALL_TARGET=$3
        _NINJA_DRY_RUN=$4
    else
        echo "err call config_ninja_target_cmd"
        exit -1
    fi

    if [ ${_NINJA_DRY_RUN} = "ON" ]; then
        NINJA_CMD="${NINJA_CMD} -d explain -n"
    else
        if [ ${_NINJA_VERBOSE} = "ON" ]; then
            NINJA_CMD="${NINJA_CMD} -d explain -v"
        fi
        if [ ${_BUILD_DEVELOP} = "ON" ]; then
            echo "add develop target"
            NINJA_CMD="${NINJA_CMD} && ${NINJA_BASE} develop"
        fi
        if [ -n "${_INSTALL_ALL_TARGET}" ]; then
            NINJA_CMD="${NINJA_CMD} && ${NINJA_BASE} ${_INSTALL_ALL_TARGET}"
        fi
    fi

    echo "build ${NINJA_BASE} target command: ${NINJA_CMD}"
}