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.

1090 lines
27 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. # 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. ########################################################
  42. # Parse input arguments, filter user parameters
  43. # The range is defined in ../updatewine.sh
  44. # All input arguments are:
  45. # <datedir> 4*<githash_override> <args>
  46. # 0 1 2 3 4 5 ...
  47. # Filter all but <args>, i.e. the first 0-4 arguments
  48. i=0
  49. for arg in ${params[@]:4}; do
  50. args[$i]="${arg}"
  51. let i++
  52. done
  53. for check in ${args[@]}; do
  54. case ${check} in
  55. --no-install)
  56. NO_INSTALL=
  57. ;;
  58. # --no-winetricks)
  59. # NO_WINETRICKS=
  60. # ;;
  61. --updateoverride)
  62. UPDATE_OVERRIDE=
  63. ;;
  64. --buildpkg-rm)
  65. BUILDPKG_RM=
  66. ;;
  67. esac
  68. done
  69. ########################################################
  70. # Check presence of Wine. Some version of Wine should
  71. # be found in the system in order to install DXVK.
  72. known_wines=(
  73. 'wine'
  74. 'wine-stable'
  75. 'wine32'
  76. 'wine64'
  77. 'libwine:amd64'
  78. 'libwine:i386'
  79. 'wine-git'
  80. 'wine-staging-git'
  81. )
  82. known_winetricks=(
  83. 'winetricks'
  84. )
  85. function runtimeCheck() {
  86. # Friendly name for this package
  87. local pkgreq_name=${1}
  88. # Known package names to check on Debian
  89. local known_pkgs=${2}
  90. # Check if any of these Wine packages are present on the system
  91. i=0
  92. for pkg in ${known_pkgs[@]}; do
  93. if [[ $(echo $(dpkg -s ${pkg} &>/dev/null)$?) -eq 0 ]]; then
  94. local pkglist[$i]=${pkg}
  95. let i++
  96. fi
  97. done
  98. if [[ -z ${pkglist[*]} ]]; then
  99. echo -e "\e[1mWARNING:\e[0m Not installing DXVK because \e[1m${pkgreq_name}\e[0m is missing on your system.\n\
  100. ${pkgreq_name} should be installed in order to use DXVK. Just compiling DXVK for later use.\n"
  101. # Do this check separately so we can warn about all missing runtime dependencies above
  102. if [[ ! -v NO_INSTALL ]]; then
  103. # Force --no-install switch
  104. NO_INSTALL=
  105. fi
  106. fi
  107. }
  108. # Check existence of known Wine packages
  109. runtimeCheck Wine "${known_wines[*]}"
  110. # Check existence of known Winetricks packages
  111. runtimeCheck Winetricks "${known_winetricks[*]}"
  112. ########################################################
  113. # If the script is interrupted (Ctrl+C/SIGINT), do the following
  114. function DXVK_intCleanup() {
  115. rm -rf ${DXVKROOT}/{dxvk-git,meson,glslang}
  116. rm -rf ${DXVKROOT}/../compiled_deb/"${datedir}"
  117. exit 0
  118. }
  119. # Allow interruption of the script at any time (Ctrl + C)
  120. trap "DXVK_intCleanup" INT
  121. ########################################################
  122. # http://wiki.bash-hackers.org/snipplets/print_horizontal_line#a_line_across_the_entire_width_of_the_terminal
  123. function INFO_SEP() { printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - ; }
  124. ########################################################
  125. # Update all packages if UPDATE_OVERRIDE given
  126. if [[ -v UPDATE_OVERRIDE ]]; then
  127. echo -en "Updating all packages" && \
  128. if [[ $(printf $(sudo -n uptime &>/dev/null)$?) -ne 0 ]]; then printf " Please provide your sudo password.\n"; else printf "\n\n"; fi
  129. sudo apt update && sudo apt upgrade -y
  130. fi
  131. ########################################################
  132. # Check do we need to compile the package
  133. # given as input for this function
  134. function pkgcompilecheck() {
  135. local pkg=${1}
  136. local install_function=${2}
  137. if [[ $(echo $(dpkg -s ${pkg} &>/dev/null)$?) -ne 0 ]] || [[ -v UPDATE_OVERRIDE ]]; then
  138. ${install_function}
  139. fi
  140. }
  141. ########################################################
  142. # Global variable to track buildtime dependencies
  143. z=0
  144. function preparepackage() {
  145. ############################
  146. # Set local variables
  147. local _pkg_name=${1}
  148. local _pkg_license=${2}
  149. local _pkg_maintainer=${3}
  150. local _pkg_section=${4}
  151. local _pkg_priority=${5}
  152. local _pkg_arch=${6}
  153. local _pkg_commondesc=${7}
  154. local _pkg_longdesc=${8}
  155. local _pkg_giturl=${9}
  156. local _pkg_homeurl=${10}
  157. local _git_commithash=${11}
  158. local _pkg_gitver=${12}
  159. local _pkg_controlfile=${13}
  160. local _pkg_rulesfile=${14}
  161. local _pkg_rules_override=${15}
  162. local _pkg_suggests=${16}
  163. local _pkg_overrides=${17}
  164. local _pkg_deps_build=${18}
  165. local _pkg_deps_runtime=${19}
  166. local _pkg_extra_1=${20}
  167. local _pkg_extra_2=${21}
  168. local _pkg_debbuilder=${22}
  169. ############################
  170. # Separate array indexes correctly
  171. # We have streamed all array indexes, separated
  172. # by | symbol. We reconstruct the arrays here.
  173. function arrayparser_reverse() {
  174. local arrays=(
  175. '_pkg_suggests'
  176. '_pkg_overrides'
  177. '_pkg_deps_build'
  178. '_pkg_deps_runtime'
  179. '_pkg_extra_1'
  180. '_pkg_extra_2'
  181. )
  182. for w in ${arrays[@]}; do
  183. local s=\${${w}}
  184. local IFS='|'
  185. local y=0
  186. for t in $(eval printf '%s\|' ${s}); do
  187. eval ${w}[$y]=\"${t}\"
  188. let y++
  189. done
  190. unset IFS
  191. done
  192. }
  193. arrayparser_reverse
  194. ############################
  195. echo -e "Starting compilation$(if [[ ! -v NO_INSTALL ]] || [[ ${_pkg_name} =~ ^meson|glslang$ ]]; then printf " & installation"; fi) of ${_pkg_name}\n"
  196. ############################
  197. # Check and install package related dependencies if they are missing
  198. function pkg_dependencies() {
  199. local _pkg_list="${1}"
  200. local _pkg_type="${2}"
  201. local IFS=$'\n'
  202. case ${_pkg_type} in
  203. buildtime)
  204. local _pkg_type_str="build time"
  205. ;;
  206. runtime)
  207. local _pkg_type_str="runtime"
  208. ;;
  209. esac
  210. if [[ ${_pkg_list[0]} == "empty" ]]; then
  211. return 0
  212. fi
  213. # Generate a list of missing dependencies
  214. local a=0
  215. for p in ${_pkg_list[@]}; do
  216. local p=$(printf '%s' ${p} | awk '{print $1}')
  217. if [[ $(echo $(dpkg -s ${p} &>/dev/null)$?) -ne 0 ]]; then
  218. local _validlist[$a]=${p}
  219. let a++
  220. # Global array to track installed build dependencies
  221. if [[ ${_pkg_type} == "buildtime" ]]; then
  222. _buildpkglist[$z]=${p}
  223. let z++
  224. fi
  225. fi
  226. done
  227. # Install missing dependencies, be informative
  228. local b=0
  229. for _pkg_dep in ${_validlist[@]}; do
  230. echo -e "$(( $b + 1 ))/$(( ${#_validlist[*]} )) - Installing ${_pkg_name} ${_pkg_type_str} dependency ${_pkg_dep}"
  231. sudo apt install -y ${_pkg_dep} &> /dev/null
  232. if [[ $? -eq 0 ]]; then
  233. let b++
  234. else
  235. echo -e "\n\e[1mERROR:\e[0m Error occured while installing ${_pkg_dep}. Aborting.\n"
  236. exit 1
  237. fi
  238. done
  239. if [[ -n ${_validlist[*]} ]]; then
  240. # Add empty newline
  241. echo ""
  242. fi
  243. }
  244. ############################
  245. # Get git-based version in order to rename the package main folder
  246. # This is required by deb builder. It retrieves the version number
  247. # from that folder name
  248. function pkg_gitversion() {
  249. if [[ -n "${_pkg_gitver}" ]] && [[ "${_pkg_gitver}" =~ ^git ]]; then
  250. cd ${_pkg_name}
  251. git reset --hard ${_git_commithash}
  252. if [[ $? -ne 0 ]]; then
  253. echo -e "\e[1mERROR:\e[0m Couldn't find commit ${_git_commithash} for ${_pkg_name}. Aborting\n"
  254. exit 1
  255. fi
  256. _pkg_gitver=$(eval "${_pkg_gitver}")
  257. cd ..
  258. fi
  259. }
  260. ############################
  261. # TODO HANDLE EMPTY LINES CORRECTLY
  262. function pkg_feed_debiancontrol() {
  263. # For correct array index handling
  264. local IFS=$'\n'
  265. cat << CONTROLFILE > "${_pkg_controlfile}"
  266. Source: ${_pkg_name}
  267. Section: ${_pkg_section}
  268. Priority: ${_pkg_priority}
  269. Maintainer: ${_pkg_maintainer}
  270. Build-Depends: debhelper (>=9), $(if [[ ${_pkg_deps_build[0]} != "empty" ]]; then \
  271. for w in ${_pkg_deps_build[@]}; do printf '%s, ' ${w}; done; fi)
  272. Standards-Version: 4.1.3
  273. Homepage: ${_pkg_homeurl}
  274. $(if [[ ${_pkg_extra_1[0]} != "empty" ]]; then for w in ${_pkg_extra_1[@]}; do echo ${w}; done ; fi)
  275. Package: ${_pkg_name}
  276. Architecture: ${_pkg_arch}
  277. Depends: \${shlibs:Depends}, \${misc:Depends}, $(if [[ ${_pkg_deps_runtime[0]} != "empty" ]]; then \
  278. for w in ${_pkg_deps_runtime[@]}; do printf '%s, ' ${w}; done; fi)
  279. Description: ${_pkg_commondesc}
  280. $(echo -e ${_pkg_longdesc} | sed 's/^/ /g; s/\n/\n /g')
  281. $(if [[ ${_pkg_extra_2[0]} != "empty" ]]; then for w in ${_pkg_extra_2[@]}; do echo ${w}; done ; fi)
  282. $(if [[ ${_pkg_suggests[0]} != "empty" ]]; then echo "Suggests: $(echo ${_pkg_suggests[*]} | sed 's/\s/, /g')"; fi)
  283. $(if [[ ${_pkg_overrides[0]} != "empty" ]]; then echo "Conflicts: $(echo ${_pkg_overrides[*]} | sed 's/\s/, /g')"; fi)
  284. $(if [[ ${_pkg_overrides[0]} != "empty" ]]; then echo "Breaks: $(echo ${_pkg_overrides[*]} | sed 's/\s/, /g')"; fi)
  285. $(if [[ ${_pkg_overrides[0]} != "empty" ]]; then echo "Replaces: $(echo ${_pkg_overrides[*]} | sed 's/\s/, /g')"; fi)
  286. $(if [[ ${_pkg_overrides[0]} != "empty" ]]; then echo "Provides: $(echo ${_pkg_overrides[*]} | sed 's/\s/, /g')"; fi)
  287. CONTROLFILE
  288. if [[ ! -f "${_pkg_controlfile}" ]]; then
  289. echo -e "\e[1mERROR:\e[0m Couldn't create Debian control file for ${_pkg_name}. Aborting\n"
  290. exit 1
  291. fi
  292. }
  293. ############################
  294. function pkg_override_debianrules() {
  295. if [[ $(echo ${_pkg_rules_override} | wc -w) -ne 0 ]]; then
  296. echo "${_pkg_rules_override}" > "${_pkg_rulesfile}"
  297. if [[ $? -ne 0 ]]; then
  298. echo "\e[1mERROR:\e[0m Couldn't create Debian rules file for ${_pkg_name}. Aborting\n"
  299. exit 1
  300. fi
  301. fi
  302. }
  303. ############################
  304. function pkg_folderprepare() {
  305. # Remove old build directory, if present
  306. rm -rf ${_pkg_name}
  307. # Create a new build directory, access it and download git sources there
  308. mkdir ${_pkg_name}
  309. cd ${_pkg_name}
  310. echo -e "Retrieving source code of ${_pkg_name} from $(printf ${_pkg_giturl} | sed 's/^.*\/\///; s/\/.*//')\n"
  311. git clone ${_pkg_giturl} ${_pkg_name}
  312. # If sources could be downloaded, rename the folder properly for deb builder
  313. # Access the folder after which package specific debianbuild function will be run
  314. # That function is defined inside package specific install_main function below
  315. if [[ $? -eq 0 ]]; then
  316. pkg_gitversion && \
  317. mv ${_pkg_name} ${_pkg_name}-${_pkg_gitver}
  318. cd ${_pkg_name}-${_pkg_gitver}
  319. dh_make --createorig -s -y -c ${_pkg_license} && \
  320. pkg_feed_debiancontrol
  321. pkg_override_debianrules
  322. else
  323. echo -e "\e[1mERROR:\e[0m Error while downloading source of ${_pkg_name} package. Aborting\n"
  324. exit 1
  325. fi
  326. }
  327. ############################
  328. function pkg_debianbuild() {
  329. # Start deb builder
  330. bash -c "${_pkg_debbuilder}"
  331. # Once our deb package is compiled, install and store it
  332. # We do not make installation optional because this is a core dependency for DXVK
  333. if [[ $? -eq 0 ]]; then
  334. rm -rf ../*.{changes,buildinfo,tar.xz} && \
  335. sudo dpkg -i ../${_pkg_name}*.deb && \
  336. mv ../${_pkg_name}*.deb ../../../compiled_deb/"${datedir}" && \
  337. echo -e "Compiled ${_pkg_name} is stored at '$(readlink -f ../../../compiled_deb/"${datedir}")/'\n"
  338. cd ../..
  339. rm -rf ${_pkg_name}
  340. else
  341. exit 1
  342. fi
  343. }
  344. ############################
  345. # Execute above functions
  346. pkg_dependencies "${_pkg_deps_build[*]}" buildtime && \
  347. if [[ ${_pkg_deps_runtime[0]} != "empty" ]] && [[ ! -v NO_INSTALL ]]; then pkg_dependencies "${_pkg_deps_runtime[*]}" runtime ; fi
  348. pkg_folderprepare
  349. # TODO use package name or separate override switch here?
  350. if [[ ${_pkg_name} != "dxvk-git" ]]; then
  351. pkg_debianbuild
  352. fi
  353. unset _pkg_gitver
  354. }
  355. ########################################################
  356. # BUILD DEPENDENCIES REMOVAL
  357. function buildpkg_removal() {
  358. # Build time dependencies which were installed but no longer needed
  359. if [[ -v _buildpkglist ]]; then
  360. if [[ -v BUILDPKG_RM ]]; then
  361. sudo apt purge --remove -y ${_buildpkglist[*]}
  362. # In some cases, glslang or meson may still be present on the system. Remove them
  363. for _extrapkg in glslang meson; do
  364. if [[ $(echo $(dpkg -s ${_extrapkg} &>/dev/null)$?) -eq 0 ]]; then
  365. sudo apt purge --remove -y ${_extrapkg}
  366. fi
  367. done
  368. else
  369. 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"
  370. fi
  371. fi
  372. }
  373. ########################################################
  374. ########################################################
  375. ########################################################
  376. # MESON COMPILATION & INSTALLATION
  377. # Required by DXVK package
  378. function meson_install_main() {
  379. # Package name
  380. local pkg_name="meson"
  381. local pkg_license="apache"
  382. local pkg_maintainer="${USER} <${USER}@unknown>"
  383. local pkg_section="devel"
  384. local pkg_priority="optional"
  385. local pkg_arch="all"
  386. local pkg_commondesc="high-productivity build system"
  387. local pkg_longdesc="
  388. Meson is a build system designed to increase programmer\n\
  389. productivity. It does this by providing a fast, simple and easy to\n\
  390. use interface for modern software development tools and practices.
  391. "
  392. local pkg_giturl="https://github.com/mesonbuild/meson"
  393. local pkg_homeurl="http://mesonbuild.com"
  394. local git_commithash=${git_commithash_meson}
  395. local pkg_gitver="git describe --long | sed 's/\-[a-z].*//; s/\-/\./; s/[a-z]//g'"
  396. local pkg_controlfile="./debian/control"
  397. local pkg_rulesfile="./debian/rules"
  398. ##############
  399. # MESON - Debian rules file override
  400. local pkg_rules_override="\
  401. #!/usr/bin/make -f
  402. # Original script by Jussi Pakkanen
  403. export MESON_PRINT_TEST_OUTPUT=1
  404. export QT_SELECT=qt5
  405. export LC_ALL=C.UTF-8
  406. %:
  407. dh \$@ --with python3 --buildsystem=pybuild
  408. override_dh_auto_configure:
  409. override_dh_auto_build:
  410. override_dh_auto_test:
  411. override_dh_clean:
  412. dh_clean
  413. rm -f *.pyc
  414. rm -rf __pycache__
  415. rm -rf mesonbuild/__pycache__
  416. rm -rf mesonbuild/*/__pycache__
  417. rm -rf work\ area
  418. rm -rf install\ dir/*
  419. rm -f meson-test-run.txt meson-test-run.xml
  420. rm -rf meson.egg-info
  421. rm -rf build
  422. rm -rf .pybuild
  423. override_dh_install:
  424. # Helper script to autogenerate cross files.
  425. python3 setup.py install --root=\$\$(pwd)/debian/meson --prefix=/usr --install-layout=deb --install-lib=/usr/share/meson --install-scripts=/usr/share/meson
  426. rm -rf \$\$(pwd)/debian/meson/usr/share/meson/mesonbuild/__pycache__
  427. rm -rf \$\$(pwd)/debian/meson/usr/share/meson/mesonbuild/*/__pycache__
  428. rm \$\$(pwd)/debian/meson/usr/bin/meson
  429. ln -s ../share/meson/meson \$\$(pwd)/debian/meson/usr/bin/meson
  430. "
  431. ##############
  432. # MESON
  433. # Debian control file Suggests section
  434. local pkg_suggests=(
  435. empty
  436. )
  437. # Debian control file override etc. sections
  438. local pkg_overrides=(
  439. empty
  440. )
  441. # Build time dependencies
  442. local pkg_deps_build=(
  443. 'python3 (>= 3.5)'
  444. 'dh-python'
  445. 'python3-setuptools'
  446. 'ninja-build (>= 1.6)'
  447. )
  448. # Runtime dependencies
  449. local pkg_deps_runtime=(
  450. 'ninja-build (>=1.6)'
  451. 'python3'
  452. )
  453. # Extra fields for Debian control file Source section
  454. local pkg_extra_1=(
  455. 'X-Python3-Version: >= 3.5'
  456. )
  457. # Extra fields for Debian control file Package section
  458. local pkg_extra_2=(
  459. empty
  460. )
  461. ############################
  462. # MESON
  463. # Deb builder execution field
  464. # Do not build either debug symbols or doc files
  465. local pkg_debbuilder="DEB_BUILD_OPTIONS=\"strip nodocs noddebs nocheck\" dpkg-buildpackage -rfakeroot -b -us -uc"
  466. ############################
  467. # MESON
  468. # Prepare these arrays for preparepackage input
  469. # Separate each array index with | in these arrays
  470. function arrayparser() {
  471. local arrays=(
  472. 'pkg_suggests'
  473. 'pkg_overrides'
  474. 'pkg_deps_build'
  475. 'pkg_deps_runtime'
  476. 'pkg_extra_1'
  477. 'pkg_extra_2'
  478. )
  479. for w in ${arrays[@]}; do
  480. local s=\${${w}[@]}
  481. local t=$(eval printf '%s\|' ${s})
  482. unset ${w}
  483. eval ${w}=\"${t}\"
  484. done
  485. }
  486. ############################
  487. # MESON
  488. # Execute above functions
  489. arrayparser && \
  490. preparepackage \
  491. "${pkg_name}" \
  492. "${pkg_license}" \
  493. "${pkg_maintainer}" \
  494. "${pkg_section}" \
  495. "${pkg_priority}" \
  496. "${pkg_arch}" \
  497. "${pkg_commondesc}" \
  498. "${pkg_longdesc}" \
  499. "${pkg_giturl}" \
  500. "${pkg_homeurl}" \
  501. "${git_commithash}" \
  502. "${pkg_gitver}" \
  503. "${pkg_controlfile}" \
  504. "${pkg_rulesfile}" \
  505. "${pkg_rules_override}" \
  506. "${pkg_suggests}" \
  507. "${pkg_overrides}" \
  508. "${pkg_deps_build}" \
  509. "${pkg_deps_runtime}" \
  510. "${pkg_extra_1}" \
  511. "${pkg_extra_2}" \
  512. "${pkg_debbuilder}"
  513. }
  514. ########################################################
  515. # GLSLANG COMPILATION & INSTALLATION
  516. # Required by DXVK package
  517. function glslang_install_main() {
  518. # Package name
  519. local pkg_name="glslang"
  520. local pkg_license="bsd"
  521. local pkg_maintainer="${USER} <${USER}@unknown>"
  522. local pkg_section="devel"
  523. local pkg_priority="optional"
  524. local pkg_arch="all"
  525. local pkg_commondesc="Khronos OpenGL and OpenGL ES shader front end and validator."
  526. local pkg_longdesc="
  527. Khronos reference front-end for GLSL and ESSL, and sample SPIR-V generator
  528. "
  529. local pkg_giturl="https://github.com/KhronosGroup/glslang"
  530. local pkg_homeurl="https://www.khronos.org/opengles/sdk/tools/Reference-Compiler/"
  531. local git_commithash=${git_commithash_glslang}
  532. local pkg_gitver="git describe --long | sed 's/\-[a-z].*//; s/\-/\./; s/[a-z]//g'"
  533. local pkg_controlfile="./debian/control"
  534. local pkg_rulesfile="./debian/rules"
  535. ##############
  536. # GLSLANG - Debian rules file override
  537. local pkgrules_override="
  538. #!/usr/bin/make -f
  539. %:
  540. dh $@
  541. override_dh_usrlocal:
  542. "
  543. ##############
  544. # GLSLANG
  545. # Debian control file Suggests section
  546. local pkg_suggests=(
  547. empty
  548. )
  549. # Debian control file override etc. sections
  550. local pkg_overrides=(
  551. empty
  552. )
  553. # Build time dependencies
  554. local pkg_deps_build=(
  555. #${_coredeps[*]}
  556. 'cmake'
  557. 'python2.7'
  558. )
  559. # Runtime dependencies
  560. local pkg_deps_runtime=(
  561. empty
  562. )
  563. # Extra fields for Debian control file Source section
  564. local pkg_extra_1=(
  565. empty
  566. )
  567. # Extra fields for Debian control file Package section
  568. local pkg_extra_2=(
  569. empty
  570. )
  571. ############################
  572. # GLSLANG
  573. # Deb builder execution field
  574. # Do not build either debug symbols
  575. local pkg_debbuilder="DEB_BUILD_OPTIONS=\"strip nodocs noddebs\" dpkg-buildpackage -rfakeroot -b -us -uc"
  576. ############################
  577. # GLSLANG
  578. # Prepare these arrays for preparepackage input
  579. # Separate each array index with | in these arrays
  580. function arrayparser() {
  581. local arrays=(
  582. 'pkg_suggests'
  583. 'pkg_overrides'
  584. 'pkg_deps_build'
  585. 'pkg_deps_runtime'
  586. 'pkg_extra_1'
  587. 'pkg_extra_2'
  588. )
  589. for w in ${arrays[@]}; do
  590. local s=\${${w}[@]}
  591. local t=$(eval printf '%s\|' ${s})
  592. unset ${w}
  593. eval ${w}=\"${t}\"
  594. done
  595. }
  596. ############################
  597. # GLSLANG
  598. # Execute above functions
  599. arrayparser && \
  600. preparepackage \
  601. "${pkg_name}" \
  602. "${pkg_license}" \
  603. "${pkg_maintainer}" \
  604. "${pkg_section}" \
  605. "${pkg_priority}" \
  606. "${pkg_arch}" \
  607. "${pkg_commondesc}" \
  608. "${pkg_longdesc}" \
  609. "${pkg_giturl}" \
  610. "${pkg_homeurl}" \
  611. "${git_commithash}" \
  612. "${pkg_gitver}" \
  613. "${pkg_controlfile}" \
  614. "${pkg_rulesfile}" \
  615. "${pkg_rules_override}" \
  616. "${pkg_suggests}" \
  617. "${pkg_overrides}" \
  618. "${pkg_deps_build}" \
  619. "${pkg_deps_runtime}" \
  620. "${pkg_extra_1}" \
  621. "${pkg_extra_2}" \
  622. "${pkg_debbuilder}"
  623. }
  624. ########################################################
  625. # DXVK COMPILATION & INSTALLATION
  626. function dxvk_install_main() {
  627. # Package name
  628. local pkg_name="dxvk-git"
  629. local pkg_license="custom --copyrightfile ../LICENSE"
  630. local pkg_maintainer="${USER} <${USER}@unknown>"
  631. local pkg_section="otherosfs"
  632. local pkg_priority="optional"
  633. local pkg_arch="all"
  634. local pkg_commondesc="Vulkan-based D3D11 and D3D10 implementation for Linux / Wine"
  635. local pkg_longdesc="
  636. A Vulkan-based translation layer for Direct3D 10/11 which
  637. allows running 3D applications on Linux using Wine.
  638. "
  639. local pkg_giturl="https://github.com/doitsujin/dxvk"
  640. local pkg_homeurl="https://github.com/doitsujin/dxvk"
  641. local git_commithash=${git_commithash_dxvk}
  642. local pkg_gitver="git describe --long | sed 's/\-[a-z].*//; s/\-/\./; s/[a-z]//g'"
  643. local pkg_controlfile="./debian/control"
  644. local pkg_rulesfile="./debian/rules"
  645. ##############
  646. # DXVK - Debian rules file override
  647. local pkg_rules_override="\
  648. #!/usr/bin/make -f
  649. %:
  650. dh \$@
  651. override_dh_auto_configure:
  652. override_dh_usrlocal:
  653. "
  654. ##############
  655. # DXVK
  656. # Debian control file Suggests section
  657. local pkg_suggests=(
  658. empty
  659. )
  660. # Debian control file override etc. sections
  661. local pkg_overrides=(
  662. empty
  663. )
  664. # Build time dependencies
  665. local pkg_deps_build=(
  666. #${_coredeps[*]}
  667. 'meson'
  668. 'glslang'
  669. 'gcc-mingw-w64-x86-64'
  670. 'gcc-mingw-w64-i686'
  671. 'g++-mingw-w64-x86-64'
  672. 'g++-mingw-w64-i686'
  673. 'mingw-w64-x86-64-dev'
  674. 'mingw-w64-i686-dev'
  675. )
  676. # Runtime dependencies
  677. local pkg_deps_runtime=(
  678. 'wine'
  679. 'winetricks'
  680. )
  681. # Extra fields for Debian control file Source section
  682. local pkg_extra_1=(
  683. empty
  684. )
  685. # Extra fields for Debian control file Package section
  686. local pkg_extra_2=(
  687. empty
  688. )
  689. ############################
  690. # DXVK
  691. # Prepare these arrays for preparepackage input
  692. # Separate each array index with | in these arrays
  693. function arrayparser() {
  694. local arrays=(
  695. 'pkg_suggests'
  696. 'pkg_overrides'
  697. 'pkg_deps_build'
  698. 'pkg_deps_runtime'
  699. 'pkg_extra_1'
  700. 'pkg_extra_2'
  701. )
  702. for w in ${arrays[@]}; do
  703. local s=\${${w}[@]}
  704. local t=$(eval printf '%s\|' ${s})
  705. unset ${w}
  706. eval ${w}=\"${t}\"
  707. done
  708. }
  709. ############################
  710. # DXVK
  711. # Use posix alternates for MinGW binaries
  712. function dxvk_posixpkgs() {
  713. local packages=(
  714. 'i686-w64-mingw32-g++'
  715. 'i686-w64-mingw32-gcc'
  716. 'x86_64-w64-mingw32-g++'
  717. 'x86_64-w64-mingw32-gcc'
  718. )
  719. for package in "${packages[@]}"; do
  720. local option=$(echo "" | sudo update-alternatives --config "${package}" | grep posix | sed 's@^[^0-9]*\([0-9]\+\).*@\1@')
  721. echo "${option}" | sudo update-alternatives --config "${package}" &> /dev/null
  722. if [[ $? -ne 0 ]]; then
  723. echo -e "\e[1mERROR:\e[0m Error occured while running 'update-alternatives' for '${package}'. Aborting\n"
  724. exit 1
  725. fi
  726. done
  727. }
  728. ############################
  729. # DXVK
  730. # Add and apply custom DXVK patches
  731. function dxvk_custompatches() {
  732. # Get our current directory, since we will change it during patching process below
  733. # We want to go back here after having applied the patches
  734. local CURDIR="${PWD}"
  735. # Check if the following folder exists, and proceed.
  736. if [[ -d "${DXVKROOT}/../../dxvk_custom_patches" ]]; then
  737. cp -r "${DXVKROOT}/../../dxvk_custom_patches/"*.{patch,diff} "${DXVKROOT}/${pkg_name}/" 2>/dev/null
  738. local dxvk_builddir_name=$(ls -l "${DXVKROOT}/${pkg_name}" | grep ^d | awk '{print $NF}')
  739. # TODO Expecting just one folder here. This method doesn't work with multiple dirs present
  740. if [[ $(echo ${dxvk_builddir_name} | wc -l) -gt 1 ]]; then
  741. echo "\e[1mERROR:\e[0m Multiple entries in dxvk build directory detected. Can't decide which one to use. Aborting\n"
  742. exit 1
  743. fi
  744. local dxvk_builddir_path="${DXVKROOT}/${pkg_name}/${dxvk_builddir_name}"
  745. cd "${dxvk_builddir_path}"
  746. for pfile in ../*.{patch,diff}; do
  747. if [[ -f ${pfile} ]]; then
  748. echo -e "Applying DXVK patch: ${pfile}\n"
  749. patch -Np1 < ${pfile}
  750. fi
  751. if [[ $? -ne 0 ]]; then
  752. echo -e "\e[1mERROR:\e[0m Error occured while applying DXVK patch '${pfile}'. Aborting\n"
  753. cd ${CURDIR}
  754. exit 1
  755. fi
  756. done
  757. cd "${CURDIR}"
  758. fi
  759. }
  760. ############################
  761. # DXVK
  762. # Debian-specific compilation & installation rules for DXVK
  763. function dxvk_custom_deb_build() {
  764. local dxvx_relative_builddir="debian/source/dxvk-master"
  765. # Tell deb builder to bundle these files
  766. printf "${dxvx_relative_builddir}/setup_dxvk.verb usr/share/dxvk/" > debian/install
  767. printf "\n${dxvx_relative_builddir}/bin/* usr/bin/" >> debian/install
  768. # Start DXVK compilation
  769. bash ./package-release.sh master debian/source/ --no-package
  770. if [[ $? -ne 0 ]]; then
  771. echo -e "\e[1mERROR:\e[0m Error while compiling ${pkg_name}. Check messages above. Aborting\n"
  772. buildpkg_removal
  773. exit 1
  774. fi
  775. # Make a proper executable script for setup_dxvk.verb file
  776. mkdir -p ${dxvx_relative_builddir}/bin
  777. echo -e "#!/bin/sh\nwinetricks --force /usr/share/dxvk/setup_dxvk.verb" \
  778. > "${dxvx_relative_builddir}/bin/setup_dxvk"
  779. chmod +x "${dxvx_relative_builddir}/bin/setup_dxvk"
  780. # Tell deb builder to install DXVK x32 & x64 subfolders
  781. for arch in 64 32; do
  782. mkdir -p ${dxvx_relative_builddir}/x${arch}
  783. printf "\n${dxvx_relative_builddir}/x${arch}/* usr/share/dxvk/x${arch}/" >> debian/install
  784. done
  785. # Start deb builder. Do not build either debug symbols or doc files
  786. DEB_BUILD_OPTIONS="strip nodocs noddebs" dpkg-buildpackage -us -uc -b --source-option=--include-binaries
  787. # Once compiled, possibly install and store the compiled deb archive
  788. if [[ $? -eq 0 ]]; then
  789. if [[ ! -v NO_INSTALL ]]; then
  790. sudo dpkg -i ../${pkgname}*.deb
  791. fi
  792. rm -rf ../*.{changes,buildinfo,tar.xz}
  793. mv ../${pkg_name}*.deb ../../../compiled_deb/"${datedir}" && \
  794. echo -e "Compiled ${pkg_name} is stored at '$(readlink -f ../../../compiled_deb/"${datedir}")/'\n"
  795. cd ../..
  796. rm -rf ${pkg_name}
  797. else
  798. exit 1
  799. fi
  800. }
  801. ############################
  802. # DXVK
  803. # Execute above functions
  804. # Do not check runtime dependencies as our check method expects exact package name in
  805. # function 'preparepackage'. This does not apply to runtime dependency 'wine', which
  806. # may be 'wine', 'wine-git', 'wine-staging-git' etc. in truth
  807. #
  808. arrayparser && \
  809. preparepackage \
  810. "${pkg_name}" \
  811. "${pkg_license}" \
  812. "${pkg_maintainer}" \
  813. "${pkg_section}" \
  814. "${pkg_priority}" \
  815. "${pkg_arch}" \
  816. "${pkg_commondesc}" \
  817. "${pkg_longdesc}" \
  818. "${pkg_giturl}" \
  819. "${pkg_homeurl}" \
  820. "${git_commithash}" \
  821. "${pkg_gitver}" \
  822. "${pkg_controlfile}" \
  823. "${pkg_rulesfile}" \
  824. "${pkg_rules_override}" \
  825. "${pkg_suggests[*]}" \
  826. "${pkg_overrides[*]}" \
  827. "${pkg_deps_build[*]}" \
  828. "${pkg_deps_runtime[*]}" \
  829. "${pkg_extra_1[*]}" \
  830. "${pkg_extra_2[*]}" \
  831. "${pkg_debbuilder}" && \
  832. \
  833. dxvk_custompatches && \
  834. dxvk_posixpkgs && \
  835. dxvk_custom_deb_build
  836. }
  837. ########################################################
  838. pkgcompilecheck meson meson_install_main
  839. pkgcompilecheck glslang glslang_install_main
  840. dxvk_install_main
  841. buildpkg_removal