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.

904 lines
24 KiB

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