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.

1006 lines
26 KiB

6 years ago
  1. #!/bin/env bash
  2. # Wine/Wine Staging build script for Debian & variants (amd64)
  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. # datedir variable supplied by ../updatewine_debian.sh script file
  21. datedir="${1}"
  22. ########################################################
  23. # The directory this script is running at
  24. BUILDROOT="${PWD}"
  25. ########################################################
  26. # Staging patchsets. Default: all patchsets.
  27. # Applies only if Wine Staging is set to be compiled
  28. # Please see Wine Staging patchinstall.sh file for individual patchset names.
  29. staging_patchsets=(--all)
  30. ########################################################
  31. # Wine build dependency lists on Debian
  32. wine_deps_build_common=(
  33. 'make'
  34. 'gcc-multilib'
  35. 'g++-multilib'
  36. 'libxml-simple-perl'
  37. 'libxml-parser-perl'
  38. 'libxml-libxml-perl'
  39. 'lzma'
  40. 'flex'
  41. 'bison'
  42. 'quilt'
  43. 'gettext'
  44. # 'oss4-dev' # Not available on Debian
  45. 'sharutils'
  46. 'pkg-config'
  47. 'dctrl-tools'
  48. 'khronos-api'
  49. 'unicode-data'
  50. 'freebsd-glue'
  51. 'icoutils'
  52. 'librsvg2-bin'
  53. 'imagemagick'
  54. 'fontforge'
  55. )
  56. wine_deps_build_amd64=(
  57. 'libxi-dev:amd64'
  58. 'libxt-dev:amd64'
  59. 'libxmu-dev:amd64'
  60. 'libx11-dev:amd64'
  61. 'libxext-dev:amd64'
  62. 'libxfixes-dev:amd64'
  63. 'libxrandr-dev:amd64'
  64. 'libxcursor-dev:amd64'
  65. 'libxrender-dev:amd64'
  66. 'libxkbfile-dev:amd64'
  67. 'libxxf86vm-dev:amd64'
  68. 'libxxf86dga-dev:amd64'
  69. 'libxinerama-dev:amd64'
  70. 'libgl1-mesa-dev:amd64'
  71. 'libglu1-mesa-dev:amd64'
  72. 'libxcomposite-dev:amd64'
  73. 'libpng-dev:amd64'
  74. 'libssl-dev:amd64'
  75. 'libv4l-dev:amd64'
  76. 'libxml2-dev:amd64'
  77. 'libgsm1-dev:amd64'
  78. 'libjpeg-dev:amd64'
  79. 'libkrb5-dev:amd64'
  80. 'libtiff-dev:amd64'
  81. 'libsane-dev:amd64'
  82. 'libudev-dev:amd64'
  83. 'libpulse-dev:amd64'
  84. 'liblcms2-dev:amd64'
  85. 'libldap2-dev:amd64'
  86. 'libxslt1-dev:amd64'
  87. 'unixodbc-dev:amd64'
  88. 'libcups2-dev:amd64'
  89. 'libcapi20-dev:amd64'
  90. 'libopenal-dev:amd64'
  91. 'libdbus-1-dev:amd64'
  92. 'freeglut3-dev:amd64'
  93. 'libmpg123-dev:amd64'
  94. 'libasound2-dev:amd64'
  95. 'libgphoto2-dev:amd64'
  96. 'libosmesa6-dev:amd64'
  97. 'libpcap0.8-dev:amd64'
  98. 'libgnutls28-dev:amd64'
  99. 'libncurses5-dev:amd64'
  100. 'libgettextpo-dev:amd64'
  101. 'libfreetype6-dev:amd64'
  102. 'libfontconfig1-dev:amd64'
  103. 'libgstreamer-plugins-base1.0-dev:amd64'
  104. 'ocl-icd-opencl-dev:amd64'
  105. 'libvulkan-dev:amd64'
  106. )
  107. wine_deps_build_i386=(
  108. 'libxi-dev:i386'
  109. 'libxt-dev:i386'
  110. 'libxmu-dev:i386'
  111. 'libx11-dev:i386'
  112. 'libxext-dev:i386'
  113. 'libxfixes-dev:i386'
  114. 'libxrandr-dev:i386'
  115. 'libxcursor-dev:i386'
  116. 'libxrender-dev:i386'
  117. 'libxkbfile-dev:i386'
  118. 'libxxf86vm-dev:i386'
  119. 'libxxf86dga-dev:i386'
  120. 'libxinerama-dev:i386'
  121. 'libgl1-mesa-dev:i386'
  122. 'libglu1-mesa-dev:i386'
  123. 'libxcomposite-dev:i386'
  124. 'libpng-dev:i386'
  125. 'libssl-dev:i386'
  126. 'libv4l-dev:i386'
  127. 'libgsm1-dev:i386'
  128. 'libjpeg-dev:i386'
  129. 'libkrb5-dev:i386'
  130. 'libsane-dev:i386'
  131. 'libudev-dev:i386'
  132. 'libpulse-dev:i386'
  133. 'liblcms2-dev:i386'
  134. 'libldap2-dev:i386'
  135. 'unixodbc-dev:i386'
  136. 'libcapi20-dev:i386'
  137. 'libopenal-dev:i386'
  138. 'libdbus-1-dev:i386'
  139. 'freeglut3-dev:i386'
  140. 'libmpg123-dev:i386'
  141. 'libasound2-dev:i386'
  142. 'libgphoto2-dev:i386'
  143. 'libosmesa6-dev:i386'
  144. 'libpcap0.8-dev:i386'
  145. 'libncurses5-dev:i386'
  146. 'libgettextpo-dev:i386'
  147. 'libfreetype6-dev:i386'
  148. 'libfontconfig1-dev:i386'
  149. 'ocl-icd-opencl-dev:i386'
  150. 'libvulkan-dev:i386'
  151. 'libicu-dev:i386'
  152. 'libxml2-dev:i386'
  153. 'libxslt1-dev:i386'
  154. 'libtiff-dev:i386'
  155. 'libcups2-dev:i386'
  156. 'libgnutls28-dev:i386'
  157. 'gir1.2-gstreamer-1.0:i386' #required by libgstreamer1.0-dev:i386
  158. 'libgstreamer1.0-dev:i386'
  159. 'libgstreamer-plugins-base1.0-dev:i386'
  160. )
  161. ########################################################
  162. # Wine runtime dependency lists on Debian
  163. wine_deps_runtime_common=(
  164. 'desktop-file-utils'
  165. )
  166. wine_deps_runtime_i386=(
  167. 'libxcursor1:i386'
  168. 'libxrandr2:i386'
  169. 'libxi6:i386'
  170. # 'gettext:i386' # Conflicts with amd64 version on multiple distros
  171. 'libsm6:i386'
  172. 'libvulkan1:i386'
  173. 'libasound2:i386'
  174. 'libc6:i386'
  175. 'libfontconfig1:i386'
  176. 'libfreetype6:i386'
  177. 'libgcc1:i386'
  178. 'libglib2.0-0:i386'
  179. 'libgphoto2-6:i386'
  180. 'libgphoto2-port12:i386'
  181. 'liblcms2-2:i386'
  182. 'libldap-2.4-2:i386'
  183. 'libmpg123-0:i386'
  184. 'libncurses5:i386'
  185. 'libopenal1:i386'
  186. 'libpcap0.8:i386'
  187. 'libpulse0:i386'
  188. 'libtinfo5:i386'
  189. 'libudev1:i386'
  190. 'libx11-6:i386'
  191. 'libxext6:i386'
  192. 'libxml2:i386'
  193. 'ocl-icd-libopencl1:i386'
  194. 'zlib1g:i386'
  195. 'libgstreamer-plugins-base1.0-0:i386'
  196. 'libgstreamer1.0-0:i386'
  197. )
  198. wine_deps_runtime_amd64=(
  199. 'fontconfig:amd64'
  200. 'libxcursor1:amd64'
  201. 'libxrandr2:amd64'
  202. 'libxi6:amd64'
  203. 'gettext:amd64'
  204. 'libsm6:amd64'
  205. 'libvulkan1:amd64'
  206. 'libasound2:amd64'
  207. 'libc6:amd64'
  208. 'libfontconfig1:amd64'
  209. 'libfreetype6:amd64'
  210. 'libgcc1:amd64'
  211. 'libglib2.0-0:amd64'
  212. 'libgphoto2-6:amd64'
  213. 'libgphoto2-port12:amd64'
  214. 'liblcms2-2:amd64'
  215. 'libldap-2.4-2:amd64'
  216. 'libmpg123-0:amd64'
  217. 'libncurses5:amd64'
  218. 'libopenal1:amd64'
  219. 'libpcap0.8:amd64'
  220. 'libpulse0:amd64'
  221. 'libtinfo5:amd64'
  222. 'libudev1:amd64'
  223. 'libx11-6:amd64'
  224. 'libxext6:amd64'
  225. 'libxml2:amd64'
  226. 'ocl-icd-libopencl1:amd64'
  227. 'zlib1g:amd64'
  228. 'libgstreamer-plugins-base1.0-0:amd64'
  229. 'libgstreamer1.0-0:amd64'
  230. )
  231. ########################################################
  232. # Wine staging override list
  233. # Wine Staging replaces and conflicts with these packages
  234. # Applies to debian/control file
  235. wine_overr_pkgs=(
  236. 'wine'
  237. 'wine-development'
  238. 'wine64-development'
  239. 'wine1.6'
  240. 'wine1.6-i386'
  241. 'wine1.6-amd64'
  242. 'libwine:amd64'
  243. 'libwine:i386'
  244. 'wine-stable'
  245. 'wine32'
  246. 'wine64'
  247. 'fonts-wine'
  248. )
  249. ############################
  250. # Suggests section in debian/control file
  251. wine_suggested_pkgs=(
  252. 'winbind'
  253. 'winetricks'
  254. 'playonlinux'
  255. 'wine-binfmt'
  256. 'dosbox'
  257. )
  258. ############################
  259. # Package name and website
  260. if [[ ! -v NO_STAGING ]]; then
  261. pkgname="wine-staging-git"
  262. else
  263. pkgname="wine-git"
  264. fi
  265. pkgurl="https://www.winehq.org"
  266. ########################################################
  267. # Architecture check. We do not support independent
  268. # i386 environments
  269. if [[ $(uname -a | grep -c x86_64) -eq 0 ]]; then
  270. echo "\e[1mERROR:\e[0m This script supports 64-bit architectures only."
  271. exit 1
  272. fi
  273. ########################################################
  274. # Divide input args into array indexes
  275. i=0
  276. for p in ${@:2}; do
  277. params[$i]=${p}
  278. let i++
  279. done
  280. ########################################################
  281. # Parse input git override hashes
  282. # This order is mandatory!
  283. # If you change the order or contents of 'githash_overrides'
  284. # array in ../updatewine.sh, make sure to update these
  285. # variables!
  286. #
  287. git_commithash_wine=${params[3]}
  288. ########################################################
  289. # Parse input arguments, filter user parameters
  290. # The range is defined in ../updatewine.sh
  291. # All input arguments are:
  292. # <datedir> 4*<githash_override> <args>
  293. # 0 1 2 3 4 5 ...
  294. # Filter all but <args>, i.e. the first 0-4 arguments
  295. i=0
  296. for arg in ${params[@]:4}; do
  297. args[$i]="${arg}"
  298. let i++
  299. done
  300. for check in ${args[@]}; do
  301. case ${check} in
  302. --no-staging)
  303. NO_STAGING=
  304. ;;
  305. --no-install)
  306. NO_INSTALL=
  307. ;;
  308. --buildpkg-rm)
  309. BUILDPKG_RM=
  310. ;;
  311. esac
  312. done
  313. ########################################################
  314. # If the script is interrupted (Ctrl+C/SIGINT), do the following
  315. function Wine_intCleanup() {
  316. cd "${BUILDROOT}"
  317. rm -rf "winebuild_${datedir}"
  318. exit 0
  319. }
  320. # Allow interruption of the script at any time (Ctrl + C)
  321. trap "Wine_intCleanup" INT
  322. ########################################################
  323. # This is specifically for Debian
  324. # Must be done in order to install Wine i386 buildtime dependencies on amd64 environment
  325. #
  326. if [[ $(dpkg --print-foreign-architectures | grep i386 | wc -w) -eq 0 ]]; then
  327. sudo dpkg --add-architecture i386
  328. sudo apt update
  329. fi
  330. ########################################################
  331. # If user has gstreamer girl (amd64) package installed on the system
  332. # before Wine compilation, then reinstall it after the compilation process
  333. #
  334. function girl_check() {
  335. girlpkg="gir1.2-gstreamer-1.0:amd64"
  336. if [[ $(echo $(dpkg -s ${girlpkg} &>/dev/null)$?) -eq 0 ]]; then
  337. GIRL_CHECK=
  338. fi
  339. }
  340. ########################################################
  341. function getWine() {
  342. local winesrc_url="git://source.winehq.org/git/wine.git"
  343. local winestagingsrc_url="git://github.com/wine-staging/wine-staging.git"
  344. function cleanOldBuilds() {
  345. if [[ $(find "${BUILDROOT}" -type d -name "winebuild_*" | wc -l) -ne 0 ]]; then
  346. echo -e "Removing old Wine build folders. This can take a while.\n"
  347. rm -rf "${BUILDROOT}"/winebuild_*
  348. fi
  349. }
  350. cleanOldBuilds
  351. ##########
  352. mkdir "${BUILDROOT}/winebuild_${datedir}"
  353. cd "${BUILDROOT}/winebuild_${datedir}"
  354. WINEROOT="${PWD}"
  355. ##########
  356. echo -e "Retrieving source code of Wine$(if [[ ! -v NO_STAGING ]]; then echo ' & Wine Staging' ; fi)\n"
  357. git clone ${winesrc_url}
  358. if [[ ! -v NO_STAGING ]]; then
  359. git clone ${winestagingsrc_url}
  360. WINEDIR_STAGING="${WINEROOT}/wine-staging"
  361. fi
  362. ##########
  363. mkdir wine-{patches,32-build,32-install,64-build,64-install,package}
  364. cp -r ../../../wine_custom_patches/*.{patch,diff} wine-patches/ 2>/dev/null
  365. WINEDIR="${WINEROOT}/wine"
  366. WINEDIR_PATCHES="${WINEROOT}/wine-patches"
  367. WINEDIR_BUILD_32="${WINEROOT}/wine-32-build"
  368. WINEDIR_BUILD_64="${WINEROOT}/wine-64-build"
  369. WINEDIR_INSTALL_32="${WINEROOT}/wine-32-install"
  370. WINEDIR_INSTALL_64="${WINEROOT}/wine-64-install"
  371. WINEDIR_PACKAGE="${WINEROOT}/wine-package"
  372. }
  373. function getDebianFiles() {
  374. local debian_archive=wine_3.0-1ubuntu1.debian.tar.xz
  375. cd "${WINEDIR}"
  376. wget http://archive.ubuntu.com/ubuntu/pool/universe/w/wine/${debian_archive}
  377. tar xvf ${debian_archive}
  378. rm ${debian_archive}
  379. }
  380. ########################################################
  381. # Parse Wine hash override if Staging is set to be installed
  382. function check_gitOverride() {
  383. # If staging is to be installed and Wine git is frozen to a specific commit
  384. # We need to determine exact commit to use for Wine Staging
  385. # to avoid any mismatches
  386. #
  387. # Basically, when user has defined 'git_commithash_wine' variable (commit), we
  388. # iterate through Wine commits and try to determine previously set
  389. # Wine Staging commit. We use that Wine Staging commit instead of
  390. # the one user has defined in 'git_commithash_wine' variable
  391. #
  392. if [[ ! -v NO_STAGING ]] && [[ "${git_commithash_wine}" != HEAD ]]; then
  393. function form_commit_array() {
  394. cd "${commit_dir}"
  395. if [[ $? -ne 0 ]]; then
  396. echo -e "\e[1mERROR:\e[0m Couldn't access Wine folder ${commit_dir} to check commits. Aborting\n"
  397. exit 1
  398. fi
  399. local array_name=${1}
  400. local commits_raw=$(eval ${2})
  401. local i=0
  402. for commit in ${commits_raw[*]}; do
  403. eval ${array_name}[$i]="${commit}"
  404. let i++
  405. done
  406. if [[ $? -ne 0 ]]; then
  407. echo -e "\e[1mERROR:\e[0m Couldn't parse Wine commits in ${commit_dir}. Aborting\n"
  408. exit 1
  409. fi
  410. cd "${WINEROOT}"
  411. }
  412. function staging_change_freeze_commit() {
  413. local wine_commits_raw="git log --pretty=oneline | awk '{print \$1}' | tr '\n' ' '"
  414. # TODO this check may break quite easily
  415. # It depends on the exact comment syntax Wine Staging developers are using (Rebase against ...)
  416. # Length and order of these two "array" variables MUST MATCH!
  417. local staging_refcommits_raw="git log --pretty=oneline | awk '{ if ((length(\$NF)==40 || length(\$NF)==41) && \$(NF-1)==\"against\") print \$1; }'"
  418. local staging_rebasecommits_raw="git log --pretty=oneline | awk '{ if ((length(\$NF)==40 || length(\$NF)==41) && \$(NF-1)==\"against\") print substr(\$NF,1,40); }' | tr '\n' ' '"
  419. # Syntax: <function> <array_name> <raw_commit_list>
  420. commit_dir="${WINEDIR}"
  421. form_commit_array wine_commits "${wine_commits_raw}"
  422. commit_dir="${WINEDIR_STAGING}"
  423. form_commit_array staging_refcommits "${staging_refcommits_raw}"
  424. form_commit_array staging_rebasecommits "${staging_rebasecommits_raw}"
  425. # User has selected vanilla Wine commit to freeze to
  426. # We must get the previous Staging commit from rebase_commits array, and
  427. # change git_commithash_wine value to that
  428. # Get all vanilla Wine commits
  429. # Filter all newer than defined in 'git_commithash_wine'
  430. #
  431. echo -e "Determining valid Wine Staging git commit. This takes a while.\n"
  432. local i=0
  433. for dropcommit in ${wine_commits[@]}; do
  434. if [[ "${dropcommit}" == "${git_commithash_wine}" ]]; then
  435. break
  436. else
  437. local wine_dropcommits[$i]="${dropcommit}"
  438. let i++
  439. fi
  440. done
  441. wine_commits=("${wine_commits[@]:${#wine_dropcommits[*]}}")
  442. # For the filtered array list, iterate through 'staging_rebasecommits' array list until
  443. # we get a match
  444. for vanilla_commit in ${wine_commits[@]}; do
  445. local k=0
  446. for rebase_commit in ${staging_rebasecommits[@]}; do
  447. if [[ "${vanilla_commit}" == "${rebase_commit}" ]]; then
  448. # This is the commit we use for vanilla Wine
  449. git_commithash_wine="${vanilla_commit}"
  450. # This is equal commit we use for Wine Staging
  451. git_commithash_winestaging="${staging_refcommits[$k]}"
  452. break 2
  453. fi
  454. let k++
  455. done
  456. done
  457. }
  458. elif [[ ! -v NO_STAGING ]] && [[ "${git_commithash_wine}" == HEAD ]]; then
  459. git_commithash_winestaging=HEAD
  460. fi
  461. staging_change_freeze_commit
  462. }
  463. ########################################################
  464. # Wine dependencies removal/installation
  465. # Global variable to track buildtime dependencies
  466. z=0
  467. function WineDeps() {
  468. local method=${1}
  469. local deps="${2}"
  470. local depsname=${3}
  471. local pkgtype=${4}
  472. case ${method} in
  473. install)
  474. local str="Installing"
  475. local mgrcmd="sudo apt install -y"
  476. ;;
  477. remove)
  478. local str="Removing"
  479. local mgrcmd="sudo apt purge --remove -y"
  480. ;;
  481. *)
  482. echo -e "\e[1mERROR:\e[0m Unknown package management input method. Aborting\n"
  483. exit 1
  484. esac
  485. echo -e "${str} Wine dependencies (${depsname}).\n"
  486. # Check and install/remove package related dependencies if they are missing/installed
  487. function pkgdependencies() {
  488. local deplist="${1}"
  489. # Get a valid logic for generating 'list' array below
  490. case ${method} in
  491. install)
  492. # Package is not installed, install it
  493. local checkstatus=0
  494. ;;
  495. remove)
  496. # Package is installed, remove it
  497. local checkstatus=1
  498. ;;
  499. esac
  500. # Generate a list of missing/removable dependencies, depending on the logic
  501. local a=0
  502. for p in ${deplist[@]}; do
  503. if [[ $(echo $(dpkg -s ${p} &>/dev/null)$?) -ne ${checkstatus} ]]; then
  504. local validlist[$a]=${p}
  505. let a++
  506. # Global array to track installed build dependencies
  507. if [[ ${method} == "install" ]] && [[ ${pkgtype} == "buildtime" ]]; then
  508. buildpkglist[$z]=${p}
  509. let z++
  510. fi
  511. fi
  512. done
  513. # Install missing/Remove existing dependencies, be informative
  514. local b=0
  515. for pkgdep in ${validlist[@]}; do
  516. echo -e "$(( $b + 1 ))/$(( ${#validlist[*]} )) - ${str} ${depsname} dependency ${pkgdep}"
  517. eval ${mgrcmd} ${pkgdep} &> /dev/null
  518. if [[ $? -eq 0 ]]; then
  519. let b++
  520. else
  521. echo -e "\n\e[1mERROR:\e[0m Error occured while processing ${pkgdep}. Aborting.\n"
  522. exit 1
  523. fi
  524. done
  525. if [[ -n ${validlist[*]} ]]; then
  526. # Add empty newline
  527. echo ""
  528. fi
  529. }
  530. pkgdependencies "${deps[*]}"
  531. }
  532. ########################################################
  533. # Feed the following data to Wine debian/control file
  534. # If we separate i386 build to be an independent one, this function
  535. # must be improved, if built with amd64 package together
  536. # If we just bundle them together, single package description for
  537. # debian/control file is enough
  538. function feed_debiancontrol() {
  539. cat << CONTROLFILE > debian/control
  540. Source: ${pkgname}
  541. Section: otherosfs
  542. Priority: optional
  543. Maintainer: ${USER} <${USER}@unknown>
  544. Build-Depends: debhelper (>=9), $(echo "${wine_deps_build[*]}" | sed 's/\s/, /g')
  545. Standards-Version: 4.1.2
  546. Homepage: ${pkgurl}
  547. Package: ${pkgname}
  548. Architecture: any
  549. Depends: $(echo ${wine_deps_runtime[*]} | sed 's/\s/, /g')
  550. Suggests: $(echo ${wine_suggested_pkgs[*]} | sed 's/\s/, /g')
  551. Conflicts: $(echo ${wine_overr_pkgs[*]} | sed 's/\s/, /g')
  552. Breaks: $(echo ${wine_overr_pkgs[*]} | sed 's/\s/, /g')
  553. Replaces: $(echo ${wine_overr_pkgs[*]} | sed 's/\s/, /g')
  554. Provides: $(echo ${wine_overr_pkgs[*]} | sed 's/\s/, /g')
  555. Description: A compatibility layer for running Windows programs.
  556. Wine is an open source Microsoft Windows API implementation for
  557. POSIX-compliant operating systems, including Linux.
  558. Git version includes the latest updates available for Wine.
  559. CONTROLFILE
  560. }
  561. ########################################################
  562. # Refresh Wine GIT
  563. function refreshWineGIT() {
  564. # Restore the wine tree to its git origin state, without wine-staging patches
  565. # (necessary for reapllying wine-staging patches in succedent builds,
  566. # otherwise the patches will fail to be reapplied)
  567. cd "${WINEDIR}"
  568. git reset --hard ${git_commithash_wine} # Get Wine commit
  569. if [[ $? -ne 0 ]]; then
  570. echo "\e[1mERROR:\e[0m Couldn't find git commit '${git_commithash_wine}' for Wine. Aborting\n"
  571. exit 1
  572. fi
  573. git clean -d -x -f # Delete untracked files
  574. if [[ ! -v NO_STAGING ]]; then
  575. if [[ ${git_commithash_wine} == HEAD ]]; then
  576. # Change back to the wine upstream commit that this version of wine-staging is based on
  577. git checkout $(bash "${WINEDIR_STAGING}"/patches/patchinstall.sh --upstream-commit)
  578. else
  579. cd "${WINEDIR_STAGING}"
  580. git reset --hard ${git_commithash_winestaging}
  581. if [[ $? -ne 0 ]]; then
  582. echo "\e[1mERROR:\e[0m Couldn't find git commit '${git_commithash_winestaging}' for Wine Staging. Aborting\n"
  583. exit 1
  584. fi
  585. fi
  586. fi
  587. }
  588. ########################################################
  589. # Get Wine version tag
  590. function wine_version() {
  591. cd "${WINEDIR}"
  592. git describe | sed 's/^[a-z]*-//; s/-[0-9]*-[a-z0-9]*$//'
  593. }
  594. ########################################################
  595. # Apply patches
  596. function patchWineSource() {
  597. if [[ ! -v NO_STAGING ]]; then
  598. bash "${WINEDIR_STAGING}/patches/patchinstall.sh" DESTDIR="${WINEDIR}" ${staging_patchsets[*]}
  599. fi
  600. cp -r ${WINEROOT}/../../../wine_custom_patches/* "${WINEDIR_PATCHES}/"
  601. if [[ $(find "${WINEDIR_PATCHES}" -mindepth 1 -maxdepth 1 -regex ".*\.\(patch\|diff\)$") ]]; then
  602. cd "${WINEDIR}"
  603. for i in "${WINEDIR_PATCHES}"/*.{patch,diff}; do
  604. patch -Np1 < $i
  605. done
  606. fi
  607. }
  608. ########################################################
  609. # 64-bit build
  610. function wine64Build() {
  611. cd "${WINEDIR_BUILD_64}"
  612. "${WINEDIR}"/configure \
  613. --with-x \
  614. --with-gstreamer \
  615. --enable-win64 \
  616. --with-xattr \
  617. --disable-mscoree \
  618. --with-vulkan \
  619. --prefix=/usr \
  620. --libdir=/usr/lib/x86_64-linux-gnu/
  621. make -j$(nproc --ignore 1)
  622. make -j$(nproc --ignore 1) prefix="${WINEDIR_INSTALL_64}/usr" \
  623. libdir="${WINEDIR_INSTALL_64}/usr/lib/x86_64-linux-gnu/" \
  624. dlldir="${WINEDIR_INSTALL_64}/usr/lib/x86_64-linux-gnu/wine" install
  625. }
  626. # 32-bit build
  627. function wine32Build() {
  628. cd "${WINEDIR_BUILD_32}"
  629. "${WINEDIR}"/configure \
  630. --with-x \
  631. --with-gstreamer \
  632. --with-xattr \
  633. --disable-mscoree \
  634. --with-vulkan \
  635. --libdir=/usr/lib/i386-linux-gnu/ \
  636. --with-wine64="${WINEDIR_BUILD_64}" \
  637. --prefix=/usr
  638. make -j$(nproc --ignore 1)
  639. make -j$(nproc --ignore 1) prefix="${WINEDIR_INSTALL_32}/usr" \
  640. libdir="${WINEDIR_INSTALL_32}/usr/lib/i386-linux-gnu/" \
  641. dlldir="${WINEDIR_INSTALL_32}/usr/lib/i386-linux-gnu/wine" install
  642. }
  643. ########################################################
  644. # Merge compiled files, build Debian archive
  645. # Prepare compiled Wine for dpkg-buildpackage
  646. function mergeWineBuilds() {
  647. cp -r "${WINEDIR_INSTALL_64}"/* "${WINEDIR_PACKAGE}"/
  648. cp -r "${WINEDIR_INSTALL_32}"/usr/bin/{wine,wine-preloader} "${WINEDIR_PACKAGE}"/usr/bin/
  649. cp -r "${WINEDIR_INSTALL_32}"/usr/lib/* "${WINEDIR_PACKAGE}"/usr/lib/
  650. }
  651. ############################
  652. # Trigger Wine compilation process
  653. # Create a new deb package
  654. function buildDebianArchive() {
  655. cd "${WINEROOT}"
  656. mv "${WINEDIR_PACKAGE}" "${WINEROOT}/${pkgname}-$(wine_version)"
  657. cd "${WINEROOT}/${pkgname}-$(wine_version)"
  658. dh_make --createorig -s -y -c lgpl
  659. rm debian/*.{ex,EX}
  660. printf "usr/* /usr" > debian/install
  661. feed_debiancontrol
  662. # Start compilation process
  663. DEB_BUILD_OPTIONS="strip nodocs noddebs" dpkg-buildpackage -b -us -uc
  664. }
  665. ############################
  666. # Install created deb package
  667. function installDebianArchive() {
  668. cd "${WINEROOT}"
  669. # TODO Although the package name ends with 'amd64', this contains both 32 and 64 bit Wine versions
  670. echo -e "\nInstalling Wine$(if [[ ! -v NO_STAGING ]]; then printf " Staging"; fi).\n"
  671. sudo dpkg -i ${pkgname}_$(wine_version)-1_amd64.deb
  672. }
  673. ############################
  674. # Store deb package for later use
  675. function storeDebianArchive() {
  676. cd "${WINEROOT}"
  677. mv ${pkgname}_$(wine_version)-1_amd64.deb ../../compiled_deb/"${datedir}" && \
  678. echo -e "Compiled ${pkgname} is stored at '$(readlink -f ../../compiled_deb/"${datedir}")/'\n"
  679. rm -rf winebuild_${datedir}
  680. }
  681. ############################
  682. # Clean temporary build files
  683. function cleanTree() {
  684. rm -rf "${WINEROOT}"
  685. }
  686. ########################################################
  687. # Check presence of Wine if compiled deb is going to be installed
  688. # This function is not relevant if --no-install switch is used
  689. function wineCheck() {
  690. # Known Wine package names to check on Debian
  691. local known_wines=(
  692. 'wine'
  693. 'wine32'
  694. 'wine64'
  695. 'wine-git'
  696. 'wine-staging-git'
  697. 'libwine:amd64'
  698. 'libwine:i386'
  699. 'fonts-wine'
  700. )
  701. # Check if any of these Wine packages are present on the system
  702. for winepkg in ${known_wines[@]}; do
  703. if [[ $(echo $(dpkg -s ${winepkg} &>/dev/null)$?) -eq 0 ]]; then
  704. sudo apt purge --remove -y ${winepkg}
  705. fi
  706. done
  707. }
  708. ########################################################
  709. # Check existence of gstreamer girl package before further operations
  710. girl_check
  711. ############################
  712. # Get Wine (& Wine-Staging) sources
  713. getWine
  714. ############################
  715. # Check whether we need to update possible hash override
  716. check_gitOverride
  717. ############################
  718. # Refresh & sync Wine (+ Wine Staging) git sources
  719. refreshWineGIT
  720. # Update Wine source files
  721. patchWineSource
  722. # Get Wine/Wine Staging version
  723. getWineVersion
  724. ########################################################
  725. # Compile 64 & 32 bit Wine/Wine Staging
  726. # WE MUST BUILD 64-BIT FIRST, THEN 32-BIT. THIS ORDER IS MANDATORY!
  727. # We split 64-bit & 32-bit compilation due to two major reasons:
  728. # - pure Debian has major conflicts between 32/64 bit dev packages
  729. # - on Mint/Ubuntu, some 32-bit dev packages must be excluded due to conflicts, too
  730. ##########################
  731. # Install Wine common buildtime dependencies
  732. WineDeps install "${wine_deps_build_common[*]}" "Wine common build time" buildtime
  733. ##########################
  734. # TODO If we do architecture separation in the future, add if check for amd64 here
  735. # Condition would be: if amd64, then
  736. #
  737. # Purge i386 buildtime dependencies
  738. # On Debian, we can't have them with i386 at the same time
  739. #
  740. echo -e "Preparing system for 64-bit Wine compilation.\n"
  741. WineDeps remove "${wine_deps_build_i386[*]}" "Wine build time (32-bit)" buildtime
  742. WineDeps install "${wine_deps_build_amd64[*]}" "Wine build time (64-bit)" buildtime
  743. wine64Build && \
  744. echo -e "\nWine 64-bit build process finished.\n"
  745. ##########################
  746. # TODO If we do architecture separation in the future, add if check for i386 here
  747. # Condition would be: if i386 or amd64, then
  748. #
  749. # Purge amd64 buildtime dependencies
  750. # On Debian, we can't have them with i386 at the same time
  751. #
  752. echo -e "Preparing system for 32-bit Wine compilation.\n"
  753. WineDeps remove "${wine_deps_build_amd64[*]}" "Wine build time (64-bit)" buildtime
  754. WineDeps install "${wine_deps_build_i386[*]}" "Wine build time (32-bit)" buildtime
  755. wine32Build &&
  756. echo -e "\nWine 32-bit build process finished.\n"
  757. ############################
  758. # Remove i386 buildtime dependencies after successful compilation process
  759. WineDeps remove "${wine_deps_build_i386[*]}" "Wine build time (32-bit)" buildtime
  760. ############################
  761. # i386/amd64 runtime dependencies have been tested and they are able to co-exist on Debian system
  762. if [[ ! -v NO_INSTALL ]]; then
  763. # Install Wine common runtime dependencies
  764. WineDeps install "${wine_deps_runtime_common[*]}" "Wine common runtime" runtime
  765. # Install architecture-dependent Wine runtime dependencies
  766. WineDeps install "${wine_deps_runtime_amd64[*]}" "Wine runtime (64-bit)" runtime
  767. WineDeps install "${wine_deps_runtime_i386[*]}" "Wine runtime (32-bit)" runtime
  768. # Check presence of already installed Wine packages and remove them
  769. wineCheck
  770. fi
  771. ############################
  772. # Build time dependencies which were installed but no longer needed
  773. if [[ -v buildpkglist ]]; then
  774. if [[ -v BUILDPKG_RM ]]; then
  775. sudo apt purge --remove -y ${buildpkglist[*]}
  776. else
  777. echo -e "The following build time dependencies were installed and no longer required:\n\n$(for l in ${buildpkglist[*]}; do echo -e ${l}; done)\n"
  778. fi
  779. fi
  780. ############################
  781. if [[ -v GIRL_CHECK ]]; then
  782. sudo apt install -y ${girlpkg}
  783. fi
  784. ########################################################
  785. # Bundle compiled Wine/Wine-Staging files
  786. mergeWineBuilds
  787. # Bundle and install Debian deb archive
  788. buildDebianArchive
  789. if [[ ! -v NO_INSTALL ]]; then
  790. installDebianArchive
  791. fi
  792. storeDebianArchive
  793. # Clean all temporary files
  794. cleanTree