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.

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