# -*- 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           muniversal 1.0
PortGroup           boost 1.0
PortGroup           qt6 1.0

# Please keep the mkvtoolnix and mkvtoolnix-devel ports as similar as
# possible.

# The developer does not accept macOS-specific bug reports, but does
# accept pull requests.

name                mkvtoolnix-devel
conflicts           mkvtoolnix mkvtoolnix-legacy
set my_name         mkvtoolnix

version             87.0
revision            0
categories          multimedia
maintainers         {ryandesign @ryandesign} {mascguy @mascguy} {i0ntempest @i0ntempest} openmaintainer
license             GPL-2+ LGPL-2.1+

description         Matroska media files manipulation tools.
long_description    mkvtoolnix will evolve to a set of tools to create, \
                    alter and inspect Matroska files under Linux and other \
                    Unices, just what the OGMtools do for the OGM format.

homepage            https://mkvtoolnix.download
master_sites        ${homepage}/sources/
use_xz              yes

checksums           rmd160  c163c96c793b0aeb5cbe4fd37f5fd4dd77f71137 \
                    sha256  01cdfcbe01d9a771da4d475ed44d882a97695d08b6939684cebf56231bdee820 \
                    size    11241000

distname            ${my_name}-${version}
dist_subdir         ${my_name}

set version_ruby    3.3
set version_ruby_mp [join [split $version_ruby "."] ""]

qt6.depends_lib     qtmultimedia \
                    qtsvg

depends_build       port:ruby${version_ruby_mp} \
                    port:docbook-xsl-nons \
                    port:pkgconfig \
                    port:libxslt \
                    port:po4a

depends_lib         port:bzip2 \
                    port:expat \
                    port:flac \
                    port:gettext-runtime \
                    port:libebml \
                    port:libmatroska \
                    port:libogg \
                    port:libvorbis \
                    port:lzo2 \
                    port:zlib \
                    port:pugixml \
                    port:cmark \
                    port:libdvdread \
                    port:gmp \
                    port:nlohmann-json

depends_run         port:ruby${version_ruby_mp}

depends_test        port:gtest

boost.version       1.81

post-patch {
    fs-traverse f ${worksrcpath} {
        set t [file tail ${f}]
        set e [file extension ${f}]
        if {${t} eq "Rakefile" || ${e} eq ".rb"} {
            reinplace -q -E "s|^#!/usr/bin/(env )?ruby|#!${prefix}/bin/ruby${version_ruby}|g" ${f}
        }
    }
}

compiler.cxx_standard \
                    2020
configure.cxxflags-append \
                    -std=c++20

set cxx_stdlibflags {}
if {[string match *clang* ${configure.cxx}]} {
    set cxx_stdlibflags -stdlib=${configure.cxx_stdlib}
}

build.cmd           rake${version_ruby}
build.target        default
# disable silent rules
build.args-append   V=1

configure.args      --mandir=${prefix}/share/man \
                    --with-boost=[boost::install_area] \
                    --with-extra-libs=${prefix}/lib \
                    --with-extra-includes=${prefix}/include \
                    --with-xsltproc=${prefix}/bin/xsltproc \
                    --with-docbook-xsl-root=${prefix}/share/xsl/docbook-xsl-nons \
                    --with-po4a=${prefix}/bin/po4a \
                    --with-po4a-translate=${prefix}/bin/po4a-translate \
                    --disable-update-check \
                    --disable-gui \
                    --with-qmake6=${qt6.dir}/bin/qmake6

configure.ldflags-append ${cxx_stdlibflags}

test.run            yes
test.cmd            rake
test.target         tests:unit

variant qtgui description {Build with the qt6 GUI} {
    PortGroup       app 1.0

    app.name        MKVToolNix
    app.executable  mkvtoolnix-gui
    app.icon        ${worksrcpath}/share/icons/256x256/mkvtoolnix-gui.png

    depends_build-append port:makeicns
    configure.args-replace \
                    --disable-gui \
                    --enable-gui
    configure.args-append \
                    --with-moc=${qt6.dir}/libexec/moc \
                    --with-uic=${qt6.dir}/libexec/uic \
                    --with-rcc=${qt6.dir}/libexec/rcc
}

default_variants    +qtgui

livecheck.type      regex
livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     ${my_name}-(\[0-9.\]+)${extract.suffix}
