forked from bambulab/BambuStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildLinux.sh
executable file
·260 lines (233 loc) · 7.4 KB
/
BuildLinux.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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/bin/bash
set -e # exit on first error
export ROOT=`pwd`
export NCORES=`nproc --all`
export CMAKE_BUILD_PARALLEL_LEVEL=${NCORES}
FOUND_GTK2=$(dpkg -l libgtk* | grep gtk2)
FOUND_GTK3=$(dpkg -l libgtk* | grep gtk-3)
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
}
unset name
while getopts ":dsiuhgbr" opt; do
case ${opt} in
u )
UPDATE_LIB="1"
;;
i )
BUILD_IMAGE="1"
;;
d )
BUILD_DEPS="1"
;;
s )
BUILD_BAMBU_STUDIO="1"
;;
b )
BUILD_DEBUG="1"
;;
g )
FOUND_GTK3=""
;;
r )
SKIP_RAM_CHECK="1"
;;
h ) echo "Usage: ./BuildLinux.sh [-i][-u][-d][-s][-b][-g]"
echo " -i: Generate appimage (optional)"
echo " -g: force gtk2 build"
echo " -b: build in debug mode"
echo " -d: build deps (optional)"
echo " -s: build bambu-studio (optional)"
echo " -u: only update clock & dependency packets (optional and need sudo)"
echo " -r: skip free ram check (low ram compiling)"
echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
echo " and then './BuildLinux.sh -dsi'"
exit 0
;;
esac
done
if [ $OPTIND -eq 1 ]
then
echo "Usage: ./BuildLinux.sh [-i][-u][-d][-s][-b][-g]"
echo " -i: Generate appimage (optional)"
echo " -g: force gtk2 build"
echo " -b: build in debug mode"
echo " -d: build deps (optional)"
echo " -s: build bambu-studio (optional)"
echo " -u: only update clock & dependency packets (optional and need sudo)"
echo " -r: skip free ram check (low ram compiling)"
echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
echo " and then './BuildLinux.sh -dsi'"
exit 0
fi
# mkdir build
if [ ! -d "build" ]
then
mkdir build
fi
# Addtional Dev packages for BambuStudio
export REQUIRED_DEV_PACKAGES="libgstreamerd-3-dev libsecret-1-dev libwebkit2gtk-4.0-dev libosmesa6-dev libssl-dev libcurl4-openssl-dev eglexternalplatform-dev libudev-dev libdbus-1-dev extra-cmake-modules"
# libwebkit2gtk-4.1-dev ??
export DEV_PACKAGES_COUNT=$(echo ${REQUIRED_DEV_PACKAGES} | wc -w)
if [ $(dpkg --get-selections | grep -E "$(echo ${REQUIRED_DEV_PACKAGES} | tr ' ' '|')" | wc -l) -lt ${DEV_PACKAGES_COUNT} ]; then
sudo apt install -y ${REQUIRED_DEV_PACKAGES} git cmake wget file
fi
#FIXME: require root for -u option
if [[ -n "$UPDATE_LIB" ]]
then
echo -n -e "Updating linux ...\n"
# hwclock -s # DeftDawg: Why does SuperSlicer want to do this?
apt update
if [[ -z "$FOUND_GTK3" ]]
then
echo -e "\nInstalling: libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
apt install -y libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git
else
echo -e "\nFind libgtk-3, installing: libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
apt install -y libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git
fi
# for ubuntu 22.04:
ubu_version="$(cat /etc/issue)"
if [[ $ubu_version == "Ubuntu 22.04"* ]]
then
apt install -y curl libssl-dev libcurl4-openssl-dev m4
fi
if [[ -n "$BUILD_DEBUG" ]]
then
echo -e "\nInstalling: libssl-dev libcurl4-openssl-dev\n"
apt install -y libssl-dev libcurl4-openssl-dev
fi
echo -e "done\n"
exit 0
fi
FOUND_GTK2_DEV=$(dpkg -l libgtk* | grep gtk2.0-dev || echo '')
FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev || echo '')
echo "FOUND_GTK2=$FOUND_GTK2)"
if [[ -z "$FOUND_GTK2_DEV" ]]
then
if [[ -z "$FOUND_GTK3_DEV" ]]
then
echo "Error, you must install the dependencies before."
echo "Use option -u with sudo"
exit 0
fi
fi
echo "[1/9] Updating submodules..."
{
# update submodule profiles
pushd resources/profiles
git submodule update --init
popd
}
echo "[2/9] Changing date in version..."
{
# change date in version
sed -i "s/+UNKNOWN/_$(date '+%F')/" version.inc
}
echo "done"
# mkdir in deps
if [ ! -d "deps/build" ]
then
mkdir deps/build
fi
if ! [[ -n "$SKIP_RAM_CHECK" ]]
then
check_available_memory_and_disk
fi
if [[ -n "$BUILD_DEPS" ]]
then
echo "[3/9] Configuring dependencies..."
BUILD_ARGS=""
if [[ -n "$FOUND_GTK3_DEV" ]]
then
BUILD_ARGS="-DDEP_WX_GTK3=ON"
fi
if [[ -n "$BUILD_DEBUG" ]]
then
# have to build deps with debug & release or the cmake won't find evrything it needs
mkdir deps/build/release
pushd deps/build/release
cmake ../.. -DDESTDIR="../destdir" $BUILD_ARGS
make -j$NCORES
popd
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
fi
# cmake deps
pushd deps/build
cmake .. $BUILD_ARGS
echo "done"
# make deps
echo "[4/9] Building dependencies..."
make -j$NCORES
echo "done"
# rename wxscintilla # TODO: DeftDawg: Does BambuStudio need this?
# echo "[5/9] Renaming wxscintilla library..."
# pushd destdir/usr/local/lib
# if [[ -z "$FOUND_GTK3_DEV" ]]
# then
# cp libwxscintilla-3.1.a libwx_gtk2u_scintilla-3.1.a
# else
# cp libwxscintilla-3.1.a libwx_gtk3u_scintilla-3.1.a
# fi
# popd
# echo "done"
# FIXME: only clean deps if compiling succeeds; otherwise reruns waste tonnes of time!
# clean deps
# echo "[6/9] Cleaning dependencies..."
# rm -rf dep_*
popd
echo "done"
fi
if [[ -n "$BUILD_BAMBU_STUDIO" ]]
then
echo "[7/9] Configuring Slic3r..."
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=1"
else
BUILD_ARGS="${BUILD_ARGS} -DBBL_RELEASE_TO_PUBLIC=1 -DBBL_INTERNAL_TESTING=0"
fi
# cmake
pushd build
cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
echo "done"
# make Slic3r
echo "[8/9] Building Slic3r..."
make -j$NCORES BambuStudio # Slic3r
# make .mo
# make gettext_po_to_mo # FIXME: DeftDawg: complains about msgfmt not existing even in SuperSlicer, did this ever work?
popd
echo "done"
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
else
$ROOT/build/src/BuildLinuxImage.sh
fi
popd
echo "done"
fi