Open main menu

Compiling ScummVM with Minimalist GNU for Windows (MinGW)

MinGW is "a collection of freely available and freely distributable Windows specific header files and import libraries combined with GNU toolsets that allow one to produce native Windows programs that do not rely on any 3rd-party C runtime DLLs".

More information can be found at the MinGW homepage. See also MinGW-w64.

Things needed

MinGW and MSYS

  • Download and install the latest MinGW Installation Manager (mingw-get-setup.exe)
  • From the list of packages shown, check mingw-developer-toolkit-bin, mingw32-base-bin and mingw32-gcc-g++-bin, as well as mingw32-libz-dev from the "MinGW Libraries" section (right-click > Mark for Installation)
  • Click the Installation > Apply Changes menu to install MinGW and MSYS
  • Once installation is complete, you can run MSYS from inside the MinGW directory (by default C:\MinGW\msys\1.0\msys.bat)

Libraries needed

  • SDL2.
    • You need the latest SDL2 development libraries: (v2.0.14 at the time of writing).
  • SDL2_net. Optional, for network support.
    • You need the latest SDL2_net source code (v2.0.1 at the time of writing).
  • SDL_net 1.2. Optional, for network support on Windows 95/98/ME.
    • You need the latest SDL_net source code (v1.2.8 at the time of writing).
  • NASM. Optional, for faster compile of scalers
    • You need the latest Win32 binary (v2.15.05 at the time of writing).
  • CMake. Optional, for compiling libjpeg-turbo.
    • You need the latest Win32 installer.
  • FLAC. Optional, for FLAC support
    • You need the latest flac source code (v1.3.3 at the time of writing).
  • libogg and libvorbis Optional, for OGG support
    • You need the latest libogg source code (v1.3.5 at the time of writing).
    • You need the latest libvorbis (not vorbis) source code (v1.3.7 at the time of writing).
  • libmad Optional, for MP3 support
    • You need the latest libmad source code (v0.15.1b at the time of writing).
  • libmpeg2 Optional, for MPEG2 cutscene support.
    • You need the latest libmpeg2 source code, (v0.5.1 at the time of writing).
  • libtheora. Optional, for Broken Sword 2.5.
    • You need the latest libtheora source code (v1.1.1 at the time of writing).
  • libfaad2. Optional, for AAC support.
    • You need the latest libfaad2 source code (v2.10.0 at the time of writing).
  • libpng. Optional, for PNG support.
    • You need the latest libpng source code (v1.6.37 at the time of writing).
  • giflib. Optional, for GIF support.
  • freetype. Optional, for TTF support.
    • You need the latest freetype source code (v2.10.4 at the time of writing).
  • FriBiDi. Optional, for bidirectional text in languages that need it (e.g. Hebrew)
    • You need the latest FriBiDi source code (v1.0.10 at the time of writing).
  • libjpeg-turbo. Optional, for JPEG support.
    • You need the latest libjpeg-turbo source code (v2.1.0 at the time of writing).
  • liba52. Optional, for AC-3 support.
    • You need the latest liba52 source code (v0.7.4 at the time of writing).
  • mbedTLS. Optional, for cloud support.
    • You need the latest mbedTLS source code (v2.26.0 at the time of writing).
  • libcurl. Optional, for cloud support.
    • You need the latest libcurl source code (v7.77.0 at the time of writing).
  • GLEW. Optional, for hardware acceleration in 3D games.
    • You need the latest GLEW source code (v2.2.0 at the time of writing).

Precompiled libraries

To ease the whole process, a package of all the needed precompiled libraries has been created. All you need to do is:

  • Download the precompiled libraries and the latest SDL runtime library - latest version is 1.2.15 at the time this was written, you can find the latest version here. Precompiled libraries:
  • Extract them to your MinGW directory (e.g. C:\MinGW)

MSYS primer

From the developer's webpage: "MSYS or Minimal SYStem is a POSIX and Bourne shell environment use with MinGW. It provides a hand picked set of tools to allow a typical configuration script with Bourne syntax to execute. This allows most of the GNU packages to create a Makefile just from executing the typical configure script which can then be used to build the package using the native MinGW version of GCC".


MSYS commands can be confusing for people using Windows, as MSYS emulates a Bourne shell environment, which is found in most Unix/Linux distributions. The available commands can be viewed by typing "help" in the command prompt. Help on a specific command is available by typing "help" followed by the command, e.g. "help alias".


Note that MSYS uses forward slashes between folder names, not backward slashes, as is the case with Windows. Additionally, some special characters like the space need to be escaped with a backward slash("\"). Drives are mounted to folders, so drive "C:" would be under folder "/c". Therefore, to switch to directory:

C:\Program Files\Test Folder

we would switch to:

/c/Program\ Files/Test\ Folder

The basic commands you'll need are:


cd - changes the current drive and directory
pwd - shows the current drive and directory
ls - lists files in a folder
make - makefile, used to compile projects
strip - remove debug information from executable files


Note that if you wish to run a file from the current folder, you need to specify it before the file name, i.e. if you wish to run "test" from the current folder, you should type:

./test


Building the libraries

Now, we need to compile the required libraries and tools.


NASM

Unzip the nasm archive in a folder, and copy both files to MinGW's bin directory.


pkg-config-lite

Unzip the pkg-config-lite archive in a folder, and copy the "bin" and "share" to MinGW's root directory.


SDL1

Unzip the SDL archive in a folder, open MSYS, go to the SDL folder and issue these commands to compile and install the library:

./configure --disable-shared --prefix=/mingw
make
make install

Note the README here, especially the need to include the DirectX development headers from here to ensure that the "dsound" rather than the "waveout" / "winmm" fallback audio driver is used.


SDL2

Note that a prebuilt version of SDL2 is required since MinGW32 doesn't have all the necessary Windows SDK headers.

Unzip the SDL2 archive in a folder, open MSYS, go to the SDL2 folder and issue this command to install the library:

make install-package arch=i686-w64-mingw32 prefix=$PREFIX


libogg

libogg should be compiled before libvorbis, libtheora and libFLAC.

Unzip the libogg archive in a folder, open MSYS, go to the libogg folder and issue these commands to compile and install the library:

./configure --disable-shared --prefix=/mingw
make
make install


libvorbis

Unzip the libvorbis archive in a folder, open MSYS, go to the libvorbis folder and issue these commands to compile and install the library:

./configure --disable-shared --prefix=/mingw
make
make install


libmad

Unzip the libmad archive in a folder, open MSYS and go to the libmad folder and issue these commands to compile and install the library:

sed -i '/-fforce-mem/d' configure
./configure --disable-shared --prefix=/mingw
make
make install


libmpeg2

Unzip the libmpeg2 archive into a folder, open MSYS, go to the libmpeg2 folder and issue these commands to compile and install the library:

sed -i -e '/AC_C_ALWAYS_INLINE/d' -e 's/-mcpu/-mtune/' configure.ac
./bootstrap
./configure --disable-sdl --disable-shared --prefix=/mingw
make
make install


FLAC

Unzip the flac archive in a folder, open MSYS, go to the flac folder and issue these commands to compile and install the library:

./configure --disable-shared --prefix=/mingw
make
make install


FluidLite

Unzip the fluidlite archive in a folder, open MSYS, go to the fluidlite folder and issue these commands to compile and install the library:

cmake -G "MSYS Makefiles" -DFLUIDLITE_BUILD_SHARED=OFF -DCMAKE_INSTALL_PREFIX=/mingw -DCMAKE_BUILD_TYPE=Release .
make
make install


libpng

Unzip the libpng archive in a folder, open MSYS, go to the libpng folder and issue these commands to compile and install the library:

./configure --disable-shared --prefix=/mingw
make pnglibconf.h
sed -i 's/\x0D//' pnglibconf.h
make
make install


giflib

Unzip the giflib archive in a folder, open MSYS, go to the giflib folder and issue these commands to compile and install the library:

./configure --disable-shared --prefix=/mingw
make
make install


libtheora

Unzip the libtheora archive in a folder, open MSYS, go to the libtheora folder and issue these commands to compile and install the library:

./configure --disable-shared --disable-examples --prefix=/mingw
make
make install


libfaad2

Unzip the libfaad2 archive in a folder, open MSYS, go to the libfaad2 folder and issue these commands to compile and install the library:

./bootstrap
./configure --disable-shared --prefix=/mingw
make
make install


freetype

Unzip the freetype archive in a folder, open MSYS, go to the freetype folder and issue these commands to compile and install the library:

./configure --disable-shared --prefix=/mingw
make
make install


fribidi

Unzip the fribidi archive in a folder, open MSYS, go to the fribidi folder and apply the following patch:

--- fribidi.pc.in.orig  2020-07-05 20:17:23 +0100
+++ fribidi.pc.in       2020-08-30 17:17:43 +0100
@@ -9,5 +9,4 @@
 Description: Unicode Bidirectional Algorithm Library
 Version: @VERSION@
 Libs: -L${libdir} -lfribidi
-Cflags: -I${includedir}/@PACKAGE@
-CFLAGS.private: -DFRIBIDI_LIB_STATIC
+Cflags: -I${includedir}/@PACKAGE@ -DFRIBIDI_LIB_STATIC

Then issue these commands to compile and install the library:

./configure --disable-shared --prefix=/mingw
make
make install


libjpeg-turbo

Unzip the libjpeg-turbo archive in a folder, open MSYS, go to the libjpeg-turbo folder and issue these commands to compile and install the library:

cmake -G "MSYS Makefiles" -DENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=/mingw -DCMAKE_BUILD_TYPE=Release .
make
make install


liba52

Unzip the liba52 archive into a folder, open MSYS, go to the liba52 folder and issue these commands to compile and install the library:

rm -f autotools/{config.guess,config.sub,install-sh,ltmain.sh,missing,mkinstalldirs} {autotools,doc,include,liba52,libao,src,test,vc++,.}/Makefile.in include/config.h.in include/stamp-h.in aclocal.m4 configure
sed -i -e '/AC_C_ALWAYS_INLINE/d' -e 's/-mcpu/-mtune/' configure.in
autoreconf -fi
./configure --disable-shared --prefix=/mingw
make
make install


SDL_net

Unzip the SDL_net archive in a folder, open MSYS, go to the SDL_net folder and apply the following patch:

--- SDL_net.pc.in.orig  2012-01-15 16:20:10 +0000
+++ SDL_net.pc.in       2020-08-30 17:42:19 +0100
@@ -7,5 +7,5 @@
 Description: net library for Simple DirectMedia Layer
 Version: @VERSION@
 Requires: sdl >= @SDL_VERSION@
-Libs: -L${libdir} -lSDL_net
+Libs: -L${libdir} -lSDL_net @INETLIB@
 Cflags: -I${includedir}/SDL

Then issue these commands to compile and install the library:

./configure --disable-shared --prefix=/mingw
make
make install


SDL2_net

Unzip the SDL2_net archive in a folder, open MSYS, go to the SDL2_net folder and apply the following patch:

--- SDL2_net.pc.in.orig 2016-01-03 07:57:09 +0000
+++ SDL2_net.pc.in      2020-08-30 17:45:28 +0100
@@ -7,5 +7,5 @@
 Description: net library for Simple DirectMedia Layer
 Version: @VERSION@
 Requires: sdl2 >= @SDL_VERSION@
-Libs: -L${libdir} -lSDL2_net
+Libs: -L${libdir} -lSDL2_net @INETLIB@
 Cflags: -I${includedir}/SDL2
EOF

Then issue these commands to compile and install the library:

./configure --disable-shared --prefix=/mingw
make
make install


mbedTLS

Unzip the mbedTLS archive in a folder, open MSYS, go to the mbedtls folder and apply the following patch:

--- library/platform_util.c.orig        2020-12-10 12:55:25 +0000
+++ library/platform_util.c     2021-03-08 23:59:37 +0000
@@ -92,9 +92,11 @@
  * threading.h. However, this macro is not part of the Mbed TLS public API, so
  * we keep it private by only defining it in this file
  */
-#if ! ( defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) )
+#if ! ( defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) ) || \
+      ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) )
 #define PLATFORM_UTIL_USE_GMTIME
-#endif /* ! ( defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) ) */
+#endif /* ! ( defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) ) || \
+             (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) ) */

 #endif /* !( ( defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L ) ||     \
              ( defined(_POSIX_THREAD_SAFE_FUNCTIONS ) &&                     \
@@ -103,7 +105,7 @@
 struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt,
                                       struct tm *tm_buf )
 {
-#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
+#if defined(_WIN32) && !defined(PLATFORM_UTIL_USE_GMTIME)
     return( ( gmtime_s( tm_buf, tt ) == 0 ) ? tm_buf : NULL );
 #elif !defined(PLATFORM_UTIL_USE_GMTIME)
     return( gmtime_r( tt, tm_buf ) );

Then issue these commands to compile and install the library:

CPPFLAGS=-D_WIN32_WINNT=0x400 cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_BUILD_TYPE=Release -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF .
make
make install


libcurl

Unzip the curl archive in a folder, open MSYS, go to the curl folder and issue these commands to compile and install the library:

CPPFLAGS=-D_WIN32_WINNT=0x400 ./configure --disable-shared --prefix=/mingw --with-winssl --with-mbedtls --disable-pthreads --disable-ldap
make
make install


GLEW

Unzip the GLEW archive in a folder, open MSYS, go to the GLEW folder and apply the following patch:

--- config/Makefile.mingw.orig  2017-07-31 12:25:39 +0100
+++ config/Makefile.mingw       2020-12-10 20:23:36 +0000
@@ -5,8 +5,7 @@
 LN :=
 LDFLAGS.GL = -lopengl32 -lgdi32 -luser32 -lkernel32
 LDFLAGS.EXTRA = -L/mingw/lib
-CFLAGS.EXTRA  += -fno-builtin -fno-stack-protector
-LDFLAGS.EXTRA += -nostdlib
+CFLAGS.EXTRA  += -fno-builtin -fno-stack-protector -Wno-cast-function-type
 WARN = -Wall -W
 POPT = -O2
 BIN.SUFFIX = .exe
@@ -14,4 +13,4 @@
 LIB.DEVLNK    = lib$(NAME).dll.a   # for mingw this is the dll import lib
 LIB.SHARED    = $(NAME).dll
 LIB.STATIC    = lib$(NAME).a       # the static lib will be broken
-LDFLAGS.SO    = -shared -Wl,-soname,$(LIB.SONAME) -Wl,--out-implib,lib/$(LIB.DEVLNK)
+LDFLAGS.SO    = -nostdlib -shared -Wl,-soname,$(LIB.SONAME) -Wl,--out-implib,lib/$(LIB.DEVLNK)

Then issue these commands to compile and install the library:

make install.all GLEW_PREFIX=$PREFIX GLEW_DEST=$PREFIX GLEW_NO_GLU=-DGLEW_NO_GLU


Compiling ScummVM

To compile ScummVM, issue the following commands inside the scummvm folder (where Makefile resides):

./configure
make

After compilation, you'll end up with a very big scummvm.exe (around 16MB). This is because debug symbols and information are embedded by default in the exe file, making it very big. To remove all the unneeded debug information from the executable, thus reducing its size by about 12MB, go to the folder where the compiled scummvm.exe file is and run the following command:

strip scummvm.exe

Compiling with Console/Text Output

By default ScummVM is compiled as a Windows subsystem application with no console output. If you need the console, you will need to apply the following patch:

diff --git a/configure b/configure
index 838c759b75..04cfd361dd 100755
--- a/configure
+++ b/configure
@@ -6070,6 +6070,9 @@ case $_host_os in
 		append_var CXXFLAGS "-fdata-sections"
 		append_var LDFLAGS "-Wl,--gc-sections"
 		;;
+	mingw*)
+		LIBS=`echo $LIBS | sed -e 's/-mconsole//g' -e 's/-mwindows//g'`
+		;;
 	n64)
 		# Move some libs down here, otherwise some symbols requires by libvorbis aren't found
 		# during linking stage

Save it to your root directory and apply it with patch -p1 -i path-to-patch.diff.

Ready to go!

OK this should be all of it (thankfully), so you should be good to go.