This repository has been archived by the owner on Feb 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·88 lines (76 loc) · 2.24 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
#!/bin/bash
# Ensure we aren't building from the repo root
if [ ! -d src ]; then
echo "Cannot build from root"
exit
fi
if [ -z $BUILD_DIR ] || [ -z $BOARD ]; then
echo "Build variables not set. Call build.sh in a board directory"
exit
fi
# TODO: Change this to a command that moves the repo out of Downloads
if [[ "$PWD" = */Downloads/* ]] || [[ "$PWD" = */downloads/* ]] ; then
figlet "Don't clone to Downloads, Will"
fi
# Build the board image
if [ ! $1 ] || [ $1 = build ]; then
if [ ! -f makefile-mbed ]; then
echo "Setting up local environment"
ln -s ../shared/mbed/$BUILD_DIR $BUILD_DIR
ln -s ../shared/mbed/mbed-os mbed-os
ln -s ../shared/mbed/.mbed .mbed
ln -s ../shared/mbed/makefile-mbed makefile-mbed
ln -s ../shared/mbed/mbed_config.h mbed_config.h
ln -s ../shared/mbed/mbed_settings.py mbed_settings.py
else
echo "Local environment already set up"
fi
# Setup files for build
echo "Setting up build environment"
mkdir -p ../shared/mbed/$BUILD_DIR/ubcr_$BOARD
cp -r src/* ../shared/mbed/$BUILD_DIR/ubcr_$BOARD
mkdir -p ../shared/mbed/$BUILD_DIR/ubcr_shared
find ../shared/ -type d | egrep -v "(mbed|^..\/shared\/$)" | xargs -ILIST cp -r LIST ../shared/mbed/$BUILD_DIR/ubcr_shared
# Find source files
C_FILES=$(find ./src/* | egrep "\.c$")
CPP_FILES=$(find ./src/* | egrep "\.cpp$")
O_FILES=""
O_FILES=$O_FILES$(echo $C_FILES | sed -e 's/.c/.o/g')
O_FILES=$O_FILES$(echo $CPP_FILES | sed -e 's/.cpp/.o/g')
O_FILES=$(echo $O_FILES | sed -e 's/src\//ubcr_'$BOARD'\//g')
# Build
echo Building $BOARD board
make -j16 -f makefile-mbed \
UBCR_TARGETDIR=$BUILD_DIR \
UBCR_SHAREDDIR=ubcr_shared \
UBCR_O_FILES=$O_FILES
if [ ! $? -eq 0 ]; then
echo -e '\033[0;31m'
figlet "Build Failed"
echo -e '\033[0m'
exit -1
else
echo -e '\033[0;32m'
figlet "Build Successful!"
echo -e '\033[0m'
cp $BUILD_DIR/mbed.bin "../builds/"$BOARD.bin
exit 0
fi
# Flash the image to a board
elif [ $1 = flash ]; then
echo "Flashing unimplemented"
exit 1
# Cleanup all the build artefacts
elif [ $1 = clean ]; then
if [ ! -f makefile-mbed ]; then
echo "You can't clean until you build"
exit 1
fi
rm -r $BUILD_DIR/*
rm $BUILD_DIR
rm mbed-os
rm .mbed
rm makefile-mbed
rm mbed_config.h
rm mbed_settings.py
fi