-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.sh
executable file
·94 lines (81 loc) · 2.77 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
#!/bin/bash -e
# Usage examples:
# $ ./build.sh src_cpp
# $ CLEANBUILD=true ./build.sh src_cpp
# $ CLEANBUILD=true USE_HAL_DRIVER=ON ./build.sh src_cpp_hal
# $ CLEANBUILD=true USE_HAL_DRIVER=ON USE_FREERTOS=ON ./build.sh src_cpp_freertos
echo "Building the project in Linux environment"
# Toolchain path
: ${TOOLCHAIN_DIR:="/opt/toolchains/gcc-arm-none-eabi-9-2019-q4-major"}
# select cmake toolchain
: ${CMAKE_TOOLCHAIN:=TOOLCHAIN_arm_none_eabi_cortex_m7.cmake}
# select to clean previous builds
: ${CLEANBUILD:=false}
# select to create eclipse project files
: ${ECLIPSE_IDE:=false}
# Select DSP/NN lib use
: ${USE_CMSIS_NN:="OFF"}
# Select compressed/uncompressed model use
: ${USE_COMP_MODEL:="OFF"}
# Select HAL/LL lib use
: ${USE_HAL_DRIVER:="ON"}
# Select Stdperiph lib use
: ${USE_FREERTOS:="OFF"}
# Use overclock
: ${USE_OVERCLOCK:="OFF"}
# Select source folder. Give a false one to trigger an error
: ${SRC:="src"}
# Set default arch to stm32
ARCHITECTURE=stm32
# default generator
IDE_GENERATOR="Unix Makefiles"
# Current working directory
WORKING_DIR=$(pwd)
# cmake scripts folder
SCRIPTS_CMAKE="${WORKING_DIR}/source/cmake"
# Compile objects in parallel, the -jN flag in make
PARALLEL=$(expr $(getconf _NPROCESSORS_ONLN) + 1)
if [ ! -d "source/${SRC}" ]; then
echo -e "You need to specify the SRC parameter to point to the source code"
exit 1
fi
if [ "${ECLIPSE}" == "true" ]; then
IDE_GENERATOR="Eclipse CDT4 - Unix Makefiles"
fi
BUILD_ARCH_DIR=${WORKING_DIR}/build-${ARCHITECTURE}
if [ "${ARCHITECTURE}" == "stm32" ]; then
CMAKE_FLAGS="${CMAKE_FLAGS} \
-DTOOLCHAIN_DIR=${TOOLCHAIN_DIR} \
-DCMAKE_TOOLCHAIN_FILE=${SCRIPTS_CMAKE}/${CMAKE_TOOLCHAIN} \
-DUSE_CMSIS_NN=${USE_CMSIS_NN} \
-DUSE_HAL_DRIVER=${USE_HAL_DRIVER} \
-DUSE_FREERTOS=${USE_FREERTOS} \
-DUSE_OVERCLOCK=${USE_OVERCLOCK} \
-DUSE_COMP_MODEL=${USE_COMP_MODEL} \
-DSRC=${SRC} \
"
else
>&2 echo "*** Error: Architecture '${ARCHITECTURE}' unknown."
exit 1
fi
if [ "${CLEANBUILD}" == "true" ]; then
echo "- removing build directory: ${BUILD_ARCH_DIR}"
rm -rf ${BUILD_ARCH_DIR}
fi
echo "--- Pre-cmake ---"
echo "architecture : ${ARCHITECTURE}"
echo "distclean : ${CLEANBUILD}"
echo "parallel : ${PARALLEL}"
echo "cmake flags : ${CMAKE_FLAGS}"
echo "cmake scripts : ${SCRIPTS_CMAKE}"
echo "IDE generator : ${IDE_GENERATOR}"
echo "Threads : ${PARALLEL}"
echo "USE_OVERCLOCK : ${USE_OVERCLOCK}"
echo "USE_CMSIS_NN : ${USE_CMSIS_NN}"
echo "USE_COMP_MODEL : ${USE_COMP_MODEL}"
mkdir -p build-stm32
cd build-stm32
# setup cmake
cmake ../source -G"${IDE_GENERATOR}" ${CMAKE_FLAGS}
# build
make -j${PARALLEL} --no-print-directory