# -*- 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 66934 2010-04-26 10:13:05Z raimue@macports.org $

PortSystem 1.0
PortGroup xcodeversion 1.0

name            ffmpeg-devel
conflicts       ffmpeg
set svn_rev     22866
set swscale_rev 31034
version         ${svn_rev}
categories      multimedia
maintainers     devans openmaintainer

description     Digital VCR and streaming server (new unstable API/ABI libavcodec version 52)

long_description \
                FFmpeg is a complete solution to record, convert and \
                stream audio and video. It includes libavcodec, the \
                leading audio/video codec library. \
                \
                FFmpeg is currently undergoing major changes in its API/ABI in \
                libavcodec version 52. This development release reflects those \
                changes and may break applications coded to libavcodec version 51. \
                \
                For the last valid revision for libavcodec version 51 (r15261) \
                please use port ffmpeg.

homepage        http://www.ffmpeg.org/
master_sites
distfiles

worksrcdir      trunk

use_parallel_build yes

depends_build   bin:svn:subversion \
                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


pre-fetch {
    if {[file isdirectory ${distpath}/${svn_rev}]} {
        if {![file isdirectory ${distpath}/${svn_rev}/trunk/.svn] || ![file exists ${distpath}/${svn_rev}/trunk/.complete]} {
             file delete -force ${distpath}/${svn_rev}
        }
    }
}

fetch {
    if {![file isdirectory ${distpath}/${svn_rev}]} {
        file mkdir ${distpath}/${svn_rev}
        system "svn co -r${svn_rev} --ignore-externals svn://svn.ffmpeg.org/ffmpeg/trunk ${distpath}/${svn_rev}/trunk"
        system "svn co -r${swscale_rev} svn://svn.ffmpeg.org/mplayer/trunk/libswscale ${distpath}/${svn_rev}/trunk/libswscale"
        system "touch ${distpath}/${svn_rev}/trunk/.complete"
    }
}

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

extract {
    file copy ${distpath}/${svn_rev}/trunk ${worksrcpath}
}

platforms       darwin

configure.cflags-append    -DHAVE_LRINTF ${configure.cppflags}
configure.args \
        --enable-nonfree \
        --enable-gpl \
        --enable-postproc \
        --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 \
        --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/ffmpeg
    file copy ${worksrcpath}/doc/APIchanges ${destroot}${prefix}/share/doc/ffmpeg
    file copy ${worksrcpath}/doc/TODO ${destroot}${prefix}/share/doc/ffmpeg
    foreach f [glob ${worksrcpath}/doc/*.txt ${worksrcpath}/doc/*.html] {
        file copy $f ${destroot}${prefix}/share/doc/ffmpeg
    }
}

platform darwin 10 {
    # ticket #20938 -- disable 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
        }
    }
}

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 if +no_nonfree is selected} {
    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
}

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
}

#
# 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.
*******
"
        }
    }
}

#
# 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.
*******
******* The following modules are GPLed:
*******
*******      postproc
*******      swscale
*******      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.
*******
"
    }
}
#
#disable livecheck
#

livecheck.type  none
