-
-
Save ntropy83/2d3ae5585d4f7c4229c46332e23e7c13 to your computer and use it in GitHub Desktop.
mesa_debian_build.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Notes: | |
# | |
# 1. Works for tags and specific hash commits too (override mesa_branch variable with needed value). | |
# | |
# 2. By default builds for /opt/mesa-<branch> and places the result in ${HOME}/mnt/vmshare/mesa-<branch> | |
# You can override the build deployment location by setting dest_dir. For example this should put it right away | |
# in /opt/mesa-<branch> | |
# | |
# dest_dir=/ mesa_debian_build.sh | |
# | |
# 3. You can override the Mesa repo and resulting Mesa directory name. For example, to build Mesa-aco | |
# for testing the new shader compiler: | |
# | |
mesa_repo='https://github.com/daniel-schuermann/mesa.git' | |
src_dir="${HOME}/build/mesa-aco" | |
mesa_dir='/opt/mesa-aco' | |
# | |
mesa_branch=${mesa_branch:-"master"} | |
#mesa_repo=${mesa_repo:-"https://gitlab.freedesktop.org/mesa/mesa.git"} | |
#src_dir=${src_dir:-"${HOME}/build/mesa"} | |
build_dir=${build_dir:-"${src_dir}/build"} | |
llvm_ver=${llvm_ver:-"9"} | |
cpuarch=${cpuarch:-"znver1"} # Zen by default. Change to your arch or "native" accordingly. | |
build_32=${build_32:-false} # Debian Mesa 32-bit cross compilation is currently broken | |
build_debug=${build_debug:-false} | |
verbose=${verbose:-false} | |
if $build_debug; then | |
build_type='debug' | |
else | |
build_type='release' | |
fi | |
#if [[ "$mesa_branch" != "mesa"* ]]; then | |
# mesa_dir=${mesa_dir:-"/opt/mesa-${mesa_branch}"} | |
#else | |
# mesa_dir=${mesa_dir:-"/opt/${mesa_branch}"} | |
#fi | |
dest_dir=${dest_dir:-"${HOME}/mnt/vmshare/$(basename ${mesa_dir})"} | |
arch_dir["32"]="x86" | |
arch_dir["64"]="x86_64" | |
function assert() { | |
rc=$1 | |
message="$2" | |
if ((rc != 0)); then | |
echo $message | |
exit $rc | |
fi | |
} | |
function ensure() { | |
local rc=1 | |
while (($rc != 0)); do | |
$@ | |
rc=$? | |
if (($rc != 0)); then | |
sleep 1 | |
fi | |
done | |
} | |
function common_prepare() { | |
echo "=== Common setup ====" | |
mkdir -p ${dest_dir} | |
rm -rfv ${dest_dir}/${mesa_dir}/* | |
ensure sudo apt-get install build-essential git | |
cd $(dirname "$src_dir") | |
git clone "$mesa_repo" $(basename "$src_dir") | |
cd "$src_dir" | |
git reset --hard HEAD | |
git clean -df | |
git checkout master | |
git pull | |
git checkout $mesa_branch | |
mkdir -p "$build_dir" | |
rm -rfv ${build_dir}/* | |
} | |
function prepare_64() { | |
echo "=== Preparing 64-bit build ====" | |
ensure sudo apt-get build-dep mesa | |
ensure sudo apt-get install llvm-${llvm_ver}-dev libclang-${llvm_ver}-dev | |
} | |
function prepare_32() { | |
echo "==== Preparing 32-bit build ====" | |
# TODO: all this needs a working method in Debian | |
echo "Not supported now" | |
return | |
ensure sudo apt-get install llvm-${llvm_ver}-dev:i386 libclang-${llvm_ver}-dev:i386 gcc-multilib g++-multilib libdrm-dev:i386 libexpat1-dev:i386 libxcb-dri3-dev:i386 libxcb-present-dev:i386 libxshmfence-dev:i386 libxext-dev:i386 libxdamage-dev:i386 libx11-xcb-dev:i386 libxcb-glx0-dev:i386 libxcb-dri2-0-dev:i386 libxxf86vm-dev:i386 libwayland-dev:i386 libsensors4-dev:i386 libelf-dev:i386 zlib1g-dev:i386 libglvnd-core-dev:i386 | |
} | |
configure_64() { | |
echo "==== Configuring 64-bit build ====" | |
cd "$build_dir" | |
local ndebug=true | |
local strip_option="--strip" | |
if $build_debug; then | |
ndebug=false | |
strip_option="" | |
fi | |
local native_config | |
read -r -d '' native_config <<EOF | |
[binaries] | |
llvm-config = "/usr/bin/llvm-config-${llvm_ver}" | |
EOF | |
# Workaround for Meson bug that prevents using implicit temporary files. | |
# See: https://github.com/mesonbuild/meson/issues/5505 | |
# Once that is fixed in the released Meson version, it can be reverted to using: | |
# --native-file=<(echo "$native_config") \ | |
echo "$native_config" > ${build_dir}/native_config | |
export CFLAGS="-march=${cpuarch} -fdebug-prefix-map=${HOME}/build=. -fstack-protector-strong -Wformat -Werror=format-security -Wall" | |
export CPPFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2" | |
export CXXFLAGS="-march=${cpuarch} -fdebug-prefix-map=${HOME}/build=. -fstack-protector-strong -Wformat -Werror=format-security -Wall" | |
export LDFLAGS="-Wl,-z,relro" | |
LC_ALL=C.UTF-8 meson "$src_dir" \ | |
--wrap-mode=nodownload \ | |
--buildtype=$build_type \ | |
--native-file=${build_dir}/native_config \ | |
$strip_option \ | |
--prefix="$mesa_dir" \ | |
--sysconfdir=/etc \ | |
--localstatedir=/var \ | |
--libdir="${arch_dir["64"]}" \ | |
--libexecdir="${arch_dir["64"]}" \ | |
-Db_ndebug=$ndebug \ | |
-Ddri-drivers= \ | |
-Ddri-drivers-path="${arch_dir["64"]}" \ | |
"-Dvulkan-drivers=amd" \ | |
-Dglvnd=true \ | |
-Dshared-glapi=true \ | |
-Dgallium-xvmc=false \ | |
-Dgallium-omx=disabled \ | |
-Dglx-direct=true \ | |
-Dgbm=true \ | |
-Ddri3=true \ | |
"-Dplatforms=x11,surfaceless,wayland,drm" \ | |
-Dllvm=true \ | |
-Dshared-llvm=false \ | |
-Dgallium-extra-hud=true \ | |
-Dvulkan-overlay-layer=true \ | |
-Dgallium-vdpau=false \ | |
-Dgallium-va=true \ | |
-Dva-libs-path="${arch_dir["64"]}" \ | |
-Dlmsensors=true \ | |
"-Dgallium-drivers=radeonsi" \ | |
-Dgles1=false \ | |
-Dgles2=true | |
assert $? "Configure failed!" | |
} | |
configure_32() { | |
echo "==== Configuring 32-bit ====" | |
echo "Not supported now" | |
return | |
} | |
function build() { | |
echo "==== Building... ====" | |
cd "$build_dir" | |
if $verbose; then | |
LC_ALL=C.UTF-8 ninja -v | |
else | |
LC_ALL=C.UTF-8 ninja | |
fi | |
assert $? "build failed!" | |
} | |
function publish() { | |
cd "$build_dir" | |
DESTDIR="$dest_dir" LC_ALL=C.UTF-8 ninja install | |
} | |
function clean_64() { | |
ensure sudo apt-get purge llvm-${llvm_ver}-dev libclang-${llvm_ver}-dev | |
ensure sudo apt-get autoremove --purge | |
} | |
function clean_32() { | |
ensure sudo apt-get purge llvm-${llvm_ver}-dev:i386 libclang-${llvm_ver}-dev:i386 libsensors4-dev:i386 | |
ensure sudo apt-get autoremove --purge | |
} | |
################################################ | |
common_prepare | |
prepare_64 | |
configure_64 | |
build | |
publish | |
clean_64 | |
if ! $build_32; then | |
exit | |
fi | |
prepare_32 | |
configure_32 | |
build | |
publish | |
clean_32 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment