# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           cmake 1.1
PortGroup           github 1.0
PortGroup           openssl 1.0

github.setup        luanti-org luanti 5.14.0
github.tarball_from archive
revision            0

set game_version    5.8.0

set main_distfile   ${distfiles}
set game_distfile   ${game_version}${extract.suffix}
set game_mastersite https://github.com/luanti-org/minetest_game/archive/refs/tags

distfiles           ${main_distfile}:main \
                    ${game_distfile}:game

master_sites        ${github.master_sites}:main \
                    ${game_mastersite}:game

checksums           ${main_distfile} \
                    rmd160  f46baeb1961972a01a547967a5b2937cd627849a \
                    sha256  b9f561fa37db3c7ea1b8ba15cfede8282b7a79b9e939b0357269c8b037cf5aea \
                    size    12421600 \
                    ${game_distfile} \
                    rmd160  9300fde834d5f7e37286225ba0e851e891db2ef1 \
                    sha256  33a3bb43b08497a0bdb2f49f140a2829e582d5c16c0ad52be1595c803f706912 \
                    size    2608281

compiler.cxx_standard 2017
compiler.thread_local_storage yes

categories          games
license             LGPL-2.1+
maintainers         {@fvhovell gmail.com:triggered} openmaintainer

description         open source infinite-world block sandbox game with survival and crafting
long_description    {*}${description} - Find more Luanti mods at <https://content.luanti.org/> and have fun.

homepage            https://www.luanti.org

depends_build-append \
                    path:bin/doxygen:doxygen \
                    port:gettext

depends_lib-append  port:curl \
                    port:freetype \
                    port:gettext-runtime \
                    port:gmp \
                    port:jsoncpp \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libogg \
                    port:libpng \
                    port:libiconv \
                    port:libvorbis \
                    path:lib/libluajit-5.1.dylib:luajit \
                    port:libsdl2 \
                    port:leveldb \
                    port:ncurses \
                    port:spatialindex \
                    port:sqlite3 \
                    port:xorg-libX11 \
                    port:xorg-libXxf86vm \
                    port:zlib \
                    port:zstd

conflicts           irrlichtmt

universal_variant   no
supported_archs     arm64 i386 x86_64

# 001. the original build calls fixup_bundle to move all the deps into the app bundle.
#      this doesn't work correctly with MacPorts' destrooting and isn't necessary
patchfiles-append   001-patch-src-CMakeLists-disable-bundlefixup.diff

# 002. patch to get the luajit include headers ahead of the system includes, or the build finds the
#      wrong lua headers if you have a newer version of lua installed
patchfiles-append   002-patch-cmake-Modules-FindLua-include-LUADIR-before-system.diff

cmake.build_type    Release
cmake.install_prefix ${applications_dir}

configure.args-append \
                    -DCMAKE_FIND_FRAMEWORK=FIRST \
                    -DBUILD_UNITTESTS=OFF \
                    -DENABLE_UPDATE_CHECKER=OFF \
                    -DBUILD_CLIENT=ON \
                    -DBUILD_SERVER=ON \
                    -DENABLE_SOUND=ON \
                    -DUSE_SDL2=ON \
                    -DENABLE_GLES2=OFF \
                    -DENABLE_OPENGL=ON \
                    -DENABLE_OPENGL3=ON \
                    -DENABLE_REDIS=OFF \
                    -DENABLE_POSTGRESQL=OFF \
                    -DENABLE_LEVELDB=ON \
                    -DENABLE_CURL=ON \
                    -DENABLE_GETTEXT=ON \
                    -DENABLE_SPATIAL=ON \
                    -DENABLE_SYSTEM_GMP=ON \
                    -DENABLE_SYSTEM_JSONCPP=ON \
                    -DENABLE_LUAJIT=ON \
                    -DINSTALL_DEVTEST=ON \
                    -DVERSION_EXTRA=MacPorts-rev${revision}

post-destroot {
    move ${workpath}/minetest_game-${game_version} ${destroot}${applications_dir}/${name}.app/Contents/Resources/games/minetest_game
}
