# $Id$

PortSystem          1.0
PortGroup           cmake 1.0

name                avidemux
version             2.5.3
revision            9
categories          multimedia
platforms           darwin
maintainers         nomaintainer
homepage            http://avidemux.sourceforge.net/
description         Avidemux is a free video editor

long_description    Avidemux is a free video editor designed for simple cutting, \
                    filtering and encoding tasks. It supports many file types, \
                    including AVI, DVD compatible MPEG files, MP4 and ASF, \
                    using a variety of codecs. Tasks can be automated using \
                    projects, job queue and powerful scripting capabilities. 

master_sites        sourceforge
distname            ${name}_${version}
checksums           md5     5a688029895b66b65ca86b7c85a03ee3 \
                    sha1    073e20007ba5097790cf84cf94b6002c54953395 \
                    rmd160  680963060cdb959d1791a4c0d481eed0e426214d

depends_build-append \
                    port:pkgconfig \
                    port:yasm

depends_lib-append  port:gtk2 \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:spidermonkey \
                    port:libxml2 \
                    port:zlib \
                    port:fontconfig \
                    port:freetype

patchfiles          patch-mangle-asm.diff \
                    patch-cmake-use-sdl.diff \
                    patch-build-plugins.diff \
                    patch-ffmpeg-libs-naming.diff \
                    patch-ffmpeg-configure.diff \
                    patch-no-bundles.diff \
                    patch-libsdl_CMakeLists.txt.diff \
                    patch-x264.diff

post-extract {
    # DOS to UNIX line endings so we can patch properly.
    fs-traverse file ${worksrcpath}/plugins/ADM_videoEncoder/ADM_vidEnc_x264 {
        switch [file extension ${file}] {
            .cpp -
            .h {
                reinplace "s|\r||g" ${file}
            }
        }
    }
}

# do a out of place build
pre-configure {
    file mkdir ${workpath}/build
}
configure.dir       ${workpath}/build
configure.post_args ${worksrcpath}
build.dir           ${workpath}/build
destroot.dir        ${workpath}/build

configure.args-append \
                    -DMAC_BUNDLE_DIR=${applications_dir} \
                    -DVERBOSE=ON \
                    -DGTK=ON \
                    -DQT4=OFF \
                    -DFONTCONFIG=ON \
                    -DGETTEXT=ON \
                    -DUSE_SYSTEM_SPIDERMONKEY=ON \
                    -DSPIDERMONKEY_INCLUDE_DIR=${prefix}/include/js \
                    -DSPIDERMONKEY_LIBRARY_DIR=${prefix}/lib/libjs.dylib

# Prevent ffmpeg in ${prefix} to be searched before bundled ffmpeg
configure.args-append \
                    -DCMAKE_INCLUDE_DIRECTORIES_BEFORE=ON

# For builds on i386
platform darwin i386 {
    configure.cxxflags-append \
		    -D__STDC_CONSTANT_MACROS
}

# SDL uses Quickdraw API, fails on 64-bit
# Xvideo is disabled for OS X, but probably could work
# FIXME: No hardware acceleration at the moment
configure.args-append \
                    -DSDL=OFF \
                    -DXVIDEO=OFF

# Drivers and codecs
configure.args-append \
                    -DALSA=OFF \
                    -DARTS=OFF \
                    -DESD=OFF \
                    -DJACK=OFF \
                    -DOSS=OFF \
                    -DPULSEAUDIOSIMPLE=OFF \
                    -DAFTEN=OFF \
                    -DLAME=OFF \
                    -DFAAC=OFF \
                    -DVORBIS=OFF \
                    -DFAAD=OFF \
                    -DLIBVORBIS=OFF \
                    -DXVID=OFF \
                    -DX264=OFF

# configure plugins
configure.args-append \
                    -DAVIDEMUX_SOURCE_DIR=${worksrcpath} \
                    -DAVIDEMUX_INSTALL_PREFIX=${workpath}/build/ \
                    -DAVIDEMUX_CORECONFIG_DIR=${workpath}/build/config/

# build plugins
post-build {
    build.dir               ${workpath}/build/plugins
    command_exec build
}

# destroot plugins
post-destroot {
    destroot.dir            ${workpath}/build/plugins
    command_exec destroot
}

# binaries will be referencing unversioned .dylibs, so add symlinks
post-destroot {
    fs-traverse -tails f ${destroot}${prefix}/lib {
        if [regexp {^(.*)\.\d+\.dylib$} $f -> fbase] {
            ln -s $f ${destroot}${prefix}/lib/${fbase}.dylib
        }
    }
}

# FIXME: Add variant for qt4 frontend (does not compile yet)

# Additional audio output drivers

variant esd description {Enable ESounD audio output} {
    depends_lib-append port:esound
    configure.args-replace s/-DESD=OFF/-DESD=ON/
}

variant jack description {Enable JACK audio output} {
    depends_lib-append port:jack
    configure.args-replace s/-DJACK=OFF/-DJACK=ON/
}

# Support for additional audio and video libraries
# XXX: additional support for aften exists, but no such port yet

variant aac description {Enable AAC en-/decoding} {
    depends_lib-append port:faac port:faad2
    configure.args-replace s/-DFAAC=OFF/-DFAAC=ON/
    configure.args-replace s/-DFAAD=OFF/-DFAAD=ON/
}

variant dts description {Enable DTS decoding} {
    depends_lib-append port:libdca
    configure.args-replace s/-DLIBDCA=OFF/-DLIBDCA=ON/
}

variant lame description {Enable MP3 encoding} {
    depends_lib-append port:lame
    configure.args-replace s/-DLAME=OFF/-DLAME=ON/
}

variant ogg description {Enable Ogg Vorbis en-/decoding} {
    depends_lib-append port:libvorbis
    configure.args-replace s/-DVORBIS=OFF/-DVORBIS=ON/
    configure.args-replace s/-DLIBVORBIS=OFF/-DLIBVORBIS=ON/
}

variant x264 description {Enable H.264 encoding} {
    depends_lib-append port:x264
    configure.args-replace s/-DX264=OFF/-DX264=ON/
}

variant xvid description {Enable XviD encoding} {
    depends_lib-append port:XviD
    configure.args-append -DXVID=ON
    configure.args-replace s/-DXVID=OFF/-DXVID=ON/
}

livecheck.type      regex
livecheck.url       ${homepage}download.html
livecheck.regex     ${name}_(\[0-9.\]+)\\.tar