-
Notifications
You must be signed in to change notification settings - Fork 975
Expand file tree
/
Copy pathBuildLinux.sh
More file actions
executable file
·247 lines (219 loc) · 7.21 KB
/
Copy pathBuildLinux.sh
File metadata and controls
executable file
·247 lines (219 loc) · 7.21 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/bash
export ROOT=$(dirname $(readlink -f ${0}))
set -e # exit on first error
function check_available_memory_and_disk() {
FREE_MEM_GB=$(free -g -t | grep 'Mem' | rev | cut -d" " -f1 | rev)
MIN_MEM_GB=10
FREE_DISK_KB=$(df -k . | tail -1 | awk '{print $4}')
MIN_DISK_KB=$((10 * 1024 * 1024))
if [ ${FREE_MEM_GB} -le ${MIN_MEM_GB} ]; then
echo -e "\nERROR: Bambu Studio Builder requires at least ${MIN_MEM_GB}G of 'available' mem (systen has only ${FREE_MEM_GB}G available)"
echo && free -h && echo
exit 2
fi
if [[ ${FREE_DISK_KB} -le ${MIN_DISK_KB} ]]; then
echo -e "\nERROR: Bambu Studio Builder requires at least $(echo $MIN_DISK_KB |awk '{ printf "%.1fG\n", $1/1024/1024; }') (systen has only $(echo ${FREE_DISK_KB} | awk '{ printf "%.1fG\n", $1/1024/1024; }') disk free)"
echo && df -h . && echo
exit 1
fi
}
# 构建类型说明:
# -b 和 -y 都不加 -> 默认走 release 模式,CMAKE_BUILD_TYPE=Release
# -y RelWithDebInfo -> CMAKE_BUILD_TYPE=RelWithDebInfo(优化 + 调试信息)
# -b -> CMAKE_BUILD_TYPE=Debug,且会忽略 -y
# -b 和 -y 同时存在 -> 以 -b 为准,走 Debug 模式(-y 无效)
function usage() {
echo "Usage: ./BuildLinux.sh [-1][-b][-c][-d][-i][-r][-s][-u]"
echo " -1: limit builds to 1 core (where possible)"
echo " -f: disable safe parallel number limit(By default, the maximum number of parallels is set to free memory/2.5)"
echo " -b: build in debug mode"
echo " -c: force a clean build"
echo " -d: build deps (optional)"
echo " -h: this help output"
echo " -i: Generate appimage (optional)"
echo " -r: skip ram and disk checks (low ram compiling)"
echo " -s: build bambu-studio (optional)"
echo " -u: update and build dependencies (optional and need sudo)"
echo " -t: set internal testing level (default=0, 1=debug, 2=beta)"
echo " -y: set release build type (Release|RelWithDebInfo, default=Release; ignored with -b)"
echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
echo " and then './BuildLinux.sh -dsi'"
}
unset name
while getopts ":1fbcdhirsut:y:" opt; do
case ${opt} in
1 )
export CMAKE_BUILD_PARALLEL_LEVEL=1
;;
f )
DISABLE_PARALLEL_LIMIT=1
;;
b )
BUILD_DEBUG="1"
;;
c )
CLEAN_BUILD=1
;;
d )
BUILD_DEPS="1"
;;
h ) usage
exit 0
;;
i )
BUILD_IMAGE="1"
;;
r )
SKIP_RAM_CHECK="1"
;;
s )
BUILD_BAMBU_STUDIO="1"
;;
u )
UPDATE_LIB="1"
;;
t )
INTERNAL_TESTING="$OPTARG"
;;
y )
SLIC3R_BUILD_TYPE="$OPTARG"
;;
esac
done
if [ "${BUILD_DEBUG}" = "1" ]; then
if [ -z "${INTERNAL_TESTING}" ]; then
INTERNAL_TESTING=1
fi
fi
INTERNAL_TESTING=${INTERNAL_TESTING:-0}
if [ ${OPTIND} -eq 1 ]
then
usage
exit 0
fi
DISTRIBUTION=$(awk -F= '/^ID=/ {print $2}' /etc/os-release)
VERSION=$(awk -F= '/^VERSION_ID=/ {print $2}' /etc/os-release)
# OSLIKE is a space-delineated list of similar distributions
OSLIKE=$(awk -F= '/^ID_LIKE=/ {print $2}' /etc/os-release | tr -d '"')
# Iterate over a list of candidate distribution targets, first match is used
for CANDIDATE in ${DISTRIBUTION} ${OSLIKE}; do
if [ -f ./linux.d/${CANDIDATE} ]
then
TARGET_DISTRO="${CANDIDATE}"
break
fi
done
if [ -z ${TARGET_DISTRO} ]
then
echo "Your distribution does not appear to be currently supported by these build scripts"
exit 1
fi
echo "OS distribution is '${DISTRIBUTION}'. Using package dependencies for '${TARGET_DISTRO}'."
source ./linux.d/${TARGET_DISTRO}
echo "FOUND_GTK3=${FOUND_GTK3}"
if [[ -z "${FOUND_GTK3_DEV}" ]]
then
echo "Error, you must install the dependencies before."
echo "Use option -u with sudo"
exit 1
fi
echo "Changing date in version..."
{
# change date in version
sed -i "s/+UNKNOWN/_$(date '+%F')/" version.inc
}
echo "done"
if ! [[ -n "${SKIP_RAM_CHECK}" ]]
then
check_available_memory_and_disk
fi
if ! [[ -n "${DISABLE_PARALLEL_LIMIT}" ]]
then
FREE_MEM_GB=$(free -g -t | grep 'Mem' | rev | cut -d" " -f1 | rev)
MAX_THREADS=$((FREE_MEM_GB * 10 / 25))
if [ "$MAX_THREADS" -lt 1 ]; then
export CMAKE_BUILD_PARALLEL_LEVEL=1
else
export CMAKE_BUILD_PARALLEL_LEVEL=${MAX_THREADS}
fi
echo "System free memory: ${FREE_MEM_GB} GB"
echo "Setting CMAKE_BUILD_PARALLEL_LEVEL: ${CMAKE_BUILD_PARALLEL_LEVEL}"
fi
if [[ -n "${BUILD_DEPS}" ]]
then
echo "Configuring dependencies..."
BUILD_ARGS="-DDEP_WX_GTK3=ON"
if [[ -n "${CLEAN_BUILD}" ]]
then
rm -fr deps/build
fi
if [ ! -d "deps/build" ]
then
mkdir deps/build
fi
if [[ -n "${BUILD_DEBUG}" ]]
then
# have to build deps with debug & release or the cmake won't find everything it needs
mkdir deps/build/release
cmake -S deps -B deps/build/release -G Ninja -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DDESTDIR="../destdir" ${BUILD_ARGS}
cmake --build deps/build/release
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
fi
echo "cmake -S deps -B deps/build -G Ninja ${BUILD_ARGS}"
cmake -S deps -B deps/build -G Ninja -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ${BUILD_ARGS}
cmake --build deps/build
fi
if [[ -n "${BUILD_BAMBU_STUDIO}" ]]
then
echo "Configuring BambuStudio..."
if [[ -n "${CLEAN_BUILD}" ]]
then
rm -fr build
fi
BUILD_ARGS=""
if [[ -n "${FOUND_GTK3_DEV}" ]]
then
BUILD_ARGS="-DSLIC3R_GTK=3"
fi
if [[ -n "${BUILD_DEBUG}" ]]
then
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug -DBBL_INTERNAL_TESTING=${INTERNAL_TESTING}"
else
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=${SLIC3R_BUILD_TYPE:-Release} -DBBL_RELEASE_TO_PUBLIC=1 -DBBL_INTERNAL_TESTING=${INTERNAL_TESTING}"
fi
echo -e "cmake -S . -B build -G Ninja -DCMAKE_PREFIX_PATH="${PWD}/deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}"
cmake -S . -B build -G Ninja \
-DCMAKE_PREFIX_PATH="${PWD}/deps/build/destdir/usr/local" \
-DSLIC3R_STATIC=1 \
${BUILD_ARGS}
echo "done"
echo "Building BambuStudio ..."
cmake --build build --target BambuStudio
echo "done"
fi
# 当构建类型为 RelWithDebInfo 时,分离出独立的调试符号文件并打包
if [ "${SLIC3R_BUILD_TYPE}" = "RelWithDebInfo" ]; then
echo "Extracting debug symbols (RelWithDebInfo) ..."
pushd ${ROOT}/build/src
if [[ -e bambu-studio ]]; then
objcopy --only-keep-debug bambu-studio bambu-studio.debug
tar -czvf ${ROOT}/build/bambu-studio.debug.tar.gz bambu-studio.debug
rm -f bambu-studio.debug
echo "done"
else
echo "WARNING: build/src/bambu-studio not found, skip debug symbol extraction"
fi
popd
fi
if [[ -e ${ROOT}/build/src/BuildLinuxImage.sh ]]; then
# Give proper permissions to script
chmod 755 ${ROOT}/build/src/BuildLinuxImage.sh
echo "[9/9] Generating Linux app..."
pushd build
if [[ -n "${BUILD_IMAGE}" ]]
then
${ROOT}/build/src/BuildLinuxImage.sh -i
fi
popd
echo "done"
fi