2022-08-13 03:57:54 +00:00
#!/bin/bash
2024-07-11 03:01:10 +00:00
export ROOT = $( dirname $( readlink -f ${ 0 } ) )
set -e # exit on first error
2022-08-13 03:57:54 +00:00
2022-12-08 23:35:48 +00:00
function check_available_memory_and_disk( ) {
2024-04-19 03:14:00 +00:00
FREE_MEM_GB = $( free -g -t | grep 'Mem' | rev | cut -d" " -f1 | rev)
2022-12-08 23:35:48 +00:00
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
}
2024-07-11 03:01:10 +00:00
function usage( ) {
echo "Usage: ./BuildLinux.sh [-1][-b][-c][-d][-i][-r][-s][-u]"
echo " -1: limit builds to 1 core (where possible)"
2024-07-12 07:25:33 +00:00
echo " -f: disable safe parallel number limit(By default, the maximum number of parallels is set to free memory/2.5)"
2024-07-11 03:01:10 +00:00
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 "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
echo " and then './BuildLinux.sh -dsi'"
}
2022-08-13 03:57:54 +00:00
unset name
2024-07-12 07:25:33 +00:00
while getopts ":1fbcdghirsu" opt; do
2022-08-13 03:57:54 +00:00
case ${ opt } in
2024-07-11 03:01:10 +00:00
1 )
export CMAKE_BUILD_PARALLEL_LEVEL = 1
2022-08-13 03:57:54 +00:00
; ;
2024-07-12 07:25:33 +00:00
f )
DISABLE_PARALLEL_LIMIT = 1
; ;
2024-07-11 03:01:10 +00:00
b )
BUILD_DEBUG = "1"
; ;
c )
CLEAN_BUILD = 1
2022-08-13 03:57:54 +00:00
; ;
d )
BUILD_DEPS = "1"
; ;
2024-07-11 03:01:10 +00:00
h ) usage
exit 0
2022-08-13 03:57:54 +00:00
; ;
2024-07-11 03:01:10 +00:00
i )
BUILD_IMAGE = "1"
2022-08-13 03:57:54 +00:00
; ;
2022-12-31 22:33:18 +00:00
r )
2024-07-11 03:01:10 +00:00
SKIP_RAM_CHECK = "1"
2022-12-31 22:33:18 +00:00
; ;
2024-07-11 03:01:10 +00:00
s )
BUILD_BAMBU_STUDIO = "1"
; ;
u )
UPDATE_LIB = "1"
2022-08-13 03:57:54 +00:00
; ;
esac
done
2024-07-11 03:01:10 +00:00
if [ ${ OPTIND } -eq 1 ]
2022-08-13 03:57:54 +00:00
then
2024-07-11 03:01:10 +00:00
usage
2022-08-13 03:57:54 +00:00
exit 0
fi
2024-07-11 03:01:10 +00:00
DISTRIBUTION = $( awk -F= '/^ID=/ {print $2}' /etc/os-release)
VERSION = $( awk -F= '/^VERSION_ID=/ {print $2}' /etc/os-release)
2025-01-03 22:01:00 +00:00
# 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 } ]
2022-08-13 03:57:54 +00:00
then
2024-07-11 03:01:10 +00:00
echo "Your distribution does not appear to be currently supported by these build scripts"
exit 1
2022-08-13 03:57:54 +00:00
fi
2025-01-03 22:01:00 +00:00
echo " OS distribution is ' ${ DISTRIBUTION } '. Using package dependencies for ' ${ TARGET_DISTRO } '. "
source ./linux.d/${ TARGET_DISTRO }
2022-08-13 03:57:54 +00:00
2024-07-11 03:01:10 +00:00
echo " FOUND_GTK3= ${ FOUND_GTK3 } "
if [ [ -z " ${ FOUND_GTK3_DEV } " ] ]
2022-08-13 03:57:54 +00:00
then
echo "Error, you must install the dependencies before."
echo "Use option -u with sudo"
2024-07-11 03:01:10 +00:00
exit 1
2022-08-13 03:57:54 +00:00
fi
2024-07-11 03:01:10 +00:00
echo "Changing date in version..."
2022-08-13 03:57:54 +00:00
{
# change date in version
sed -i " s/+UNKNOWN/_ $( date '+%F' ) / " version.inc
}
echo "done"
2024-07-11 03:01:10 +00:00
if ! [ [ -n " ${ SKIP_RAM_CHECK } " ] ]
2022-12-31 22:33:18 +00:00
then
2024-07-11 03:01:10 +00:00
check_available_memory_and_disk
2022-12-31 22:33:18 +00:00
fi
2022-12-08 23:35:48 +00:00
2024-07-12 07:25:33 +00:00
if ! [ [ -n " ${ DISABLE_PARALLEL_LIMIT } " ] ]
then
FREE_MEM_GB = $( free -g -t | grep 'Mem' | rev | cut -d" " -f1 | rev)
2024-09-23 01:55:22 +00:00
MAX_THREADS = $(( FREE_MEM_GB * 10 / 25 ))
2024-07-12 07:25:33 +00:00
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
2024-07-11 03:01:10 +00:00
if [ [ -n " ${ BUILD_DEPS } " ] ]
2022-08-13 03:57:54 +00:00
then
2024-07-11 03:01:10 +00:00
echo "Configuring dependencies..."
BUILD_ARGS = "-DDEP_WX_GTK3=ON"
if [ [ -n " ${ CLEAN_BUILD } " ] ]
then
rm -fr deps/build
fi
if [ ! -d "deps/build" ]
2022-08-13 03:57:54 +00:00
then
2024-07-11 03:01:10 +00:00
mkdir deps/build
2022-08-13 03:57:54 +00:00
fi
2024-07-11 03:01:10 +00:00
if [ [ -n " ${ BUILD_DEBUG } " ] ]
2022-08-13 03:57:54 +00:00
then
2024-07-11 03:01:10 +00:00
# have to build deps with debug & release or the cmake won't find everything it needs
2022-08-13 03:57:54 +00:00
mkdir deps/build/release
2024-07-11 03:01:10 +00:00
cmake -S deps -B deps/build/release -G Ninja -DDESTDIR= "../destdir" ${ BUILD_ARGS }
cmake --build deps/build/release
2022-08-13 03:57:54 +00:00
BUILD_ARGS = " ${ BUILD_ARGS } -DCMAKE_BUILD_TYPE=Debug "
fi
2024-07-11 03:01:10 +00:00
echo " cmake -S deps -B deps/build -G Ninja ${ BUILD_ARGS } "
cmake -S deps -B deps/build -G Ninja ${ BUILD_ARGS }
cmake --build deps/build
2022-08-13 03:57:54 +00:00
fi
2024-07-11 03:01:10 +00:00
if [ [ -n " ${ BUILD_BAMBU_STUDIO } " ] ]
2022-08-13 03:57:54 +00:00
then
2024-07-11 03:01:10 +00:00
echo "Configuring BambuStudio..."
if [ [ -n " ${ CLEAN_BUILD } " ] ]
then
rm -fr build
fi
2022-08-13 03:57:54 +00:00
BUILD_ARGS = ""
2024-07-11 03:01:10 +00:00
if [ [ -n " ${ FOUND_GTK3_DEV } " ] ]
2022-08-13 03:57:54 +00:00
then
BUILD_ARGS = "-DSLIC3R_GTK=3"
fi
2024-07-11 03:01:10 +00:00
if [ [ -n " ${ BUILD_DEBUG } " ] ]
2022-08-13 03:57:54 +00:00
then
2023-03-08 00:40:33 +00:00
BUILD_ARGS = " ${ BUILD_ARGS } -DCMAKE_BUILD_TYPE=Debug -DBBL_INTERNAL_TESTING=1 "
2022-10-08 15:59:01 +00:00
else
2023-03-08 00:40:33 +00:00
BUILD_ARGS = " ${ BUILD_ARGS } -DBBL_RELEASE_TO_PUBLIC=1 -DBBL_INTERNAL_TESTING=0 "
2022-08-13 03:57:54 +00:00
fi
2024-07-11 03:01:10 +00:00
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
2022-08-13 03:57:54 +00:00
echo "done"
fi
2024-07-11 03:01:10 +00:00
if [ [ -e ${ ROOT } /build/src/BuildLinuxImage.sh ] ] ; then
2022-08-13 03:57:54 +00:00
# Give proper permissions to script
2024-07-11 03:01:10 +00:00
chmod 755 ${ ROOT } /build/src/BuildLinuxImage.sh
2022-08-13 03:57:54 +00:00
echo "[9/9] Generating Linux app..."
pushd build
2024-07-11 03:01:10 +00:00
if [ [ -n " ${ BUILD_IMAGE } " ] ]
2022-08-13 03:57:54 +00:00
then
2024-07-11 03:01:10 +00:00
${ ROOT } /build/src/BuildLinuxImage.sh -i
2022-08-13 03:57:54 +00:00
fi
popd
echo "done"
2025-01-03 22:01:00 +00:00
fi