forked from supermerill/SuperSlicer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildLinux.sh
executable file
·367 lines (329 loc) · 9.42 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/bin/bash
#
# This script can download and compile dependencies, compile SuperSlicer
# and optional build a .tgz and an appimage.
#
# Original script from SuperSlicer by supermerill https://github.com/supermerill/SuperSlicer
#
# Change log:
#
# 20 Nov 2023, wschadow, branding and minor changes
# 01 Jan 2024, wschadow, added build options
#
set -e # exit on first error
export ROOT=`pwd`
export NCORES=`nproc`
function usage() {
echo "Usage: ./BuildLinux.sh [-h][-u][-w][-g][-b][-r][-d][-s][-l][-t][-i][-v]"
echo " -h: this message"
echo " -u: only update dependency packets (optional and need sudo)"
echo " -w: wipe build directories before building"
echo " -g: force gtk2 build"
echo " -b: build in debug mode"
echo " -r: clean dependencies"
echo " -d: build deps"
echo " -s: build Slic3r"
echo " -l: update language .pot file"
echo " -t: build tests (in combination with -s)"
echo " -i: generate .tgz and appimage (optional)"
echo " -v: change the version 'UNKNOWN' to the date of the day"
echo -e "\n For a first use, you want to 'sudo ./BuildLinux.sh -u'"
echo -e " and then './BuildLinux.sh -dsi'\n"
exit 0
}
function check_operating_system() {
# check operating system
OS_FOUND=$( command -v uname)
case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
linux*)
TARGET_OS="linux"
;;
msys*|cygwin*|mingw*)
# or possible 'bash on windows'
TARGET_OS='windows'
;;
nt|win*)
TARGET_OS='windows'
;;
darwin)
TARGET_OS='macos'
;;
*)
TARGET_OS='unknown'
;;
esac
echo
if [ $TARGET_OS == "linux" ]; then
if [ $(uname -m) == "x86_64" ]; then
echo -e "$(tput setaf 2)Linux 64-bit found$(tput sgr0)\n"
Processor="64"
elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)\n"
Processor="32"
else
echo "$(tput setaf 1)Unsupported OS: Linux $(uname -m)"
exit -1
fi
else
echo -e "$(tput setaf 1)This script doesn't support your Operating system!"
echo -e "Please use Linux 64-bit or Windows 10 64-bit with Linux subsystem / git-bash.$(tput sgr0)\n"
exit -1
fi
}
function check_available_memory_and_disk() {
FREE_MEM_GB=$(free -g -t | grep 'Mem:' | rev | cut -d" " -f1 | rev)
MIN_MEM_GB=3
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: SuperSlicer 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: SuperSlicer 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
}
function check_distribution() {
DISTRIBUTION=$(awk -F= '/^ID=/ {print $2}' /etc/os-release)
# treat ubuntu as debian
if [ "${DISTRIBUTION}" == "ubuntu" ]
then
DISTRIBUTION="debian"
fi
echo -e "$(tput setaf 2)${DISTRIBUTION} found$(tput sgr0)\n"
if [ ! -f ./src/platform/unix/linux.d/${DISTRIBUTION} ]
then
echo "Your distribution does not appear to be currently supported by these build scripts"
exit 1
fi
}
#=======================================================================================
check_operating_system
check_distribution
check_available_memory_and_disk
#---------------------------------------------------------------------------------------
#check command line arguments
unset name
while getopts ":bdghilrstuvw" opt; do
case ${opt} in
u )
UPDATE_LIB="1"
;;
i )
BUILD_IMAGE="1"
;;
d )
BUILD_DEPS="1"
;;
s )
BUILD_SLIC3R="1"
;;
l )
UPDATE_POTFILE="1"
;;
t )
BUILD_TESTS="1"
;;
b )
BUILD_DEBUG="1"
;;
g )
FORCE_GTK2="-g"
;;
r )
BUILD_CLEANDEPEND="1"
;;
v )
VERSION_DATE="1"
;;
w )
BUILD_WIPE="1"
;;
h ) usage
# exit 0
;;
* ) usage
# exit 0
;;
esac
done
if [ ${OPTIND} -eq 1 ]
then
usage
exit 0
fi
#---------------------------------------------------------------------------------------
# check installation of required packages or update when -u is set
source ./src/platform/unix/linux.d/${DISTRIBUTION}
if [[ -n "$FORCE_GTK2" ]]
then
FOUND_GTK2=$(dpkg -l libgtk* | grep gtk2)
FOUND_GTK2_DEV=$(dpkg -l libgtk* | grep gtk2.0-dev)
echo -e "\nFOUND_GTK2:\n$FOUND_GTK2\n"
else
FOUND_GTK3=$(dpkg -l libgtk* | grep gtk-3)
FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev)
echo -e "\nFOUND_GTK3:\n$FOUND_GTK3)\n"
fi
if [[ -n "$BUILD_DEPS" ]]
then
if [[ -n $BUILD_WIPE ]]
then
echo -e "\n wiping deps/build directory...\n"
rm -fr deps/build
echo -e " ... done\n"
fi
# mkdir build in deps
if [ ! -d "deps/build" ]
then
mkdir deps/build
fi
echo -e "[1/9] Configuring dependencies ...\n"
BUILD_ARGS=""
if [[ -n "$FOUND_GTK3_DEV" ]]
then
BUILD_ARGS="-DDEP_WX_GTK3=ON"
else
BUILD_ARGS="-DDEP_WX_GTK3=OFF"
fi
if [[ -n "$BUILD_DEBUG" ]]
then
# have to build deps with debug & release or the cmake won't find evrything it needs
if [ ! -d "deps/build/release" ]
then
mkdir deps/build/release
fi
pushd deps/build/release > /dev/null
cmake ../.. -DDESTDIR="../destdir" $BUILD_ARGS
popd > /dev/null
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
fi
pushd deps/build > /dev/null
cmake .. $BUILD_ARGS
echo -e "\n ... done\n"
echo -e "\n[2/9] Building dependencies...\n"
# make deps
make -j$NCORES
echo -e "\n ... done\n"
# rename wxscintilla
echo "[3/9] Renaming wxscintilla library..."
pushd destdir/usr/local/lib > /dev/null
if [[ -z "$FOUND_GTK3_DEV" ]]
then
cp libwxscintilla-3.2.a libwx_gtk2u_scintilla-3.2.a
else
cp libwxscintilla-3.2.a libwx_gtk3u_scintilla-3.2.a
fi
echo "> ls destdir/usr/local/lib"
ls -al .
echo "> ls ROOT/deps/build/destdir/usr/local/lib"
ls -al $ROOT/deps/build/destdir/usr/local/lib
popd > /dev/null
popd > /dev/null
echo -e "\n ... done\n"
fi
if [[ -n "$BUILD_CLEANDEPEND" ]]
then
echo -e "[4/9] Cleaning dependencies...\n"
pushd deps/build > /dev/null
rm -fr dep_*
popd > /dev/null
echo -e " ... done\n"
fi
if [[ -n "$BUILD_SLIC3R" ]]
then
echo -e "[5/9] Configuring SuperSlicer ...\n"
if [[ -n $BUILD_WIPE ]]
then
echo -n "wiping build directory ..."
rm -fr build
echo " done"
fi
echo -n "Updating submodules ..."
{
# update submodule profiles
pushd resources/profiles
git submodule update --init
popd
} #> $ROOT/build/Build.log # Capture all command output
echo " done"
if [[ -n $VERSION_DATE ]]
then
echo -n "Changing date in version ..."
# change date in version
sed "s/+UNKNOWN/-$(date '+%F')/" version.inc > version.date.inc
echo " done"
else
sed "s/+UNKNOWN//" version.inc > version.date.inc
fi
# mkdir build
if [ ! -d "build" ]
then
mkdir 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"
fi
if [[ -n "$BUILD_TESTS" ]]
then
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=1"
else
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=0"
fi
# cmake
pushd build > /dev/null
cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
echo " ... done"
# make SuperSlicer
echo -e "\n[6/9] Building SuperSlicer ...\n"
make -j$NCORES Slic3r
make -j$NCORES OCCTWrapper
echo -e "\n ... done"
echo -e "\n[7/9] Generating language files ...\n"
#make .mo
if [[ -n "$UPDATE_POTFILE" ]]
then
make gettext_make_pot
fi
make gettext_po_to_mo
popd > /dev/null
echo -e "\n ... done"
# Give proper permissions to script
chmod 755 $ROOT/build/src/BuildLinuxImage.sh
pushd build > /dev/null
$ROOT/build/src/BuildLinuxImage.sh -a $FORCE_GTK2
popd > /dev/null
echo "> ls ROOT"
ls -al $ROOT
echo "> ls ROOT/build"
ls -al $ROOT/build
echo "> ls -al ROOT/build/bin"
ls -al $ROOT/build/bin
echo "> ls -al ROOT/build/src"
ls -al $ROOT/build/src
fi
if [[ -n "$BUILD_IMAGE" ]]
then
# Give proper permissions to script
chmod 755 $ROOT/build/src/BuildLinuxImage.sh
pushd build > /dev/null
$ROOT/build/src/BuildLinuxImage.sh -i $FORCE_GTK2
popd > /dev/null
echo "> ls ROOT"
ls -al $ROOT
echo "> ls ROOT/build"
ls -al $ROOT/build
echo "> ls -al ROOT/build/bin"
ls -al $ROOT/build/bin
echo "> ls -al ROOT/build/src"
ls -al $ROOT/build/src
fi