perpetually_high

Compile 32-bit Mesa drivers for Linux

Nov 16th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.01 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Compile the 32-bit Mesa drivers from git. Works on all Linux distributions.
  4. #
  5. # Note: Must be run on a 32-bit OS/virtual machine. Assumes all dependencies already met.
  6. #
  7. # Supports:
  8. # radeon, intel, nouveau
  9. # Vulkan, Gallium Nine, Wayland
  10. #
  11. # Usage:
  12. # To run the build script with the defaults (master branch and LLVM 7):
  13. # bash ./build_mesa_32bit.sh
  14. #
  15. # or to override defaults:
  16. # MESA_BRANCH=18.3 LLVM_VER=8 bash ./build_mesa_32bit.sh
  17. #
  18. # or you can use any combination of the variables below.
  19. #
  20. # You should also edit the Vulkan, DRI, Gallium, and Platform drivers
  21. # to match your needs. The defaults includes everything to make the
  22. # script a little more robust.
  23. #
  24. # e.g. if you have an AMD Radeon RX 470/480/570/580/etc:
  25. #
  26. # VULKAN_DRIVERS=${VULKAN_DRIVERS:-"radeon"}
  27. # DRI_DRIVERS=${DRI_DRIVERS:-"radeon"}
  28. # GALLIUM_DRIVERS=${GALLIUM_DRIVERS:-"radeonsi swrast"}
  29. # PLATFORM_DRIVERS=${PLATFORM_DRIVERS:-"x11,surfaceless wayland drm"}
  30. #
  31. # or you can always pass the variables in when invoking the script.
  32.  
  33. set -o errexit
  34. set -o pipefail
  35.  
  36. ARCH_NAME=${ARCH_NAME:-"i386-linux-gnu"}
  37. MESA_BRANCH=${MESA_BRANCH:-"master"}
  38. LLVM_VER=${LLVM_VER:-"7"}
  39. OPTIMIZE_LEVEL=${OPTIMIZE_LEVEL:-"-O2"}
  40. OPTIMIZE_FLAGS=${OPTIMIZE_FLAGS:-"-march=native"}
  41.  
  42. VULKAN_DRIVERS=${VULKAN_DRIVERS:-"intel radeon"}
  43. DRI_DRIVERS=${DRI_DRIVERS:-"nouveau i915 i965 r200 radeon"}
  44. GALLIUM_DRIVERS=${GALLIUM_DRIVERS:-"nouveau virgl svga r600 r300 radeonsi swrast"}
  45. PLATFORM_DRIVERS=${PLATFORM_DRIVERS:-"x11,surfaceless wayland drm"}
  46.  
  47. SOURCE_URL=${SOURCE_URL:-"https://gitlab.freedesktop.org/mesa/mesa.git"}
  48. BUILD_DIR=${BUILD_DIR:-"${HOME}/mesa-build"}
  49. INSTALL_DIR=${INSTALL_DIR:-"${HOME}/mesa-${MESA_BRANCH}"}
  50.  
  51. # Make sure we're on a 32-bit OS
  52. if [[ $(arch) != "i686" ]]; then
  53.     printf "Must be run on a 32-bit OS. Exiting.\n"
  54.     exit 1
  55. fi
  56.  
  57. # Start fresh, remove previous build dir if it exists
  58. if [[ -d "${BUILD_DIR}" ]]; then
  59.     rm -rf "${BUILD_DIR}"
  60. fi
  61.  
  62. # Create build dir and clone from source
  63. mkdir -pv "${BUILD_DIR}"
  64. cd "${BUILD_DIR}"
  65. git clone --depth 1 --branch "${MESA_BRANCH}" "${SOURCE_URL}"
  66. cd mesa
  67.  
  68. # Run the autogen script
  69. ./autogen.sh
  70.  
  71. # Let's override the autogen defaults with our own
  72. ./configure --build=$(arch)-linux-gnu --prefix=${INSTALL_DIR} --includedir=\${prefix}/include --mandir=\${prefix}/share/man --infodir=\${prefix}/share/info --libdir=\${prefix}/lib/${ARCH_NAME} --libexecdir=\${prefix}/lib/${ARCH_NAME} --sysconfdir=/etc --localstatedir=/var --runstatedir=/run --disable-silent-rules --disable-dependency-tracking --disable-xvmc --disable-omx-bellagio --disable-gles1 --enable-gles2 --enable-libglvnd --enable-osmesa --enable-glx-tls --enable-shared-glapi --enable-driglx-direct --enable-gbm --enable-lmsensors --enable-xa --enable-llvm --enable-opencl --enable-opencl-icd --enable-vdpau --enable-va --enable-gallium-extra-hud --enable-nine --enable-dri --enable-dri3 ac_cv_path_LLVM_CONFIG=llvm-config-${LLVM_VER} "--with-dri-drivers=${DRI_DRIVERS}" "--with-dri-driverdir=/usr/lib/${ARCH_NAME}/dri" "--with-dri-searchpath=/usr/lib/${ARCH_NAME}/dri:\\\$\${ORIGIN}/dri:/usr/lib/dri" "--with-vulkan-drivers=${VULKAN_DRIVERS}" "--with-platforms=${PLATFORM_DRIVERS}" "--with-gallium-drivers=${GALLIUM_DRIVERS}" "CFLAGS=-g ${OPTIMIZE_LEVEL} ${OPTIMIZE_FLAGS} -fstack-protector-strong -Wformat -Werror=format-security -Wall" "CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2" "CXXFLAGS=-g ${OPTIMIZE_LEVEL} ${OPTIMIZE_FLAGS} -fstack-protector-strong -Wformat -Werror=format-security -Wall" "FCFLAGS=-g ${OPTIMIZE_LEVEL} -fstack-protector-strong" "FFLAGS=-g ${OPTIMIZE_LEVEL} ${OPTIMIZE_FLAGS} -fstack-protector-strong" "GCJFLAGS=-g ${OPTIMIZE_LEVEL} -fstack-protector-strong" "LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro" "OBJCFLAGS=-g ${OPTIMIZE_LEVEL} ${OPTIMIZE_FLAGS} -fstack-protector-strong -Wformat -Werror=format-security" "OBJCXXFLAGS=-g ${OPTIMIZE_LEVEL} ${OPTIMIZE_FLAGS} -fstack-protector-strong -Wformat -Werror=format-security"
  73.  
  74. # Begin compiling
  75. make -j$(nproc)
  76.  
  77. # Finished compiling, move gallium files up a dir to flatten
  78. mv -v "${ARCH_NAME}"/gallium/* "${ARCH_NAME}"
  79. rmdir -v "${ARCH_NAME}"/gallium
  80.  
  81. # If we've installed Mesa drivers before, backup the current one
  82. if [ -d "${INSTALL_DIR}"/lib/"${ARCH_NAME}" ]; then
  83.     rm -rf "${INSTALL_DIR}"/lib/"${ARCH_NAME}"-old
  84.     mv -vf "${INSTALL_DIR}"/lib/"${ARCH_NAME}"{,-old}
  85. fi
  86.  
  87. # Create the Mesa drivers directory and move libraries into it
  88. mkdir -pv "${INSTALL_DIR}"/lib/"${ARCH_NAME}"
  89. mv -v "${ARCH_NAME}"/* "${INSTALL_DIR}"/lib/"${ARCH_NAME}"
  90.  
  91. # Copy over the Vulkan icd files as well
  92. if [[ ${VULKAN_DRIVERS} == *"intel"* ]]; then
  93.     cp -v src/intel/vulkan/intel_icd.$(arch).json "${INSTALL_DIR}"/lib/"${ARCH_NAME}"
  94. fi
  95. if [[ ${VULKAN_DRIVERS} == *"radeon"* ]]; then
  96.     cp -v src/amd/vulkan/radeon_icd.$(arch).json "${INSTALL_DIR}"/lib/"${ARCH_NAME}"
  97. fi
  98.  
  99. # Create archive of the 32-bit drivers to be used on a 64-bit host
  100. tar czvf "${HOME}/mesa-${MESA_BRANCH}-${ARCH_NAME}.tar.gz" -C "${INSTALL_DIR}/lib" .
  101.  
  102. # Cleanup
  103. rm -rf "${BUILD_DIR}"
  104. rm -rf "${INSTALL_DIR}"
  105.  
  106. # Script complete. Change back into home directory and show help info
  107. cd
  108.  
  109. VIEOPENGLINFO="LIBGL_DRIVERS_PATH=${INSTALL_DIR}/lib/${ARCH_NAME}\
  110. EGL_DRIVERS_PATH=${INSTALL_DIR}/lib/${ARCH_NAME} glxinfo | grep OpenGL"
  111. VIEWVULKANINFO="VK_ICD_FILENAMES=${INSTALL_DIR}/lib/${ARCH_NAME}\
  112. /radeon_icd.$(arch).json vulkaninfo | head -n 5"
  113.  
  114. printf "\n✓ All done.\n\n"
  115. printf " To verify your 32-bit OpenGL drivers, copy and paste the following (requires glxinfo/mesa-utils): \n\n"
  116. printf "\t${VIEOPENGLINFO}\n\n"
  117. printf " To verify your 32-bit Vulkan drivers, copy and paste the following (requires vulkaninfo): \n\n"
  118. printf "\t${VIEWVULKANINFO}\n\n"
  119. printf " You'll now want to move the following archive: \n\n"
  120. printf "\t$HOME/mesa-${MESA_BRANCH}-${ARCH_NAME}.tar.gz\n\n"
  121. printf " to your 64-bit host machine and extract it to the appropriate location. e.g:\n\n"
  122. printf "\t32-bit drivers in: ${INSTALL_DIR}/lib/i386-linux-gnu\n\n"
  123. printf "\t64-bit drivers in: ${INSTALL_DIR}/lib/x86_64-linux-gnu\n\n"
Advertisement
Add Comment
Please, Sign In to add comment