# -*- 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
# $Id: Portfile 91852 2012-04-12 00:32:25Z jeremyhu@macports.org $

PortSystem              1.0

name                    mplayer2
version                 2.0
revision                4
categories              multimedia
platforms               darwin
license                 Restrictive
maintainers             cal openmaintainer
description             mplayer2 is an advanced general-purpose video player. A fork of the original MPlayer project, it contains significant \
                        further development and supports a number of features not available in other Unix players.
long_description        ${description}

homepage                http://www.mplayer2.org/
master_sites            http://ftp.mplayer2.org/pub/release
distname                ${name}-build-${version}
use_xz                  yes

checksums               rmd160  48193cf6a48e16cce7f74d8f0915e64dc4b7d1cd \
                        sha256  e0a4dba087ba8c6a916d8bc9c7063bd2fd86d36bb08e31a2bd2d82e56b3c4058

conflicts               MPlayer mplayer-devel

depends_build           port:pkgconfig \
                        port:yasm

depends_lib             port:xorg-libXv \
                        port:xorg-libXvMC \
                        port:freetype \
                        port:fontconfig \
                        port:libdvdnav \
                        port:libdvdread \
                        port:libdvdcss \
                        port:libcddb \
                        port:fribidi \
                        port:giflib \
                        port:libpng \
                        port:libmng \
                        port:jpeg \
                        port:openjpeg \
                        port:libcdio \
                        port:libdv \
                        port:libvorbis \
                        port:libtheora \
                        port:faac \
                        port:faad2 \
                        port:a52dec \
                        path:lib/pkgconfig/sdl.pc:libsdl \
                        port:dirac \
                        port:schroedinger \
                        port:lame \
                        port:speex \
                        port:libvpx \
                        port:XviD \
                        port:x264

use_configure           no
universal_variant       no

set mplayercflags      "--disable-smb \
                        --enable-menu \
                        --enable-macosx-finder \
                        --enable-gif \
                        --enable-png \
                        --enable-mng \
                        --enable-jpeg \
                        --enable-libcdio \
                        --enable-xvid \
                        --enable-theora \
                        --enable-faad \
                        --enable-liba52 \
                        --enable-sdl \
                        --enable-xv \
                        --enable-xvmc \
                        --enable-corevideo \
                        --enable-quartz \
                        --enable-coreaudio \
                        --enable-translation \
                        --language=all"

set ffmpegcflags       "--enable-libdirac \
                        --enable-libschroedinger \
                        --enable-libmp3lame \
                        --enable-libopenjpeg \
                        --enable-libspeex \
                        --enable-libtheora \
                        --enable-libvorbis \
                        --enable-libvpx \
                        --enable-libx264 \
                        --enable-libxvid \
                        --enable-libfaac \
                        --enable-nonfree"

configure.cppflags-append \
                        -I${prefix}/include/dirac \
                        -I${prefix}/include/schroedinger-1.0

patchfiles              no-cflags-in-cpp-ffmpeg-mt-configure.patch

if {${configure.compiler} == "clang"} {
    patchfiles-append   clang-compatibility-mplayer-configure.patch
}

pre-build {
    set commonconf  [open "${worksrcpath}/common_options" "a"]
    set ffmpegconf  [open "${worksrcpath}/ffmpeg_options" "a"]
    set mplayerconf [open "${worksrcpath}/mplayer_options" "a"]

    puts $commonconf "--cc=${configure.cc}"
    puts $commonconf "--extra-cflags=${configure.cflags} ${configure.cppflags} [get_canonical_archflags]"
    puts $commonconf "--extra-ldflags=${configure.ldflags} [get_canonical_archflags]"

    foreach option $mplayercflags {
        puts $mplayerconf $option
    }

    foreach option $ffmpegcflags {
        puts $ffmpegconf $option
    }

    puts $mplayerconf "--extra-ldflags=-lintl -lcdio_cdda -lcdio_paranoia -la52"
    puts $mplayerconf "--prefix=${prefix}"

    close $commonconf
    close $ffmpegconf
    close $mplayerconf

    reinplace -E "s|'--cpu=host',||" ${worksrcpath}/script/ffmpeg-config
}

build.target            mplayer
build.env-append        CC=${configure.cc} \
                        CPP=${configure.cpp} \
                        CFLAGS="${configure.optflags} [get_canonical_archflags]" \
                        CPPFLAGS="${configure.cppflags}" \
                        LDFLAGS="${configure.ldflags} [get_canonical_archflags]"

variant smb description {Enable Samba support} {
    depends_lib-append  port:samba3
    configure.args-append --enable-smb
}
