# -*- 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 66961 2010-04-26 23:32:44Z devans@macports.org $

PortSystem 1.0
PortGroup xcodeversion 1.0

name            ffmpeg
conflicts       ffmpeg-devel
epoch           1
version         0.5.1
revision        2
categories      multimedia
maintainers     devans openmaintainer

description     FFmpeg is a complete solution to play, record, convert and \
                stream audio and video.

long_description        FFmpeg is a complete solution to record, convert and \
                        stream audio and video. It includes libavcodec, the \
                        leading audio/video codec library. \
                        \
                        The project is made of several components: \
                        \
                        ffmpeg is a command line tool to convert one video \
                        file format to another. It also supports grabbing and \
                        encoding in real time from a TV card. \
                        \
                        ffserver is an HTTP (RTSP is being developped) \
                        multimedia streaming server for live broadcasts. Time \
                        shifting of live broadcast is also supported. \
                        \
                        ffplay is a simple media player based on SDL and on \
                        the ffmpeg libraries. \
                        \
                        libavcodec is a library containing all the ffmpeg \
                        audio/video encoders and decoders. Most codecs were \
                        developped from scratch to ensure best performances \
                        and high code reusability. \
                        \
                        libavformat is a library containing parsers and \
                        generators for all common audio/video formats.

platforms       darwin
homepage        http://www.ffmpeg.org/
master_sites    http://www.ffmpeg.org/releases/

use_bzip2       yes

checksums           md5     c7b0e1729f7aafb10496d79bb963bb26 \
                    sha1    ab29dbfc7510e34e47b491279533d2f8c18efc38 \
                    rmd160  9765798cabbf937f97ca7137b4ab398df5a4ec47

patchfiles      patch-libavfilter-avfilter.h.diff \
                patch-libswscale-Makefile.diff \
                patch-libswscale-swscale.h.diff


use_parallel_build yes

depends_build   port:gmake

depends_lib     port:lame \
                port:libvorbis \
                port:libogg \
                port:libtheora \
                port:dirac \
                port:schroedinger \
                port:faac \
                port:faad2 \
                port:XviD \
                port:x264 \
                path:lib/pkgconfig/sdl.pc:libsdl \
                port:bzip2 \
                port:zlib

build.cmd       gmake

#
# enable auto configure of mmx and related Intel optimizations by default
# requires Xcode 3.1 or better on Leopard
#
minimum_xcodeversions {9 3.1}

configure.cflags-append    -DHAVE_LRINTF ${configure.cppflags}
configure.args \
        --disable-vhook \
        --enable-gpl \
        --enable-postproc \
        --enable-swscale --enable-avfilter --enable-avfilter-lavf \
        --enable-libmp3lame \
        --enable-libvorbis \
        --enable-libtheora \
        --enable-libdirac --enable-libschroedinger \
        --enable-libfaac \
        --enable-libfaad \
        --enable-libxvid \
        --enable-libx264 \
        --enable-nonfree \
        --mandir=${prefix}/share/man \
        --enable-shared --enable-pthreads \
        --cc=${configure.cc}

#add --enable-libopenjpeg when problems with openjpeg.h are resolved

if {$build_arch != ""} {
    configure.args-append --arch=${build_arch}
}

test.run        yes

#
# configure isn't autoconf and they do use a dep cache
#

universal_variant no

post-destroot {
    file mkdir ${destroot}${prefix}/share/doc/${name}
    file copy ${worksrcpath}/doc/TODO ${destroot}${prefix}/share/doc/${name}
    foreach f [glob ${worksrcpath}/doc/*.txt ${worksrcpath}/doc/*.html] {
        file copy $f ${destroot}${prefix}/share/doc/${name}
    }
}

platform darwin 10 {
    # ticket #20938 -- disable mmx for 32 bit intel only
    if { $build_arch == "i386" } {
        if { ![variant_isset no_gpl] } {
            configure.args-delete --enable-swscale
        }
        if { ![variant_isset no_mmx] } {
            configure.args-append --disable-mmx --disable-mmx2 --disable-sse --disable-ssse3 --disable-amd3dnow --disable-amd3dnowext
        }
    }
}

platform powerpc {
    # absence of altivec is not automatically detected
    if {[exec sysctl -n hw.vectorunit] == 0} {
        configure.args-append --disable-altivec
    }
}

variant no_mmx description {disable all x86 asm optimizations} {
    configure.args-append --disable-mmx --disable-mmx2 --disable-sse --disable-ssse3 --disable-amd3dnow --disable-amd3dnowext
}

variant no_gpl description {disallow use of GPL code, license will be LGPL} {
    configure.args-delete   --enable-gpl
    configure.args-delete   --enable-postproc
    configure.args-delete   --enable-swscale
    configure.args-delete   --enable-libfaad
    depends_lib-delete      port:faad2
    configure.args-delete   --enable-libx264
    depends_build-delete      port:x264
    configure.args-delete   --enable-libxvid
    depends_lib-delete      port:XviD
}

#
# make speex a variant since it requires speex version 1.2
# which is currently only available via port speex-devel
# remove variant and make default when 1.2 is available in speex
#

variant speex description {enable Speex decoding via libspeex} {
    configure.args-append   --enable-libspeex
    depends_lib-append      path:lib/libspeex.dylib:speex-devel
}

pre-configure {
    if {[variant_isset speex]} {
        if {![file exists ${prefix}/lib/libspeexdsp.dylib]} {
            error "
*******
******* Variant speex requires port speex-devel but
******* port speex is active.  Please deactivate port speex
******* and install/activate port speex-devel then try
******* again.
*******
"
        }
    }
}

post-activate {
    if {![variant_isset no_gpl]} {
        ui_msg "
*******
******* This build of ${name} includes GPLed code and
******* is therefore licensed under GPL.
*******
******* The following modules are GPLed:
*******
*******      postproc
*******      swscale
*******      libfaad
*******      libx264
*******      libxvid
*******
******* To include only LGPLed code use variant +no_gpl
*******
"
    } else {
        ui_msg "
*******
******* This build of ${name} includes no GPLed
******* code and is therefore licensed under LGPL.
*******
"
    }
}
#
#disable livecheck
#

livecheck.type  regex
livecheck.url   ${master_sites}
livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
