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.

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