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

# VLC-2.1 and later are x86_64-only: https://trac.videolan.org/vlc/ticket/8161
universal_variant   no
supported_archs     x86_64

version             3.0.11.1
license             GPL-2

platforms           darwin

# 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 \
                    vlc-${version}.dmg:installer

checksums           vlc-${version}.tar.xz \
                    rmd160  a19eb43a0ea6307f0923efe28acae1b803df6a69 \
                    sha256  189311d28aa814f106a7b3645211ac52c0b3e2b9f4b348de2f63bab3218086b8 \
                    size    25886644 \
                    vlc-${version}.dmg \
                    rmd160  69f9f1b4134ce37805f495f8e78eb1c791306793 \
                    sha256  021212d2f6e6701ec3b254d56dfa5c5f848c9c02813c5750c6944a8458de8fb5 \
                    size    51971868

subport lib${name} {}
if {${subport} eq "lib${name}"} {
    description     the core engine and interface to VLC's multimedia framework
    long_description \
                    libVLC is the core engine and the interface to the multimedia \
                    framework on which VLC media player is based.  It allows developers \
                    to create a wide range of multimedia applications using the VLC features.
    conflicts       ${name}
    homepage        https://www.videolan.org/vlc/libvlc.html
    replaced_by     VLC
    PortGroup       obsolete 1.0
} else {
    conflicts       lib${name}
    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
    }
}

use_dmg             yes
extract.only        vlc-${version}.dmg

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+)?)
