~aleteoryx/muditaos

ref: 6c32205e1be369cbadf752c77eff68d1a2f963e1 muditaos/configure.sh -rwxr-xr-x 3.0 KiB
6c32205e — Marek Niepieklo [CP-371] Updater miscelanous developer mode and logs changes 4 years ago
                                                                                
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
44
45
46
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

if [[ $BASH_VERSINFO -lt 4 ]]; then
    echo "Please update your bash to at last version 4"
	echo "your is: ${BASH_VERSINFO}"
    exit 4
fi

function help() {
    echo -e "Use this script for faster configuring build types"
    echo -e "ussage:"
    echo -e "\t$0 <target> <build_type> [other cmake options]"
    echo -e "available targets are:"
    echo -e "\t\t\tlinux\n\t\t\trt1051"
    echo -e "available build types:"
    echo -e "\t\t\tDebug\t\t- standard debug build"
    echo -e "\t\t\tRelease\t\t- release build (not for debugging)"
    echo -e "\t\t\tRelWithDebInfo\t - release with debug info in separate file"
    echo -e "\n\e[1m\e[31mThis script will delete previous build dir!\e[0m"
}

function check_target() {
    case ${TARGET,,} in
        linux ) 
            CMAKE_TOOLCHAIN_FILE="Target_Linux.cmake"
            return 0 ;;
        rt1051 ) 
            CMAKE_TOOLCHAIN_FILE="Target_RT1051.cmake"
            return 0 ;;
        *) 
            echo "Wrong target: \"${TARGET}\""
            return 1
            ;;
    esac
}
function check_build_type() {
    case ${BUILD_TYPE,,} in
        debug)
            CMAKE_BUILD_TYPE="Debug"
            return 0;;
        release)
            CMAKE_BUILD_TYPE="Release"
            return 0;;
        relwithdebinfo)
            CMAKE_BUILD_TYPE="RelWithDebInfo"
            return 0;;
        *)
            echo "wrong build type \"${BUILD_TYPE}\""
            return 1;;
    esac
}

function github_return_build_dir() {
    if [[ -n "${GITHUB_WORKSPACE}" ]]; then
        echo "setting out package_path:$1"
        echo "::set-output name=package_path::$1"
    fi
}

TARGET=$1
BUILD_TYPE=$2

if check_target && check_build_type ; then
    shift 2
    BUILD_DIR="build-${TARGET,,}-${CMAKE_BUILD_TYPE}"
    echo -e "build dir:\e[34m\n\t${BUILD_DIR}\e[0m"
    SRC_DIR=`pwd`
    if [ -d ${BUILD_DIR} ]; then
        rm -Rf ${BUILD_DIR}
    fi
    if [ -e ${BUILD_DIR} ]; then
        echo "couldn't delete: ${BUILD_DIR}"
        exit 6
    fi
    github_return_build_dir ${BUILD_DIR}
    mkdir -p ${BUILD_DIR}
    if cd ${BUILD_DIR} ; then
        CMAKE_CMD="cmake \
                    -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
                    -DCMAKE_TOOLCHAIN_FILE=${SRC_DIR}/${CMAKE_TOOLCHAIN_FILE} \
                    -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
                    $@ \
                    ${SRC_DIR} "
        echo -e "\e[32m${CMAKE_CMD}\e[0m" | tr -s " "
        if $CMAKE_CMD; then
            Ninja=$(echo $@ | grep "Ninja")
            if [[ -z ${Ninja} ]]; then
                echo -e "\e[32mcd ${BUILD_DIR} && make -j $(nproc) <Pure|Bell>\e[0m"
            else
                echo -e "\e[32mcd ${BUILD_DIR} && ninja <Pure|Bell>\e[0m"
            fi
        else
            echo -e "configuration error!"
        fi
    else
        echo "Cannot switch to\"$BUILD_DIR\"!"
        exit 5
    fi
else
    echo "stop"
    exit 3
fi