-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·231 lines (205 loc) · 8.08 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·231 lines (205 loc) · 8.08 KB
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
#!/bin/bash
usage()
{
echo "Usage: build.sh [clean] [arm64|x86_64|universal] [CUSTOM_BUILD_FLAGS=x] [noroot] [release|debug] [-h|-?] [-l (static|shared)] [-D CMAKE_OPTION] [-v]"
echo " "
echo "options: "
echo " "
echo "Positional options: "
echo "[clean] - perform clean build "
echo "[arm64|x86_64|universal] - Apple platform build type. Not applicable to other OS. "
echo "[CUSTOM_BUILD_FLAGS] - custom CXX compiler flags "
echo "[noroot] - custom CXX compiler flags "
echo "[release|debug] - Specify build type (defaults to Debug) "
echo " "
echo "Additional parameters: "
echo " -h | -? - this help. "
echo " -l [static|shared] - build static (default) or shared library. "
echo " -D [CMAKE_OPTION] - additional options to pass to cmake. Could be multiple. "
echo " -v - increase build verbosity (reserved for future use) "
echo " "
echo "Environment variables: "
echo "CMAKE_OPTS - any additional cmake options. "
echo "GIT_PULL_TOKEN - authorization token for Microsoft-proprietary modules. "
echo "MACOSX_DEPLOYMENT_TARGET - optional parameter for setting macosx deployment target "
echo "Plus any other environment variables respected by CMake build system. "
exit 0
}
export PATH=/usr/local/bin:$PATH
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Current directory: $DIR"
cd $DIR
. "$DIR/tools/build-common.sh"
export NOROOT=$NOROOT
# Evaluate arguments that are not switches
while [[ $# -gt 0 ]]; do
ARG="$1"
case "$ARG" in
clean|noroot|release|debug|arm64|x86_64|universal|CUSTOM_BUILD_FLAGS*)
case "$ARG" in
clean)
CLEAN=true
echo "CLEAN = true"
;;
noroot)
export NOROOT=true
echo "NOROOT = true"
;;
release|debug)
if [[ -n "$BUILD_TYPE" ]]; then
echo "Error: BUILD_TYPE is already set to '$BUILD_TYPE'. Cannot overwrite with $ARG." 1>&2
exit 1
elif [[ "$ARG" == "release" ]]; then
BUILD_TYPE="Release"
elif [[ "$ARG" == "debug" ]]; then
BUILD_TYPE="Debug"
fi
echo "BUILD_TYPE = $BUILD_TYPE"
;;
arm64|x86_64|universal)
if [[ -n "$APPLE_ARCH" ]]; then
echo "Error: APPLE_ARCH is already set to '$APPLE_ARCH'. Cannot overwrite with $ARG." 1>&2
exit 1
else
APPLE_ARCH="$ARG"
fi
echo "APPLE_ARCH = $APPLE_ARCH"
;;
CUSTOM_BUILD_FLAGS*)
CUSTOM_CMAKE_CXX_FLAG="${ARG:19:999}"
echo "custom compiler flags = $CUSTOM_CMAKE_CXX_FLAG"
;;
*)
echo "Error: case not added: $ARG" 1>&2
exit 1
;;
esac
shift
;;
*)
break
;;
esac
done
if [[ -z "$BUILD_TYPE" ]]; then
BUILD_TYPE="Debug"
echo "Assuming default BUILD_TYPE = Debug"
fi
if [[ -z "$APPLE_ARCH" ]]; then
APPLE_ARCH=$(/usr/bin/uname -m)
echo "Using current machine APPLE_ARCH = $APPLE_ARCH"
fi
# Evaluate switches
LINK_TYPE=
CMAKE_OPTS="${CMAKE_OPTS:--DBUILD_SHARED_LIBS=OFF}"
while getopts "h?vl:D:" opt; do
case "$opt" in
h|\?) usage
;;
:) echo "Invalid option: $OPTARG requires an argument" 1>&2
exit 0
;;
v) verbose=1
;;
D) CMAKE_OPTS="${CMAKE_OPTS} -D${OPTARG}"
;;
l) LINK_TYPE=$OPTARG
;;
esac
done
# Detect args accidentally passed after the last switch argument
shift $((OPTIND -1))
if [[ $# -gt 0 ]]; then
echo "Error: There are arguments remaining after parsing all positional arguments and switches: $@" 1>&2
exit 1
fi
if [[ "$CLEAN" == "true" ]]; then
matsdk_clean_build_outputs "build.sh"
fi
echo "CMAKE_OPTS from caller: $CMAKE_OPTS"
if [ "$LINK_TYPE" == "shared" ]; then
CMAKE_OPTS="${CMAKE_OPTS} -DBUILD_SHARED_LIBS=ON"
fi
# Set target MacOS minver
default_mac_os_target=$([ "$APPLE_ARCH" == "arm64" ] && echo "11.10" || echo "10.10")
[ -z $MACOSX_DEPLOYMENT_TARGET ] && export MACOSX_DEPLOYMENT_TARGET=${default_mac_os_target}
echo "macosx deployment target="$MACOSX_DEPLOYMENT_TARGET
# Install build tools and recent sqlite3
BUILD_TOOLS_MARKER=.buildtools
OS_NAME=`uname -a`
if [ ! -f "$BUILD_TOOLS_MARKER" ]; then
buildtools_cmd=()
case "$OS_NAME" in
*Darwin*) buildtools_cmd=(tools/setup-buildtools-apple.sh "$APPLE_ARCH") ;;
*Linux*) buildtools_cmd=(tools/setup-buildtools.sh) ;;
*) echo "WARNING: unsupported OS $OS_NAME, skipping build tools installation.." ;;
esac
if [[ ${#buildtools_cmd[@]} -gt 0 ]]; then
if [[ -z "$NOROOT" ]]; then
matsdk_try_buildtools_once "$BUILD_TOOLS_MARKER" \
"No root: skipping build tools installation." \
sudo "${buildtools_cmd[@]}"
else
echo "No root: skipping build tools installation."
matsdk_mark_buildtools_checked "$BUILD_TOOLS_MARKER"
fi
else
matsdk_mark_buildtools_checked "$BUILD_TOOLS_MARKER"
fi
fi
matsdk_print_compiler_versions
matsdk_require_cmake_preset_support
# Skip Version.hpp changes
# git update-index --skip-worktree lib/include/public/Version.hpp
# .tgz package
CPACK_GENERATOR=TGZ
if [ -f /usr/bin/dpkg ]; then
# .deb package
export CPACK_GENERATOR=DEB
elif [ -f /usr/bin/rpmbuild ]; then
# .rpm package
export CPACK_GENERATOR=RPM
fi
# Fail on error
set -e
PRESET="matsdk-$(echo "$BUILD_TYPE" | tr '[:upper:]' '[:lower:]')"
cmake_args=(cmake --preset "$PRESET")
if [[ "$OS_NAME" == *Darwin* ]]; then
if [[ "$APPLE_ARCH" == "universal" ]]; then
cmake_args+=("-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64")
else
cmake_args+=("-DCMAKE_OSX_ARCHITECTURES=$APPLE_ARCH")
fi
fi
cmake_args+=(
"-DCPACK_GENERATOR=$CPACK_GENERATOR"
)
if [[ -n "$CUSTOM_CMAKE_CXX_FLAG" ]]; then
cmake_args+=("-DCMAKE_CXX_FLAGS=$CUSTOM_CMAKE_CXX_FLAG")
fi
matsdk_append_cmake_opts_to_cmake_args
matsdk_run_logged_command "${cmake_args[@]}"
rm -f out/*.deb out/*.rpm
matsdk_build_and_package_preset "$PRESET"
cd out
# Install newly generated package
if [ -f /usr/bin/dpkg ]; then
# Ubuntu / Debian / Raspbian
[[ -z "$NOROOT" ]] && sudo dpkg -i *.deb || echo "No root: skipping package deployment."
elif [ -f /usr/bin/rpmbuild ]; then
# Redhat / Centos
[[ -z "$NOROOT" ]] && sudo rpm -i --force -v *.rpm || echo "No root: skipping package deployment."
fi
# Install SDK headers and lib to /usr/local
#
## TODO: [MG] - fix this section for shared library
## strip --strip-unneeded out/lib/libmat.so
## strip -S --strip-unneeded --remove-section=.note.gnu.gold-version --remove-section=.comment --remove-section=.note --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag out/lib/libmat.so
if [ "$CPACK_GENERATOR" == "TGZ" ]; then
cd ..
MATSDK_INSTALL_DIR="${MATSDK_INSTALL_DIR:-/usr/local}"
echo "+-----------------------------------------------------------------------------------+"
echo " This step may prompt for your sudo password to deploy SDK to $MATSDK_INSTALL_DIR "
echo "+-----------------------------------------------------------------------------------+"
[[ -z "$NOROOT" ]] && sudo ./install.sh $MATSDK_INSTALL_DIR || echo "No root: skipping package deployment."
fi