# -*- 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 56368 2009-08-26 18:59:25Z devans@macports.org $

PortSystem 1.0

name            ffmpeg
epoch           1
version         0.5
revision        3
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     be8503f15c3b81ba00eb8379ca8dcf33 \
                sha1    f930971bc0ac3d11a4ffbb1af439425c24f6f5b1 \
                rmd160  23b4a591c422f98b634eba0ba82817ad27a4ff07

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 \
                port:libsdl \
                port:bzip2 \
                port:zlib

build.cmd       gmake
configure.compiler gcc-4.0

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

pre-extract {
    if {"darwin" == ${os.platform} && 9 == ${os.major}} {
        set minimum_xcodeversion 3.1
        set current_xcodeversion [exec defaults read /Developer/Applications/Xcode.app/Contents/Info CFBundleShortVersionString]
        if {[rpm-vercomp ${current_xcodeversion} ${minimum_xcodeversion}] < 0} {
            ui_error "On Mac OS X ${macosx_version}, ${name} ${version} requires Xcode ${minimum_xcodeversion} or later but you have Xcode ${current_xcodeversion}."
            return -code error "incompatible Xcode version"
        }
    }
}

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 \
        --mandir=${prefix}/share/man \
        --enable-shared --enable-pthreads \
        --cc=gcc-4.0

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

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

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.check regex
livecheck.url   ${master_sites}
livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
