1
0

build_wine.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #!/usr/bin/env bash
  2. ########################################################################
  3. ##
  4. ## A script for Wine compilation.
  5. ## By default it uses two Ubuntu bootstraps (x32 and x64), which it enters
  6. ## with bubblewrap (root rights are not required).
  7. ##
  8. ## This script requires: git, wget, autoconf, xz, bubblewrap
  9. ##
  10. ## You can change the environment variables below to your desired values.
  11. ##
  12. ########################################################################
  13. # Prevent launching as root
  14. if [ $EUID = 0 ] && [ -z "$ALLOW_ROOT" ]; then
  15. echo "Do not run this script as root!"
  16. echo
  17. echo "If you really need to run it as root and you know what you are doing,"
  18. echo "set the ALLOW_ROOT environment variable."
  19. exit 1
  20. fi
  21. # Wine version to compile.
  22. # You can set it to "latest" to compile the latest available version.
  23. # You can also set it to "git" to compile the latest git revision.
  24. #
  25. # This variable affects only vanilla and staging branches. Other branches
  26. # use their own versions.
  27. export WINE_VERSION="${WINE_VERSION:-latest}"
  28. # Available branches: vanilla, staging, proton, staging-tkg, staging-tkg-ntsync
  29. export WINE_BRANCH="${WINE_BRANCH:-staging}"
  30. # Available proton branches: proton_3.7, proton_3.16, proton_4.2, proton_4.11
  31. # proton_5.0, proton_5.13, experimental_5.13, proton_6.3, experimental_6.3
  32. # proton_7.0, experimental_7.0, proton_8.0, experimental_8.0, experimental_9.0
  33. # bleeding-edge
  34. # Leave empty to use the default branch.
  35. export PROTON_BRANCH="${PROTON_BRANCH:-proton_10.0}"
  36. # Sometimes Wine and Staging versions don't match (for example, 5.15.2).
  37. # Leave this empty to use Staging version that matches the Wine version.
  38. export STAGING_VERSION="${STAGING_VERSION:-}"
  39. # Specify custom arguments for the Staging's patchinstall.sh script.
  40. # For example, if you want to disable ntdll-NtAlertThreadByThreadId
  41. # patchset, but apply all other patches, then set this variable to
  42. # "--all -W ntdll-NtAlertThreadByThreadId"
  43. # Leave empty to apply all Staging patches
  44. export STAGING_ARGS="${STAGING_ARGS:-}"
  45. # Make 64-bit Wine builds with the new WoW64 mode (32-on-64)
  46. export EXPERIMENTAL_WOW64="${EXPERIMENTAL_WOW64:-false}"
  47. # Set this to a path to your Wine source code (for example, /home/username/wine-custom-src).
  48. # This is useful if you already have the Wine source code somewhere on your
  49. # storage and you want to compile it.
  50. #
  51. # You can also set this to a GitHub clone url instead of a local path.
  52. #
  53. # If you don't want to compile a custom Wine source code, then just leave this
  54. # variable empty.
  55. export CUSTOM_SRC_PATH=""
  56. # Set to true to download and prepare the source code, but do not compile it.
  57. # If this variable is set to true, root rights are not required.
  58. export DO_NOT_COMPILE="false"
  59. # Set to true to use ccache to speed up subsequent compilations.
  60. # First compilation will be a little longer, but subsequent compilations
  61. # will be significantly faster (especially if you use a fast storage like SSD).
  62. #
  63. # Note that ccache requires additional storage space.
  64. # By default it has a 5 GB limit for its cache size.
  65. #
  66. # Make sure that ccache is installed before enabling this.
  67. export USE_CCACHE="false"
  68. export WINE_BUILD_OPTIONS="--without-ldap --without-oss --disable-winemenubuilder --disable-win16 --disable-tests"
  69. # A temporary directory where the Wine source code will be stored.
  70. # Do not set this variable to an existing non-empty directory!
  71. # This directory is removed and recreated on each script run.
  72. export BUILD_DIR="${HOME}"/build_wine
  73. # Change these paths to where your Ubuntu bootstraps reside
  74. export BOOTSTRAP_X64=/opt/chroots/bionic64_chroot
  75. export BOOTSTRAP_X32=/opt/chroots/bionic32_chroot
  76. export scriptdir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
  77. export CC="gcc-11"
  78. export CXX="g++-11"
  79. export CROSSCC_X32="i686-w64-mingw32-gcc"
  80. export CROSSCXX_X32="i686-w64-mingw32-g++"
  81. export CROSSCC_X64="x86_64-w64-mingw32-gcc"
  82. export CROSSCXX_X64="x86_64-w64-mingw32-g++"
  83. export CFLAGS_X32="-march=i686 -msse2 -mfpmath=sse -O2 -ftree-vectorize"
  84. export CFLAGS_X64="-march=x86-64 -msse3 -mfpmath=sse -O2 -ftree-vectorize"
  85. export LDFLAGS="-Wl,-O1,--sort-common,--as-needed"
  86. export CROSSCFLAGS_X32="${CFLAGS_X32}"
  87. export CROSSCFLAGS_X64="${CFLAGS_X64}"
  88. export CROSSLDFLAGS="${LDFLAGS}"
  89. if [ "$USE_CCACHE" = "true" ]; then
  90. export CC="ccache ${CC}"
  91. export CXX="ccache ${CXX}"
  92. export i386_CC="ccache ${CROSSCC_X32}"
  93. export x86_64_CC="ccache ${CROSSCC_X64}"
  94. export CROSSCC_X32="ccache ${CROSSCC_X32}"
  95. export CROSSCXX_X32="ccache ${CROSSCXX_X32}"
  96. export CROSSCC_X64="ccache ${CROSSCC_X64}"
  97. export CROSSCXX_X64="ccache ${CROSSCXX_X64}"
  98. if [ -z "${XDG_CACHE_HOME}" ]; then
  99. export XDG_CACHE_HOME="${HOME}"/.cache
  100. fi
  101. mkdir -p "${XDG_CACHE_HOME}"/ccache
  102. mkdir -p "${HOME}"/.ccache
  103. fi
  104. build_with_bwrap () {
  105. if [ "${1}" = "32" ]; then
  106. BOOTSTRAP_PATH="${BOOTSTRAP_X32}"
  107. else
  108. BOOTSTRAP_PATH="${BOOTSTRAP_X64}"
  109. fi
  110. if [ "${1}" = "32" ] || [ "${1}" = "64" ]; then
  111. shift
  112. fi
  113. bwrap --ro-bind "${BOOTSTRAP_PATH}" / --dev /dev --ro-bind /sys /sys \
  114. --proc /proc --tmpfs /tmp --tmpfs /home --tmpfs /run --tmpfs /var \
  115. --tmpfs /mnt --tmpfs /media --bind "${BUILD_DIR}" "${BUILD_DIR}" \
  116. --bind-try "${XDG_CACHE_HOME}"/ccache "${XDG_CACHE_HOME}"/ccache \
  117. --bind-try "${HOME}"/.ccache "${HOME}"/.ccache \
  118. --setenv PATH "/opt/mingw/x86_64/bin:/opt/mingw/i686/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin" \
  119. "$@"
  120. }
  121. if ! command -v git 1>/dev/null; then
  122. echo "Please install git and run the script again"
  123. exit 1
  124. fi
  125. if ! command -v autoconf 1>/dev/null; then
  126. echo "Please install autoconf and run the script again"
  127. exit 1
  128. fi
  129. if ! command -v wget 1>/dev/null; then
  130. echo "Please install wget and run the script again"
  131. exit 1
  132. fi
  133. if ! command -v xz 1>/dev/null; then
  134. echo "Please install xz and run the script again"
  135. exit 1
  136. fi
  137. # Replace the "latest" parameter with the actual latest Wine version
  138. if [ "${WINE_VERSION}" = "latest" ] || [ -z "${WINE_VERSION}" ]; then
  139. WINE_VERSION="$(wget -q -O - "https://raw.githubusercontent.com/wine-mirror/wine/master/VERSION" | tail -c +14)"
  140. fi
  141. # Stable and Development versions have a different source code location
  142. # Determine if the chosen version is stable or development
  143. if [ "$(echo "$WINE_VERSION" | cut -d "." -f2 | cut -c1)" = "0" ]; then
  144. WINE_URL_VERSION=$(echo "$WINE_VERSION" | cut -d "." -f 1).0
  145. else
  146. WINE_URL_VERSION=$(echo "$WINE_VERSION" | cut --d "." -f 1).x
  147. fi
  148. rm -rf "${BUILD_DIR}"
  149. mkdir -p "${BUILD_DIR}"
  150. cd "${BUILD_DIR}" || exit 1
  151. echo
  152. echo "Downloading the source code and patches"
  153. echo "Preparing Wine for compilation"
  154. echo
  155. if [ -n "${CUSTOM_SRC_PATH}" ]; then
  156. is_url="$(echo "${CUSTOM_SRC_PATH}" | head -c 6)"
  157. if [ "${is_url}" = "git://" ] || [ "${is_url}" = "https:" ]; then
  158. git clone "${CUSTOM_SRC_PATH}" wine
  159. else
  160. if [ ! -f "${CUSTOM_SRC_PATH}"/configure ]; then
  161. echo "CUSTOM_SRC_PATH is set to an incorrect or non-existent directory!"
  162. echo "Please make sure to use a directory with the correct Wine source code."
  163. exit 1
  164. fi
  165. cp -r "${CUSTOM_SRC_PATH}" wine
  166. fi
  167. WINE_VERSION="$(cat wine/VERSION | tail -c +14)"
  168. BUILD_NAME="${WINE_VERSION}"-custom
  169. elif [ "$WINE_BRANCH" = "staging-tkg" ] || [ "$WINE_BRANCH" = "staging-tkg-ntsync" ]; then
  170. if [ "$WINE_BRANCH" = "staging-tkg" ] && [ "${EXPERIMENTAL_WOW64}" = "true" ]; then
  171. git clone https://github.com/Kron4ek/wine-tkg wine -b wow64
  172. else
  173. if [ "$WINE_BRANCH" = "staging-tkg" ]; then
  174. git clone https://github.com/Kron4ek/wine-tkg wine
  175. else
  176. git clone https://github.com/Kron4ek/wine-tkg wine -b ntsync
  177. fi
  178. fi
  179. WINE_VERSION="$(cat wine/VERSION | tail -c +14)"
  180. BUILD_NAME="${WINE_VERSION}"-"${WINE_BRANCH}"
  181. elif [ "$WINE_BRANCH" = "proton" ]; then
  182. if [ -z "${PROTON_BRANCH}" ]; then
  183. git clone https://github.com/ValveSoftware/wine
  184. else
  185. git clone https://github.com/ValveSoftware/wine -b "${PROTON_BRANCH}"
  186. fi
  187. WINE_VERSION="$(cat wine/VERSION | tail -c +14)-$(git -C wine rev-parse --short HEAD)"
  188. if [[ "${PROTON_BRANCH}" == "experimental_"* ]] || [ "${PROTON_BRANCH}" = "bleeding-edge" ]; then
  189. cd wine
  190. patch -Np1 < "${scriptdir}"/opencl.patch
  191. cd ..
  192. BUILD_NAME=proton-exp-"${WINE_VERSION}"
  193. else
  194. BUILD_NAME=proton-"${WINE_VERSION}"
  195. fi
  196. else
  197. if [ "${WINE_VERSION}" = "git" ]; then
  198. git clone https://gitlab.winehq.org/wine/wine.git wine
  199. BUILD_NAME="${WINE_VERSION}-$(git -C wine rev-parse --short HEAD)"
  200. else
  201. BUILD_NAME="${WINE_VERSION}"
  202. wget -q --show-progress "https://dl.winehq.org/wine/source/${WINE_URL_VERSION}/wine-${WINE_VERSION}.tar.xz"
  203. tar xf "wine-${WINE_VERSION}.tar.xz"
  204. mv "wine-${WINE_VERSION}" wine
  205. fi
  206. if [ "${WINE_BRANCH}" = "staging" ]; then
  207. if [ "${WINE_VERSION}" = "git" ]; then
  208. git clone https://github.com/wine-staging/wine-staging wine-staging-"${WINE_VERSION}"
  209. upstream_commit="$(cat wine-staging-"${WINE_VERSION}"/staging/upstream-commit | head -c 7)"
  210. git -C wine checkout "${upstream_commit}"
  211. BUILD_NAME="${WINE_VERSION}-${upstream_commit}-staging"
  212. else
  213. if [ -n "${STAGING_VERSION}" ]; then
  214. WINE_VERSION="${STAGING_VERSION}"
  215. fi
  216. BUILD_NAME="${WINE_VERSION}"-staging
  217. wget -q --show-progress "https://github.com/wine-staging/wine-staging/archive/v${WINE_VERSION}.tar.gz"
  218. tar xf v"${WINE_VERSION}".tar.gz
  219. if [ ! -f v"${WINE_VERSION}".tar.gz ]; then
  220. git clone https://github.com/wine-staging/wine-staging wine-staging-"${WINE_VERSION}"
  221. fi
  222. fi
  223. if [ -f wine-staging-"${WINE_VERSION}"/patches/patchinstall.sh ]; then
  224. staging_patcher=("${BUILD_DIR}"/wine-staging-"${WINE_VERSION}"/patches/patchinstall.sh
  225. DESTDIR="${BUILD_DIR}"/wine)
  226. else
  227. staging_patcher=("${BUILD_DIR}"/wine-staging-"${WINE_VERSION}"/staging/patchinstall.py)
  228. fi
  229. cd wine || exit 1
  230. if [ -n "${STAGING_ARGS}" ]; then
  231. "${staging_patcher[@]}" ${STAGING_ARGS}
  232. else
  233. "${staging_patcher[@]}" --all
  234. fi
  235. if [ $? -ne 0 ]; then
  236. echo
  237. echo "Wine-Staging patches were not applied correctly!"
  238. exit 1
  239. fi
  240. cd "${BUILD_DIR}" || exit 1
  241. fi
  242. fi
  243. if [ ! -d wine ]; then
  244. clear
  245. echo "No Wine source code found!"
  246. echo "Make sure that the correct Wine version is specified."
  247. exit 1
  248. fi
  249. cd wine || exit 1
  250. dlls/winevulkan/make_vulkan
  251. tools/make_requests
  252. tools/make_specfiles
  253. autoreconf -f
  254. cd "${BUILD_DIR}" || exit 1
  255. if [ "${DO_NOT_COMPILE}" = "true" ]; then
  256. clear
  257. echo "DO_NOT_COMPILE is set to true"
  258. echo "Force exiting"
  259. exit
  260. fi
  261. if ! command -v bwrap 1>/dev/null; then
  262. echo "Bubblewrap is not installed on your system!"
  263. echo "Please install it and run the script again"
  264. exit 1
  265. fi
  266. if [ ! -d "${BOOTSTRAP_X64}" ] || [ ! -d "${BOOTSTRAP_X32}" ]; then
  267. clear
  268. echo "Bootstraps are required for compilation!"
  269. exit 1
  270. fi
  271. BWRAP64="build_with_bwrap 64"
  272. BWRAP32="build_with_bwrap 32"
  273. export CROSSCC="${CROSSCC_X64}"
  274. export CROSSCXX="${CROSSCXX_X64}"
  275. export CFLAGS="${CFLAGS_X64}"
  276. export CXXFLAGS="${CFLAGS_X64}"
  277. export CROSSCFLAGS="${CROSSCFLAGS_X64}"
  278. export CROSSCXXFLAGS="${CROSSCFLAGS_X64}"
  279. mkdir "${BUILD_DIR}"/build64
  280. cd "${BUILD_DIR}"/build64 || exit
  281. ${BWRAP64} "${BUILD_DIR}"/wine/configure --enable-win64 ${WINE_BUILD_OPTIONS} --prefix "${BUILD_DIR}"/wine-"${BUILD_NAME}"-amd64
  282. ${BWRAP64} make -j$(nproc) install
  283. export CROSSCC="${CROSSCC_X32}"
  284. export CROSSCXX="${CROSSCXX_X32}"
  285. export CFLAGS="${CFLAGS_X32}"
  286. export CXXFLAGS="${CFLAGS_X32}"
  287. export CROSSCFLAGS="${CROSSCFLAGS_X32}"
  288. export CROSSCXXFLAGS="${CROSSCFLAGS_X32}"
  289. mkdir "${BUILD_DIR}"/build32-tools
  290. cd "${BUILD_DIR}"/build32-tools || exit
  291. PKG_CONFIG_LIBDIR=/usr/lib/i386-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/lib/i386-linux-gnu/pkgconfig ${BWRAP32} "${BUILD_DIR}"/wine/configure ${WINE_BUILD_OPTIONS} --prefix "${BUILD_DIR}"/wine-"${BUILD_NAME}"-x86
  292. ${BWRAP32} make -j$(nproc) install
  293. export CFLAGS="${CFLAGS_X64}"
  294. export CXXFLAGS="${CFLAGS_X64}"
  295. export CROSSCFLAGS="${CROSSCFLAGS_X64}"
  296. export CROSSCXXFLAGS="${CROSSCFLAGS_X64}"
  297. mkdir "${BUILD_DIR}"/build32
  298. cd "${BUILD_DIR}"/build32 || exit
  299. PKG_CONFIG_LIBDIR=/usr/lib/i386-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/lib/i386-linux-gnu/pkgconfig ${BWRAP32} "${BUILD_DIR}"/wine/configure --with-wine64="${BUILD_DIR}"/build64 --with-wine-tools="${BUILD_DIR}"/build32-tools ${WINE_BUILD_OPTIONS} --prefix "${BUILD_DIR}"/wine-${BUILD_NAME}-amd64
  300. ${BWRAP32} make -j$(nproc) install
  301. echo
  302. echo "Compilation complete"
  303. echo "Creating and compressing archives..."
  304. cd "${BUILD_DIR}" || exit
  305. if touch "${scriptdir}"/write_test; then
  306. rm -f "${scriptdir}"/write_test
  307. result_dir="${scriptdir}"
  308. else
  309. result_dir="${HOME}"
  310. fi
  311. export XZ_OPT="-9"
  312. if [ "${EXPERIMENTAL_WOW64}" = "true" ]; then
  313. mv wine-${BUILD_NAME}-amd64 wine-${BUILD_NAME}-amd64-wow64
  314. builds_list="wine-${BUILD_NAME}-amd64-wow64"
  315. else
  316. builds_list="wine-${BUILD_NAME}-x86 wine-${BUILD_NAME}-amd64"
  317. fi
  318. for build in ${builds_list}; do
  319. if [ -d "${build}" ]; then
  320. if [ -f wine/wine-tkg-config.txt ]; then
  321. cp wine/wine-tkg-config.txt "${build}"
  322. fi
  323. if [ "${EXPERIMENTAL_WOW64}" = "true" ]; then
  324. if [ -f "${build}"/bin/wine64 ]; then
  325. rm "${build}"/bin/wine "${build}"/bin/wine-preloader
  326. cp "${build}"/bin/wine64 "${build}"/bin/wine
  327. else
  328. rm "${build}"/lib/wine/i386-unix/wine "${build}"/lib/wine/i386-unix/wine-preloader
  329. fi
  330. fi
  331. tar -Jcf "${build}".tar.xz "${build}"
  332. mv "${build}".tar.xz "${result_dir}"
  333. fi
  334. done
  335. rm -rf "${BUILD_DIR}"
  336. echo
  337. echo "Done"
  338. echo "The builds should be in ${result_dir}"