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.

1032 lines
26 KiB

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