Linux下Minetest编译安装

整体步骤

编译minetest的步骤和开发流程是一样的!首先需要安装系统必须的依赖!这些依赖是代码需要引用的库数据。然后下载游戏的源代码接着编译。对于非专业的开发人员来说,你要注意一下问题:

  • 1.安装的依赖不同的linux发行版名称可能不一样
  • 2.下载源代码需要使用Git工具或者常规的文件下载
  • 3.git wget这里两个命令可以先学习

依赖

依赖 版本 描述
GCC 4.9+ 可以使用Clang 3.4+替代
CMake 2.6+
Irrlicht 1.7.3+
SQLite3 3.0+
LuaJIT 2.0+ 如果不存在使用捆绑的 Lua 5.1 t
GMP 5.0.0+ 如果不存在使用捆绑的 mini-GMPt
JsonCPP 1.0.0+ 如果不存在使用捆绑的 JsonCPP

Debain10依赖安装

sudo apt install g++ make libc6-dev libirrlicht-dev cmake libbz2-dev libpng-dev libjpeg-dev libxxf86vm-dev libgl1-mesa-dev libsqlite3-dev libogg-dev libvorbis-dev libopenal-dev libcurl4-gnutls-dev libfreetype6-dev zlib1g-dev libgmp-dev libjsoncpp-dev doxygen libleveldb-dev libhiredis-dev libspatialindex-dev doxygen libcurl-devel mesa-libGLU-devel

Debain11依赖安装

sudo apt install g++ make libc6-dev libirrlicht-dev cmake libbz2-dev libpng-dev libjpeg-dev libxxf86vm-dev libgl1-mesa-dev libsqlite3-dev libogg-dev libvorbis-dev libopenal-dev libcurl4-gnutls-dev libfreetype6-dev zlib1g-dev libgmp-dev libjsoncpp-dev doxygen libleveldb-dev libhiredis-dev libspatialindex-dev doxygen libluajit-5.1-dev libzstd-dev  gettext libncurses5-dev  libpq-dev

Centos8依赖安装

需要先配置其他仓库,否则很多软件包找不到
参考地址: Configuration - RPM Fusion

sudo dnf install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sduo dnf install --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
sduo dnf install --nogpgcheck https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm
sudo dnf config-manager --enable PowerTools

centos8 依赖包

dnf install leveldb-devel openal-soft-devel libvorbis-devel  mesa-libGL-devel sqlite-devel bzip2-devel gmp-devel  ncurses-devel libXxf86vm-devel libjpeg-turbo-devel  libpng-devel freetype-devel postgresql13-devel spatialindex-devel doxygen libzstd-devel

Centos8在这篇文章出之时并没有 irrlicht-devel spatialindex-devel 的包!我的解决方案:irrlicht-devel使用fadora31中的包 spatialindex-devel 使用centos7中的包

包的下载地址:https://fedora.pkgs.org/31/fedora-x86_64/irrlicht-devel-1.8.4-10.fc31.x86_64.rpm.html
当然就这个包时不够的,还需要连带下载如下包

irrlicht-1.8.4-10.fc31.x86_64.rpm
irrXML-devel-1.8.4-10.fc31.x86_64.rpm
irrlicht-devel-1.8.4-10.fc31.x86_64.rpm
libaesgm-20090429-21.fc31.x86_64.rpm
irrXML-1.8.4-10.fc31.x86_64.rpm
spatialindex-1.8.5-1.el7.x86_64.rpm
spatialindex-devel-1.8.5-1.el7.x86_64.rpm

使用 rpm -i package_name 进修安装

Centos8中如果psql数据找不到可以这样设置参数

 cmake . -DCMAKE_BUILD_TYPE=Release  -DRUN_IN_PLACE=TRUE -DBUILD_SERVER=TRUE -DPostgreSQL_INCLUDE_DIR=/usr/pgsql-13/include/ -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/pgsql-13/include -DPostgreSQL_LIBRARY=/usr/pgsql-13/lib/libpq.so

Fedora依赖安装

sudo dnf install make automake gcc gcc-c++ kernel-devel cmake libcurl-devel openal-soft-devel libvorbis-devel libXxf86vm-devel libogg-devel freetype-devel mesa-libGL-devel zlib-devel jsoncpp-devel irrlicht-devel bzip2-libs gmp-devel sqlite-devel luajit-devel leveldb-devel ncurses-devel doxygen spatialindex-devel bzip2-devel  

Arch依赖安装

sudo pacman -S base-devel libcurl-gnutls cmake libxxf86vm irrlicht libpng sqlite libogg libvorbis openal freetype2 jsoncpp gmp luajit leveldb ncurses

Alpine绑定安装

sudo apk add build-base irrlicht-dev cmake bzip2-dev libpng-dev jpeg-dev libxxf86vm-dev mesa-dev sqlite-dev libogg-dev libvorbis-dev openal-soft-dev curl-dev freetype-dev zlib-dev gmp-dev jsoncpp-dev luajit-dev

下载源代码

使用Git工具拉取

您可以安装Git来轻松保持副本最新。如果您不想要Git,请阅读以下有关如何在不使用Git的情况下获取源代码的信息。

Debian / Ubuntu上安装Git

sudo apt install git

Fedora安装Git

dnf install git

使用Git下载源(这是最新版本的源存储库的URL,可能并非始终都有效):

git clone --depth 1 https://github.com/minetest/minetest.git
cd minetest

使用Git下载minetest_game(否则,只有“最小开发测试”游戏可用):

git clone --depth 1 https://github.com/minetest/minetest_game.git games/minetest_game

将IrrlichtMt 下载到lib/irrlichtmt ,它将用于满足 IrrlichtMt 依赖关系:

git clone --depth 1 https://github.com/minetest/irrlicht.git lib/irrlichtmt

下载源,不使用Git:

wget https://github.com/minetest/minetest/archive/master.tar.gz
tar xf master.tar.gz
cd minetest-master

下载minetest_game,无需使用Git:

cd games/
wget https://github.com/minetest/minetest_game/archive/master.tar.gz
tar xf master.tar.gz
mv minetest_game-master minetest_game
cd ..

下载 IrrlichtMt,不使用 Git:

cd lib/
wget https://github.com/minetest/irrlicht/archive/master.tar.gz
tar xf master.tar.gz
mv irrlicht-master irrlichtmt
cd ..

构建

当我们源代码准备好以后就可以开始构建游戏了

构建操作:

cmake . -DRUN_IN_PLACE=TRUE
make -j$(nproc)

游戏运行

./bin/minetest

备注

  • 使用 cmake . -LH 看到所有CMake的选项和它们当前的状态。
  • 如果要在全系统范围内安装(或正在制作分发包),请使用 -DRUN_IN_PLACE=FALSE
  • 您可以通过指定来构建裸服务器 -DBUILD_SERVER=TRUE
  • 您可以通过指定禁用客户端构建 -DBUILD_CLIENT=FALSE
  • 您可以在发布版本和调试版本之间进行选择 -DCMAKE_BUILD_TYPE=<Debug or Release>
    • 调试构建速度较慢,但​​在调试器中提供了更多有用的输出。
  • 如果您构建裸服务器,则无需安装Irrlicht。
    • 在这种情况下,请使用 -DIRRLICHT_SOURCE_DIR=/the/irrlicht/source

CMake选项

常规选项及其默认值:

BUILD_CLIENT=TRUE          - Build Minetest client
BUILD_SERVER=FALSE         - Build Minetest server
CMAKE_BUILD_TYPE=Release   - Type of build (Release vs. Debug)
    Release                - Release build
    Debug                  - Debug build
    SemiDebug              - Partially optimized debug build
    RelWithDebInfo         - Release build with debug information
    MinSizeRel             - Release build with -Os passed to compiler to make executable as small as possible
ENABLE_CURL=ON             - Build with cURL; Enables use of online mod repo, public serverlist and remote media fetching via http
ENABLE_CURSES=ON           - Build with (n)curses; Enables a server side terminal (command line option: --terminal)
ENABLE_FREETYPE=ON         - Build with FreeType2; Allows using TTF fonts
ENABLE_GETTEXT=ON          - Build with Gettext; Allows using translations
ENABLE_GLES=OFF            - Build for OpenGL ES instead of OpenGL (requires support by Irrlicht)
ENABLE_LEVELDB=ON          - Build with LevelDB; Enables use of LevelDB map backend
ENABLE_POSTGRESQL=ON       - Build with libpq; Enables use of PostgreSQL map backend (PostgreSQL 9.5 or greater recommended)
ENABLE_REDIS=ON            - Build with libhiredis; Enables use of Redis map backend
ENABLE_SPATIAL=ON          - Build with LibSpatial; Speeds up AreaStores
ENABLE_SOUND=ON            - Build with OpenAL, libogg & libvorbis; in-game sounds
ENABLE_LUAJIT=ON           - Build with LuaJIT (much faster than non-JIT Lua)
ENABLE_SYSTEM_GMP=ON       - Use GMP from system (much faster than bundled mini-gmp)
ENABLE_SYSTEM_JSONCPP=OFF  - Use JsonCPP from system
OPENGL_GL_PREFERENCE=LEGACY - Linux client build only; See CMake Policy CMP0072 for reference
RUN_IN_PLACE=FALSE         - Create a portable install (worlds, settings etc. in current directory)
USE_GPROF=FALSE            - Enable profiling using GProf
VERSION_EXTRA=             - Text to append to version (e.g. VERSION_EXTRA=foobar -> Minetest 0.4.9-foobar

Library specific 选项:

BZIP2_INCLUDE_DIR               - Linux only; directory where bzlib.h is located
BZIP2_LIBRARY                   - Linux only; path to libbz2.a/libbz2.so
CURL_DLL                        - Only if building with cURL on Windows; path to libcurl.dll
CURL_INCLUDE_DIR                - Only if building with cURL; directory where curl.h is located
CURL_LIBRARY                    - Only if building with cURL; path to libcurl.a/libcurl.so/libcurl.lib
EGL_INCLUDE_DIR                 - Only if building with GLES; directory that contains egl.h
EGL_LIBRARY                     - Only if building with GLES; path to libEGL.a/libEGL.so
FREETYPE_INCLUDE_DIR_freetype2  - Only if building with FreeType 2; directory that contains an freetype directory with files such as ftimage.h in it
FREETYPE_INCLUDE_DIR_ft2build   - Only if building with FreeType 2; directory that contains ft2build.h
FREETYPE_LIBRARY                - Only if building with FreeType 2; path to libfreetype.a/libfreetype.so/freetype.lib
FREETYPE_DLL                    - Only if building with FreeType 2 on Windows; path to libfreetype.dll
GETTEXT_DLL                     - Only when building with gettext on Windows; path to libintl3.dll
GETTEXT_ICONV_DLL               - Only when building with gettext on Windows; path to libiconv2.dll
GETTEXT_INCLUDE_DIR             - Only when building with gettext; directory that contains iconv.h
GETTEXT_LIBRARY                 - Only when building with gettext on Windows; path to libintl.dll.a
GETTEXT_MSGFMT                  - Only when building with gettext; path to msgfmt/msgfmt.exe
IRRLICHT_DLL                    - Only on Windows; path to Irrlicht.dll
IRRLICHT_INCLUDE_DIR            - Directory that contains IrrCompileConfig.h
IRRLICHT_LIBRARY                - Path to libIrrlicht.a/libIrrlicht.so/libIrrlicht.dll.a/Irrlicht.lib
LEVELDB_INCLUDE_DIR             - Only when building with LevelDB; directory that contains db.h
LEVELDB_LIBRARY                 - Only when building with LevelDB; path to libleveldb.a/libleveldb.so/libleveldb.dll.a
LEVELDB_DLL                     - Only when building with LevelDB on Windows; path to libleveldb.dll
PostgreSQL_INCLUDE_DIR          - Only when building with PostgreSQL; directory that contains libpq-fe.h
PostgreSQL_LIBRARY              - Only when building with PostgreSQL; path to libpq.a/libpq.so/libpq.lib
REDIS_INCLUDE_DIR               - Only when building with Redis; directory that contains hiredis.h
REDIS_LIBRARY                   - Only when building with Redis; path to libhiredis.a/libhiredis.so
SPATIAL_INCLUDE_DIR             - Only when building with LibSpatial; directory that contains spatialindex/SpatialIndex.h
SPATIAL_LIBRARY                 - Only when building with LibSpatial; path to libspatialindex_c.so/spatialindex-32.lib
LUA_INCLUDE_DIR                 - Only if you want to use LuaJIT; directory where luajit.h is located
LUA_LIBRARY                     - Only if you want to use LuaJIT; path to libluajit.a/libluajit.so
MINGWM10_DLL                    - Only if compiling with MinGW; path to mingwm10.dll
OGG_DLL                         - Only if building with sound on Windows; path to libogg.dll
OGG_INCLUDE_DIR                 - Only if building with sound; directory that contains an ogg directory which contains ogg.h
OGG_LIBRARY                     - Only if building with sound; path to libogg.a/libogg.so/libogg.dll.a
OPENAL_DLL                      - Only if building with sound on Windows; path to OpenAL32.dll
OPENAL_INCLUDE_DIR              - Only if building with sound; directory where al.h is located
OPENAL_LIBRARY                  - Only if building with sound; path to libopenal.a/libopenal.so/OpenAL32.lib
OPENGLES2_INCLUDE_DIR           - Only if building with GLES; directory that contains gl2.h
OPENGLES2_LIBRARY               - Only if building with GLES; path to libGLESv2.a/libGLESv2.so
SQLITE3_INCLUDE_DIR             - Directory that contains sqlite3.h
SQLITE3_LIBRARY                 - Path to libsqlite3.a/libsqlite3.so/sqlite3.lib
VORBISFILE_DLL                  - Only if building with sound on Windows; path to libvorbisfile-3.dll
VORBISFILE_LIBRARY              - Only if building with sound; path to libvorbisfile.a/libvorbisfile.so/libvorbisfile.dll.a
VORBIS_DLL                      - Only if building with sound on Windows; path to libvorbis-0.dll
VORBIS_INCLUDE_DIR              - Only if building with sound; directory that contains a directory vorbis with vorbisenc.h inside
VORBIS_LIBRARY                  - Only if building with sound; path to libvorbis.a/libvorbis.so/libvorbis.dll.a
XXF86VM_LIBRARY                 - Only on Linux; path to libXXf86vm.a/libXXf86vm.so
ZLIB_DLL                        - Only on Windows; path to zlib1.dll
ZLIB_INCLUDE_DIR                - Directory that contains zlib.h
ZLIB_LIBRARY                    - Path to libz.a/libz.so/zlib.lib

Windows编译

这里我们不涉及到window的编译安装!如果您只是普通用户,window可以直接下载游戏并运行!

执行

cmake . -DRUN_IN_PLACE=TRUE

如果报错

CMake Error at CMakeLists.txt:78 (message):
  Irrlicht found, but it is not IrrlichtMt (Minetest's Irrlicht fork).  The
  Minetest team has forked Irrlicht to make their own customizations.  It can
  be found here: https://github.com/minetest/irrlicht

查看该帖子

Debian11下我的cmake选项

cmake . -DCMAKE_BUILD_TYPE=Release  -DRUN_IN_PLACE=TRUE -DBUILD_SERVER=TRUE -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql/ -DIRRLICHT_INCLUDE_DIR=/usr/local/include/irrlichtmt/