-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.sh
executable file
·351 lines (339 loc) · 11.5 KB
/
build.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/bash
###############################################################################
#Variables
export PROJECT_LIST=$(find project | grep "GCC/Makefile$")
export BOARD_LIST="project/*"
export OUT="$PWD/out"
export FLASHGENERATOR="tools/flashgen/flashgen.pl"
feature_mk=""
platform=$(uname)
if [[ "$platform" =~ "MINGW" ]]; then
export EXTRA_VAR=-j
else
export EXTRA_VAR=-j`cat /proc/cpuinfo |grep ^processor|wc -l`
fi
###############################################################################
#Functions
show_usage () {
echo "==============================================================="
echo "Build Project"
echo "==============================================================="
echo "Usage: $0 <board> <project> [bl|clean] <argument>"
echo ""
echo "Example:"
echo " $0 mt7687_hdk iot_sdk_demo"
echo " $0 mt7687_hdk iot_sdk_demo bl (build with bootloader)"
echo " $0 clean (clean folder: out)"
echo " $0 mt7687_hdk clean (clean folder: out/mt7687_hdk)"
echo " $0 mt7687_hdk iot_sdk_demo clean (clean folder: out/mt7687_hdk/iot_sdk_demo)"
echo ""
echo "Argument:"
echo " -f=<feature makefile> or --feature=<feature makefile>"
echo " Replace feature.mk with other makefile. For example, "
echo " the feature_example.mk is under project folder, -f=feature_example.mk"
echo " will replace feature.mk with feature_example.mk."
echo ""
echo " -o=<make option> or --option=<make option>"
echo " Assign additional make option. For example, "
echo " to compile module sequentially, use -o=-j1."
echo " to turn on specific feature in feature makefile, use -o=<feature_name>=y"
echo " to assign more than one options, use -o=<option_1> -o=<option_2>."
echo ""
echo "==============================================================="
echo "List Available Example Projects"
echo "==============================================================="
echo "Usage: $0 list"
echo ""
}
show_available_proj () {
echo "==============================================================="
echo "Available Build Projects:"
echo "==============================================================="
for b in $BOARD_LIST
do
project_path=""
project_name_list=""
p=$(echo $PROJECT_LIST | tr " " "\n" | grep "$b")
if [ ! -z "$p" ]; then
echo " "`basename $b`
fi
for q in $p
do
if [ -e "$q" ]; then
project_path=$(echo $q | sed 's/GCC\/Makefile//')
project_name_list="${project_name_list} $(basename $project_path)"
fi
done
for i in `echo $project_name_list | tr " " "\n" | sort`
do
echo " "" "$i
done
done
}
use_new_out_folder="FALSE"
target_check () {
for p in $PROJECT_LIST
do
q=$(echo $p | grep "project/$1/")
if [ ! -z "$q" ]; then
r=$(echo $q | sed 's/GCC\/Makefile//')
s=`basename $r`
if [ "$s" == "$2" ]; then
echo "Build board:$1 project:$2"
if [ $use_new_out_folder == "FALSE" ]; then
OUT=$OUT/$1/$2
fi
BUILD=project/$1/$2
export TARGET_PATH=$(dirname $q)
return 0
fi
fi
done
return 1
}
# support MinGW
mingw_check () {
echo "platform=$platform"
if [[ "$platform" =~ "MINGW" ]]; then
pwdpath=$(pwd)
echo $pwdpath
if [[ "$pwdpath" =~ "\[|\]| " ]]; then
echo "Build.sh Exception: The codebase folder name should not have spacing, [ or ]."
exit 1
fi
fi
}
clean_out () {
rm -rf $1
echo "rm -rf $1"
}
###############################################################################
#Begin here
if [ "$#" -eq "0" ]; then
show_usage
exit 1
fi
# parsing arguments
declare -a argv=($0)
ori_argv=$@
do_make_clean="FALSE"
for i in $@
do
case $i in
-o=*|--option=*)
opt=" ${i#*=}"
echo "$opt" | grep -q -E " OUT="
if [[ $? -eq 0 ]]; then
OUT=`echo $opt | grep -o "OUT=[^ |^ ]*" | cut -d '=' -f2 | tr -d ' '`
if [ -z "$OUT" ]; then
echo "Error: -o=OUT= cannot be empty!"
show_usage
exit 1
fi
OUT=$PWD/$OUT
use_new_out_folder="TRUE"
echo "output folder change to: $OUT"
fi
extra_opt+=$opt
do_make_clean="TRUE"
shift
;;
-f=*|--feature=*)
feature_mk="${i#*=}"
shift
;;
list)
show_available_proj
exit 0
;;
-*)
echo "Error: unknown parameter \"$i\""
show_usage
exit 1
;;
*)
argv+=($i)
;;
esac
done
export PROJ_NAME=${argv[2]}
###############################################################################
if [ "${argv[3]}" == "bl" ]; then
if [ "${#argv[@]}" != "4" ]; then
show_usage
exit 1
fi
target_check ${argv[1]} ${argv[2]}
if [ "$?" -ne "0" ]; then
echo "Error: ${argv[1]} ${argv[2]} is not available board & project"
show_usage
exit 1
fi
if [ $do_make_clean == "TRUE" ]; then
clean_out $OUT
fi
mingw_check
where_to_find_feature_mk=$TARGET_PATH
if [ ! -z $feature_mk ]; then
if [ ! -e "$TARGET_PATH/$feature_mk" ]; then
echo "Error: cannot find $feature_mk under $TARGET_PATH."
exit 1
fi
EXTRA_VAR+=" FEATURE=$feature_mk"
else
where_to_find_feature_mk=`grep "^TARGET_PATH\ *[?:]\{0,1\}=\ *" $TARGET_PATH/Makefile | cut -d '=' -f2 | tr -d ' ' | tail -1`
if [ -z $where_to_find_feature_mk ]; then
where_to_find_feature_mk=$TARGET_PATH
fi
feature_mk=`grep "^FEATURE\ *[?:]\{0,1\}=\ *" $TARGET_PATH/Makefile | cut -d '=' -f2 | tr -d ' ' | tail -1`
echo "FEATURE=$feature_mk"
fi
if [ -e "$OUT/obj/$TARGET_PATH/tmp.mk" ]; then
diff -q $where_to_find_feature_mk/$feature_mk $OUT/obj/$TARGET_PATH/tmp.mk
if [ $? -ne 0 ]; then
clean_out $OUT
fi
fi
mkdir -p $OUT/obj/$TARGET_PATH
cp $where_to_find_feature_mk/$feature_mk $OUT/obj/$TARGET_PATH/tmp.mk
CM4_TARGET_PATH_BAK=$TARGET_PATH
TARGET_PATH="project/${argv[1]}/apps/bootloader/GCC"
if [ "${argv[2]}" == "iot_sdk_lite" ]; then
TARGET_PATH="project/${argv[1]}/apps/bootloader_lite/GCC"
fi
mkdir -p $OUT/log
echo "$0 $ori_argv" > $OUT/log/build_time.log
echo "Start Build: "`date` >> $OUT/log/build_time.log
echo "Build bootloader..."
# Check if the source dir is existed
if [ ! -d "project/${argv[1]}/apps/bootloader" ]; then
echo "Error: no bootloader source in project/${argv[1]}/apps/bootloader"
exit 1
fi
mkdir -p $OUT
make -C $TARGET_PATH BUILD_DIR=$OUT/obj/bootloader OUTPATH=$OUT BL_MAIN_PROJECT=${argv[2]} 2>> $OUT/err.log
BUILD_RESULT=$?
mkdir -p $OUT/lib
mv -f $OUT/*.a $OUT/lib/ 2> /dev/null
mkdir -p $OUT/log
mv -f $OUT/*.log $OUT/log/ 2> /dev/null
if [ $BUILD_RESULT -ne 0 ]; then
echo "Error: bootloader build failed!!"
echo "BOOTLOADER BUILD : FAIL" >> $OUT/log/build_time.log
exit 2;
else
echo "BOOTLOADER BUILD : PASS" >> $OUT/log/build_time.log
fi
echo "Build bootloader...Done"
# build cm4 firmware
echo "Build CM4 Firmware..."
TARGET_PATH=$CM4_TARGET_PATH_BAK
mkdir -p $OUT/autogen
EXTRA_VAR+="$extra_opt"
#echo "make -C $TARGET_PATH BUILD_DIR=$OUT/obj OUTPATH=$OUT $EXTRA_VAR"
make -C $TARGET_PATH BUILD_DIR=$OUT/obj OUTPATH=$OUT $EXTRA_VAR 2>> $OUT/err.log
BUILD_RESULT=$?
mkdir -p $OUT/lib
mv -f $OUT/*.a $OUT/lib/ 2> /dev/null
mkdir -p $OUT/log
mv -f $OUT/*.log $OUT/log/ 2> /dev/null
echo "Build CM4 Firmware...Done"
echo "End Build: "`date` >> $OUT/log/build_time.log
cat $OUT/log/build.log | grep "MODULE BUILD" >> $OUT/log/build_time.log
if [ "$BUILD_RESULT" -eq "0" ]; then
echo "TOTAL BUILD: PASS" >> $OUT/log/build_time.log
else
echo "TOTAL BUILD: FAIL" >> $OUT/log/build_time.log
fi
echo "=============================================================="
cat $OUT/log/build_time.log
exit $BUILD_RESULT
elif [ "${argv[3]}" == "clean" ]; then
if [ "${#argv[@]}" != "4" ]; then
show_usage
exit 1
fi
if [ "$use_new_out_folder" == "TRUE" ]; then
rm -rf $OUT
else
rm -rf $OUT/${argv[1]}/${argv[2]}
fi
elif [ "${argv[2]}" == "clean" ]; then
if [ "${#argv[@]}" != "3" ]; then
show_usage
exit 1
fi
if [ "$use_new_out_folder" == "TRUE" ]; then
rm -rf $OUT
else
rm -rf $OUT/${argv[1]}
fi
elif [ "${argv[1]}" == "clean" ]; then
if [ "${#argv[@]}" != "2" ]; then
show_usage
exit 1
fi
rm -rf $OUT
else
if [ "${#argv[@]}" != "3" ]; then
show_usage
exit 1
fi
target_check ${argv[1]} ${argv[2]}
if [ "$?" -ne "0" ]; then
echo "Error: ${argv[1]} ${argv[2]} is not available board & project or module"
show_usage
exit 1
fi
if [ $do_make_clean == "TRUE" ]; then
clean_out $OUT
fi
mingw_check
where_to_find_feature_mk=$TARGET_PATH
if [ ! -z $feature_mk ]; then
if [ ! -e "$TARGET_PATH/$feature_mk" ]; then
echo "Error: cannot find $feature_mk under $TARGET_PATH."
exit 1
fi
EXTRA_VAR+=" FEATURE=$feature_mk"
else
where_to_find_feature_mk=`grep "^TARGET_PATH\ *[?:]\{0,1\}=\ *" $TARGET_PATH/Makefile | cut -d '=' -f2 | tr -d ' ' | tail -1`
if [ -z $where_to_find_feature_mk ]; then
where_to_find_feature_mk=$TARGET_PATH
fi
feature_mk=`grep "^FEATURE\ *[?:]\{0,1\}=\ *" $TARGET_PATH/Makefile | cut -d '=' -f2 | tr -d ' ' | tail -1`
echo "FEATURE=$feature_mk"
fi
if [ -e "$OUT/obj/$TARGET_PATH/tmp.mk" ]; then
diff -q $where_to_find_feature_mk/$feature_mk $OUT/obj/$TARGET_PATH/tmp.mk
if [ $? -ne 0 ]; then
clean_out $OUT
fi
fi
mkdir -p $OUT/obj/$TARGET_PATH
cp $where_to_find_feature_mk/$feature_mk $OUT/obj/$TARGET_PATH/tmp.mk
mkdir -p $OUT/autogen
mkdir -p $OUT/log
echo "$0 $ori_argv" > $OUT/log/build_time.log
echo "Start Build: "`date` >> $OUT/log/build_time.log
if [ ! -z $feature_mk ]; then
EXTRA_VAR+=" FEATURE=$feature_mk"
fi
EXTRA_VAR+="$extra_opt"
#echo "make -C $TARGET_PATH BUILD_DIR=$OUT/obj OUTPATH=$OUT $EXTRA_VAR"
make -C $TARGET_PATH BUILD_DIR=$OUT/obj OUTPATH=$OUT $EXTRA_VAR 2>> $OUT/err.log
BUILD_RESULT=$?
mkdir -p $OUT/lib
mv -f $OUT/*.a $OUT/lib/ 2> /dev/null
mv -f $OUT/*.log $OUT/log/ 2> /dev/null
echo "End Build: "`date` >> $OUT/log/build_time.log
cat $OUT/log/build.log | grep "MODULE BUILD" >> $OUT/log/build_time.log
if [ "$BUILD_RESULT" -eq "0" ]; then
echo "TOTAL BUILD: PASS" >> $OUT/log/build_time.log
else
echo "TOTAL BUILD: FAIL" >> $OUT/log/build_time.log
fi
echo "=============================================================="
cat $OUT/log/build_time.log
exit $BUILD_RESULT
fi