# -*- 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           legacysupport 1.1

# Only used for the wrapper
legacysupport.newest_darwin_requires_legacy 0

name                tomato-tox
github.setup        Green-Sky tomato 862 dev- -f009db0
revision            0
epoch               1
categories          net chat p2p
license             MIT
maintainers         {@barracuda156 macos-powerpc.org:barracuda}

description         Experimental solanaceae client
long_description    ${name}, a plant from the solanaceae family with Tox built-in.

fetch.type          git
post-fetch {
    system -W ${worksrcpath} "git submodule update --init"
}

# tomato(86921) malloc: *** error for object 0xa00a6754: pointer being freed was not allocated
legacysupport.redirect_bins tomato

patchfiles-append   patch-fix-install-exec.diff

depends_build-append \
                    path:bin/pkg-config:pkgconfig

# Consider using external libconfig-hr and toxcore.
# See: https://github.com/Green-Sky/tomato/issues/53
depends_lib-append  path:lib/pkgconfig/freetype2.pc:freetype \
                    port:libsodium \
                    port:plutosvg \
                    port:SDL3 \
                    port:SDL3_image \
                    port:webp

# Looks like these are only used for the build
# to produce static libs for the binary.
depends_build-append \
                    port:zlib \
                    port:zstd

configure.args-append \
                    -DTOMATO_ASAN=OFF \
                    -DTOMATO_BREAKPAD=OFF \
                    -DTOMATO_DEP_LIBWEBP_USE_SYSTEM=ON \
                    -DTOMATO_DEP_PLUTOSVG_USE_SYSTEM=ON \
                    -DTOMATO_DEP_SDL_USE_SYSTEM=ON \
                    -DTOMATO_DEP_SDL_IMAGE_USE_SYSTEM=ON \
                    -DTOMATO_TOX_AV=OFF

compiler.cxx_standard   2017

# ___atomic_fetch_add_8, ___atomic_load_8, ___atomic_store_8
if {[string match *gcc* ${configure.compiler}] \
    && (${configure.build_arch} in [list arm i386 ppc])} {
    configure.ldflags-append \
                    -latomic
}

variant toxav description "Enable toxav in toxcore" {
    depends_lib-append \
                    port:libopus \
                    path:lib/pkgconfig/vpx.pc:libvpx
    configure.args-replace \
                    -DTOMATO_TOX_AV=OFF -DTOMATO_TOX_AV=ON
}

default_variants    +toxav

# TODO: switch to normal install target on the next update.
destroot {
    copy ${cmake.build_dir}/bin/tomato ${destroot}${prefix}/bin/
}
