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

User avatar
Posts: 895
Joined: Sun Jul 31, 2011 11:23
Location: Ukraine
IRC: Fixer
In-game: Fixer

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

by Fixer » Sun Jun 04, 2017 16:28

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 http://www.msys2.org/ 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
wget https://raw.githubusercontent.com/minetest/minetest/master/util/buildbot/buildwin64.sh
wget https://raw.githubusercontent.com/minetest/minetest/master/util/buildbot/toolchain_mingw64.cmake

* 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 buildwin64.sh:
** 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
./buildwin64.sh ../build

* This will start minetest compilation.
* Compiled minetest will appear in ~/minetest/build/minetest/_build directory with name like minetest-0.4.16-bla-bla-win64.zip
* 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 "./buildwin64.sh ../build" again:

Code: Select all
cd ~/minetest/buildbot
./buildwin64.sh ../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 buildwin64.sh 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 buildwin64_compileonly.sh 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-$irrlicht_version.zip ] || wget http://minetest.kitsunemimi.pw/irrlicht-$irrlicht_version-win64.zip \
   -c -O $packagedir/irrlicht-$irrlicht_version.zip
[ -e $packagedir/zlib-$zlib_version.zip ] || wget http://minetest.kitsunemimi.pw/zlib-$zlib_version-win64.zip \
   -c -O $packagedir/zlib-$zlib_version.zip
[ -e $packagedir/libogg-$ogg_version.zip ] || wget http://minetest.kitsunemimi.pw/libogg-$ogg_version-win64.zip \
   -c -O $packagedir/libogg-$ogg_version.zip
[ -e $packagedir/libvorbis-$vorbis_version.zip ] || wget http://minetest.kitsunemimi.pw/libvorbis-$vorbis_version-win64.zip \
   -c -O $packagedir/libvorbis-$vorbis_version.zip
[ -e $packagedir/curl-$curl_version.zip ] || wget http://minetest.kitsunemimi.pw/curl-$curl_version-win64.zip \
   -c -O $packagedir/curl-$curl_version.zip
[ -e $packagedir/gettext-$gettext_version.zip ] || wget http://minetest.kitsunemimi.pw/gettext-$gettext_version-win64.zip \
   -c -O $packagedir/gettext-$gettext_version.zip
[ -e $packagedir/freetype2-$freetype_version.zip ] || wget http://minetest.kitsunemimi.pw/freetype2-$freetype_version-win64.zip \
   -c -O $packagedir/freetype2-$freetype_version.zip
[ -e $packagedir/sqlite3-$sqlite3_version.zip ] || wget http://minetest.kitsunemimi.pw/sqlite3-$sqlite3_version-win64.zip \
   -c -O $packagedir/sqlite3-$sqlite3_version.zip
[ -e $packagedir/luajit-$luajit_version.zip ] || wget http://minetest.kitsunemimi.pw/luajit-$luajit_version-win64.zip \
   -c -O $packagedir/luajit-$luajit_version.zip
[ -e $packagedir/libleveldb-$leveldb_version.zip ] || wget http://minetest.kitsunemimi.pw/libleveldb-$leveldb_version-win64.zip \
   -c -O $packagedir/libleveldb-$leveldb_version.zip
[ -e $packagedir/openal_stripped.zip ] || wget http://minetest.kitsunemimi.pw/openal_stripped64.zip \
   -c -O $packagedir/openal_stripped.zip

# Extract stuff
cd $libdir
[ -d irrlicht ] || unzip -o $packagedir/irrlicht-$irrlicht_version.zip -d irrlicht
[ -d zlib ] || unzip -o $packagedir/zlib-$zlib_version.zip -d zlib
[ -d libogg ] || unzip -o $packagedir/libogg-$ogg_version.zip -d libogg
[ -d libvorbis ] || unzip -o $packagedir/libvorbis-$vorbis_version.zip -d libvorbis
[ -d libcurl ] || unzip -o $packagedir/curl-$curl_version.zip -d libcurl
[ -d gettext ] || unzip -o $packagedir/gettext-$gettext_version.zip -d gettext
[ -d freetype ] || unzip -o $packagedir/freetype2-$freetype_version.zip -d freetype
[ -d sqlite3 ] || unzip -o $packagedir/sqlite3-$sqlite3_version.zip -d sqlite3
[ -d openal_stripped ] || unzip -o $packagedir/openal_stripped.zip
[ -d luajit ] || unzip -o $packagedir/luajit-$luajit_version.zip -d luajit
[ -d leveldb ] || unzip -o $packagedir/libleveldb-$leveldb_version.zip -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 https://github.com/minetest/minetest)
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 https://github.com/minetest/minetest_game)
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


User avatar
Posts: 320
Joined: Fri Sep 22, 2017 06:46
GitHub: ChimneySwift
IRC: ChimneySwift
In-game: ChimneySwift

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

by ChimneySwift » Mon Mar 26, 2018 00:26

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.
A spoon is basically a tiny bowl with a stick on it

Posts: 10
Joined: Fri May 19, 2017 05:24

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

by bomberman » Tue May 22, 2018 17:10

it downloads version 0.5, how download 0.4.16 with this script?

User avatar
Posts: 895
Joined: Sun Jul 31, 2011 11:23
Location: Ukraine
IRC: Fixer
In-game: Fixer

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

by Fixer » Tue May 22, 2018 20:01

bomberman wrote:it downloads version 0.5, how download 0.4.16 with this script?

I don't remember exactly, but after "git clone https://github.com/minetest/minetest" 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.

User avatar
Posts: 452
Joined: Thu Nov 16, 2017 18:18
Location: Germany
GitHub: Enrikoo
IRC: Enrico - Enricoo - Enrlco
In-game: Enrico - Enriko

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

by Enrikoo » Wed Nov 27, 2019 18:19

The information is outdated, because I get cmake errors, can you renew these informations please so, that I don't get cmake errors anymore?


Return to Builds

Who is online

Users browsing this forum: No registered users and 8 guests