# -*- 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 80649 2011-07-16 06:38:12Z jeremyhu@macports.org $

PortSystem 1.0
PortGroup xcodeversion 1.0

name            ffmpeg
conflicts       ffmpeg-devel
epoch           1
version         0.7.1
license         nonfree GPL-2+ LGPL-2.1+
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. \
                        \
                        ffprobe gathers information from multimedia streams and \
                        prints it in human- and machine-readable fashion. \
                        \
                        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       sha1    d006cf0fb61d654c0845240da868ecf3a94c043f \
                rmd160  6539f725d869b97a1821636bd1416312970a6457

depends_build   port:pkgconfig \
                port:gmake \
                port:texi2html

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

build.cmd       ${prefix}/bin/gmake
build.env-append V=1

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

# Under some conditions, llvm-gcc-4.2 drops some "unused" code even though it is used
# fixed in llvm-gcc trunk, but not in Apple's shipped llvm-gccs.
if {${configure.compiler} == "llvm-gcc-4.2"} {
	configure.compiler clang
}

configure.cflags-append    -DHAVE_LRINTF ${configure.cppflags}
configure.args \
        --enable-gpl \
        --enable-postproc \
        --enable-swscale --enable-avfilter \
        --enable-libmp3lame \
        --enable-libvorbis \
        --enable-libtheora \
        --enable-libdirac --enable-libschroedinger \
        --enable-libfaac \
        --enable-libxvid \
        --enable-libx264 \
        --enable-libvpx \
        --enable-libspeex \
        --enable-nonfree \
        --mandir=${prefix}/share/man \
        --enable-shared --enable-pthreads \
        --disable-indevs \
        --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" } {
        # swscale is no longer GPL only
        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-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
}

variant no_nonfree description {disallow use of nonfree code, libraries and binaries will be redistributable under GPL/LGPL} {
    configure.args-delete   --enable-nonfree
    configure.args-delete   --enable-libfaac
    depends_lib-delete      port:faac
}

#
# jack indev support is currently broken
# since Darwin doesn't support memory based POSIX semaphores
# only named ones
#

variant jack description {Enable jack input device support (currently broken)} {
    configure.args-delete --disable-indevs
    depends_lib-append port:jack
}

post-activate {
    if {![variant_isset no_nonfree]} {
        ui_msg "
*******
******* This build of ${name} includes nonfree code as follows:
*******
*******     libfaac
*******
******* The following libraries and binaries may not be redistributed:
*******
*******     ffmpeg
*******     libavcodec
*******     libavdevice
*******     libavfilter
*******     libavformat
*******     libavutil
*******
******* To remove this restriction use variant +no_nonfree
*******
"
    } elseif {![variant_isset no_gpl]} {
        ui_msg "
*******
******* This build of ${name} includes GPLed code and
******* is therefore licensed under GPL v2 or later.
*******
******* The following modules are GPLed:
*******
*******      postproc
*******      libfaad
*******      libx264
*******      libxvid
*******
******* To include only LGPLed code use variant +no_gpl +no_nonfree
*******
"
    } else {
        ui_msg "
*******
******* This build of ${name} includes no GPLed or nonfree
******* code and is therefore licensed under LGPL v2.1 or later.
*******
"
    }
}

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