forked from mudita/MuditaOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.sh
executable file
·150 lines (138 loc) · 4 KB
/
configure.sh
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
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
146
147
#!/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 [-dh] <product> <target> <build_type> [other cmake options]"
echo -e "options:"
echo -e "\t\t\td\t\t- turn on development features"
echo -e "\t\t\th\t\t- print this help"
echo -e "available products are:"
echo -e "\t\t\tpure"
echo -e "\t\t\tbell"
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 validate_product_selection() {
case ${PRODUCT,,} in
pure | purephone)
PRODUCT_SHORTNAME="pure"
PRODUCT="PurePhone"
return 0 ;;
bell | bellhybrid)
PRODUCT_SHORTNAME="bell"
PRODUCT="BellHybrid"
return 0 ;;
*)
echo "Wrong product: \"${PRODUCT}\""
esac
}
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
}
DEVELOPMENT_FEATURES="OFF"
while getopts ":d" o; do
case "${o}" in
d)
DEVELOPMENT_FEATURES="ON"
;;
h)
help
exit 0
;;
*)
help
exit 1
;;
esac
done
shift $((OPTIND-1))
PRODUCT=$1
TARGET=$2
BUILD_TYPE=$3
if validate_product_selection && check_target && check_build_type ; then
shift 3
BUILD_DIR="build-${PRODUCT}-${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} \
-DPRODUCT=${PRODUCT} \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
-DWITH_DEVELOPMENT_FEATURES=${DEVELOPMENT_FEATURES} \
$@ \
${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