-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.sh
executable file
·63 lines (48 loc) · 1.21 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
#!/bin/bash
if [ -f "toolpath" ]; then
toolPath=$(cat toolpath)
PATH="$toolPath:$PATH"
fi
mcu="cortex-m3" # "cortex-m0"
arch="armv7-m" # "armv6-m" for Cortex-M0/+
sources=`ls *.c`
mkdir -p obj
rm obj/*
objs=""
count=0
for s in $sources; do
f=$(basename $s | sed -E 's/(^.*)\.[a-zA-Z]+$/\1/')
o="obj/$count-$f.$arch.o"
count=$(($count + 1))
echo "Building $s => $o"
arm-none-eabi-gcc -Wall -Wno-switch -nostdlib -nodefaultlibs -fno-exceptions \
-g -Os -mthumb -march=$arch -mcpu=$mcu -Wno-attributes \
--function-sections \
-I . \
-o $o -x c -c $s
if [ $? -ne 0 ]; then
echo "Compiling failed."
exit -1
fi
objs="$objs $o"
done
echo Linking...
# use single-object pre-link
arm-none-eabi-ld -o obj/zlib.$arch.o -r $objs
if [ $? -ne 0 ]; then
echo "Linking failed."
exit -1
fi
echo Archiving...
arm-none-eabi-ar r obj/zlib.$arch.a obj/zlib.$arch.o
if [ $? -ne 0 ]; then
echo "Archiving failed."
exit -1
fi
# report symbols
arm-none-eabi-size obj/zlib.$arch.a > obj/zlib.$arch.report.txt
arm-none-eabi-nm obj/zlib.$arch.a >> obj/zlib.$arch.report.txt
arm-none-eabi-objdump -d obj/zlib.armv7-m.o >> obj/zlib.$arch.report.txt
echo "Build succeeded."
# link to final firmware with -Wl,--gc-sections
exit 0