# $Id: Portfile 92326 2012-04-25 07:01:14Z jeremyhu@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-devel
version             34874
revision            1
categories          multimedia
maintainers         acho jeremyhu openmaintainer
platforms           darwin

set dvdnav_ver      1243
set ffmpeg_ver      70d54392f5015b9c6594fcae558f59f952501e3b

description         The MPlayer movie player built from SVN.
long_description    ${description} It plays most MPEG/VOB, AVI, Ogg/OGM, \
                    VIVO, ASF/WMA/WMV, QT/MOV/MP4, RealMedia, Matroska, \
                    NUT, NuppelVideo, FLI, YUV4MPEG, FILM, RoQ, PVA files, \
                    supported by many native, XAnim, and Win32 DLL codecs. \
                    You can watch VideoCD, SVCD, DVD, 3ivx, DivX 3/4/5, WMV \
                    and even H.264 movies.
homepage            http://www.mplayerhq.hu/

livecheck.type      none

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

fetch.type          svn
#svn.revision        ${version}
#svn.url             svn://svn.mplayerhq.hu/mplayer/trunk
depends_fetch-append bin:git:git-core
worksrcdir          trunk

fetch {
    system "svn export -r${version} --ignore-externals svn://svn.mplayerhq.hu/mplayer/trunk ${worksrcpath}/"
    system "svn export -r${dvdnav_ver} svn://svn.mplayerhq.hu/dvdnav/trunk/libdvdnav/src ${worksrcpath}/libdvdnav/"
    system "svn export -r${dvdnav_ver} svn://svn.mplayerhq.hu/dvdnav/trunk/libdvdread/src ${worksrcpath}/libdvdread4/"

    # 1000 should be deep enough to find out checkout
    system "git clone --depth 1000 git://git.videolan.org/ffmpeg.git ${worksrcpath}/ffmpeg"
    system "cd ${worksrcpath}/ffmpeg && git checkout -f ${ffmpeg_ver}"
}

# Do not use the following environment variables, otherwise the build phase
# will fail.
configure.cflags    {}
configure.cppflags  {}
configure.cxxflags  {}
configure.ldflags   {}
configure.cc_archflags  {}
configure.cxx_archflags {}

# Do not use pipes, otherwise the build phase will fail.
configure.pipe      no

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

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

patchfiles configure.x11.patch

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
}

universal_variant no

# 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

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
# Allow autodetect to pick up fontconfig & freetype
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-menu
}

variant fribidi requires osd \
    description {Enable FriBidi Unicode support} {
    depends_lib-append      port:fribidi
    configure.args-delete   --disable-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
}

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

#####

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

variant smb description {Enable Samba support} {
    depends_lib-append port:samba3
    configure.args-append --enable-smb
    configure.args-delete --disable-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 mng \
    description {Enable mng codec support} {
    depends_lib-append      port:libmng
    configure.args-delete   --disable-mng
}

variant dirac \
    description {Enable dirac codec support} {
    depends_lib-append      port:dirac port:schroedinger
    configure.args-delete   --disable-libdirac-lavc
    configure.args-delete   --disable-libschroedinger-lavc
}

variant a52 \
    description {Enable AC-3 codec support} {
    depends_lib-append      port:a52dec
    configure.args-delete   --disable-liba52
}

##### 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, this disables corevideo support} {
    depends_lib-append      port:mesa
    configure.args-delete   --disable-gl
    configure.args-append   --enable-gl --disable-corevideo
}

variant debug description {Compile with debugging symbols} {
    configure.args-append   --enable-debug=gdb3 --disable-altivec
}

platform darwin {
    # gcc-4.0 and older gcc-4.2 fail to build cpudetect.c properly
    if {(${configure.compiler} == "gcc-4.0" || ${configure.compiler} == "gcc-4.2") && [vercmp ${xcodeversion} 3.2] < 0} {
        depends_build-append    port:apple-gcc42 port:ld64
        depends_skip_archcheck-append apple-gcc42 ld64

        configure.compiler apple-gcc-4.2
    }
}

platform darwin 8 {
    depends_build-append port:gmake
    depends_skip_archcheck-append gmake

    build.cmd               ${prefix}/bin/gmake
    destroot.cmd            ${prefix}/bin/gmake
}

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

if {${configure.compiler} == "llvm-gcc-4.2"} {
    # llvm-gcc-4.2 fails to build vf_fspp.c properly with -O2 and above
    patchfiles-append llvm-gcc-workaround.patch

    post-patch {
        # link time optimization fails to find references for ff_mlp_firorder*
        # For some reason -O4 -fno-lto doesn't work as well, so just use -O3
        reinplace "s:-O4:-O3:" ${worksrcpath}/configure
    }
}

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