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

name                VLC

categories          multimedia devel
maintainers         {gmail.com:rjvbertin @RJVB} @jrabinow openmaintainer

description         VLC is a cross-platform media player and streaming server
long_description    VLC media player is a highly portable multimedia player for \
                    various audio and video formats (MPEG-1, MPEG-2, MPEG-4, DivX, \
                    mp3, ogg, ...) as well as DVDs, VCDs, and various streaming protocols. \
                    It can also be used as a server to stream in unicast or multicast \
                    in IPv4 or IPv6 on a high-bandwidth network.

homepage            https://www.videolan.org

# This port repackages VideoLAN's signed binary app bundle, which is published
# as one disk image per architecture plus a universal one.
supported_archs     arm64 x86_64
variant universal   {}

version             3.0.24
license             GPL-2

# make VLC2 and VLC(3) co-installable.
set vlcprefix       ${prefix}/libexec/vlc3

master_sites        https://download.videolan.org/pub/videolan/vlc/${version}/:source \
                    https://download.videolan.org/pub/videolan/vlc/${version}/macosx:installer
dist_subdir         VLC

distfiles           vlc-${version}.tar.xz:source

if {[variant_exists universal] && [variant_isset universal]} {
    set dmg         vlc-${version}-universal.dmg
} else {
    switch ${build_arch} {
        arm64   { set dmg vlc-${version}-arm64.dmg }
        x86_64  { set dmg vlc-${version}-intel64.dmg }
    }
}
# the Portfile is still parsed on architectures the port does not support
if {[info exists dmg]} {
    distfiles-append \
                    ${dmg}:installer
    use_dmg         yes
    extract.only    ${dmg}
}

checksums           vlc-${version}.tar.xz \
                    rmd160  67ac6835b27c754ae7519e02a25b7f77d361780a \
                    sha256  e7cab503d1d7d5849b89d2cf0e1ee60d0ef6d012407791b644b9cfc0cc225fdf \
                    size    27620304 \
                    vlc-${version}-arm64.dmg \
                    rmd160  d63cad72e5805f840dde9894a6feb11eafc62074 \
                    sha256  64a89d93cdd30b0e97131743e246373db82d6826ea882d265d46d74b136da2b7 \
                    size    56960605 \
                    vlc-${version}-intel64.dmg \
                    rmd160  8787a68236c0c967c4b622cea41c82b8b11856a2 \
                    sha256  1ef6c903e2dc026d4e58ddf7b2a9ed0eb6f8caf80a9a9f46f96490340b962707 \
                    size    63465193 \
                    vlc-${version}-universal.dmg \
                    rmd160  9e423f80acab446fda0bfa14646486be55d22f3d \
                    sha256  2c8e89f7f42e53c2fb0e87b6dfa39b49f1364b25080aaa2e476ac74c0d7beb3c \
                    size    99312422

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    # VLC 3 doesn't run on OS X < 10.7
    replaced_by     VLC2
    PortGroup       obsolete 1.0
}

post-extract {
    ui_msg "--->    Extracting sources (partial)"
    system -W ${workpath} "tar -xf ${distpath}/vlc-${version}.tar.xz vlc-${version}/include"
}

use_configure       no
build               {}

destroot {
    xinstall -m 755 -d ${destroot}${applications_dir}
    system "ditto --rsrc ${workpath}/VLC-${version}/VLC.app ${destroot}${applications_dir}/VLC.app"
    xinstall -m 755 -d ${destroot}${vlcprefix}/lib/vlc
    xinstall -m 755 -d ${destroot}${vlcprefix}/include/vlc/plugins
    ln -s ${applications_dir}/VLC.app/Contents/MacOS/plugins ${destroot}${vlcprefix}/lib/vlc
    ln -s ${applications_dir}/VLC.app/Contents/MacOS/share/lua ${destroot}${vlcprefix}/lib/vlc
    foreach l [glob ${destroot}${applications_dir}/VLC.app/Contents/MacOS/lib/*.dylib] {
        ln -s [string map [list ${destroot} ""] ${l}] ${destroot}${vlcprefix}/lib
    }
    foreach l [glob ${destroot}${applications_dir}/VLC.app/Contents/MacOS/include/vlc/*.h] {
        ln -s [string map [list ${destroot} ""] ${l}] ${destroot}${vlcprefix}/include/vlc
    }
    foreach l [glob ${workpath}/vlc-${version}/include/*.h] {
        xinstall -m 644 ${l} ${destroot}${vlcprefix}/include/vlc/plugins/
    }
}

post-destroot {
    xinstall -m 755 -d ${destroot}${vlcprefix}/lib/pkgconfig
    foreach l {libvlc.pc vlc-plugin.pc} {
        xinstall -m 644 ${filespath}/${l} ${destroot}${vlcprefix}/lib/pkgconfig
        reinplace "s|@PREFIX@|${prefix}|g" ${destroot}${vlcprefix}/lib/pkgconfig/${l}
        reinplace "s|@VERSION@|${version}|g" ${destroot}${vlcprefix}/lib/pkgconfig/${l}
    }
    system "echo \"#!/bin/sh\nexec \\\"${applications_dir}/VLC.app/Contents/MacOS/VLC\\\" \\\"\\\$\@\\\"\" > ${destroot}${prefix}/bin/vlc3"
    system "chmod 755 ${destroot}${prefix}/bin/vlc3"
}


notes-append "MIDI support requires installing one or more SoundFont files,\
    in ${prefix}/share/sounds/sf2, for instance from port:generaluser-soundfont."

# kate: backspace-indents true; indent-pasted-text true; indent-width 4; keep-extra-spaces true; remove-trailing-spaces modified; replace-tabs true; replace-tabs-save true; syntax Tcl/Tk; tab-indents true; tab-width 4;

livecheck.type      regex
livecheck.url       https://download.videolan.org/pub/videolan/vlc/
livecheck.regex     (\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?)
