# $Id: Portfile 56368 2009-08-26 18:59:25Z devans@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.0rc2
revision            6
categories          multimedia
maintainers         ecronin \
                    openmaintainer
description         The Unix movie player
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.

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      stream_cddb_fix_20080120.diff \
                url_fix_20080120.diff \
                demux_mov_fix_20080129.diff \
                demux_audio_fix_20080129.diff \
                configure.x11.patch \
                qt.x11.patch \
                gl_dlsym.patch
use_bzip2       yes
checksums       ${distname}${extract.suffix} \
                    md5 7e27e535c2d267637df34898f1b91707 \
                    sha1 e9b496f3527c552004ec6d01d6b43f196b43ce2d \
                    rmd160 3b5cba1529856a177a5191e22f8dcc00b5a83c52 \
                stream_cddb_fix_20080120.diff \
                    md5 c7d1bcdd61fcceb7598d61fe2213c587 \
                    sha1 8d901c7a88fa120ed26492e741e1ae0fbe57e12d \
                    rmd160 92999593ff6dfbb8c05f5c9f15efa992193030df \
                url_fix_20080120.diff \
                    md5 6a2c124586e1e6c44ae4ca1b4be9b6e4 \
                    sha1 1e92ded6f27bf07601fa318e24ec468fe225ffe5 \
                    rmd160 82b0ed4f4213767474c8ea7b011237caa24fc604 \
                demux_mov_fix_20080129.diff \
                    md5 ce999929155f509a3e6bee41d9d613ed \
                    sha1 a17d82baff58e8cc569365341503273956fd26c8 \
                    rmd160 69a71376ee817983d400fffde8e5c689156de50f \
                demux_audio_fix_20080129.diff \
                    md5 320af7daa1b248ee8e8c15d34d7923e3 \
                    sha1 e25ba7d8d696d9c6365f105134ba723404adb4e1 \
                    rmd160 68a98b6110b22c4f590f48a2464ba21af7f7faa0

livecheck.check     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 path:include/gif_lib.h:giflib \
                port:libvorbis port:lzo2 port:ncurses port:zlib
depends_build   port:pkgconfig

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

# configure is not autoconf
universal_variant no

configure.args \
        --with-extraincdir=${prefix}/include/lzo:${prefix}/include \
        --with-extralibdir=${prefix}/lib:${prefix}/lib/samba3 \
        --datadir=${prefix}/share/${name} \
        --confdir=${prefix}/etc/${name} \
        --mandir=${prefix}/share/man \
        --enable-gif --enable-png --enable-jpeg --enable-liblzo \
        --enable-libvorbis --enable-mad --disable-faad-external \
        --enable-largefiles

# MPlayer autodetects many support libs.  To prevent undeclared
# dependencies, explicitly disable everything optional first.
# Later, let autodetect do its magic not explicit --enable
configure.args-append \
        --disable-smb --disable-live --disable-dvdnav \
        --disable-dvdread --disable-cdparanoia --disable-freetype \
        --disable-fontconfig --disable-unrarlib --disable-fribidi \
        --disable-enca --disable-libcdio --disable-xvid \
        --disable-x264 --disable-speex --disable-theora \
        --disable-faac --disable-ladspa --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

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

##### 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 theora \
    description {Enable OggTheora support} {
    depends_lib-append      port:libtheora
    configure.args-delete   --disable-theora
    configure.args-append   --enable-theora
}

variant xvid \
    description {Enable XviD encoding} {
    depends_lib-append      port:XviD
    configure.args-delete   --disable-xvid
}

## Needs 20070316 snapshot of x264 or later
variant x264 \
    description {Enable H.264 encoding} {
    depends_lib-append      port:x264
    configure.args-delete   --disable-x264
}

platform darwin powerpc {}
platform darwin i386 {}
variant binary_codecs \
    description {Enable platform-specific binary codecs} {
    if {[variant_isset darwin_powerpc]} {
        global mplayercodecs mplayercodecsfile
        set mplayercodecs       rp9codecs-macosx-20041107.pkg
        set mplayercodecsfile   ${mplayercodecs}.zip
        distfiles-append        ${mplayercodecsfile}:codecs
        checksums-append        ${mplayercodecsfile} \
                                    md5 788cf4940280fd787c0a2141d88ce3c7 \
                                    sha1 18abd6d0424c4682815a13b34695d37d2fda2a73 \
                                    rmd160 c6f49012633bbb84ffa405b8881dc90605d26fc6

        extract.only            ${distname}${extract.suffix}

        depends_build-append    bin:unzip:unzip

        post-extract {
            system "unzip -q -d ${worksrcpath} ${distpath}/${mplayercodecsfile}"
        }

        configure.args-append   --codecsdir=${prefix}/share/${name}/codecs

        post-destroot {
            xinstall -m 755 -d ${destroot}${prefix}/share/${name}/codecs
            system "cd ${destroot}${prefix}/share/${name}/codecs && \
                pax -r -z -f \"${worksrcpath}/${mplayercodecs}/Contents/Archive.pax.gz\""
        }
    }
    if {[variant_isset darwin_i386]} {
        # Wine/DLL loader broken in 1.0rc2
    }
}

variant speex \
    description {Enable Speex playback} {
    depends_lib-append      port:speex-devel
    configure.args-delete   --disable-speex
}

variant faac \
    description {Enable AAC encoding} {
    depends_lib-append      port:faac
    configure.args-delete   --disable-faac
}

variant dv \
    description {Enable DV encoding} {
    depends_lib-append      port:libdv
    configure.args-delete   --disable-libdv
}

variant twolame \
    description {Enable MPEG Audio Layer 2 encoding} {
    depends_lib-append      port:twolame
    configure.args-delete   --disable-twolame
}

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

##### Outputs

variant sdl \
    description {Enable SDL video output} {
    depends_lib-append      port: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 {
    configure.args-append   --enable-macosx --enable-macosx-finder-support \
                            --enable-macosx-bundle --enable-qtx
}

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

platform darwin {
    post-patch {
        reinplace "s|\$\(CC\) \$\(CFLAGS\) -o|\$\(LD\) \$\(CFLAGS\) -o|g" \
            ${worksrcpath}/Makefile
        reinplace "s|-isysroot /Developer/SDKs/MacOSX10.4u.sdk||g" \
            ${worksrcpath}/configure
    }
    build.env           LD=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=c++
}
