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.

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