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.

1012 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. git_branch_wine=${params[7]}
  289. ########################################################
  290. # Parse input arguments, filter user parameters
  291. # The range is defined in ../updatewine.sh
  292. # All input arguments are:
  293. # <datedir> 4*<githash_override> 4*<gitbranch_override> <args>
  294. # 0 1 2 3 4 5 6 7 8 9...
  295. # Filter all but <args>, i.e. the first 0-8 arguments
  296. i=0
  297. for arg in ${params[@]:8}; do
  298. args[$i]="${arg}"
  299. let i++
  300. done
  301. for check in ${args[@]}; do
  302. case ${check} in
  303. --no-staging)
  304. NO_STAGING=
  305. ;;
  306. --no-install)
  307. NO_INSTALL=
  308. ;;
  309. --buildpkg-rm)
  310. BUILDPKG_RM=
  311. ;;
  312. esac
  313. done
  314. ########################################################
  315. # If the script is interrupted (Ctrl+C/SIGINT), do the following
  316. function Wine_intCleanup() {
  317. cd "${BUILDROOT}"
  318. rm -rf "winebuild_${datedir}"
  319. exit 0
  320. }
  321. # Allow interruption of the script at any time (Ctrl + C)
  322. trap "Wine_intCleanup" INT
  323. ########################################################
  324. # This is specifically for Debian
  325. # Must be done in order to install Wine i386 buildtime dependencies on amd64 environment
  326. #
  327. if [[ $(dpkg --print-foreign-architectures | grep i386 | wc -w) -eq 0 ]]; then
  328. sudo dpkg --add-architecture i386
  329. sudo apt update
  330. fi
  331. ########################################################
  332. # If user has gstreamer girl (amd64) package installed on the system
  333. # before Wine compilation, then reinstall it after the compilation process
  334. #
  335. function girl_check() {
  336. girlpkg="gir1.2-gstreamer-1.0:amd64"
  337. if [[ $(echo $(dpkg -s ${girlpkg} &>/dev/null)$?) -eq 0 ]]; then
  338. GIRL_CHECK=
  339. fi
  340. }
  341. ########################################################
  342. function getWine() {
  343. local winesrc_url="git://source.winehq.org/git/wine.git"
  344. local winestagingsrc_url="git://github.com/wine-staging/wine-staging.git"
  345. function cleanOldBuilds() {
  346. if [[ $(find "${BUILDROOT}" -type d -name "winebuild_*" | wc -l) -ne 0 ]]; then
  347. echo -e "Removing old Wine build folders. This can take a while.\n"
  348. rm -rf "${BUILDROOT}"/winebuild_*
  349. fi
  350. }
  351. cleanOldBuilds
  352. ##########
  353. mkdir "${BUILDROOT}/winebuild_${datedir}"
  354. cd "${BUILDROOT}/winebuild_${datedir}"
  355. WINEROOT="${PWD}"
  356. ##########
  357. echo -e "Retrieving source code of Wine$(if [[ ! -v NO_STAGING ]]; then echo ' & Wine Staging' ; fi)\n"
  358. git clone ${winesrc_url}
  359. if [[ ! -v NO_STAGING ]]; then
  360. git clone ${winestagingsrc_url}
  361. WINEDIR_STAGING="${WINEROOT}/wine-staging"
  362. fi
  363. ##########
  364. mkdir wine-{patches,32-build,32-install,64-build,64-install,package}
  365. cp -r ../../../wine_custom_patches/*.{patch,diff} wine-patches/ 2>/dev/null
  366. WINEDIR="${WINEROOT}/wine"
  367. WINEDIR_PATCHES="${WINEROOT}/wine-patches"
  368. WINEDIR_BUILD_32="${WINEROOT}/wine-32-build"
  369. WINEDIR_BUILD_64="${WINEROOT}/wine-64-build"
  370. WINEDIR_INSTALL_32="${WINEROOT}/wine-32-install"
  371. WINEDIR_INSTALL_64="${WINEROOT}/wine-64-install"
  372. WINEDIR_PACKAGE="${WINEROOT}/wine-package"
  373. }
  374. function getDebianFiles() {
  375. local debian_archive=wine_3.0-1ubuntu1.debian.tar.xz
  376. cd "${WINEDIR}"
  377. wget http://archive.ubuntu.com/ubuntu/pool/universe/w/wine/${debian_archive}
  378. tar xvf ${debian_archive}
  379. rm ${debian_archive}
  380. }
  381. ########################################################
  382. # Parse Wine hash override if Staging is set to be installed
  383. function check_gitOverride() {
  384. # If staging is to be installed and Wine git is frozen to a specific commit
  385. # We need to determine exact commit to use for Wine Staging
  386. # to avoid any mismatches
  387. #
  388. # Basically, when user has defined 'git_commithash_wine' variable (commit), we
  389. # iterate through Wine commits and try to determine previously set
  390. # Wine Staging commit. We use that Wine Staging commit instead of
  391. # the one user has defined in 'git_commithash_wine' variable
  392. #
  393. if [[ ! -v NO_STAGING ]] && [[ "${git_commithash_wine}" != HEAD ]]; then
  394. function form_commit_array() {
  395. cd "${commit_dir}"
  396. if [[ $? -ne 0 ]]; then
  397. echo -e "\e[1mERROR:\e[0m Couldn't access Wine folder ${commit_dir} to check commits. Aborting\n"
  398. exit 1
  399. fi
  400. local array_name=${1}
  401. local commits_raw=$(eval ${2})
  402. local i=0
  403. for commit in ${commits_raw[*]}; do
  404. eval ${array_name}[$i]="${commit}"
  405. let i++
  406. done
  407. if [[ $? -ne 0 ]]; then
  408. echo -e "\e[1mERROR:\e[0m Couldn't parse Wine commits in ${commit_dir}. Aborting\n"
  409. exit 1
  410. fi
  411. cd "${WINEROOT}"
  412. }
  413. function staging_change_freeze_commit() {
  414. local wine_commits_raw="git log --pretty=oneline | awk '{print \$1}' | tr '\n' ' '"
  415. # TODO this check may break quite easily
  416. # It depends on the exact comment syntax Wine Staging developers are using (Rebase against ...)
  417. # Length and order of these two "array" variables MUST MATCH!
  418. local staging_refcommits_raw="git log --pretty=oneline | awk '{ if ((length(\$NF)==40 || length(\$NF)==41) && \$(NF-1)==\"against\") print \$1; }'"
  419. 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' ' '"
  420. # Syntax: <function> <array_name> <raw_commit_list>
  421. commit_dir="${WINEDIR}"
  422. form_commit_array wine_commits "${wine_commits_raw}"
  423. commit_dir="${WINEDIR_STAGING}"
  424. form_commit_array staging_refcommits "${staging_refcommits_raw}"
  425. form_commit_array staging_rebasecommits "${staging_rebasecommits_raw}"
  426. # User has selected vanilla Wine commit to freeze to
  427. # We must get the previous Staging commit from rebase_commits array, and
  428. # change git_commithash_wine value to that
  429. # Get all vanilla Wine commits
  430. # Filter all newer than defined in 'git_commithash_wine'
  431. #
  432. echo -e "Determining valid Wine Staging git commit. This takes a while.\n"
  433. local i=0
  434. for dropcommit in ${wine_commits[@]}; do
  435. if [[ "${dropcommit}" == "${git_commithash_wine}" ]]; then
  436. break
  437. else
  438. local wine_dropcommits[$i]="${dropcommit}"
  439. let i++
  440. fi
  441. done
  442. wine_commits=("${wine_commits[@]:${#wine_dropcommits[*]}}")
  443. # For the filtered array list, iterate through 'staging_rebasecommits' array list until
  444. # we get a match
  445. for vanilla_commit in ${wine_commits[@]}; do
  446. local k=0
  447. for rebase_commit in ${staging_rebasecommits[@]}; do
  448. if [[ "${vanilla_commit}" == "${rebase_commit}" ]]; then
  449. # This is the commit we use for vanilla Wine
  450. git_commithash_wine="${vanilla_commit}"
  451. # This is equal commit we use for Wine Staging
  452. git_commithash_winestaging="${staging_refcommits[$k]}"
  453. break 2
  454. fi
  455. let k++
  456. done
  457. done
  458. }
  459. git_branch_wine=master
  460. staging_change_freeze_commit
  461. elif [[ ! -v NO_STAGING ]] && [[ "${git_commithash_wine}" == HEAD ]]; then
  462. git_branch_wine=master
  463. git_commithash_winestaging=HEAD
  464. fi
  465. }
  466. ########################################################
  467. # Wine dependencies removal/installation
  468. # Global variable to track buildtime dependencies
  469. z=0
  470. function WineDeps() {
  471. local method=${1}
  472. local deps="${2}"
  473. local depsname=${3}
  474. local pkgtype=${4}
  475. case ${method} in
  476. install)
  477. local str="Installing"
  478. local mgrcmd="sudo apt install -y"
  479. ;;
  480. remove)
  481. local str="Removing"
  482. local mgrcmd="sudo apt purge --remove -y"
  483. ;;
  484. *)
  485. echo -e "\e[1mERROR:\e[0m Unknown package management input method. Aborting\n"
  486. exit 1
  487. esac
  488. echo -e "${str} Wine dependencies (${depsname}).\n"
  489. # Check and install/remove package related dependencies if they are missing/installed
  490. function pkgdependencies() {
  491. local deplist="${1}"
  492. # Get a valid logic for generating 'list' array below
  493. case ${method} in
  494. install)
  495. # Package is not installed, install it
  496. local checkstatus=0
  497. ;;
  498. remove)
  499. # Package is installed, remove it
  500. local checkstatus=1
  501. ;;
  502. esac
  503. # Generate a list of missing/removable dependencies, depending on the logic
  504. local a=0
  505. for p in ${deplist[@]}; do
  506. if [[ $(echo $(dpkg -s ${p} &>/dev/null)$?) -ne ${checkstatus} ]]; then
  507. local validlist[$a]=${p}
  508. let a++
  509. # Global array to track installed build dependencies
  510. if [[ ${method} == "install" ]] && [[ ${pkgtype} == "buildtime" ]]; then
  511. buildpkglist[$z]=${p}
  512. let z++
  513. fi
  514. fi
  515. done
  516. # Install missing/Remove existing dependencies, be informative
  517. local b=0
  518. for pkgdep in ${validlist[@]}; do
  519. echo -e "$(( $b + 1 ))/$(( ${#validlist[*]} )) - ${str} ${depsname} dependency ${pkgdep}"
  520. eval ${mgrcmd} ${pkgdep} &> /dev/null
  521. if [[ $? -eq 0 ]]; then
  522. let b++
  523. else
  524. echo -e "\n\e[1mERROR:\e[0m Error occured while processing ${pkgdep}. Aborting.\n"
  525. exit 1
  526. fi
  527. done
  528. if [[ -n ${validlist[*]} ]]; then
  529. # Add empty newline
  530. echo ""
  531. fi
  532. }
  533. pkgdependencies "${deps[*]}"
  534. }
  535. ########################################################
  536. # Feed the following data to Wine debian/control file
  537. # If we separate i386 build to be an independent one, this function
  538. # must be improved, if built with amd64 package together
  539. # If we just bundle them together, single package description for
  540. # debian/control file is enough
  541. function feed_debiancontrol() {
  542. cat << CONTROLFILE > debian/control
  543. Source: ${pkgname}
  544. Section: otherosfs
  545. Priority: optional
  546. Maintainer: ${USER} <${USER}@unknown>
  547. Build-Depends: debhelper (>=9), $(echo "${wine_deps_build[*]}" | sed 's/\s/, /g')
  548. Standards-Version: 4.1.2
  549. Homepage: ${pkgurl}
  550. Package: ${pkgname}
  551. Architecture: any
  552. Depends: $(echo ${wine_deps_runtime[*]} | sed 's/\s/, /g')
  553. Suggests: $(echo ${wine_suggested_pkgs[*]} | sed 's/\s/, /g')
  554. Conflicts: $(echo ${wine_overr_pkgs[*]} | sed 's/\s/, /g')
  555. Breaks: $(echo ${wine_overr_pkgs[*]} | sed 's/\s/, /g')
  556. Replaces: $(echo ${wine_overr_pkgs[*]} | sed 's/\s/, /g')
  557. Provides: $(echo ${wine_overr_pkgs[*]} | sed 's/\s/, /g')
  558. Description: A compatibility layer for running Windows programs.
  559. Wine is an open source Microsoft Windows API implementation for
  560. POSIX-compliant operating systems, including Linux.
  561. Git version includes the latest updates available for Wine.
  562. CONTROLFILE
  563. }
  564. ########################################################
  565. # Refresh Wine GIT
  566. function refreshWineGIT() {
  567. # Restore the wine tree to its git origin state, without wine-staging patches
  568. # (necessary for reapllying wine-staging patches in succedent builds,
  569. # otherwise the patches will fail to be reapplied)
  570. cd "${WINEDIR}"
  571. if [[ -v NO_STAGING ]]; then
  572. git checkout ${git_branch_wine} # Get Wine branch
  573. fi
  574. git reset --hard ${git_commithash_wine} # Get Wine commit
  575. if [[ $? -ne 0 ]]; then
  576. echo "\e[1mERROR:\e[0m Couldn't find git commit '${git_commithash_wine}' for Wine. Aborting\n"
  577. exit 1
  578. fi
  579. git clean -d -x -f # Delete untracked files
  580. if [[ ! -v NO_STAGING ]]; then
  581. if [[ ${git_commithash_wine} == HEAD ]]; then
  582. # Change back to the wine upstream commit that this version of wine-staging is based on
  583. git checkout $(bash "${WINEDIR_STAGING}"/patches/patchinstall.sh --upstream-commit)
  584. else
  585. cd "${WINEDIR_STAGING}"
  586. git reset --hard ${git_commithash_winestaging}
  587. if [[ $? -ne 0 ]]; then
  588. echo "\e[1mERROR:\e[0m Couldn't find git commit '${git_commithash_winestaging}' for Wine Staging. Aborting\n"
  589. exit 1
  590. fi
  591. fi
  592. fi
  593. }
  594. ########################################################
  595. # Get Wine version tag
  596. function wine_version() {
  597. cd "${WINEDIR}"
  598. git describe | sed 's/^[a-z]*-//; s/-[0-9]*-[a-z0-9]*$//'
  599. }
  600. ########################################################
  601. # Apply patches
  602. function patchWineSource() {
  603. if [[ ! -v NO_STAGING ]]; then
  604. bash "${WINEDIR_STAGING}/patches/patchinstall.sh" DESTDIR="${WINEDIR}" ${staging_patchsets[*]}
  605. fi
  606. cp -r ${WINEROOT}/../../../wine_custom_patches/* "${WINEDIR_PATCHES}/"
  607. if [[ $(find "${WINEDIR_PATCHES}" -mindepth 1 -maxdepth 1 -regex ".*\.\(patch\|diff\)$") ]]; then
  608. cd "${WINEDIR}"
  609. for i in "${WINEDIR_PATCHES}"/*.{patch,diff}; do
  610. patch -Np1 < $i
  611. done
  612. fi
  613. }
  614. ########################################################
  615. # 64-bit build
  616. function wine64Build() {
  617. cd "${WINEDIR_BUILD_64}"
  618. "${WINEDIR}"/configure \
  619. --with-x \
  620. --with-gstreamer \
  621. --enable-win64 \
  622. --with-xattr \
  623. --disable-mscoree \
  624. --with-vulkan \
  625. --prefix=/usr \
  626. --libdir=/usr/lib/x86_64-linux-gnu/
  627. make -j$(nproc --ignore 1)
  628. make -j$(nproc --ignore 1) prefix="${WINEDIR_INSTALL_64}/usr" \
  629. libdir="${WINEDIR_INSTALL_64}/usr/lib/x86_64-linux-gnu/" \
  630. dlldir="${WINEDIR_INSTALL_64}/usr/lib/x86_64-linux-gnu/wine" install
  631. }
  632. # 32-bit build
  633. function wine32Build() {
  634. cd "${WINEDIR_BUILD_32}"
  635. "${WINEDIR}"/configure \
  636. --with-x \
  637. --with-gstreamer \
  638. --with-xattr \
  639. --disable-mscoree \
  640. --with-vulkan \
  641. --libdir=/usr/lib/i386-linux-gnu/ \
  642. --with-wine64="${WINEDIR_BUILD_64}" \
  643. --prefix=/usr
  644. make -j$(nproc --ignore 1)
  645. make -j$(nproc --ignore 1) prefix="${WINEDIR_INSTALL_32}/usr" \
  646. libdir="${WINEDIR_INSTALL_32}/usr/lib/i386-linux-gnu/" \
  647. dlldir="${WINEDIR_INSTALL_32}/usr/lib/i386-linux-gnu/wine" install
  648. }
  649. ########################################################
  650. # Merge compiled files, build Debian archive
  651. # Prepare compiled Wine for dpkg-buildpackage
  652. function mergeWineBuilds() {
  653. cp -r "${WINEDIR_INSTALL_64}"/* "${WINEDIR_PACKAGE}"/
  654. cp -r "${WINEDIR_INSTALL_32}"/usr/bin/{wine,wine-preloader} "${WINEDIR_PACKAGE}"/usr/bin/
  655. cp -r "${WINEDIR_INSTALL_32}"/usr/lib/* "${WINEDIR_PACKAGE}"/usr/lib/
  656. }
  657. ############################
  658. # Trigger Wine compilation process
  659. # Create a new deb package
  660. function buildDebianArchive() {
  661. cd "${WINEROOT}"
  662. mv "${WINEDIR_PACKAGE}" "${WINEROOT}/${pkgname}-$(wine_version)"
  663. cd "${WINEROOT}/${pkgname}-$(wine_version)"
  664. dh_make --createorig -s -y -c lgpl
  665. rm debian/*.{ex,EX}
  666. printf "usr/* /usr" > debian/install
  667. feed_debiancontrol
  668. # Start compilation process
  669. DEB_BUILD_OPTIONS="strip nodocs noddebs" dpkg-buildpackage -b -us -uc
  670. }
  671. ############################
  672. # Install created deb package
  673. function installDebianArchive() {
  674. cd "${WINEROOT}"
  675. # TODO Although the package name ends with 'amd64', this contains both 32 and 64 bit Wine versions
  676. echo -e "\nInstalling Wine$(if [[ ! -v NO_STAGING ]]; then printf " Staging"; fi).\n"
  677. sudo dpkg -i ${pkgname}_$(wine_version)-1_amd64.deb
  678. }
  679. ############################
  680. # Store deb package for later use
  681. function storeDebianArchive() {
  682. cd "${WINEROOT}"
  683. mv ${pkgname}_$(wine_version)-1_amd64.deb ../../compiled_deb/"${datedir}" && \
  684. echo -e "Compiled ${pkgname} is stored at '$(readlink -f ../../compiled_deb/"${datedir}")/'\n"
  685. rm -rf winebuild_${datedir}
  686. }
  687. ############################
  688. # Clean temporary build files
  689. function cleanTree() {
  690. rm -rf "${WINEROOT}"
  691. }
  692. ########################################################
  693. # Check presence of Wine if compiled deb is going to be installed
  694. # This function is not relevant if --no-install switch is used
  695. function wineCheck() {
  696. # Known Wine package names to check on Debian
  697. local known_wines=(
  698. 'wine'
  699. 'wine32'
  700. 'wine64'
  701. 'wine-git'
  702. 'wine-staging-git'
  703. 'libwine:amd64'
  704. 'libwine:i386'
  705. 'fonts-wine'
  706. )
  707. # Check if any of these Wine packages are present on the system
  708. for winepkg in ${known_wines[@]}; do
  709. if [[ $(echo $(dpkg -s ${winepkg} &>/dev/null)$?) -eq 0 ]]; then
  710. sudo apt purge --remove -y ${winepkg}
  711. fi
  712. done
  713. }
  714. ########################################################
  715. # Check existence of gstreamer girl package before further operations
  716. girl_check
  717. ############################
  718. # Get Wine (& Wine-Staging) sources
  719. getWine
  720. ############################
  721. # Check whether we need to update possible hash override
  722. check_gitOverride
  723. ############################
  724. # Refresh & sync Wine (+ Wine Staging) git sources
  725. refreshWineGIT
  726. # Update Wine source files
  727. patchWineSource
  728. ########################################################
  729. # Compile 64 & 32 bit Wine/Wine Staging
  730. # WE MUST BUILD 64-BIT FIRST, THEN 32-BIT. THIS ORDER IS MANDATORY!
  731. # We split 64-bit & 32-bit compilation due to two major reasons:
  732. # - pure Debian has major conflicts between 32/64 bit dev packages
  733. # - on Mint/Ubuntu, some 32-bit dev packages must be excluded due to conflicts, too
  734. ##########################
  735. # Install Wine common buildtime dependencies
  736. WineDeps install "${wine_deps_build_common[*]}" "Wine common build time" buildtime
  737. ##########################
  738. # TODO If we do architecture separation in the future, add if check for amd64 here
  739. # Condition would be: if amd64, then
  740. #
  741. # Purge i386 buildtime dependencies
  742. # On Debian, we can't have them with i386 at the same time
  743. #
  744. echo -e "Preparing system for 64-bit Wine compilation.\n"
  745. WineDeps remove "${wine_deps_build_i386[*]}" "Wine build time (32-bit)" buildtime
  746. WineDeps install "${wine_deps_build_amd64[*]}" "Wine build time (64-bit)" buildtime
  747. wine64Build && \
  748. echo -e "\nWine 64-bit build process finished.\n"
  749. ##########################
  750. # TODO If we do architecture separation in the future, add if check for i386 here
  751. # Condition would be: if i386 or amd64, then
  752. #
  753. # Purge amd64 buildtime dependencies
  754. # On Debian, we can't have them with i386 at the same time
  755. #
  756. echo -e "Preparing system for 32-bit Wine compilation.\n"
  757. WineDeps remove "${wine_deps_build_amd64[*]}" "Wine build time (64-bit)" buildtime
  758. WineDeps install "${wine_deps_build_i386[*]}" "Wine build time (32-bit)" buildtime
  759. wine32Build &&
  760. echo -e "\nWine 32-bit build process finished.\n"
  761. ############################
  762. # Remove i386 buildtime dependencies after successful compilation process
  763. WineDeps remove "${wine_deps_build_i386[*]}" "Wine build time (32-bit)" buildtime
  764. ############################
  765. # i386/amd64 runtime dependencies have been tested and they are able to co-exist on Debian system
  766. if [[ ! -v NO_INSTALL ]]; then
  767. # Install Wine common runtime dependencies
  768. WineDeps install "${wine_deps_runtime_common[*]}" "Wine common runtime" runtime
  769. # Install architecture-dependent Wine runtime dependencies
  770. WineDeps install "${wine_deps_runtime_amd64[*]}" "Wine runtime (64-bit)" runtime
  771. WineDeps install "${wine_deps_runtime_i386[*]}" "Wine runtime (32-bit)" runtime
  772. # Check presence of already installed Wine packages and remove them
  773. wineCheck
  774. fi
  775. ############################
  776. # Build time dependencies which were installed but no longer needed
  777. if [[ -v buildpkglist ]]; then
  778. if [[ -v BUILDPKG_RM ]]; then
  779. sudo apt purge --remove -y ${buildpkglist[*]}
  780. else
  781. 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"
  782. fi
  783. fi
  784. ############################
  785. if [[ -v GIRL_CHECK ]]; then
  786. sudo apt install -y ${girlpkg}
  787. fi
  788. ########################################################
  789. # Bundle compiled Wine/Wine-Staging files
  790. mergeWineBuilds
  791. # Bundle and install Debian deb archive
  792. buildDebianArchive
  793. if [[ ! -v NO_INSTALL ]]; then
  794. installDebianArchive
  795. fi
  796. storeDebianArchive
  797. # Clean all temporary files
  798. cleanTree