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

PortSystem          1.0
PortGroup           openssl 1.0

name                live555
version             2024.03.08
revision            0
categories          multimedia
maintainers         nomaintainer
license             LGPL-2.1+

description         LIVE555 Streaming Media

long_description    This code forms a set of C++ libraries for multimedia \
                    streaming, using open standard protocols (RTP/RTCP, RTSP, \
                    SIP). These libraries - which can be compiled for UNIX \
                    (including Linux and macOS), Windows, and QNX (and other \
                    POSIX-compliant systems) - can be used to build streaming \
                    applications.

homepage            http://www.live555.com/liveMedia/
master_sites        ${homepage}public/ \
                    http://mirror.sobukus.de/files/src/live555/

checksums           rmd160  3640891dc543da9ab17d452ee974bf9416600379 \
                    sha256  c16502e046f1c5f2be3b15e2c8d6cd30639b54c64ea9bfbc8d31b4efca670de5 \
                    size    692953

distname            live.${version}
worksrcdir          live

# older systems fail to build with old libtool versions
# so use a modern version of cctools on all systems to ensure success
depends_build-append \
                    port:cctools

patchfiles          patch-config.macosx.diff 

# https://github.com/rgaufman/live555/issues/45
compiler.cxx_standard 2020
configure.cxxflags-append \
                    -std=c++20

# Configure settings remain in installed Makefiles, so be minimalistic
configure.ccache    no
configure.distcc    no

post-patch {
    set cxx_stdlibflags {}
    if {[string match *clang* ${configure.cxx}] && ${configure.cxx_stdlib} ne ""} {
        set cxx_stdlibflags -stdlib=${configure.cxx_stdlib}
    }

    reinplace "s|@ARCHFLAGS@|[get_canonical_archflags]|g
        s|@CC@|${configure.cc}|g
        s|@CXX@|${configure.cxx} ${cxx_stdlibflags}|g
        s|@CPPFLAGS@|${configure.cppflags}|g
        s|@CFLAGS@|${configure.cflags}|g
        s|@CXXFLAGS@|${configure.cxxflags}|g
        s|@LDFLAGS@|${configure.ldflags}|g
        s|@LIBTOOL@|${prefix}/bin/libtool|g" \
        ${worksrcpath}/config.macosx-bigsur
}

set files_0         ${workpath}/files-0.txt
set files_1         ${workpath}/files-1.txt
set files_new       ${workpath}/files-new.txt

configure.cmd       ./genMakefiles
configure.pre_args {}
configure.universal_args-delete --disable-dependency-tracking

post-configure {
    ui_debug "Create a list of files: \[${files_0}\]"
    system -W ${worksrcpath} "find -s . ! -type d > ${files_0}"
}

post-build {
    ui_debug "Create an updated list of files: \[${files_1}\]"
    system -W ${worksrcpath} "find -s . ! -type d > ${files_1}"

    ui_debug "Create a list of new files: \[${files_new}\]"
    system "comm -1 -3 ${files_0} ${files_1} > ${files_new}"
}

destroot {
    set dst ${destroot}${prefix}/lib/live

    ui_debug "Copy worksrcpath into destroot"
    file copy ${worksrcpath} ${dst}

    ui_debug "Delete everything but *.hh and *.h files listed in \[${files_0}\]"
    system -W ${dst} "grep -v -e '\\.h\$' -e '\\.hh\$' ${files_0} | xargs rm"

    ui_debug "Delete every *.o file listed in \[${files_new}\]"
    system -W ${dst} "grep -e '\\.o\$' ${files_new} | xargs rm"
}

platform macosx {
    configure.args  macosx-bigsur
}

platform linux {
    configure.args  linux
}

livecheck.type      regex
livecheck.url       ${homepage}public/
livecheck.regex     live\\.(\[0-9a-z.\]+)\\.tar\\.gz
