Automate installation of DXVK, D9VK + Wine/Wine Staging & update GPU drivers + PlayonLinux wineprefixes (Debian/Ubuntu/Mint/Arch Linux/Manjaro)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

503 lines
14 KiB

6 years ago
6 years ago
  1. #!/bin/env bash
  2. # Compile DXVK git on Debian/Ubuntu/Mint and variants
  3. # Copyright (C) 2018 Pekka Helenius
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. ###########################################################
  18. # DO NOT RUN INDIVIDUALLY, ONLY VIA ../../updatewine.sh PARENT SCRIPT!
  19. ########################################################
  20. # Root directory of this script file
  21. DXVKROOT="${PWD}"
  22. # datedir variable supplied by ../updatewine_debian.sh script file
  23. datedir="${1}"
  24. ###########################################################
  25. # Parse input arguments
  26. i=0
  27. for arg in ${@:2}; do
  28. args[$i]="${arg}"
  29. let i++
  30. done
  31. # Must be a true array as defined above, not a single index list!
  32. #args="${@:2}"
  33. for check in ${args[@]}; do
  34. case ${check} in
  35. --no-install)
  36. NO_INSTALL=
  37. ;;
  38. --updateoverride)
  39. updateoverride=
  40. ;;
  41. esac
  42. done
  43. ###########################################################
  44. # Some version of Wine must be found in the system
  45. # Warn the user
  46. function wineCheck() {
  47. if [[ ! $(which wine 2>/dev/null) ]]; then
  48. echo -e "Warning: You must have Wine installed before DXVK can be compiled.\n"
  49. fi
  50. }
  51. wineCheck
  52. ###########################################################
  53. # If the script is interrupted (Ctrl+C/SIGINT), do the following
  54. function DXVK_intCleanup() {
  55. rm -rf ${DXVKROOT}/{dxvk-git,meson,glslang}
  56. rm -rf ${DXVKROOT}/../compiled_deb/"${datedir}"
  57. exit 0
  58. }
  59. # Allow interruption of the script at any time (Ctrl + C)
  60. trap "DXVK_intCleanup" INT
  61. ########################################################
  62. # http://wiki.bash-hackers.org/snipplets/print_horizontal_line#a_line_across_the_entire_width_of_the_terminal
  63. function INFO_SEP() { printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - ; }
  64. ########################################################
  65. # Universal core dependencies for package compilation
  66. _coredeps=('dh-make' 'make' 'gcc' 'build-essential' 'fakeroot')
  67. ##################################
  68. # Update package databases
  69. # Check existence of necessary commands
  70. # Check and install core dependencies
  71. function customReqs() {
  72. if [[ -v updateoverride ]]; then
  73. echo -en "Updating package databases." && \
  74. if [[ $(printf $(sudo -n uptime &>/dev/null)$?) -ne 0 ]]; then printf " Please provide your sudo password.\n"; else printf "\n\n"; fi
  75. sudo apt update
  76. fi
  77. for cmd in git tar wget; do
  78. if [[ $(printf $(which ${cmd} &> /dev/null)$?) -ne 0 ]]; then
  79. echo -e "Missing ${cmd}. Installing...\n"
  80. sudo apt update && sudo apt install -y ${cmd}
  81. fi
  82. done
  83. for coredep in ${_coredeps[@]}; do
  84. if [[ $(apt version ${coredep} | wc -w) -eq 0 ]]; then
  85. echo -e "Installing core dependency ${coredep}.\n"
  86. sudo apt install -y ${coredep}
  87. if [[ $? -ne 0 ]]; then
  88. echo -e "Could not install ${coredep}. Aborting.\n"
  89. exit 1
  90. fi
  91. fi
  92. done
  93. }
  94. customReqs
  95. ##################################
  96. # Check do we need to compile the package
  97. # given as input for this function
  98. function pkgcompilecheck() {
  99. local pkg=${1}
  100. local install_function=${2}
  101. if [[ $(apt version ${coredep} | wc -w) -eq 0 ]] || [[ -v updateoverride ]]; then
  102. ${install_function}
  103. fi
  104. }
  105. ###################################################
  106. function preparepackage() {
  107. echo -e "Starting compilation (& installation) of ${1}\n"
  108. # Set local variables
  109. local a=0
  110. local _pkgname=${1}
  111. local _pkgdeps=${2}
  112. local _pkgurl=${3}
  113. local _pkgver=${4}
  114. # Optional variable for runtime dependencies array
  115. if [[ -n ${5} ]]; then local _pkgdeps_runtime=${5}; fi
  116. # Check and install package related dependencies if they are missing
  117. function pkgdependencies() {
  118. for pkgdep in ${@}; do
  119. if [[ $(apt version ${pkgdep} | wc -w) -eq 0 ]]; then
  120. echo -e "Installing ${_pkgname} dependency ${pkgdep} ($(($a + 1 )) / $((${#*} + 1)))\n."
  121. sudo apt install -y ${pkgdep} &> /dev/null
  122. if [[ $? -eq 0 ]]; then
  123. let a++
  124. else
  125. echo -e "\nError occured while installing ${pkgdep}. Aborting.\n"
  126. exit 1
  127. fi
  128. fi
  129. done
  130. }
  131. # Get git-based version in order to rename the package main folder
  132. # This is required by deb builder. It retrieves the version number
  133. # from that folder name
  134. function pkgversion() {
  135. if [[ -n "${_pkgver}" ]] && [[ "${_pkgver}" =~ ^git ]]; then
  136. cd ${_pkgname}
  137. _pkgver=$(eval "${_pkgver}")
  138. cd ..
  139. fi
  140. }
  141. function pkgfoldername() {
  142. # Remove old build directory, if present
  143. rm -rf ${_pkgname}
  144. # Create a new build directory, access it and download git sources there
  145. mkdir ${_pkgname}
  146. cd ${_pkgname}
  147. echo -e "Retrieving source code of ${_pkgname} from $(printf ${_pkgurl} | sed 's/^.*\/\///; s/\/.*//')\n"
  148. git clone ${_pkgurl} ${_pkgname}
  149. # If sources could be downloaded, rename the folder properly for deb builder
  150. # Access the folder after which package specific debianbuild function will be run
  151. # That function is defined inside package specific install_main function below
  152. if [[ $? -eq 0 ]]; then
  153. pkgversion && \
  154. mv ${_pkgname} ${_pkgname}-${_pkgver}
  155. cd ${_pkgname}-${_pkgver}
  156. else
  157. echo -e "Error while downloading source of ${_pkgname} package. Aborting\n"
  158. exit 1
  159. fi
  160. }
  161. # Execute above functions
  162. pkgdependencies "${_pkgdeps[*]}" && \
  163. if [[ -v _pkgdeps_runtime ]]; then pkgdependencies "${_pkgdeps_runtime[*]}"; fi
  164. pkgfoldername
  165. unset _pkgver
  166. }
  167. ###################################################
  168. # MESON COMPILATION & INSTALLATION
  169. # Required by DXVK package
  170. function meson_install_main() {
  171. # Package name
  172. local pkgname="meson"
  173. # Build time dependencies
  174. local pkgdeps_build=(
  175. 'python3'
  176. 'dh-python'
  177. 'python3-setuptools'
  178. 'ninja-build'
  179. )
  180. # Git source location
  181. local pkgurl="https://github.com/mesonbuild/meson"
  182. # Parsed version number from git source files
  183. local pkgver_git="git describe --long | sed 's/\-[a-z].*//; s/\-/\./; s/[a-z]//g'"
  184. # Location of Debian compilation instructions archive
  185. local pkgurl_debian="http://archive.ubuntu.com/ubuntu/pool/universe/m/meson/meson_0.45.1-2.debian.tar.xz"
  186. function meson_debianbuild() {
  187. # Download predefined Meson debian rules archive
  188. # Extract it, and finally delete the archive
  189. wget ${pkgurl_debian} -O debian.tar.xz
  190. tar xf debian.tar.xz && rm debian.tar.xz
  191. # Get sed compatible Meson version string
  192. local meson_version=$(printf '%s' $(pwd | sed -e 's/.*\-//' -e 's/\./\\\./g'))
  193. # Do not perform any tests or checks during compilation process
  194. sed -ir '/nocheck/d' debian/control
  195. sed -ir '/\.\/run_tests\.py/d' debian/rules
  196. # Downgrade debhelper version requirement for Debian compatilibity
  197. sed -ir 's/debhelper (>= 11)/debhelper (>= 10)/' debian/control
  198. # Correct & update package version number + debian rules
  199. sed -ir "s/0\.45\.1-2/${meson_version}/" debian/changelog
  200. # Delete the following strings from debian/rules file
  201. # They are deprecated
  202. sed -ir '/rm \$\$(pwd)\/debian\/meson\/usr\/bin\/mesontest/d' debian/rules
  203. sed -ir '/rm \$\$(pwd)\/debian\/meson\/usr\/bin\/mesonconf/d' debian/rules
  204. sed -ir '/rm \$\$(pwd)\/debian\/meson\/usr\/bin\/mesonintrospect/d' debian/rules
  205. sed -ir '/rm \$\$(pwd)\/debian\/meson\/usr\/bin\/wraptool/d' debian/rules
  206. sed -ir '/rm \-rf \$\$(pwd)\/debian\/meson\/usr\/lib\/python3/d' debian/rules
  207. # Remove deprecated, downloaded patch files
  208. rm -r debian/patches
  209. # Remove irrelevant sample files
  210. rm -r debian/*.{ex,EX}
  211. # Start deb builder. Do not build either debug symbols or doc files
  212. DEB_BUILD_OPTIONS="strip nodocs noddebs" dpkg-buildpackage -rfakeroot -b -us -uc
  213. # Once compiled, install and store the compiled deb archive
  214. # We do not make installation optional because this is a core dependency for DXVK
  215. if [[ $? -eq 0 ]]; then
  216. rm -rf ../*.{changes,buildinfo,tar.xz} && \
  217. sudo dpkg -i ../${pkgname}*.deb && \
  218. mv ../${pkgname}*.deb ../../../compiled_deb/"${datedir}" && \
  219. echo -e "Compiled ${pkgname} is stored at '$(readlink -f ../../../compiled_deb/"${datedir}")/'\n"
  220. cd ../..
  221. rm -rf ${pkgname}
  222. else
  223. exit 1
  224. fi
  225. }
  226. # Execute above functions
  227. preparepackage "${pkgname}" "${pkgdeps_build[*]}" "${pkgurl}" "${pkgver_git}" && \
  228. meson_debianbuild
  229. }
  230. ###################################################
  231. # GLSLANG COMPILATION & INSTALLATION
  232. # Required by DXVK package
  233. function glslang_install_main() {
  234. # Package name
  235. local pkgname="glslang"
  236. # Build time dependencies
  237. local pkgdeps_build=('cmake' 'python2.7')
  238. # Git source location
  239. local pkgurl="https://github.com/KhronosGroup/glslang"
  240. # Parsed version number from git source files
  241. local pkgver_git="git describe --long | sed 's/\-[a-z].*//; s/\-/\./; s/[a-z]//g'"
  242. function glslang_debianbuild() {
  243. # Create debian subdirectory
  244. dh_make --createorig -s -y
  245. # Set Build dependencies into debian/control file
  246. sed -ie "s/^Build-Depends:.*$/Build-Depends: debhelper (>=10), $(echo ${_coredeps[*]} | \
  247. sed 's/\s/, /g'), $(echo ${pkgdeps_build[*]} | sed 's/\s/, /g')/g" debian/control
  248. # Skip running override_dh_usrlocal while executing deb builder
  249. printf 'override_dh_usrlocal:' | tee -a debian/rules
  250. # Remove irrelevant sample files
  251. rm -r debian/*.{ex,EX}
  252. # Start deb builder. Do not build either debug symbols or doc files
  253. DEB_BUILD_OPTIONS="strip nodocs noddebs" dpkg-buildpackage -rfakeroot -b -us -uc
  254. # Once compiled, install and store the compiled deb archive
  255. # We do not make installation optional because this is a core dependency for DXVK
  256. if [[ $? -eq 0 ]]; then
  257. rm -rf ../*.{changes,buildinfo,tar.xz} && \
  258. sudo dpkg -i ../${pkgname}*.deb && \
  259. mv ../${pkgname}*.deb ../../../compiled_deb/"${datedir}" && \
  260. echo -e "Compiled ${pkgname} is stored at '$(readlink -f ../../../compiled_deb/"${datedir}")/'\n"
  261. cd ../..
  262. rm -rf ${pkgname}
  263. else
  264. exit 1
  265. fi
  266. }
  267. # Execute above functions
  268. preparepackage "${pkgname}" "${pkgdeps_build[*]}" "${pkgurl}" "${pkgver_git}" && \
  269. glslang_debianbuild
  270. }
  271. ###################################################
  272. # DXVK COMPILATION & INSTALLATION
  273. function dxvk_install_main() {
  274. # Package name
  275. local pkgname="dxvk-git"
  276. # Build time dependencies
  277. local pkgdeps_build=(
  278. 'meson'
  279. 'glslang'
  280. 'gcc-mingw-w64-x86-64'
  281. 'gcc-mingw-w64-i686'
  282. 'g++-mingw-w64-x86-64'
  283. 'g++-mingw-w64-i686'
  284. 'mingw-w64-x86-64-dev'
  285. 'mingw-w64-i686-dev'
  286. )
  287. # Runtime dependencies
  288. local pkgdeps_runtime=('wine' 'winetricks')
  289. # Git source location
  290. local pkgurl="https://github.com/doitsujin/dxvk"
  291. # Parsed version number from git source files
  292. local pkgver_git="git describe --long | sed 's/\-[a-z].*//; s/\-/\./; s/[a-z]//g'"
  293. # Use posix alternates for MinGW binaries
  294. function dxvk_posixpkgs() {
  295. local packages=(
  296. 'i686-w64-mingw32-g++'
  297. 'i686-w64-mingw32-gcc'
  298. 'x86_64-w64-mingw32-g++'
  299. 'x86_64-w64-mingw32-gcc'
  300. )
  301. for package in "${packages[@]}"; do
  302. local option=$(echo "" | sudo update-alternatives --config "${package}" | grep posix | sed 's@^[^0-9]*\([0-9]\+\).*@\1@')
  303. echo "${option}" | sudo update-alternatives --config "${package}" &> /dev/null
  304. done
  305. }
  306. # Debian-specific compilation & installation rules
  307. function dxvk_debianbuild() {
  308. local dxvx_relative_builddir="debian/source/dxvk-master"
  309. # Create debian subdirectory
  310. dh_make --createorig -s -y
  311. # Set Build dependencies into debian/control file
  312. sed -ie "s/^Build-Depends:.*$/Build-Depends: debhelper (>=10), $(echo ${_coredeps[*]} | \
  313. sed 's/\s/, /g'), $(echo ${pkgdeps_build[*]} | sed 's/\s/, /g')/g" debian/control
  314. # Set Runtime dependencies into debian/control file
  315. sed -ie "s/^Depends:.*$/Depends: $(echo ${pkgdeps_runtime} | sed 's/\s/, /g')/g" debian/control
  316. # Tell deb builder to bundle these files
  317. printf "${dxvx_relative_builddir}/setup_dxvk.verb usr/share/dxvk/" > debian/install
  318. printf "\n${dxvx_relative_builddir}/bin/* usr/bin/" >> debian/install
  319. # Remove irrelevant sample files
  320. rm -r debian/*.{ex,EX}
  321. # Overwrite debian/rules file with the following contents
  322. cat << 'DXVK-DEBIANRULES' > debian/rules
  323. #!/usr/bin/make -f
  324. %:
  325. dh $@
  326. override_dh_auto_configure:
  327. override_dh_usrlocal:
  328. DXVK-DEBIANRULES
  329. # Start DXVK compilation
  330. bash ./package-release.sh master debian/source/ --no-package
  331. if [[ $? -ne 0 ]]; then
  332. echo "Error while compiling ${pkgname}. Check messages above. Aborting\n"
  333. exit 1
  334. fi
  335. # Make a proper executable script for setup_dxvk.verb file
  336. mkdir -p ${dxvx_relative_builddir}/bin
  337. echo -e "#!/bin/sh\nwinetricks --force /usr/share/dxvk/setup_dxvk.verb" \
  338. > "${dxvx_relative_builddir}/bin/setup_dxvk"
  339. chmod +x "${dxvx_relative_builddir}/bin/setup_dxvk"
  340. # Tell deb builder to install DXVK x32 & x64 subfolders
  341. for arch in 64 32; do
  342. mkdir -p ${dxvx_relative_builddir}/x${arch}
  343. printf "\n${dxvx_relative_builddir}/x${arch}/* usr/share/dxvk/x${arch}/" >> debian/install
  344. done
  345. # Start deb builder. Do not build either debug symbols or doc files
  346. DEB_BUILD_OPTIONS="strip nodocs noddebs" dpkg-buildpackage -us -uc -b --source-option=--include-binaries
  347. # Once compiled, possibly install and store the compiled deb archive
  348. if [[ $? -eq 0 ]]; then
  349. if [[ ! -v NO_INSTALL ]]; then
  350. sudo dpkg -i ../${pkgname}*.deb
  351. fi
  352. rm -rf ../*.{changes,buildinfo,tar.xz}
  353. mv ../${pkgname}*.deb ../../../compiled_deb/"${datedir}" && \
  354. echo -e "Compiled ${pkgname} is stored at '$(readlink -f ../../../compiled_deb/"${datedir}")/'\n"
  355. cd ../..
  356. rm -rf ${pkgname}
  357. else
  358. exit 1
  359. fi
  360. }
  361. # Execute above functions
  362. preparepackage "${pkgname}" "${pkgdeps_build[*]}" "${pkgurl}" "${pkgver_git}" "${pkgdeps_runtime[*]}" && \
  363. dxvk_posixpkgs && \
  364. dxvk_debianbuild
  365. }
  366. ####################################################################
  367. pkgcompilecheck meson meson_install_main
  368. pkgcompilecheck glslang glslang_install_main
  369. dxvk_install_main