utils.sh 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/env bash
set -e

MAKEFILE_TYPE="Unix"
OS=$(uname -s)

if [[ $OS =~ "NT" ]]; then
    echo "BUILD in NT ..."
    MAKEFILE_TYPE="Unix"
fi

function build_flatc() {
    BUILD_DIR=$1/build_dir/host_flatc/build
    INSTALL_DIR=$BUILD_DIR/../install
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
    REMOVE_OLD_BUILD=$2

    if [ $REMOVE_OLD_BUILD = "true" ]; then
        if [ -e $BUILD_DIR ];then
            echo "clean old dir: $BUILD_DIR"
            rm -rf $BUILD_DIR
        fi
        if [ -e $INSTALL_DIR ];then
            echo "clean old dir: $INSTALL_DIR"
            rm -rf $INSTALL_DIR
        fi
    else
        echo "strip remove old build"
    fi

    if [ ! -e $BUILD_DIR ];then
        echo "create build: $BUILD_DIR"
        mkdir -p $BUILD_DIR
33
    fi
34 35 36
    if [ ! -e $INSTALL_DIR ];then
        echo "create install $INSTALL_DIR"
        mkdir -p $INSTALL_DIR
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    fi

    cd $BUILD_DIR
    cmake -G "$MAKEFILE_TYPE Makefiles" \
        -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

    make -j$(nproc)
    make install/strip
}
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

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
        if [ -e $BUILD_DIR ];then
            echo "clean old dir: $BUILD_DIR"
            rm -rf $BUILD_DIR
        fi
        if [ -e $INSTALL_DIR ];then
            echo "clean old dir: $INSTALL_DIR"
            rm -rf $INSTALL_DIR
        fi
    else
        echo "strip remove old build"
    fi
}