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.

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