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

From ScummVM :: Wiki
Jump to navigation Jump to search
(→‎Common Issues: Note about msys mode)
m (Describe packages that were removed for 32 bit builds due to MSYS2 deprectation of 32 bit platforms)
 
(79 intermediate revisions by 10 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 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 do not support building in this way''', but if you want to use it, instructions are below.


Our officially supported MinGW build instructions are at [[Compiling_ScummVM/MinGW]].
|}


== Things needed ==
== Prepare your build environment ==


=== Setup MinGW-w64 and MSYS2 ===
=== Setup MinGW-w64 and MSYS2 ===
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].


'''NOTE:''' This guide is a vast simplification of that found [https://sourceforge.net/p/msys2/wiki/MSYS2%20installation/ here]. While this article should be enough, we recommend you read through the entire guide.
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).


==== Download ====
'''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:
'''Download''' and '''execute''' the MSYS2 bundle for your architecture from [http://msys2.github.io/ here].


==== Update the core of MSYS2 ====
* curl-winssl
In the installation folder run msys2-shell.bat, which should open a MSYS2 terminal.
* winsparkle
Type the following command, to update the core dependencies of the environment:


<syntax type="bash">
To create an i686 or x86_64 build environment, we need to first update the already installed packages and the MSYS2 environment itself.
$> update-core
To do that, type the following in the MSYS2 terminal:
</syntax>
<syntaxhighlight lang="bash">
pacman -Syuu
</syntaxhighlight>


''Restart the MSYS2 terminal.''
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.
Type the following command, to update the managed packages:
<syntax type="bash">
$> pacman -Su
</syntax>


==== Download and install the compilation toolchain====
In order to install all required tools and libraries, open the MinGW shell matching the architecture you want to build for, and use the following commands:
In the MSYS2 terminal, type:
<syntax type="bash">
$> pacman -S mingw-w64-<env>-toolchain
</syntax>
where <env> is either x86_64 or i686, depending on your architecture (64-bit and 32-bit, respectively).


This command will fetch and install the packages needed for compiling, including (but not limited to) GCC 5.x, GDB, and libwinpthread-git.
'''For 64 bit builds:'''
<syntaxhighlight lang="bash">
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>


==== Install make ====
'''For 32 bit builds:'''
ScummVM uses Makefiles to build the project. Makefiles are build configuration files that the compiler uses to compile, link and solve dependencies. "make" is the software that runs the Makefiles.
pacman -S --needed --noconfirm base-devel git ${MINGW_PACKAGE_PREFIX}-{a52dec,binutils,ccache,cairo,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,zlib,ntldd-git}
'''The following features are not available in 32 bit builds because the MSYS2 projects removed the required packages: curl, winsparkle'''


MSYS2 does not support make out of the box, but it has its own implementation. Install it by typing:
These commands will fetch and install the packages needed for compiling, including (but not limited to) GCC 12.x, GDB, and libwinpthread-git.


<syntax type="bash">
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.
$> pacman -S make
</syntax>


=== Install the needed libraries ===
== Let's get compiling! ==
In order to compile properly, ScummVM needs you to have certain libraries installed. All the libraries in the list can be installed with similar commands:
<syntax type="bash">
$> pacman -S mingw-w64-<env>-<library>
</syntax>
where <env> is the environment as previously stated, and <library> is the name of the library, as stated in the list (e.g. pacman -S mingw-w64-x86_64-SDL):


* '''SDL''' Mandatory.
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)


* '''nasm''' Optional, for faster compile of scalers.
'''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.


* '''flac'''. Optional, for FLAC support.
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


* '''libogg''' and '''libvorbis''' Optional, for OGG support.
Please note that using this step is not necessary if you build a distributable package.


* '''libmad''' Optional, for MP3 support.
That's it, you successfully compiled ScummVM from the source code.


* '''libmpeg2''' Optional, for MPEG2 cutscene support.
== Ship required libraries for running ScummVM on a "non-MSYS2" machine ==


* '''zlib'''. Optional, for compressed saved games.
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.


* '''libtheora'''. Optional, for Broken Sword 2.5.
If you intend to build a ScummVM package that includes all the necessary files, you can build such a redistributable package by using


* '''libfaad2'''. Optional, for AAC support.
  make win32dist-mingw WIN32PATH=<target>


* '''libpng'''. Optional, for PNG support.
where <code><target></code> specifies the directory that will contain the redistributable packages.


* '''freetype'''. Optional, for TTF support.
== 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)
* '''fluidsynth'''. Optional, for soundfont MIDI support.
* 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/
 
=== Let's get compiling! ===
 
Finally, we are ready to compile the project!
To do that, just open a MSYS2 console, [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:
<syntax type="bash">
$> ./configure # Executes a bash script that helps you configure.
$> make # Executes the make program, which triggers the compilation.
</syntax>


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 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.
<syntax type="bash">
$> strip scummvm.exe
</syntax>


== Ready to go! ==
== 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.'''


OK this should be all of it (hopefully), so you should be good to go.
* 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]]
 
== Common Issues ==
 
* 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 scripts 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.
* MinGW-w64 makes heavy use of the pacman package manager, which may not be available under other MinGW setups

Latest revision as of 09:08, 9 November 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, and use the following commands:

For 64 bit builds:

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}

For 32 bit builds:

pacman -S --needed --noconfirm base-devel git ${MINGW_PACKAGE_PREFIX}-{a52dec,binutils,ccache,cairo,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,zlib,ntldd-git}

The following features are not available in 32 bit builds because the MSYS2 projects removed the required packages: curl, winsparkle

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