Page 1 of 1

[Windows] Building 64-bit minetest with MSYS2/mingw64

PostPosted: Sun Jun 04, 2017 16:28
by Fixer
Building 64bit Minetest under Windows by using MSYS2/Mingw64 environment (C++11 compatible)

MSYS2 is a software distro and building platform for Windows. At its core is an independent rewrite of MSYS, based on modern Cygwin (POSIX compatibility layer) and MinGW-w64 with the aim of better interoperability with native Windows software. It provides a bash shell, Autotools, revision control systems and the like for building native Windows applications using MinGW-w64 toolchains. Windows XP and FAT partitions are not supported!

* Go to and download msys2-x86-64 installer
* Follow install instructions on website (important)

After MSYS2 is fully installed and updated, follow steps below.
The commands shown below should be run from within the MSYS2 Shell (Start -> MSYS2 64bit -> MSYS2 MinGW 64-bit)

* To install git and the base development packages, run:

Code: Select all
pacman -S base-devel git unzip

* To install the mingw-w64 GCC toolchain and cmake for your system, run:

Code: Select all
pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake

* Close it and start "MSYS2 MinGW 64-bit" again
* You will appear in your home directory, execute this command to create directories for building:

Code: Select all
mkdir minetest minetest/build minetest/buildbot minetest/build/copy2bin

* Execute this to change directory and download compile scripts:

Code: Select all
cd ~/minetest/buildbot

* Modify toolchain_mingw64.cmake with your favourite editor in msys2 or with usual tools, like notepad++:
** Replace

Code: Select all
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
Code: Select all

** Replace

Code: Select all
SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
Code: Select all
SET(CMAKE_FIND_ROOT_PATH /mingw64/x86_64-w64-mingw32)

* Now modify
** go to "cmake .. \" section and insert those lines right below it:

Code: Select all
-G"MinGW Makefiles" \
-DCMAKE_AR=/mingw64/x86_64-w64-mingw32/bin/ar \

** near end of the file replace
Code: Select all
make package -j2
Code: Select all
mingw32-make package -j$(nproc)

* Go to /usr/bin and rename sh.exe to sh.exe~ (to avoid CMAKE errors, please show me better way):

Code: Select all
mv /usr/bin/sh.exe /usr/bin/sh.exe~

* Copy those libraries from /mingw64/bin to ~/minetest/build/copy2bin for easier access, those will be needed:

Code: Select all
cp /mingw64/bin/libgcc_s_seh-1.dll ~/minetest/build/copy2bin/
cp /mingw64/bin/libstdc++-6.dll ~/minetest/build/copy2bin/
cp /mingw64/bin/libwinpthread-1.dll ~/minetest/build/copy2bin/

* Now go back to your buildbot directory:

Code: Select all
cd ~/minetest/buildbot

and execute final building script:

Code: Select all
./ ../build

* This will start minetest compilation.
* Compiled minetest will appear in ~/minetest/build/minetest/_build directory with name like
* Final touch, copy files from copy2bin directory into this compiled minetest zip archive into /bin where minetest.exe is located.

* Done! You are ready!

* If you want to compile newer version of minetest, run "./ ../build" again:

Code: Select all
cd ~/minetest/buildbot
./ ../build

It will automatically update all files and repos if need, all you need is to wait for compilation completion and add those 3 dlls into /bin directory of zip file with compiled minetest. You can modify script to your needs, for example, to avoid full recompilation - don't run cmake, unless there were CMakeLists.txt changes, just run "mingw32-make package -j$(nproc)". Doing sh.exe rename before/after cmake is also advised. Without sh.exe some other features will not work properly, like git bisect and other.

Here is my final buildbot script that should work, copy it to .sh file and run it within MSYS2 MinGW 64-bit shell:
Code: Select all
# Using cmake for regular compile with recompile everything (slow)
# Use to compile fast, and use this if problems

set -e

echo -n "Start of compilation: "; date -R

dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ $# -ne 1 ]; then
   echo "Usage: $0 <build directory>"
   exit 1
mkdir -p $builddir
builddir="$( cd "$builddir" && pwd )"


mkdir -p $packagedir
mkdir -p $libdir

cd $builddir

# Get stuff
[ -e $packagedir/irrlicht-$ ] || wget$ \
   -c -O $packagedir/irrlicht-$
[ -e $packagedir/zlib-$ ] || wget$ \
   -c -O $packagedir/zlib-$
[ -e $packagedir/libogg-$ ] || wget$ \
   -c -O $packagedir/libogg-$
[ -e $packagedir/libvorbis-$ ] || wget$ \
   -c -O $packagedir/libvorbis-$
[ -e $packagedir/curl-$ ] || wget$ \
   -c -O $packagedir/curl-$
[ -e $packagedir/gettext-$ ] || wget$ \
   -c -O $packagedir/gettext-$
[ -e $packagedir/freetype2-$ ] || wget$ \
   -c -O $packagedir/freetype2-$
[ -e $packagedir/sqlite3-$ ] || wget$ \
   -c -O $packagedir/sqlite3-$
[ -e $packagedir/luajit-$ ] || wget$ \
   -c -O $packagedir/luajit-$
[ -e $packagedir/libleveldb-$ ] || wget$ \
   -c -O $packagedir/libleveldb-$
[ -e $packagedir/ ] || wget \
   -c -O $packagedir/

# Extract stuff
cd $libdir
[ -d irrlicht ] || unzip -o $packagedir/irrlicht-$ -d irrlicht
[ -d zlib ] || unzip -o $packagedir/zlib-$ -d zlib
[ -d libogg ] || unzip -o $packagedir/libogg-$ -d libogg
[ -d libvorbis ] || unzip -o $packagedir/libvorbis-$ -d libvorbis
[ -d libcurl ] || unzip -o $packagedir/curl-$ -d libcurl
[ -d gettext ] || unzip -o $packagedir/gettext-$ -d gettext
[ -d freetype ] || unzip -o $packagedir/freetype2-$ -d freetype
[ -d sqlite3 ] || unzip -o $packagedir/sqlite3-$ -d sqlite3
[ -d openal_stripped ] || unzip -o $packagedir/
[ -d luajit ] || unzip -o $packagedir/luajit-$ -d luajit
[ -d leveldb ] || unzip -o $packagedir/libleveldb-$ -d leveldb

# Get minetest
cd $builddir
if [ ! "x$EXISTING_MINETEST_DIR" = "x" ]; then
   ln -s $EXISTING_MINETEST_DIR minetest
   [ -d minetest ] && (cd minetest && git pull) || (git clone
cd minetest
git_hash=$(git rev-parse --short HEAD)

# Get minetest_game
cd games
if [ "x$NO_MINETEST_GAME" = "x" ]; then
   [ -d minetest_game ] && (cd minetest_game && git pull) || (git clone
cd ../..

# Build the thing
cd minetest
[ -d _build ] && rm -Rf _build/
mkdir _build
cd _build
mv /usr/bin/sh.exe /usr/bin/sh.exe~
cmake .. \
   -G"MinGW Makefiles" \
   -DCMAKE_AR=/mingw64/x86_64-w64-mingw32/bin/ar \
   -DCMAKE_TOOLCHAIN_FILE=$toolchain_file \
   -DVERSION_EXTRA=$git_hash \
   -DIRRLICHT_INCLUDE_DIR=$libdir/irrlicht/include \
   -DIRRLICHT_LIBRARY=$libdir/irrlicht/lib/Win64-gcc/libIrrlicht.dll.a \
   -DIRRLICHT_DLL=$libdir/irrlicht/bin/Win64-gcc/Irrlicht.dll \
   -DZLIB_INCLUDE_DIR=$libdir/zlib/include \
   -DZLIB_LIBRARIES=$libdir/zlib/lib/libz.dll.a \
   -DZLIB_DLL=$libdir/zlib/bin/zlib1.dll \
   -DLUA_INCLUDE_DIR=$libdir/luajit/include \
   -DLUA_LIBRARY=$libdir/luajit/libluajit.a \
   -DOGG_INCLUDE_DIR=$libdir/libogg/include \
   -DOGG_LIBRARY=$libdir/libogg/lib/libogg.dll.a \
   -DOGG_DLL=$libdir/libogg/bin/libogg-0.dll \
   -DVORBIS_INCLUDE_DIR=$libdir/libvorbis/include \
   -DVORBIS_LIBRARY=$libdir/libvorbis/lib/libvorbis.dll.a \
   -DVORBIS_DLL=$libdir/libvorbis/bin/libvorbis-0.dll \
   -DVORBISFILE_LIBRARY=$libdir/libvorbis/lib/libvorbisfile.dll.a \
   -DVORBISFILE_DLL=$libdir/libvorbis/bin/libvorbisfile-3.dll \
   -DOPENAL_INCLUDE_DIR=$libdir/openal_stripped/include/AL \
   -DOPENAL_LIBRARY=$libdir/openal_stripped/lib/libOpenAL32.dll.a \
   -DOPENAL_DLL=$libdir/openal_stripped/bin/OpenAL32.dll \
   -DCURL_DLL=$libdir/libcurl/bin/libcurl-4.dll \
   -DCURL_INCLUDE_DIR=$libdir/libcurl/include \
   -DCURL_LIBRARY=$libdir/libcurl/lib/libcurl.dll.a \
   -DGETTEXT_MSGFMT=`which msgfmt` \
   -DGETTEXT_DLL=$libdir/gettext/bin/libintl-8.dll \
   -DGETTEXT_ICONV_DLL=$libdir/gettext/bin/libiconv-2.dll \
   -DGETTEXT_INCLUDE_DIR=$libdir/gettext/include \
   -DGETTEXT_LIBRARY=$libdir/gettext/lib/libintl.dll.a \
   -DFREETYPE_INCLUDE_DIR_freetype2=$libdir/freetype/include/freetype2 \
   -DFREETYPE_INCLUDE_DIR_ft2build=$libdir/freetype/include/freetype2 \
   -DFREETYPE_LIBRARY=$libdir/freetype/lib/libfreetype.dll.a \
   -DFREETYPE_DLL=$libdir/freetype/bin/libfreetype-6.dll \
   -DSQLITE3_INCLUDE_DIR=$libdir/sqlite3/include \
   -DSQLITE3_LIBRARY=$libdir/sqlite3/lib/libsqlite3.dll.a \
   -DSQLITE3_DLL=$libdir/sqlite3/bin/libsqlite3-0.dll \
   -DLEVELDB_INCLUDE_DIR=$libdir/leveldb/include \
   -DLEVELDB_LIBRARY=$libdir/leveldb/lib/libleveldb.dll.a \

mv /usr/bin/sh.exe~ /usr/bin/sh.exe
mingw32-make package -j$(nproc)

cd _CPack_Packages/win64/ZIP/
cp /mingw64/bin/libgcc_s_seh-1.dll minetest-*/bin
cp /mingw64/bin/libstdc++-6.dll minetest-*/bin
cp /mingw64/bin/libwinpthread-1.dll minetest-*/bin
zip -ur minetest-*.zip minetest-*
cp minetest-*.zip ../../../

echo -n "End of compilation: "; date -R

} |& tee build.log


Re: [Windows] Building 64-bit minetest with MSYS2/mingw64

PostPosted: Mon Mar 26, 2018 00:26
by ChimneySwift
Thank you so much for this!

I was tearing my hair out trying to compile manually but this is much nicer! I made some modifications but the basis of my success has been this post.

Re: [Windows] Building 64-bit minetest with MSYS2/mingw64

PostPosted: Tue May 22, 2018 17:10
by bomberman
it downloads version 0.5, how download 0.4.16 with this script?

Re: [Windows] Building 64-bit minetest with MSYS2/mingw64

PostPosted: Tue May 22, 2018 20:01
by Fixer
bomberman wrote:it downloads version 0.5, how download 0.4.16 with this script?

I don't remember exactly, but after "git clone" step you should do "git checkout 80dc961d24e1964e25d57039ddb2ba639f9f4d22", it will switch to 0.4.16, don't forget to DL minetest_game 0.4.16 for it.

Re: [Windows] Building 64-bit minetest with MSYS2/mingw64

PostPosted: Wed Nov 27, 2019 18:19
by Enrikoo
The information is outdated, because I get cmake errors, can you renew these informations please so, that I don't get cmake errors anymore?