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.

750 lines
22 KiB

6 years ago
6 years ago
  1. #!/bin/env bash
  2. # Compile DXVK git on Debian/Ubuntu/Mint and variants
  3. # Copyright (C) 2019 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. # Divide input args into array indexes
  26. i=0
  27. for p in ${@:2}; do
  28. params[$i]=${p}
  29. let i++
  30. done
  31. ########################################################
  32. # Parse input git override hashes
  33. # This order is mandatory!
  34. # If you change the order or contents of 'githash_overrides'
  35. # array in ../updatewine.sh, make sure to update these
  36. # variables!
  37. #
  38. git_commithash_dxvk=${params[0]}
  39. git_commithash_glslang=${params[1]}
  40. git_commithash_meson=${params[2]}
  41. git_branch_dxvk=${params[3]}
  42. git_branch_glslang=${params[5]}
  43. git_branch_meson=${params[6]}
  44. ########################################################
  45. # Parse input arguments, filter user parameters
  46. # The range is defined in ../updatewine.sh
  47. # All input arguments are:
  48. # <datedir> 4*<githash_override> 4*<gitbranch_override> <args>
  49. # 0 1 2 3 4 5 6 7 8 9...
  50. # Filter all but <args>, i.e. the first 0-8 arguments
  51. i=0
  52. for arg in ${params[@]:8}; do
  53. args[$i]="${arg}"
  54. let i++
  55. done
  56. for check in ${args[@]}; do
  57. case ${check} in
  58. --no-install)
  59. NO_INSTALL=
  60. ;;
  61. --updateoverride)
  62. UPDATE_OVERRIDE=
  63. ;;
  64. --buildpkg-rm)
  65. BUILDPKG_RM=
  66. ;;
  67. --no-dxvk)
  68. NO_DXVK=
  69. ;;
  70. esac
  71. done
  72. ########################################################
  73. # Check presence of Wine. Some version of Wine should
  74. # be found in the system in order to install DXVK.
  75. known_wines=(
  76. 'wine'
  77. 'wine-stable'
  78. 'wine32'
  79. 'wine64'
  80. 'libwine:amd64'
  81. 'libwine:i386'
  82. 'wine-git'
  83. 'wine-staging-git'
  84. )
  85. # Alternative remote dependency packages for Debian distributions which offer too old packages for DXVK
  86. #
  87. # Left side: <package name in repositories>,<version_number>
  88. # Right side: package alternative source URL
  89. #
  90. # NOTE: Determine these packages in corresponding debdata files as runtime or buildtime dependencies
  91. #
  92. typeset -A remotePackagesAlt
  93. remotePackagesAlt=(
  94. [gcc-mingw-w64-base,830]="http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-mingw-w64/gcc-mingw-w64-base_8.3.0-6ubuntu1+21.1build2_amd64.deb"
  95. [mingw-w64-common,600]="http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-common_6.0.0-3_all.deb"
  96. # [binutils-common,232]="http://mirrors.kernel.org/ubuntu/pool/main/b/binutils/binutils-common_2.32-7ubuntu4_amd64.deb"
  97. [binutils-mingw-w64-x86-64,232]="http://mirrors.kernel.org/ubuntu/pool/universe/b/binutils-mingw-w64/binutils-mingw-w64-x86-64_2.32-7ubuntu4+8.3ubuntu2_amd64.deb"
  98. [binutils-mingw-w64-i686,232]="http://mirrors.kernel.org/ubuntu/pool/universe/b/binutils-mingw-w64/binutils-mingw-w64-i686_2.32-7ubuntu4+8.3ubuntu2_amd64.deb"
  99. [mingw-w64-x86-64-dev,600]="http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-x86-64-dev_6.0.0-3_all.deb"
  100. [gcc-mingw-w64-x86-64,830]="http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-mingw-w64/gcc-mingw-w64-x86-64_8.3.0-6ubuntu1+21.1build2_amd64.deb"
  101. [g++-mingw-w64-x86-64,830]="http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-mingw-w64/g++-mingw-w64-x86-64_8.3.0-6ubuntu1+21.1build2_amd64.deb"
  102. [mingw-w64-i686-dev,600]="http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-i686-dev_6.0.0-3_all.deb"
  103. [gcc-mingw-w64-i686,830]="http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-mingw-w64/gcc-mingw-w64-i686_8.3.0-6ubuntu1+21.1build2_amd64.deb"
  104. [g++-mingw-w64-i686,830]="http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-mingw-w64/g++-mingw-w64-i686_8.3.0-6ubuntu1+21.1build2_amd64.deb"
  105. )
  106. # Posix-compliant MingW alternative executables
  107. #
  108. typeset -A alternatives
  109. alternatives=(
  110. [x86_64-w64-mingw32-gcc]="x86_64-w64-mingw32-gcc-posix"
  111. [x86_64-w64-mingw32-g++]="x86_64-w64-mingw32-g++-posix"
  112. [i686-w64-mingw32-gcc]="i686-w64-mingw32-gcc-posix"
  113. [i686-w64-mingw32-g++]="i686-w64-mingw32-g++-posix"
  114. )
  115. # Temporary symbolic links for DXVK compilation
  116. #
  117. typeset -A tempLinks
  118. tempLinks=(
  119. ['/usr/bin/i686-w64-mingw32-gcc']='/usr/bin/i686-w64-mingw32-gcc-posix'
  120. ['/usr/bin/i686-w64-mingw32-g++']='/usr/bin/i686-w64-mingw32-g++-posix'
  121. ['/usr/bin/x86_64-w64-mingw32-gcc']='x86_64-w64-mingw32-gcc-posix'
  122. ['/usr/bin/x86_64-w64-mingw32-g++']='x86_64-w64-mingw32-g++-posix'
  123. )
  124. ########################################################
  125. function runtimeCheck() {
  126. # Friendly name for this package
  127. local pkgreq_name=${1}
  128. # Known package names to check on Debian
  129. local known_pkgs=${2}
  130. # Check if any of these Wine packages are present on the system
  131. i=0
  132. for pkg in ${known_pkgs[@]}; do
  133. if [[ $(echo $(dpkg -s ${pkg} &>/dev/null)$?) -eq 0 ]]; then
  134. local pkglist[$i]=${pkg}
  135. let i++
  136. fi
  137. done
  138. if [[ -z ${pkglist[*]} ]]; then
  139. echo -e "\e[1mWARNING:\e[0m Not installing DXVK because \e[1m${pkgreq_name}\e[0m is missing on your system.\n\
  140. ${pkgreq_name} should be installed in order to use DXVK. Just compiling DXVK for later use.\n"
  141. # Do this check separately so we can warn about all missing runtime dependencies above
  142. if [[ ! -v NO_INSTALL ]]; then
  143. # Force --no-install switch
  144. NO_INSTALL=
  145. fi
  146. fi
  147. }
  148. ########################################################
  149. # If the script is interrupted (Ctrl+C/SIGINT), do the following
  150. function DXVK_intCleanup() {
  151. rm -rf ${DXVKROOT}/{dxvk-git,meson,glslang,*.deb}
  152. rm -rf ${DXVKROOT}/../compiled_deb/"${datedir}"
  153. exit 0
  154. }
  155. # Allow interruption of the script at any time (Ctrl + C)
  156. trap "DXVK_intCleanup" INT
  157. # Error event
  158. #trap "DXVK_intCleanup" ERR
  159. ########################################################
  160. # http://wiki.bash-hackers.org/snipplets/print_horizontal_line#a_line_across_the_entire_width_of_the_terminal
  161. function INFO_SEP() { printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - ; }
  162. ########################################################
  163. # Update all packages if UPDATE_OVERRIDE given
  164. if [[ -v UPDATE_OVERRIDE ]]; then
  165. echo -en "Updating all packages" && \
  166. if [[ $(printf $(sudo -n uptime &>/dev/null)$?) -ne 0 ]]; then printf " Please provide your sudo password.\n"; else printf "\n\n"; fi
  167. sudo apt update && sudo apt upgrade -y
  168. fi
  169. ########################################################
  170. # Check do we need to compile the package
  171. # given as input for this function
  172. function pkgcompilecheck() {
  173. local install_function=${1}
  174. local pkg=${2}
  175. local pkg_data=${3}
  176. if [[ $(echo $(dpkg -s ${pkg} &>/dev/null)$?) -ne 0 ]] || [[ -v UPDATE_OVERRIDE ]]; then
  177. ${install_function} ${pkg_data}
  178. fi
  179. }
  180. ########################################################
  181. # DXVK CUSTOM INSTALLATION HOOKS
  182. # These are custom installation instructions for DXVK
  183. # They are not used independently.
  184. function dxvk_install_custom() {
  185. local PATCHDIR="${1}"
  186. # Use posix alternates for MinGW binaries
  187. function dxvk_posixpkgs() {
  188. for alt in ${!alternatives[@]}; do
  189. echo "Linking MingW executable ${alt} to ${alternatives[$alt]}"
  190. sudo rm -rf /etc/alternatives/"${alt}" 2>/dev/null
  191. sudo ln -sf /usr/bin/"${alternatives[$alt]}" /etc/alternatives/"${alt}"
  192. if [[ $? -ne 0 ]]; then
  193. echo -e "\e[1mERROR:\e[0m Error occured while linking executable ${alt} to ${alternatives[$alt]}. Aborting\n"
  194. exit 1
  195. fi
  196. done
  197. for link in ${!tempLinks[@]}; do
  198. if [[ ! -f ${link} ]]; then
  199. echo "Creating temporary links for MingW executable ${link}"
  200. sudo ln -sf ${tempLinks["${link}"]} "${link}"
  201. if [[ $? -ne 0 ]]; then
  202. echo -e "\e[1mERROR:\e[0m Error occured while linking executable ${link}. Aborting\n"
  203. exit 1
  204. fi
  205. fi
  206. done
  207. }
  208. ############################
  209. # DXVK - CUSTOM PATCHES
  210. # Add and apply custom DXVK patches
  211. function dxvk_custompatches() {
  212. # Get our current directory, since we will change it during patching process below
  213. # We want to go back here after having applied the patches
  214. local CURDIR="${PWD}"
  215. # Check if the following folder exists, and proceed.
  216. if [[ -d "${DXVKROOT}/../../${PATCHDIR}" ]]; then
  217. cp -r "${DXVKROOT}/../../${PATCHDIR}/"*.{patch,diff} "${DXVKROOT}/${pkg_name}/" 2>/dev/null
  218. local dxvk_builddir_name=$(ls -l "${DXVKROOT}/${pkg_name}" | grep ^d | awk '{print $NF}')
  219. # TODO Expecting just one folder here. This method doesn't work with multiple dirs present
  220. if [[ $(echo ${dxvk_builddir_name} | wc -l) -gt 1 ]]; then
  221. echo -e "\e[1mERROR:\e[0m Multiple entries in dxvk build directory detected. Can't decide which one to use. Aborting\n"
  222. exit 1
  223. fi
  224. local dxvk_builddir_path="${DXVKROOT}/${pkg_name}/${dxvk_builddir_name}"
  225. cd "${dxvk_builddir_path}"
  226. for pfile in ../*.{patch,diff}; do
  227. if [[ -f ${pfile} ]]; then
  228. echo -e "Applying DXVK patch: ${pfile}\n"
  229. patch -Np1 < ${pfile}
  230. fi
  231. if [[ $? -ne 0 ]]; then
  232. echo -e "\e[1mERROR:\e[0m Error occured while applying DXVK patch '${pfile}'. Aborting\n"
  233. cd ${CURDIR}
  234. exit 1
  235. fi
  236. done
  237. cd "${CURDIR}"
  238. fi
  239. }
  240. ############################
  241. # DXVK - CUSTOM HOOKS EXECUTION
  242. dxvk_custompatches && \
  243. dxvk_posixpkgs
  244. }
  245. ########################################################
  246. # COMMON - COMPILE AND INSTALL DEB PACKAGE
  247. # Instructions to compile and install a deb package
  248. # on Debian system
  249. # Global variable to track buildtime dependencies
  250. z=0
  251. function compile_and_install_deb() {
  252. ############################
  253. # Set local variables
  254. local _pkg_name="${1}"
  255. local _pkg_license="${2}"
  256. local _pkg_giturl="${3}"
  257. local _pkg_gitbranch="${4}"
  258. local _git_commithash="${5}"
  259. local _pkg_gitver="${6}"
  260. local _pkg_debinstall="${7}"
  261. local _pkg_debcontrol="${8}"
  262. local _pkg_debrules="${9}"
  263. local _pkg_installfile="${10}"
  264. local _pkg_controlfile="${11}"
  265. local _pkg_rulesfile="${12}"
  266. local _pkg_deps_build="${13}"
  267. local _pkg_deps_runtime="${14}"
  268. local _pkg_debbuilder="${15}"
  269. local _pkg_debcompat="${16}"
  270. local _pkg_compatfile="${17}"
  271. ############################
  272. # COMMON - ARRAY PARAMETER FIX
  273. # Separate array indexes correctly
  274. # We have streamed all array indexes, separated
  275. # by | symbol. We reconstruct the arrays here.
  276. function arrayparser_reverse() {
  277. local arrays=(
  278. '_pkg_deps_build'
  279. '_pkg_deps_runtime'
  280. )
  281. for w in ${arrays[@]}; do
  282. local s=\${${w}}
  283. local IFS='|'
  284. local y=0
  285. for t in $(eval printf '%s\|' ${s}); do
  286. eval ${w}[$y]=\"${t}\"
  287. let y++
  288. done
  289. unset IFS
  290. done
  291. }
  292. arrayparser_reverse
  293. ############################
  294. function pkg_installcheck() {
  295. return $(echo $(dpkg -s "${1}" &>/dev/null)$?)
  296. }
  297. ############################
  298. echo -e "Starting compilation$(if [[ ! -v NO_INSTALL ]] || [[ ${_pkg_name} =~ ^meson|glslang$ ]]; then printf " & installation"; fi) of ${_pkg_name}\n"
  299. ############################
  300. # COMMON - PACKAGE DEPENDENCIES CHECK
  301. # Check and install package related dependencies if they are missing
  302. function pkg_dependencies() {
  303. local _pkg_list="${1}"
  304. local _pkg_type="${2}"
  305. local IFS=$'\n'
  306. _pkg_list=$(echo "${_pkg_list}" | sed 's/([^)]*)//g')
  307. unset IFS
  308. case ${_pkg_type} in
  309. buildtime)
  310. local _pkg_type_str="build time"
  311. ;;
  312. runtime)
  313. local _pkg_type_str="runtime"
  314. ;;
  315. esac
  316. if [[ ${_pkg_list[0]} == "empty" ]]; then
  317. return 0
  318. fi
  319. # Generate a list of missing dependencies
  320. local a=0
  321. for p in ${_pkg_list[@]}; do
  322. if [[ $(pkg_installcheck ${p})$? -eq 0 ]]; then
  323. local _validlist[$a]=${p}
  324. let a++
  325. # Global array to track installed build dependencies
  326. if [[ ${_pkg_type} == "buildtime" ]]; then
  327. _buildpkglist[$z]="${p}"
  328. let z++
  329. fi
  330. fi
  331. done
  332. function pkg_remoteinstall() {
  333. sudo apt install -y ${1} &> /dev/null
  334. }
  335. function pkg_localinstall() {
  336. wget ${1} -O ${DXVKROOT}/"${2}".deb
  337. sudo dpkg -i --force-all ${DXVKROOT}/"${2}".deb
  338. }
  339. function pkg_configure() {
  340. if [[ $(sudo dpkg-reconfigure ${1} | grep "is broken or not fully installed") ]]; then
  341. if [[ -v ${2} ]]; then
  342. pkg_localinstall ${2} ${1}
  343. else
  344. pkg_remoteinstall ${1}
  345. fi
  346. fi
  347. }
  348. # Install missing dependencies, be informative
  349. local b=0
  350. for _pkg_dep in ${_validlist[@]}; do
  351. echo -e "$(( $b + 1 ))/$(( ${#_validlist[*]} )) - Installing ${_pkg_name} ${_pkg_type_str} dependency ${_pkg_dep}"
  352. if [[ ${#remotePackagesAlt[@]} -gt 0 ]]; then
  353. for altRemote in ${!remotePackagesAlt[@]}; do
  354. altRemotepkg=$(echo ${altRemote} | awk -F ',' '{print $1}')
  355. altRemotever=$(echo ${altRemote} | awk -F ',' '{print $2}')
  356. if [[ "${_pkg_dep}" == "${altRemotepkg}" ]]; then
  357. if [[ $(pkg_installcheck ${altRemotepkg})$? -ne 0 ]]; then
  358. # TODO remove duplicate functionality
  359. if [[ $(apt-cache show "${altRemotepkg}" | grep -m1 -oP "(?<=^Version: )[0-9|\.]*" | sed 's/\.//g') < ${altRemotever} ]]; then
  360. pkg_localinstall ${remotePackagesAlt["${altRemote}"]} "${altRemotepkg}"
  361. pkg_configure "${altRemotepkg}" ${remotePackagesAlt["${altRemote}"]}
  362. else
  363. pkg_remoteinstall "${altRemotepkg}"
  364. pkg_configure "${altRemotepkg}"
  365. fi
  366. else
  367. if [[ $(dpkg -s "${altRemotepkg}" | grep -m1 -oP "(?<=^Version: )[0-9|\.]*" | sed 's/\.//g') < ${altRemotever} ]]; then
  368. pkg_localinstall ${remotePackagesAlt["${altRemote}"]} "${altRemotepkg}"
  369. pkg_configure "${altRemotepkg}" ${remotePackagesAlt["${altRemote}"]}
  370. else
  371. pkg_remoteinstall "${altRemotepkg}"
  372. pkg_configure "${altRemotepkg}"
  373. fi
  374. fi
  375. fi
  376. done
  377. fi
  378. if [[ $(pkg_installcheck ${_pkg_dep})$? -ne 0 ]]; then
  379. pkg_remoteinstall "${_pkg_dep}"
  380. pkg_configure "${_pkg_dep}"
  381. fi
  382. if [[ $? -eq 0 ]]; then
  383. let b++
  384. else
  385. echo -e "\n\e[1mERROR:\e[0m Error occured while installing ${_pkg_dep}. Aborting.\n"
  386. exit 1
  387. fi
  388. done
  389. if [[ -n ${_validlist[*]} ]]; then
  390. # Add empty newline
  391. echo ""
  392. fi
  393. }
  394. ############################
  395. # COMMON - RETRIEVE PACKAGE
  396. # GIT VERSION TAG
  397. # Get git-based version in order to rename the package main folder
  398. # This is required by deb builder. It retrieves the version number
  399. # from that folder name
  400. function pkg_gitversion() {
  401. if [[ -n "${_pkg_gitver}" ]] && [[ "${_pkg_gitver}" =~ ^git ]]; then
  402. cd ${_pkg_name}
  403. git checkout ${_pkg_gitbranch}
  404. git reset --hard ${_git_commithash}
  405. if [[ $? -ne 0 ]]; then
  406. echo -e "\e[1mERROR:\e[0m Couldn't find commit ${_git_commithash} for ${_pkg_name}. Aborting\n"
  407. exit 1
  408. fi
  409. _pkg_gitver=$(eval "${_pkg_gitver}")
  410. cd ..
  411. fi
  412. }
  413. ############################
  414. # COMMON - OVERWRITE
  415. # DEBIAN BUILD ENV FILES
  416. # Overwrite a file which is given as user input
  417. # The contents are supplied as input, too.
  418. function pkg_override_debianfile() {
  419. local contents=${1}
  420. local targetfile=${2}
  421. if [[ ${contents} != "empty" ]]; then
  422. echo "${contents}" > "${targetfile}"
  423. if [[ $? -ne 0 ]]; then
  424. echo -e "\e[1mERROR:\e[0m Couldn't create Debian file '${targetfile}' for ${_pkg_name}. Aborting\n"
  425. exit 1
  426. fi
  427. fi
  428. }
  429. ############################
  430. # COMMON - GET SOURCE AND
  431. # PREPARE SOURCE FOLDER
  432. function pkg_folderprepare() {
  433. # Remove old build directory, if present
  434. rm -rf ${_pkg_name}
  435. # Create a new build directory, access it and download git sources there
  436. mkdir ${_pkg_name}
  437. cd ${_pkg_name}
  438. echo -e "Retrieving source code of ${_pkg_name} from $(printf ${_pkg_giturl} | sed 's/^.*\/\///; s/\/.*//')\n"
  439. git clone ${_pkg_giturl} ${_pkg_name}
  440. # If sources could be downloaded, rename the folder properly for deb builder
  441. # Access the folder after which package specific debianbuild function will be run
  442. # That function is defined inside package specific install_main function below
  443. if [[ $? -eq 0 ]]; then
  444. pkg_gitversion && \
  445. mv ${_pkg_name} ${_pkg_name}-${_pkg_gitver}
  446. cd ${_pkg_name}-${_pkg_gitver}
  447. dh_make --createorig -s -y -c ${_pkg_license} && \
  448. pkg_override_debianfile "${_pkg_debinstall}" "${_pkg_installfile}"
  449. pkg_override_debianfile "${_pkg_debcontrol}" "${_pkg_controlfile}"
  450. pkg_override_debianfile "${_pkg_debrules}" "${_pkg_rulesfile}"
  451. pkg_override_debianfile "${_pkg_debcompat}" "${_pkg_compatfile}"
  452. else
  453. echo -e "\e[1mERROR:\e[0m Error while downloading source of ${_pkg_name} package. Aborting\n"
  454. exit 1
  455. fi
  456. }
  457. ############################
  458. # COMMON - COMPILE, INSTALL
  459. # AND STORE DEB PACKAGE
  460. function pkg_debianbuild() {
  461. # Start deb builder
  462. bash -c "${_pkg_debbuilder}"
  463. # Once our deb package is compiled, install and store it
  464. # We do not make installation optional for deps because they are required by DXVK
  465. if [[ $? -eq 0 ]]; then
  466. rm -rf ../*.{changes,buildinfo,tar.xz}
  467. if [[ "${_pkg_name}" == *"dxvk"* ]] && [[ ! -v NO_INSTALL ]]; then
  468. sudo dpkg -i ../${_pkg_name}*.deb
  469. elif [[ "${_pkg_name}" != *"dxvk"* ]]; then
  470. sudo dpkg -i ../${_pkg_name}*.deb
  471. fi
  472. mv ../${_pkg_name}*.deb ../../../compiled_deb/"${datedir}" && \
  473. echo -e "Compiled ${_pkg_name} is stored at '$(readlink -f ../../../compiled_deb/"${datedir}")/'\n"
  474. cd ../..
  475. rm -rf {${_pkg_name},*.deb}
  476. else
  477. buildpkg_removal
  478. exit 1
  479. fi
  480. }
  481. ############################
  482. # COMMON - EXECUTION HOOKS
  483. pkg_dependencies "${_pkg_deps_build[*]}" buildtime
  484. if [[ ${_pkg_deps_runtime[0]} != "empty" ]] && [[ ! -v NO_INSTALL ]]; then
  485. pkg_dependencies "${_pkg_deps_runtime[*]}" runtime
  486. fi
  487. pkg_folderprepare
  488. # TODO use package name or separate override switch here?
  489. if [[ "${_pkg_name}" == *"dxvk"* ]]; then
  490. dxvk_install_custom "dxvk_custom_patches"
  491. fi
  492. pkg_debianbuild
  493. unset _pkg_gitver
  494. }
  495. ########################################################
  496. # BUILD DEPENDENCIES REMOVAL
  497. function buildpkg_removal() {
  498. _buildpkglist=($(echo ${_buildpkglist[@]} | tr ' ' '\n' |sort -u | tr '\n' ' '))
  499. for link in ${!tempLinks[@]}; do
  500. if [[ $(file ${link}) == *"symbolic link"* ]]; then
  501. sudo rm -f "${link}"
  502. fi
  503. done
  504. # Build time dependencies which were installed but no longer needed
  505. if [[ -v _buildpkglist ]]; then
  506. if [[ -v BUILDPKG_RM ]]; then
  507. sudo apt purge --remove -y ${_buildpkglist[*]}
  508. # In some cases, glslang or meson may still be present on the system. Remove them
  509. for _extrapkg in glslang meson; do
  510. if [[ $(echo $(dpkg -s ${_extrapkg} &>/dev/null)$?) -eq 0 ]]; then
  511. sudo dpkg --remove --force-remove-reinstreq ${_extrapkg}
  512. fi
  513. done
  514. # Manually obtained deb packages are expected to break system configuration, thus we need to fix it.
  515. sudo apt --fix-broken -y install
  516. else
  517. echo -e "The following build time dependencies were installed and no longer needed:\n\n$(for l in ${_buildpkglist[*]}; do echo -e ${l}; done)\n"
  518. fi
  519. fi
  520. }
  521. ########################################################
  522. # Package installation instructions
  523. function pkg_install_main() {
  524. # Read necessary variables from debdata file
  525. local pkg_datafile=${1}
  526. if [[ -f ${pkg_datafile} ]]; then
  527. source ${pkg_datafile}
  528. else
  529. echo -e "\e[1mERROR:\e[0m Couldn't read datafile '${pkg_datafile}'. Check the file path and try again.\n"
  530. exit 1
  531. fi
  532. ############################
  533. # Prepare these arrays for 'compile_and_install_deb' input
  534. # Separate each array index with | in these arrays
  535. function pkg_arrayparser() {
  536. local pkg_arrays=(
  537. 'pkg_deps_build'
  538. 'pkg_deps_runtime'
  539. )
  540. local IFS=$'\n'
  541. for w in ${pkg_arrays[@]}; do
  542. local s=\${${w}[@]}
  543. local t=$(eval printf '%s\|' ${s})
  544. unset ${w}
  545. eval ${w}=\"${t}\"
  546. done
  547. }
  548. ############################
  549. # Execute package installation procedure
  550. pkg_arrayparser && \
  551. compile_and_install_deb \
  552. "${pkg_name}" \
  553. "${pkg_license}" \
  554. "${pkg_giturl}" \
  555. "${pkg_gitbranch}" \
  556. "${git_commithash}" \
  557. "${pkg_gitver}" \
  558. "${pkg_debinstall}" \
  559. "${pkg_debcontrol}" \
  560. "${pkg_debrules}" \
  561. "${pkg_installfile}" \
  562. "${pkg_controlfile}" \
  563. "${pkg_rulesfile}" \
  564. "${pkg_deps_build}" \
  565. "${pkg_deps_runtime}" \
  566. "${pkg_debbuilder}" \
  567. "${pkg_debcompat}" \
  568. "${pkg_compatfile}"
  569. }
  570. ########################################################
  571. # Check existence of known Wine packages
  572. runtimeCheck Wine "${known_wines[*]}"
  573. # Meson - compile (& install)
  574. pkgcompilecheck pkg_install_main meson "${DXVKROOT}/meson.debdata"
  575. # Glslang - compile (& install)
  576. pkgcompilecheck pkg_install_main glslang "${DXVKROOT}/glslang.debdata"
  577. if [[ ! -v NO_DXVK ]]; then
  578. # DXVK - compile (& install)
  579. pkg_install_main "${DXVKROOT}/dxvk.debdata"
  580. fi
  581. # Clean buildtime dependencies
  582. buildpkg_removal