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.

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