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.

865 lines
23 KiB

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