# $Id$

# -*- 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
PortGroup           compiler_blacklist_versions 1.0

name                mplayer-devel
version             35203
revision            2
categories          multimedia
license             GPL-2+
maintainers         acho jeremyhu openmaintainer
platforms           darwin

set dvdnav_ver      1243
set ffmpeg_ver      1ad63ff14adb652996c4604da59a330cef0d494e

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:libopus 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/"

    # 5000 should be deep enough to find out checkout within a year
    system "git clone --depth 5000 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-libopus --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
}

# gcc-4.0 and older gcc-4.2 fail to build cpudetect.c properly
compiler.blacklist-append gcc-4.0 {gcc-4.2 < 5646}

# TODO: base should do this: http://trac.macports.org/ticket/32542
if {[info exists portconfigure::compiler_name_map(${configure.compiler})]} {
    depends_build-append port:$portconfigure::compiler_name_map(${configure.compiler})

    # base 2.1.x ignores the argument and just use ${configure.compiler}
    if {[portconfigure::arch_flag_supported ${configure.compiler}]} {
        depends_skip_archcheck-append $portconfigure::compiler_name_map(${configure.compiler})
    }

    if {[string match macports-gcc* ${configure.compiler}]} {
        depends_lib-append port:$portconfigure::compiler_name_map(${configure.compiler})
    }
}

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