Support Linux distros & others in build script

This adds Debian, Fedora, Arch and Gentoo to compile when using Linux distros, also supports based with popular Linux operating systems.

Fixed wrong swap of Git pull command vvenc & vvdec, added -p argument for making a directory to avoid error.

- Martin Eesmaa
This commit is contained in:
MartinEesmaa
2024-09-28 19:57:33 +10:00
parent bc767c1cd3
commit 4abde3c3b4

View File

@@ -1,12 +1,42 @@
#!/bin/bash #!/bin/bash
OS=$(uname) OS=$(uname)
DISTRO=""
# Detect Linux distribution
if [ "$OS" = "Linux" ]; then
if [ -f /etc/os-release ]; then
DISTRO=$(awk -F= '/^ID=/{print $2}' /etc/os-release)
fi
fi
echo "Martin Eesmaa / VVC Compiler (vvenc and vvdec)" echo "Martin Eesmaa / VVC Compiler (vvenc and vvdec)"
if [ "$OS" = "Linux" ]; then
echo "You're running on $OS with distribution $DISTRO of bash script version to compile VVC binaries"
else
echo "You're running on $OS of bash script version to compile VVC binaries" echo "You're running on $OS of bash script version to compile VVC binaries"
fi
echo "Checking and installing required packages..." echo "Checking and installing required packages..."
setup_linux() { setup_debian() {
sudo apt update && sudo apt upgrade -y sudo apt update && sudo apt upgrade -y
sudo apt install build-essential cmake -y sudo apt install build-essential cmake git -y
}
setup_fedora() {
sudo dnf update -y
sudo dnf install cmake gcc gcc-c++ make git -y
}
setup_arch() {
sudo pacman -Syu --noconfirm
sudo pacman -S --noconfirm base-devel cmake git
}
setup_gentoo() {
sudo emerge --sync
sudo emerge cmake git
} }
setup_macos() { setup_macos() {
@@ -35,24 +65,26 @@ build_repos() {
if [ ! -d vvenc ]; then if [ ! -d vvenc ]; then
git clone --depth=1 https://github.com/fraunhoferhhi/vvenc git clone --depth=1 https://github.com/fraunhoferhhi/vvenc
else else
git pull -C vvenc git -C vvenc pull
fi fi
if [ ! -d vvdec ]; then if [ ! -d vvdec ]; then
git clone --depth=1 https://github.com/fraunhoferhhi/vvdec git clone --depth=1 https://github.com/fraunhoferhhi/vvdec
else else
git pull -C vvdec git -C vvdec pull
fi fi
for REPO in vvenc vvdec; do for REPO in vvenc vvdec; do
cd $REPO cd $REPO
mkdir build && cd build mkdir -p build && cd build
if [ "$OS" = "Darwin" ]; then if [ "$OS" = "Darwin" ]; then
CORES=$(sysctl -n hw.ncpu || echo 1)
cmake -DCMAKE_BUILD_TYPE=Release .. cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . -j $(sysctl -n hw.ncpu) cmake --build . -j $CORES
else else
CORES=$(nproc || echo 1)
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-static" .. cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-static" ..
cmake --build . -j $(nproc) cmake --build . -j $CORES
fi fi
cd - cd -
done done
@@ -62,7 +94,24 @@ done
# Main script execution # Main script execution
case "$OS" in case "$OS" in
Linux) Linux)
setup_linux case "$DISTRO" in
debian|ubuntu)
setup_debian
;;
fedora)
setup_fedora
;;
arch)
setup_arch
;;
gentoo)
setup_gentoo
;;
*)
echo "Unsupported Linux distribution: $DISTRO"
exit 1
;;
esac
;; ;;
Darwin) Darwin)
setup_macos setup_macos