-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-gn.sh
executable file
·245 lines (191 loc) · 4.55 KB
/
build-gn.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/bin/bash
RUN_SH=`basename $0`
HINT="$0 {build|clean|distclean|rebuild} [x86|i486|aarch64]"
ACTION=$1
ARCH=$2
[ -z "$ARCH" ] && export ARCH="x86"
export PJ_TARGET_CONF="_$ARCH"
#** Toolchain **
#** Setup Environment **
export PJ_ROOT=`pwd`
[ ! -z "$PJ_INSTALL" ] || export PJ_INSTALL="${PJ_ROOT}/install"
[ ! -z "$PJ_CPACK" ] || export PJ_CPACK="${PJ_ROOT}/install_Cpack"
[ ! -z "$SDK_ROOT_DIR" ] || export SDK_ROOT_DIR="${PJ_INSTALL}"
export SDK_USR_PREFIX_DIR="usr"
export CONFIG_CUSTOMER_DEF_H="${PJ_ROOT}/include/customer_def.h"
export CROSS_FILE=
export PJ_BUILD_DIR="build_xxx"
export PJ_BUILD_VERBOSE="-v"
#export PJ_MAKE_VERBOSE="VERBOSE=1"
export PJ_GN_ARGS="--args='is_debug=true'"
#export PKG_CONFIG_SYSROOT_DIR="${PJ_INSTALL}"
now_fn()
{
NOW_t=`date +"%Y%m%d%H%M%S"`
return $NOW_t
}
datetime_fn()
{
PROMPT=$1
if [ "${PROMPT}" = "" ]; then
echo
else
now_fn
DO_COMMAND_NOW="echo \"$NOW_t ${RUN_SH}|${PROMPT}\" $TEE_ARG"; sh -c "$DO_COMMAND_NOW"
fi
return 0
}
do_commandX_fn()
{
FUNCX=$1
LINEX=$2
DO_COMMAND=$3
datetime_fn "${FUNCX}:${LINEX}- [$DO_COMMAND]"
sh -c "$DO_COMMAND"
}
do_env_fn()
{
. confs/simple${PJ_TARGET_CONF}.conf >/dev/null 2>&1
return 0
}
die_fn()
{
datetime_fn "$@"; datetime_fn ""
exit 1
}
distclean_install_fn()
{
while true; do
echo
echo "install: ${SDK_ROOT_DIR}"
echo "Cpack: ${PJ_CPACK}"
read -p "WARNING! They will be removed [y/N] ? " yn
case $yn in
[Yy]* )
DO_COMMAND="rm -rf ${SDK_ROOT_DIR} ${PJ_CPACK}"
do_commandX_fn "${FUNCNAME[0]}" "${LINENO}" "${DO_COMMAND}"
break
;;
[Nn]* )
break
;;
* )
break
;;
esac
done
return 0
}
distclean_fn()
{
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ..."
DO_COMMAND="(rm -rf ${PJ_BUILD_DIR}; rm -f gnX/toolchain/BUILD.gn;)"
do_commandX_fn "${FUNCNAME[0]}" "${LINENO}" "${DO_COMMAND}"
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ok."
return 0
}
cfg_fn()
{
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ..."
#** customer_def.h **
#** build_xxx **
DO_COMMAND="(mkdir -p ${PJ_BUILD_DIR})"
do_commandX_fn "${FUNCNAME[0]}" "${LINENO}" "${DO_COMMAND}"
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ok."
datetime_fn
return 0
}
showusage_fn()
{
#datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ..."
printf "$HINT"; datetime_fn ""; exit 1
return 0
}
build_setup_fn()
{
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ..."
#** build setup **
if [ -d ${PJ_BUILD_DIR} ]; then
DO_COMMAND="(ln -s BUILD${PJ_TARGET_CONF}.gn gnX/toolchain/BUILD.gn; gn gen ${PJ_GN_ARGS} --root=${PJ_ROOT} -C ${PJ_BUILD_DIR})"
do_commandX_fn "${FUNCNAME[0]}" "${LINENO}" "${DO_COMMAND}"
fi
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ok."
datetime_fn
}
build_run_fn()
{
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ..."
if [ -d ${PJ_BUILD_DIR} ]; then
DO_COMMAND="(ninja ${PJ_BUILD_VERBOSE} -C ${PJ_BUILD_DIR})"
do_commandX_fn "${FUNCNAME[0]}" "${LINENO}" "${DO_COMMAND}"
fi
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ok."
datetime_fn
}
build_install_fn()
{
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ..."
if [ -d ${PJ_BUILD_DIR} ]; then
#DO_COMMAND="(ninja ${PJ_BUILD_VERBOSE} -C ${PJ_BUILD_DIR} install)"
#do_commandX_fn "${FUNCNAME[0]}" "${LINENO}" "${DO_COMMAND}"
DO_COMMAND="(mkdir -p ${SDK_BIN_DIR}; cp -avr ${PJ_BUILD_DIR}/bin/* ${SDK_BIN_DIR})"
do_commandX_fn "${FUNCNAME[0]}" "${LINENO}" "${DO_COMMAND}"
DO_COMMAND="(mkdir -p ${SDK_INC_DIR}; cp -avr ${PJ_BUILD_DIR}/include/* ${SDK_INC_DIR})"
do_commandX_fn "${FUNCNAME[0]}" "${LINENO}" "${DO_COMMAND}"
DO_COMMAND="(mkdir -p ${SDK_LIB_DIR}; cp -avr ${PJ_BUILD_DIR}/lib/* ${SDK_LIB_DIR})"
do_commandX_fn "${FUNCNAME[0]}" "${LINENO}" "${DO_COMMAND}"
fi
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ok."
datetime_fn
}
build_clean_fn()
{
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ..."
if [ -d ${PJ_BUILD_DIR} ]; then
DO_COMMAND="(ninja ${PJ_BUILD_VERBOSE} -C ${PJ_BUILD_DIR} -t clean)"
do_commandX_fn "${FUNCNAME[0]}" "${LINENO}" "${DO_COMMAND}"
fi
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ok."
datetime_fn
}
build_cpack_fn()
{
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ..."
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ok."
datetime_fn
}
build_fn()
{
datetime_fn "${FUNCNAME[0]}:${LINENO}- ($PID) ..."
distclean_fn
cfg_fn
build_setup_fn
build_run_fn
build_install_fn
build_cpack_fn
}
main_fn()
{
do_env_fn
case $ACTION in
build)
build_fn
;;
clean)
build_clean_fn
;;
rebuild)
build_clean_fn
build_fn
;;
distclean)
distclean_fn
distclean_install_fn
;;
*)
showusage_fn
;;
esac
}
main_fn
exit 0