1
1
#! /usr/bin/env bash
2
2
3
+ # Function to display usage information
3
4
usage () {
4
- echo -e " USAGE: $0 [-c] [-u] [-f <main|initial>] [-p <device|simulator>] [-t <dev|debug|release|unit_tests>]"
5
+ echo -e " USAGE: $0 [-c] [-u] [-b] [- f <main|initial>] [-p <device|simulator>] [-t <dev|debug|release|unit_tests>]"
5
6
echo -e " Parameters are optional and assumes 'main debug device' if not provided"
6
7
echo -e " \n\n -c \t Performs a forced clean before invoking build"
7
8
echo -e " \n\n -u \t Generate unsigned binary"
9
+ echo -e " \n\n -b \t Build BTC-only firmware"
8
10
echo -e " \n\n -f \t Sets the preferred firmware to build. Can be main or initial"
9
11
echo -e " \n\n -p \t Provides the preferred platform to build for. Can be simulator or device"
10
12
echo -e " \n\n -t \t Tells the build type that should be generate. Can be a valid build type."
11
13
echo -e " \t \t For example release, debug, dev, unit_tests"
12
14
exit 1
13
15
}
14
16
17
+ # Function to validate the firmware name
15
18
validate_name () {
16
19
if ! [[ " $ACTIVE_TYPE " =~ ^(Main| Initial)$ ]]; then
17
20
echo -e " Incorrect firmware ($ACTIVE_TYPE ) selected for build\n"
18
21
usage
19
22
fi
20
23
}
21
24
25
+ # Function to validate the build platform
22
26
validate_platform () {
23
27
if ! [[ " $BUILD_PLATFORM " =~ ^(Device| Simulator)$ ]]; then
24
28
echo -e " Incorrect platform ($BUILD_PLATFORM ) selected for build\n"
25
29
usage
26
30
fi
27
31
}
28
32
33
+ # Function to validate the build type
29
34
validate_type () {
30
35
if ! [[ " $BUILD_TYPE " =~ ^(Debug| Release| Dev| Unit_tests)$ ]]; then
31
36
echo -e " Incorrect type ($BUILD_TYPE ) selected for build\n"
32
37
usage
33
38
fi
34
39
}
35
40
41
+ # --- Script Defaults ---
36
42
ACTIVE_ROOT_DIR=$( pwd)
37
43
ACTIVE_TYPE=Main
38
44
BUILD_TYPE=Debug
39
45
BUILD_PLATFORM=Device
40
46
UNIT_TESTS=OFF
41
47
DEV=OFF
42
48
SIGN_BINARY=ON
49
+ BTC_ONLY=OFF # Default to multi-coin build
43
50
44
- while getopts ' cf:p:t:u' flag; do
51
+ # --- Parse Command Line Arguments ---
52
+ while getopts ' cbuf:p:t:' flag; do
45
53
case " ${flag} " in
46
54
c) clean_flag=" true" ;;
55
+ b) BTC_ONLY=ON ;;
47
56
f) ACTIVE_TYPE=$( echo " ${OPTARG} " | awk ' {print toupper(substr($0, 1, 1)) tolower(substr($0, 2))}' ) ;;
48
57
p) BUILD_PLATFORM=$( echo " ${OPTARG} " | awk ' {print toupper(substr($0, 1, 1)) tolower(substr($0, 2))}' ) ;;
49
58
t) BUILD_TYPE=$( echo " ${OPTARG} " | awk ' {print toupper(substr($0, 1, 1)) tolower(substr($0, 2))}' ) ;;
@@ -52,6 +61,7 @@ while getopts 'cf:p:t:u' flag; do
52
61
esac
53
62
done
54
63
64
+ # --- Validate Inputs ---
55
65
shift " $(( OPTIND - 1 )) "
56
66
validate_name
57
67
validate_platform
@@ -61,6 +71,7 @@ if [ $# -gt 0 ]; then
61
71
usage
62
72
fi
63
73
74
+ # --- Set Build-specific Variables ---
64
75
case $BUILD_TYPE in
65
76
Dev)
66
77
DEV=ON
@@ -74,17 +85,26 @@ Unit_tests)
74
85
;;
75
86
esac
76
87
88
+ # --- Prepare Build Directory ---
89
+ BUILD_DIR_SUFFIX=" "
90
+ if [ " ${BTC_ONLY} " = " ON" ]; then
91
+ BUILD_DIR_SUFFIX=" _BTC"
92
+ fi
93
+
94
+ BUILD_DIR=" build/${ACTIVE_TYPE}${BUILD_DIR_SUFFIX} "
95
+
77
96
cd " ${ACTIVE_ROOT_DIR} " || exit
78
- mkdir -p " build/ ${ACTIVE_TYPE }"
79
- cd " build/ ${ACTIVE_TYPE }" || exit
97
+ mkdir -p " ${BUILD_DIR }"
98
+ cd " ${BUILD_DIR }" || exit
80
99
81
- # remove previous cmake configuration to ensure we are building with
100
+ # Remove previous cmake configuration to ensure we are building with
82
101
# currently requested build configuration; it is important to delete
83
102
# the existing cmake configuration
84
103
if [ -f " CMakeCache.txt" ]; then
85
104
rm " CMakeCache.txt"
86
105
fi
87
106
107
+ # --- Find Build Tools ---
88
108
# Detect if any one (cmake or mingw32-cmake) exists
89
109
CMAKE=$( which cmake)
90
110
if [ " ${CMAKE} " = " " ]; then
@@ -115,12 +135,15 @@ if [ "${BUILD_TOOL}" = "" ]; then
115
135
exit 1
116
136
fi
117
137
138
+ # --- Run Build ---
118
139
if [[ " ${clean_flag} " = " true" ]]; then
119
140
rm -rf " ${ACTIVE_ROOT_DIR} /generated/proto"
120
141
fi
121
142
143
+ # Configure the project with CMake
122
144
" ${CMAKE} " -DDEV_SWITCH=${DEV} \
123
145
-DUNIT_TESTS_SWITCH:BOOL=" ${UNIT_TESTS} " \
146
+ -DBTC_ONLY:BOOL=" ${BTC_ONLY} " \
124
147
-DSIGN_BINARY:BOOL=" ${SIGN_BINARY} " \
125
148
-DCMAKE_BUILD_TYPE:STRING=" ${BUILD_TYPE} " \
126
149
-DFIRMWARE_TYPE=" ${ACTIVE_TYPE} " \
131
154
# exit if configuration failed with errors
132
155
if [ ! $? -eq 0 ]; then exit 1; fi
133
156
157
+ # Clean and build the project
134
158
if [[ " ${clean_flag} " = " true" ]]; then
135
159
" ${BUILD_TOOL} " clean
136
160
fi
0 commit comments