# -*- 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           github 1.0
PortGroup           meson 1.0
PortGroup           boost 1.0
PortGroup           legacysupport 1.1

github.setup        bredelings BAli-Phy 4.1
github.tarball_from archive
name                bali-phy
conflicts           bali-phy-devel
revision            0

categories          science
license             GPL-2+
maintainers         {reneeotten @reneeotten} openmaintainer

description         Bayesian co-estimation of phylogenies and multiple alignments via MCMC
long_description    BAli-Phy estimates multiple sequence alignments and evolutionary trees \
                    from DNA, amino acid, or codon sequences. It uses likelihood-based \
                    evolutionary models of substitutions and insertions and deletions to \
                    place gaps.

homepage            https://www.bali-phy.org/

checksums           rmd160  26eb75c8b5a844cb63faf558abacf96c9084eea9 \
                    sha256  94ddb61de0983df70ecc5664050e4616a8d24884d7ac961179a2b2865407cd97 \
                    size    2703926

subport bali-phy-devel {
    github.setup        bredelings BAli-Phy 472371dc734e4daf70df73bc398f049ce065b388
    version             08162025-[string range ${github.version} 0 7]
    github.tarball_from archive
    conflicts           bali-phy
    revision            0
    checksums           rmd160  6a54bc3286b87f6ef0c7a4efc86b4a6ce365c7b9 \
                        sha256  bb01f025a5d7b03079a996b5186fe7f8fe55b8db47e9862a692d7a0dbb6c7c3a \
                        size    2710277
}

boost.version       1.87

compiler.cxx_standard 2020

# uses std::variant<>, which is broken on macOS <= 10.12; use MacPorts' libc++ instead
legacysupport.newest_darwin_requires_legacy 16
legacysupport.use_mp_libcxx yes

# use the same Python version as in meson
set python_version 3.13
set python_ver_no_dot [string map {. {}} ${python_version}]
set python_bin ${frameworks_dir}/Python.framework/Versions/${python_version}/bin/python${python_version}

variant doc description {Build documentation and man pages} {
    depends_build-append \
                    port:pandoc
}

set port_libfmt     libfmt11
depends_lib-append  port:${port_libfmt}
configure.env-append \
                    PKG_CONFIG_PATH=${prefix}/lib/${port_libfmt}/pkgconfig
configure.ldflags-append \
                    -L${prefix}/lib/${port_libfmt}

# pandoc / stack fails to build on macOS 10.12 and older
# see: https://ports.macports.org/port/pandoc/summary
if {${os.platform} eq "darwin" && ${os.major} > 16} {
    default_variants +doc
}

patchfiles-append   patch-bali_phy_pkg.diff \
                    patch-bp_analyze.diff \
                    patch-run_tests.py.diff

# https://trac.macports.org/ticket/70096
patchfiles-append   patch-bitset.diff

post-patch {
    reinplace "s|@@PYTHON_BIN@@|${python_bin}|g" ${worksrcpath}/tests/run-tests.py \
        ${worksrcpath}/scripts/bp-analyze

    reinplace "s|@@PERL_BIN@@|${prefix}/bin/perl|g" ${worksrcpath}/scripts/bali-phy-pkg \

    if {[file exists ${worksrcpath}/examples/sequences/lrRNA/keep.pl]} {
        reinplace "s|@@PERL_BIN@@|${prefix}/bin/perl|g" ${worksrcpath}/examples/sequences/lrRNA/keep.pl
    }
}

configure.args-append       -Djson=system
configure.post_args-append  --buildtype=release

configure.cppflags-append   -Wno-missing-template-arg-list-after-template-kw

set port_libfmt     libfmt11
depends_lib-append  port:${port_libfmt}
configure.env-append \
                    PKG_CONFIG_PATH=${prefix}/lib/${port_libfmt}/pkgconfig
configure.ldflags-append \
                    -L${prefix}/lib/${port_libfmt}

depends_build-append \
                    port:cereal \
                    port:cmake \
                    path:share/pkgconfig/eigen3.pc:eigen3 \
                    port:nlohmann-json \
                    path:bin/pkg-config:pkgconfig \
                    port:range-v3

depends_lib-append  path:lib/pkgconfig/cairo.pc:cairo

depends_run-append  path:bin/perl:perl5

depends_test-append port:python${python_ver_no_dot}

test.run            yes
test.cmd            ${build.cmd}

post-destroot {
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} README.md NEWS.md \
       COPYING CONTRIBUTING.md ${destroot}${docdir}
}

github.livecheck.regex  {([0-9.]+)}
