# $Id: Portfile 90625 2012-03-10 05:14:42Z ecronin@macports.org $

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

name                MPlayer
version             1.0rc4
revision            4
categories          multimedia
license             GPL-2+
maintainers         nomaintainer
description         The Unix movie player
set notestxt \
    "The MPlayer developers do not believe in making regular releases. \
    You are likely better off using the mplayer-devel port."
long_description \
    MPlayer can play most standard video formats out of the box and almost \
    all others with the help of external codecs.  MPlayer currently works \
    best from the command line, but visual feedback for many functions is \
    available from its onscreen status display (OSD), which is also used for \
    displaying subtitles. MPlayer also has a GUI with skin support and \
    several unofficial alternative graphical frontends are available. \
    \nNOTE: ${notestxt}
notes ${notestxt}

platforms       darwin

homepage        http://www.mplayerhq.hu/
master_sites    ftp://ftp1.mplayerhq.hu/MPlayer/releases/ \
                http://www2.mplayerhq.hu/MPlayer/releases/ \
                ftp://ftp2.mplayerhq.hu/MPlayer/releases/ \
                ftp://ftp5.mplayerhq.hu/MPlayer/releases/ \
                ftp://ftp.fu-berlin.de/unix/X11/multimedia/MPlayer/releases/ \
                http://www1.mplayerhq.hu/MPlayer/releases/ \
                http://www.people.virginia.edu/~drf8f/MPlayer/releases/ \
                http://www1.mplayerhq.hu/MPlayer/releases/codecs/:codecs \
                http://www2.mplayerhq.hu/MPlayer/releases/codecs/:codecs
patch_sites     http://www.mplayerhq.hu/MPlayer/patches/
patchfiles      configure.x11.patch
use_bzip2       yes
checksums       ${distname}${extract.suffix} \
                    sha1    36dfaeda726896b6831d66b0fe179623e0385fbe \
                    rmd160  f112c53e43143d6f02850ee3d8326e25e7396cff \
livecheck.type      regex
#livecheck.url       http://www1.mplayerhq.hu/MPlayer/releases/
livecheck.url       http://www1.mplayerhq.hu/design7/dload.html
livecheck.regex     MPlayer-(1.0rc\[0-9\]+)\.tar\.bz2


depends_lib     port:jpeg port:lame port:libiconv port:libmad \
                port:libogg port:libpng port:libtheora port:libvorbis \
                port:lzo2 port:ncurses port:zlib port:bzip2
depends_build   port:pkgconfig port:yasm

# MPlayer's ./configure REALLY does not want you to use ENV for this
configure.cflags    {}
configure.cxxflags  {}
configure.cppflags  {}
configure.ldflags   {}
configure.cc_archflags {}
configure.cxx_archflags {}
configure.objc_archflags {}
# And the assembler has issues with -pipe
configure.pipe      no

# configure is not autoconf
universal_variant no

if {${configure.compiler} == "llvm-gcc-4.2"} {
    configure.compiler gcc-4.2
} elseif {${configure.compiler} == "clang"} {
    depends_build-append port:apple-gcc42
    configure.compiler apple-gcc-4.2
    # base (as of 2.0.3) doesn't set cxx for apple-gcc-4.2
    configure.cxx ${prefix}/bin/g++-apple-4.2
}

configure.args \
    --extra-cflags="-I${prefix}/include/lzo -I${prefix}/include" \
    --extra-ldflags="-L${prefix}/lib -L${prefix}/lib/samba3" \
    --datadir=${prefix}/share/${name} \
    --confdir=${prefix}/etc/${name} \
    --mandir=${prefix}/share/man \
    --enable-png --enable-jpeg --enable-liblzo \
    --enable-theora --enable-libvorbis --enable-mad \
    --enable-largefiles

# MPlayer autodetects many support libs.  To prevent undeclared
# dependencies, explicitly disable everything optional first.
# This list should be expanded each time the port is updated to a
# new version, disabling any newly added options.
configure.args-append \
    --disable-smb --disable-live --disable-dvdnav \
    --disable-dvdread --disable-cdparanoia --disable-freetype \
    --disable-fontconfig --disable-fribidi \
    --disable-enca --disable-libcdio --disable-xvid \
    --disable-x264 --disable-speex \
    --disable-faac --disable-libdv \
    --disable-toolame --disable-twolame --disable-xmms \
    --disable-musepack --disable-sdl --disable-aa \
    --disable-caca --disable-x11 --disable-gl --disable-arts \
    --disable-esd --disable-lirc --disable-mng --disable-libdirac-lavc \
    --disable-libschroedinger-lavc --disable-liba52 \
    --disable-gif --disable-libopencore_amrnb --disable-libopencore_amrwb

post-destroot {
    xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}
    eval file copy [glob ${worksrcpath}/DOCS/*] \
        ${destroot}${prefix}/share/doc/${name}
    xinstall -d -m 0755 ${destroot}${prefix}/etc/${name}
    foreach etcfile {codecs.conf dvb-menu.conf example.conf \
                     input.conf menu.conf} {
        xinstall -m 0644 ${worksrcpath}/etc/${etcfile} \
            ${destroot}${prefix}/etc/${name}/${etcfile}
    }
    xinstall -d -m 0755 ${destroot}${prefix}/share/man/man1
    xinstall -m 0644 ${worksrcpath}/DOCS/man/en/mplayer.1 \
        ${destroot}${prefix}/share/man/man1/
    xinstall -m 0755 ${worksrcpath}/TOOLS/midentify.sh ${destroot}${prefix}/bin/midentify
}

# When adding back in extra features it usually works better to
# just list the correct depends_lib and then let the auto-detect
# code find the library versus using an explicit --enable-feature.
# The later often ends up failing to find the headers or libs or both

##### Mplayer features

variant man_all_lang \
    description {Install all possible languages for man pages} {
    configure.args-append --language=all
}

# Bundle all the font deps into one onscreen display variant
# configure doesn't fully build up necessary flags when --enable-fontconfig
# is used, so use autodetect instead
variant osd \
    description {Enable onscreen display and TrueType font support} {
    depends_lib-append      port:fontconfig port:freetype
    configure.args-delete   --disable-fontconfig
    configure.args-delete   --disable-freetype
    configure.args-append   --enable-freetype --enable-menu
}

variant fribidi requires osd \
    description {Enable FriBidi Unicode support} {
    depends_lib-append      port:fribidi
    configure.args-delete   --disable-fribidi
    #configure.args-append   --enable-fribidi
}

variant noappleremote \
    description {Disable Apple Infrared Remote support} {
    configure.args-append   --disable-apple-remote
}

variant lirc \
    description {Enable Linux Infrared Remote Daemon support} {
    depends_lib-append      port:lirc
    configure.args-delete   --disable-lirc
}

##### Inputs

variant nodvd \
    description {Disable DVD and DeCSS support} {
    configure.args-append   --disable-dvdread-internal --disable-libdvdcss-internal
}

variant smb \
    description {Enable smb:// network support} {
    depends_lib-append      port:samba3
    configure.args-delete   --disable-smb
    configure.args-append   --enable-smb
}

##### External codecs

variant mencoder_extras \
    description {Enable extra codecs for encoding (XviD, x264, aac, DV, MP2)} {

    depends_lib-append      port:XviD port:x264 port:faac port:libdv \
        port:twolame
    configure.args-delete   --disable-xvid
    configure.args-delete   --disable-x264
    configure.args-delete   --disable-faac
    configure.args-delete   --disable-libdv
    configure.args-delete   --disable-twolame
}
variant xvid requires mencoder_extras \
    description {deprecated: use +mencoder_extras instead} {}
variant x264 requires mencoder_extras \
    description {deprecated: use +mencoder_extras instead} {}
variant faac requires mencoder_extras \
    description {deprecated: use +mencoder_extras instead} {}
variant dv requires mencoder_extras \
    description {deprecated: use +mencoder_extras instead} {}
variant twolame requires mencoder_extras \
    description {deprecated: use +mencoder_extras instead} {}

variant speex \
    description {Enable Speex playback} {
    depends_lib-append      path:lib/libspeex.dylib:speex
    configure.args-delete   --disable-speex
}

variant dts \
    description {Enable non-passthrough DTS playback} {
    depends_lib-append      port:libdca
    configure.args-delete   --disable-libdts
}

variant live \
    description {Enable live555 streaming media input} {
    depends_lib-append      port:live555
    configure.args-delete   --disable-live
}

##### Outputs

variant sdl \
    description {Enable SDL video output} {
    depends_lib-append      path:lib/pkgconfig/sdl.pc:libsdl
    configure.args-delete   --disable-sdl
}

variant aa \
    description {Enable animated ASCII art video output} {
    depends_lib-append      port:aalib
    configure.args-delete   --disable-aa
}

variant caca \
    description {Enable animated ASCII art video output} {
    depends_lib-append      port:libcaca
    configure.args-delete   --disable-caca
}

variant x11 {
    depends_lib-append \
        port:xorg-libXinerama \
        port:xorg-libXv \
        port:xorg-libXxf86vm

    configure.args-delete   --disable-x11
    configure.args-append   --enable-x11 --enable-xv --enable-xinerama --enable-xshape 
}

variant esd \
    description {Enable EsounD audio output} {
    depends_lib-append      port:esound
    configure.args-delete   --disable-esd
}


platform macosx {
    if { ${configure.build_arch} == "x86_64" } {
        configure.args-append   --disable-qtx
    } else {
        configure.args-append   --enable-qtx
    }
}

variant glx requires x11 description {Enable glx output support.  Due to a bug in Mplayer's build system, this disables Mac OS X-specific features} {
    depends_lib-append      port:mesa
    configure.args-delete   --disable-gl --enable-qtx
    configure.args-append   --enable-gl
}

platform darwin {
    if { ${configure.build_arch} == "x86_64" } {
        configure.args-append --target=${configure.build_arch}-Darwin
    }
    build.env           LD=${configure.cc}
}

platform darwin 8 {
    # Need to force use of c++ for linking when Xcode 2.2 is used since some
    # bits of libstdc++ are needed during linking
    build.env           LD=${configure.cxx}
}

platform darwin 9 {
    configure.args-delete   --extra-cflags="-I${prefix}/include/lzo -I${prefix}/include"
    configure.args-append   --extra-cflags="-fomit-frame-pointer -I${prefix}/include/lzo -I${prefix}/include"
}
