rework of Linux build scripts (#4850)

* rework of Linux build scripts

* change to ninja build system
* distribution specific logic broken out
* n/9 progress entries make no sense, removing
* {}'ing all variables
* sorting help output
* sorting package lists
* project doesn't use submodules, removing logic

Signed-off-by: Jamin W. Collins <jamin.collins@gmail.com>

* drop gtk-2

Signed-off-by: Jamin W. Collins <jamin.collins@gmail.com>

* further refinements of BuildLinux.sh

Signed-off-by: Jamin W. Collins <jamin.collins@gmail.com>

---------

Signed-off-by: Jamin W. Collins <jamin.collins@gmail.com>
This commit is contained in:
Jamin Collins 2024-04-11 08:11:31 -06:00 committed by GitHub
parent ec8d91e14f
commit 654af8e0e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 228 additions and 157 deletions

View file

@ -1,10 +1,6 @@
#!/bin/bash
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)
export ROOT=$(dirname $(readlink -f ${0}))
set -e # exit on first error
@ -22,237 +18,166 @@ function check_available_memory_and_disk() {
fi
if [[ ${FREE_DISK_KB} -le ${MIN_DISK_KB} ]]; then
echo -e "\nERROR: Orca Slicer 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 -e "\nERROR: Orca Slicer 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 usage() {
echo "Usage: ./BuildLinux.sh [-i][-u][-d][-s][-b][-g]"
echo " -i: Generate appimage (optional)"
echo " -g: force gtk2 build"
echo "Usage: ./BuildLinux.sh [-1][-b][-c][-d][-i][-r][-s][-u]"
echo " -1: limit builds to 1 core (where possible)"
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 orca-slicer (optional)"
echo " -u: only update clock & dependency packets (optional and need sudo)"
echo " -r: skip free ram check (low ram compiling)"
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'"
}
unset name
while getopts ":dsiuhgbr" opt; do
while getopts ":1bcdghirsu" opt; do
case ${opt} in
u )
UPDATE_LIB="1"
;;
i )
BUILD_IMAGE="1"
;;
d )
BUILD_DEPS="1"
;;
s )
BUILD_ORCA="1"
1 )
export CMAKE_BUILD_PARALLEL_LEVEL=1
;;
b )
BUILD_DEBUG="1"
;;
g )
FOUND_GTK3=""
c )
CLEAN_BUILD=1
;;
r )
SKIP_RAM_CHECK="1"
d )
BUILD_DEPS="1"
;;
h ) usage
exit 0
;;
i )
BUILD_IMAGE="1"
;;
r )
SKIP_RAM_CHECK="1"
;;
s )
BUILD_ORCA="1"
;;
u )
UPDATE_LIB="1"
;;
esac
done
if [ $OPTIND -eq 1 ]
if [ ${OPTIND} -eq 1 ]
then
usage
exit 0
fi
# Addtional Dev packages for OrcaSlicer
export REQUIRED_DEV_PACKAGES="libmspack-dev 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 texinfo"
# 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 gettext
DISTRIBUTION=$(awk -F= '/^ID=/ {print $2}' /etc/os-release)
if [ ! -f ./linux.d/${DISTRIBUTION} ]
then
echo "Your distribution does not appear to be currently supported by these build scripts"
exit 1
fi
source ./linux.d/${DISTRIBUTION}
#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+ and 23+:
ubu_major_version="$(grep VERSION_ID /etc/os-release | cut -d "=" -f 2 | cut -d "." -f 1 | tr -d /\"/)"
if [ $ubu_major_version == "22" ] || [ $ubu_major_version == "23" ]
then
apt install -y curl libfuse-dev 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" ]]
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 0
fi
exit 1
fi
echo "[1/9] Updating submodules..."
{
# update submodule profiles
pushd resources/profiles
git submodule update --init
popd
}
echo "[2/9] Changing date in version..."
echo "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" ]]
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" ]]
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 [[ -n "$BUILD_DEBUG" ]]
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
pushd deps/build/release
echo -e "cmake ../.. -DDESTDIR=\"../destdir\" $BUILD_ARGS"
cmake ../.. -DDESTDIR="../destdir" $BUILD_ARGS
make -j$NCORES
popd
cmake -S deps -B deps/build/release -G Ninja -DDESTDIR="../destdir" ${BUILD_ARGS}
cmake --build deps/build/release
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
fi
# cmake deps
pushd deps/build
echo "cmake .. $BUILD_ARGS"
cmake .. $BUILD_ARGS
echo "done"
# make deps
echo "[4/9] Building dependencies..."
make deps -j$NCORES
echo "done"
# rename wxscintilla # TODO: DeftDawg: Does OrcaSlicer 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"
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
fi
# Create main "build" directory
if [ ! -d "build" ]
then
mkdir build
fi
if [[ -n "$BUILD_ORCA" ]]
if [[ -n "${BUILD_ORCA}" ]]
then
echo "[7/9] Configuring Slic3r..."
echo "Configuring OrcaSlicer..."
if [[ -n "${CLEAN_BUILD}" ]]
then
rm -fr build
fi
BUILD_ARGS=""
if [[ -n "$FOUND_GTK3_DEV" ]]
if [[ -n "${FOUND_GTK3_DEV}" ]]
then
BUILD_ARGS="-DSLIC3R_GTK=3"
fi
if [[ -n "$BUILD_DEBUG" ]]
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
echo -e "cmake .. -DCMAKE_PREFIX_PATH=\"$PWD/../deps/build/destdir/usr/local\" -DSLIC3R_STATIC=1 -DORCA_TOOLS=ON ${BUILD_ARGS}"
cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS} -DORCA_TOOLS=ON
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 \
-DORCA_TOOLS=ON \
${BUILD_ARGS}
echo "done"
# make Slic3r
echo "[8/9] Building Slic3r..."
make -j$NCORES OrcaSlicer # Slic3r
# make OrcaSlicer_profile_validator
make -j$NCORES OrcaSlicer_profile_validator
popd
echo "Building OrcaSlicer ..."
cmake --build build --target OrcaSlicer
echo "Building OrcaSlicer_profile_validator .."
cmake --build build --target OrcaSlicer_profile_validator
./run_gettext.sh
echo "done"
fi
if [[ -e $ROOT/build/src/BuildLinuxImage.sh ]]; then
if [[ -e ${ROOT}/build/src/BuildLinuxImage.sh ]]; then
# Give proper permissions to script
chmod 755 $ROOT/build/src/BuildLinuxImage.sh
chmod 755 ${ROOT}/build/src/BuildLinuxImage.sh
echo "[9/9] Generating Linux app..."
pushd build
if [[ -n "$BUILD_IMAGE" ]]
if [[ -n "${BUILD_IMAGE}" ]]
then
$ROOT/build/src/BuildLinuxImage.sh -i
${ROOT}/build/src/BuildLinuxImage.sh -i
else
$ROOT/build/src/BuildLinuxImage.sh
${ROOT}/build/src/BuildLinuxImage.sh
fi
popd
echo "done"

3
linux.d/README.md Normal file
View file

@ -0,0 +1,3 @@
Files in this directory are named for the **exact** output of `awk -F= '/^ID=/ {print $2}' /etc/os-release` for their respective distribution.
When `BuildLinux.sh` is executed, the respective file for the distribution will be sourced so the distribution specific instructions/logic are used.

44
linux.d/arch Normal file
View file

@ -0,0 +1,44 @@
# these are the Arch Linux specific build functions
FOUND_GTK3=$(pacman -Q gtk3)
# Addtional Dev packages for OrcaSlicer
export REQUIRED_DEV_PACKAGES=(
cmake
curl
dbus
eglexternalplatform
extra-cmake-modules
file
gettext
git
glew
gstreamer
gstreamermm
gtk3
libmspack
libsecret
mesa
ninja
openssl
texinfo
wayland-protocols
webkit2gtk
wget
)
if [[ -n "$UPDATE_LIB" ]]
then
echo -n -e "Updating linux ...\n"
NEEDED_PKGS=""
for PKG in ${REQUIRED_DEV_PACKAGES[@]}; do
pacman -Q ${PKG} > /dev/null || NEEDED_PKGS+=" ${PKG}"
done
if [ -n "${NEEDED_PKGS}" ]; then
sudo pacman -Syy --noconfirm ${NEEDED_PKGS}
fi
echo -e "done\n"
exit 0
fi
FOUND_GTK3_DEV=${FOUND_GTK3}

48
linux.d/fedora Normal file
View file

@ -0,0 +1,48 @@
FOUND_GTK3=$(rpm -qa | grep -P '^gtk3' || true)
REQUIRED_DEV_PACKAGES=(
autoconf
automake
cmake
dbus-devel
eglexternalplatform-devel
extra-cmake-modules
file
gcc
gcc-c++
gettext
git
gstreamer1-devel
gstreamermm-devel
gtk3-devel
libmspack-devel
libsecret-devel
libtool
m4
mesa-libGLU-devel
mesa-libOSMesa-devel
ninja-build
openssl-devel
perl-FindBin
texinfo
wayland-protocols-devel
webkit2gtk4.0-devel
wget
libcurl-devel
)
if [[ -n "$UPDATE_LIB" ]]
then
NEEDED_PKGS=""
for PKG in ${REQUIRED_DEV_PACKAGES[@]}; do
rpm -q ${PKG} > /dev/null || NEEDED_PKGS+=" ${PKG}"
done
if [ -n "${NEEDED_PKGS}" ]; then
sudo dnf install -y ${NEEDED_PKGS}
fi
echo -e "done\n"
exit 0
fi
FOUND_GTK3_DEV=$(rpm -qa | grep -P '^gtk3-devel' || true)

51
linux.d/ubuntu Normal file
View file

@ -0,0 +1,51 @@
FOUND_GTK3=$(dpkg -l libgtk* | grep gtk-3)
REQUIRED_DEV_PACKAGES=(
autoconf
build-essential
cmake
eglexternalplatform-dev
extra-cmake-modules
file
gettext
git
libcurl4-openssl-dev
libdbus-1-dev
libglew-dev
libgstreamerd-3-dev
libgtk-3-dev
libmspack-dev
libosmesa6-dev
libsecret-1-dev
libssl-dev
libtool
libudev-dev
libwebkit2gtk-4.0-dev
ninja-build
texinfo
wget
)
if [[ -n "$UPDATE_LIB" ]]
then
# for ubuntu 22+ and 23+:
ubu_major_version="$(grep VERSION_ID /etc/os-release | cut -d "=" -f 2 | cut -d "." -f 1 | tr -d /\"/)"
if [ $ubu_major_version == "22" ] || [ $ubu_major_version == "23" ]
then
REQUIRED_DEV_PACKAGES+=(curl libfuse-dev libssl-dev libcurl4-openssl-dev m4)
fi
if [[ -n "$BUILD_DEBUG" ]]
then
REQUIRED_DEV_PACKAGES+=(libssl-dev libcurl4-openssl-dev)
fi
# TODO: optimize this by checking which, if any, packages are already installed
# install them all at once
sudo apt update
sudo apt install -y ${REQUIRED_DEV_PACKAGES[@]}
echo -e "done\n"
exit 0
fi
FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev || echo '')