Open main menu

Difference between revisions of "Compiling ScummVM/MinGW-w64"

(Add libopenmpt, remove duplicates)
 
(24 intermediate revisions by 5 users not shown)
Line 4: Line 4:
|- style="margin-left:1em; background:#ffffff;"
|- style="margin-left:1em; background:#ffffff;"
|- style="background:#ffffff"
|- style="background:#ffffff"
| This guide covers '''only''' the compilation under MinGW-w64 and MSYS2 (which is very different from [[Compiling_ScummVM/MinGW|MinGW and MSYS]]), and makes heavy use of the pacman package manager, which may not be available under other MinGW setups.
| Compiling with MinGw-w64 should currently be used only for debug builds, as the executable is linked dynamically with the MinGW libraries. Release builds should be done using [[Compiling ScummVM/MXE|MXE]] if possible, since this allows building an (almost) statically linked executable for easy distribution. Feel free to contact me (rootfather) either via eMail or IRC if you have questions regarding MSYS2/MinGW-w64.
 
We don't recommend using this method if you want to distribute your ScummVM builds. Release builds should be done using [[Compiling ScummVM/MXE|MXE]] if possible, since this allows building an (almost) statically linked executable for easy distribution. Feel free to contact me (rootfather) either via eMail or IRC if you have questions regarding MSYS2/MinGW-w64.
|}
 
 
{| border="0" cellpadding="1" cellspacing="2" style="margin-left:5em; background:#FF9999; width:80%"
|- align="center"
| '''NOTE'''
|- style="margin-left:1em; background:#ffffff;"
|- style="background:#ffffff"
| Despite the name, MinGW-w64 works on both 32-bit and 64-bit systems, but the latest versions cannot be installed on Windows XP anymore. '''However, builds produced will still work on Windows XP.'''
 
If you need to support older Windows, check out [[Compiling_ScummVM/MinGW|MinGW]].
|}
|}


Line 26: Line 13:
You can find [https://www.msys2.org/ MSYS2 on the official webpage] and detailed installation instructions on the [https://github.com/msys2/msys2/wiki/MSYS2-installation MSYS2 github wiki].
You can find [https://www.msys2.org/ MSYS2 on the official webpage] and detailed installation instructions on the [https://github.com/msys2/msys2/wiki/MSYS2-installation MSYS2 github wiki].


The MinGW packages are named mingw-<env>-<package>, where <env> is either x86_64 or i686, depending on your architecture (64-bit and 32-bit, respectively).
The MinGW packages are named <code>mingw-<env>-<package></code>, where <code><env></code> is either x86_64 or i686, depending on your architecture (64-bit and 32-bit, respectively).
 
'''NOTE:''' The Mingw-w64/MSYS2 project is phasing out support for 32 Bit packages due to the obsolescence of the architecture. In the future, it is likely that we'll see more and more packages removed from the 32 Bit branch. Currently (2024-08-15), two packages are not available anymore for 32 Bit builds:
 
* curl-winssl
* winsparkle


To create an i686 or x86_64 build environment, we need to first update the already installed packages and the MSYS2 environment itself.
To create an i686 or x86_64 build environment, we need to first update the already installed packages and the MSYS2 environment itself.
Line 36: Line 28:
Follow the instructions (one upgrade step may require that the MSYS2 terminal window is closed directly from the window's e(X)it button on the top right. Keep issuing the above command in the MSYS2 terminal until there's no more updating tasks to be done.
Follow the instructions (one upgrade step may require that the MSYS2 terminal window is closed directly from the window's e(X)it button on the top right. Keep issuing the above command in the MSYS2 terminal until there's no more updating tasks to be done.


For i686 (32-bit), type the following in the MSYS2 terminal to automatically install all packages/libraries needed to compile ScummVM:
In order to install all required tools and libraries, open the MinGW shell matching the architecture you want to build for (32 or 64 bits) and use the following command:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
pacman -S --needed --noconfirm base-devel git mingw-w64-i686-{a52dec,ccache,cairo,faad2,freetype,flac,fluidsynth,fribidi,glew,libjpeg-turbo,libogg,libvorbis,libmad,libmpeg2-git,libtheora,libpng,nasm,readline,SDL2,SDL2_net,toolchain,winsparkle,zlib,ntldd-git}
pacman -S --needed --noconfirm base-devel git ${MINGW_PACKAGE_PREFIX}-{a52dec,binutils,ccache,cairo,curl-winssl,faad2,freetype,flac,fluidsynth,fribidi,libjpeg-turbo,libmikmod,libmpcdec,libogg,libopenmpt,libvorbis,libvpx,libmad,libmpeg2-git,libtheora,libpng,lld,nasm,readline,SDL2,SDL2_net,toolchain,winsparkle,zlib,ntldd-git}
</syntaxhighlight>
</syntaxhighlight>


For x86_64 (64-bit), type the following in the MSYS2 terminal to automatically install all packages/libraries needed to compile ScummVM:
These commands will fetch and install the packages needed for compiling, including (but not limited to) GCC 12.x, GDB, and libwinpthread-git.
<syntaxhighlight lang="bash">
pacman -S --needed --noconfirm base-devel git mingw-w64-x86_64-{a52dec,ccache,cairo,faad2,freetype,flac,fluidsynth,fribidi,glew,libjpeg-turbo,libogg,libvorbis,libmad,libmpeg2-git,libtheora,libpng,nasm,readline,SDL2,SDL2_net,toolchain,winsparkle,zlib,ntldd-git}
</syntaxhighlight>


These commands will fetch and install the packages needed for compiling, including (but not limited to) GCC 10.x, GDB, and libwinpthread-git.
Additionally, if you would like to include Discord Rich Presence support, the pre-compiled libraries are [https://github.com/discord/discord-rpc/releases here]. Simply copy the files into your base MinGW directory.


=== Install modified curl package ===
== Let's get compiling! ==
The default curl version shipped with MSYS2 relies on an external certificate bundle for verifying SSL/TLS certificates. While this works fine in the mingw-w64 shell itself, it will break SSL verification outside the mingw-w64 shell. Since our cloud integration features rely on a working SSL implementation, we need to build our own curl release using the winssl backend instead. WinSSL - as the name implies - is the SSL/TLS library shipped withing Windows itself, so we can rely on the Windows certificate store.


Thanks to the PKGBUILD already provided by the MSYS2/Mingw-w64 developers, this is pretty straight forward.
Finally, we are ready to compile the project!
To do that, just open a '''MinGW-w64''' shell (''not'' the MSYS2 shell), [http://gvsigce.sourceforge.net/wiki/index.php/Getting_started_with_MSYS#Navigating_the_file_system navigate] to the source folder where you have cloned scummvm.git, and type the following commands:
  ./configure
  make -j$(nproc)


First, clone the repository containing the mingw-w64 package files in a seperate directory:
'''Note:''' Depending on what you are working on, have a look at <code>./configure --help</code>. Sometimes, you want to enable some features or engines that are disabled by default, while working on a specific engine won't require a full build at all.
git clone <nowiki>https://github.com/msys2/MINGW-packages</nowiki>
Now, we need to modify the file <code>mingw-w64-curl/PKGBUILD</code> which contains all the instructions <code>makepkg</code> uses for building the final package. At the beginning of the file, select the winssl variant instead of the default openssl version.
#_variant=-openssl
_variant=-winssl
#_variant=-gnutls
Since support for METALINK seems to be broken at the moment (and we don't need it), modify the PKGBUILD file as shown below:
  79   if [ "${_variant}" = "-winssl" ]; then
...
  86     _variant_config+=("--without-librtmp")
  87     _variant_config+=("--without-libmetalink")
Finally, we can build and install the modified package.


Before building the package itself, you need to add the GPG key of the curl developer to your local keychain, so makepkg can validate the package. Under no circumstances you should try skipping the signature checks since you really, REALLY don't want a malicious curl package on your system.
If everything went well, you should have a big executable in the compilation folder, named scummvm.exe. The size of the executable comes from the debug symbols embedded in the file, so you can run the following command to shrink it:
  strip scummvm.exe


  $> gpg --recv-keys 5CC908FDB71E12C2
Please note that using this step is not necessary if you build a distributable package.


Enter the <code>mingw-w64-curl</code> directory and start the build process:
That's it, you successfully compiled ScummVM from the source code.
  $> makepkg --syncdeps


Depending on your system, building the package should only take a couple of minutes. Finally, install the package using pacman:
== Ship required libraries for running ScummVM on a "non-MSYS2" machine ==
  $> pacman -U mingw-w64-x86_64-curl-winssl-7.xx.0-1-any.pkg.tar.zst


If you have installed curl previously, you need to accept the removal of the previous package since you can't have multiple variants installed at the same time.
In case you want to distribute your builds to machines without a running MSYS2 installation or if you excluded MSYS2/Mingw-w64 from your PATH, you need to bundle the required .dll files with the executable - otherwise, running ScummVM will fail due to missing dependencies.
 
== Let's get compiling! ==
 
Finally, we are ready to compile the project!
To do that, just open a '''MinGW-w64''' shell (''not'' the MSYS2 shell), [http://gvsigce.sourceforge.net/wiki/index.php/Getting_started_with_MSYS#Navigating_the_file_system navigate] to the source folder where you have cloned scummvm.git, and type the following commands:
<syntaxhighlight lang="bash">
$> ./configure # Executes a bash script that helps you configure.
$> make # Executes the make program, which triggers the compilation.
</syntaxhighlight>


If everything went well, you should have a big executable in the compilation folder, named scummvm.exe. The size of the executable comes from the debug symbols embedded in the file, so you can run the following command to shrink it:
If you intend to build a ScummVM package that includes all the necessary files, you can build such a redistributable package by using
<syntaxhighlight lang="bash">
$> strip scummvm.exe
</syntaxhighlight>


== Ready to go! ==
  make win32dist-mingw WIN32PATH=<target>


OK this should be all of it (hopefully), so you should be good to go.
where <code><target></code> specifies the directory that will contain the redistributable packages.
 
== Common Issues ==


== Common Issues ==
* If configure fails to find required libraries such as SDL, make sure that you have all the required libraries available for the target system and that you are using the correct MinGW shell (32-bit vs 64-bit)
* If the executable compiles correctly, but you get a "somelibrary.dll missing" error when executing it, you just need to add the following path to your PATH variable: <installdir>/msys<env>/mingw64/bin/
* If the executable compiles correctly, but you get a "somelibrary.dll missing" error when executing it, you just need to add the following path to your PATH variable: <installdir>/msys<env>/mingw64/bin/


* If the configure script gives an error about using msys mode, please make sure you are running the '''mingw-w64 win32 shell''' or the '''mingw-w64 win64 shell''', and not the '''msys2 shell''' from the MSYS2 package, when building ScummVM.
* If the configure script gives an error about using msys mode, please make sure you are running the '''mingw-w64 win32 shell''' or the '''mingw-w64 win64 shell''', and not the '''msys2 shell''' from the MSYS2 package, when building ScummVM.


== Ship required libraries for running ScummVM on a "non-MSYS2" machine ==
== Notes ==
* Despite the name, MinGW-w64 works on both 32-bit and 64-bit systems, but the latest versions cannot be installed on Windows XP anymore. '''However, builds produced will still work on Windows XP.'''


In case you want to distribute your builds to machines without a running MSYS2 installation or if you excluded MSYS2/Mingw-w64 from your PATH, you need to bundle the required .dll files with the executable - otherwise, running ScummVM will fail due to missing dependencies.
* MinGW-w64 and MSYS2 is a fork of MinGW. If you wish to compile with the (older) MinGW toolset, e.g. to support versions older than Windows XP, check out [[Compiling_ScummVM/MinGW|MinGW and MSYS]]


In order to copy all required .dll files to the directory where the ScummVM executable is located, run the following command in your build directory:
* MinGW-w64 makes heavy use of the pacman package manager, which may not be available under other MinGW setups
<code>for i in $(seq 3); do for bin in $(ntldd -R *exe | grep -i mingw | cut -d">" -f2 | cut -d" " -f2); do cp -vu "$bin" . ; done; done</code>

Latest revision as of 14:09, 12 October 2024

NOTE
Compiling with MinGw-w64 should currently be used only for debug builds, as the executable is linked dynamically with the MinGW libraries. Release builds should be done using MXE if possible, since this allows building an (almost) statically linked executable for easy distribution. Feel free to contact me (rootfather) either via eMail or IRC if you have questions regarding MSYS2/MinGW-w64.


Prepare your build environment

Setup MinGW-w64 and MSYS2

You can find MSYS2 on the official webpage and detailed installation instructions on the MSYS2 github wiki.

The MinGW packages are named mingw-<env>-<package>, where <env> is either x86_64 or i686, depending on your architecture (64-bit and 32-bit, respectively).

NOTE: The Mingw-w64/MSYS2 project is phasing out support for 32 Bit packages due to the obsolescence of the architecture. In the future, it is likely that we'll see more and more packages removed from the 32 Bit branch. Currently (2024-08-15), two packages are not available anymore for 32 Bit builds:

  • curl-winssl
  • winsparkle

To create an i686 or x86_64 build environment, we need to first update the already installed packages and the MSYS2 environment itself. To do that, type the following in the MSYS2 terminal:

pacman -Syuu

Follow the instructions (one upgrade step may require that the MSYS2 terminal window is closed directly from the window's e(X)it button on the top right. Keep issuing the above command in the MSYS2 terminal until there's no more updating tasks to be done.

In order to install all required tools and libraries, open the MinGW shell matching the architecture you want to build for (32 or 64 bits) and use the following command:

pacman -S --needed --noconfirm base-devel git ${MINGW_PACKAGE_PREFIX}-{a52dec,binutils,ccache,cairo,curl-winssl,faad2,freetype,flac,fluidsynth,fribidi,libjpeg-turbo,libmikmod,libmpcdec,libogg,libopenmpt,libvorbis,libvpx,libmad,libmpeg2-git,libtheora,libpng,lld,nasm,readline,SDL2,SDL2_net,toolchain,winsparkle,zlib,ntldd-git}

These commands will fetch and install the packages needed for compiling, including (but not limited to) GCC 12.x, GDB, and libwinpthread-git.

Additionally, if you would like to include Discord Rich Presence support, the pre-compiled libraries are here. Simply copy the files into your base MinGW directory.

Let's get compiling!

Finally, we are ready to compile the project! To do that, just open a MinGW-w64 shell (not the MSYS2 shell), navigate to the source folder where you have cloned scummvm.git, and type the following commands:

 ./configure
 make -j$(nproc)

Note: Depending on what you are working on, have a look at ./configure --help. Sometimes, you want to enable some features or engines that are disabled by default, while working on a specific engine won't require a full build at all.

If everything went well, you should have a big executable in the compilation folder, named scummvm.exe. The size of the executable comes from the debug symbols embedded in the file, so you can run the following command to shrink it:

 strip scummvm.exe

Please note that using this step is not necessary if you build a distributable package.

That's it, you successfully compiled ScummVM from the source code.

Ship required libraries for running ScummVM on a "non-MSYS2" machine

In case you want to distribute your builds to machines without a running MSYS2 installation or if you excluded MSYS2/Mingw-w64 from your PATH, you need to bundle the required .dll files with the executable - otherwise, running ScummVM will fail due to missing dependencies.

If you intend to build a ScummVM package that includes all the necessary files, you can build such a redistributable package by using

 make win32dist-mingw WIN32PATH=<target>

where <target> specifies the directory that will contain the redistributable packages.

Common Issues

  • If configure fails to find required libraries such as SDL, make sure that you have all the required libraries available for the target system and that you are using the correct MinGW shell (32-bit vs 64-bit)
  • If the executable compiles correctly, but you get a "somelibrary.dll missing" error when executing it, you just need to add the following path to your PATH variable: <installdir>/msys<env>/mingw64/bin/
  • If the configure script gives an error about using msys mode, please make sure you are running the mingw-w64 win32 shell or the mingw-w64 win64 shell, and not the msys2 shell from the MSYS2 package, when building ScummVM.

Notes

  • Despite the name, MinGW-w64 works on both 32-bit and 64-bit systems, but the latest versions cannot be installed on Windows XP anymore. However, builds produced will still work on Windows XP.
  • MinGW-w64 and MSYS2 is a fork of MinGW. If you wish to compile with the (older) MinGW toolset, e.g. to support versions older than Windows XP, check out MinGW and MSYS
  • MinGW-w64 makes heavy use of the pacman package manager, which may not be available under other MinGW setups