# -*- 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 119932 2014-05-11 00:04:51Z mf2k@macports.org $

PortSystem                  1.0
PortGroup                   cmake 1.0
PortGroup                   app 1.0

name                        avidemux
version                     2.6.8
categories                  multimedia
platforms                   macosx
license                     GPL-2
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:project/avidemux/avidemux/${version}
distname                    ${name}_${version}

checksums                   md5     33d0cd47cb84a4e9f4e1b3160405c85c \
                            rmd160  b3d3af569fc2b3ccf485e591313b84000423d182 \
                            sha256  02998c235a89894d184d745c94cac37b78bc20e9eb44b318ee2bb83f2507e682

patchfiles                  patch-cmake-ffmpeg_make.sh.cmake.diff

depends_build-append        port:pkgconfig \
                            port:yasm

depends_lib-append          port:qt4-mac

default_variants            +aac +gettext +lame +sqlite +twolame +x264

# no automatic configure step, everything is done inside build
use_configure               no
# only build with one job (otherwise it fails in avidemux_core)
use_parallel_build          no

configure.args-append       -DCMAKE_C_COMPILER=${configure.cc} \
                            -DCMAKE_C_FLAGS=${configure.cflags} \
                            -DCMAKE_CXX_COMPILER=${configure.cxx} \
                            -DCMAKE_CXX_FLAGS=${configure.cxxflags} \
                            -DFAKEROOT=${workpath}/destroot \
                            -DAVIDEMUX_SOURCE_DIR=${worksrcpath} \
                            -G \"Unix Makefiles\"

# some default settings
configure.args-append       -DSDL=OFF \
                            -DGTK=OFF -DQT4=ON
                            
# disable all options, enable them in variants
configure.args-append       -DFONTCONFIG=OFF -DFREETYPE2=OFF \
                            -DFRIDIBI=OFF \
                            -DGETTEXT=OFF \
                            -DALSA=OFF \
                            -DARTS=OFF \
                            -DESD=OFF \
                            -DJACK=OFF \
                            -DOSS=OFF \
                            -DPULSEAUDIOSIMPLE=OFF \
                            -DAFTEN=OFF \
                            -DDCAENC=OFF -DLIBDCA=OFF \
                            -DFAAC=OFF -DFAAD=OFF \
                            -DLAME=OFF \
                            -DLIBVORBIS=OFF -DVORBIS=OFF \
                            -DOPENCORE_AMRNB=OFF -DOPENCORE_AMRWB=OFF \
                            -DTWOLAME=OFF \
                            -DVPXDEC=OFF \
                            -DX264=OFF \
                            -DXVID=OFF

build {
    # mimic bootStrap.bash Process() behaviour
    proc process {work src module build extra} {
        # make build dir
        file mkdir ${work}/${build}
    
        # configure
        configure.post_args     ${extra} ${src}/${module}
        configure.dir           ${work}/${build}
        command_exec configure
        
        # build
        build.dir               ${work}/${build}
        command_exec build
        
        # install to destroot
        destroot.dir            ${work}/${build}
        command_exec destroot
    }

    # build avidemux core
    process ${workpath} ${worksrcpath} avidemux_core build_core ""
    # build avidemux GTK UI
    #process ${workpath} ${worksrcpath} avidemux/gtk build_gtk "-DCMAKE_EXE_LINKER_FLAGS=-Wl,-framework,Cocoa"
    # build avidemux QT UI
    process ${workpath} ${worksrcpath} avidemux/qt4 build_qt4 ""
    # build avidemux cli UI
    process ${workpath} ${worksrcpath} avidemux/cli build_cli ""
    # build common plugins
    process ${workpath} ${worksrcpath} avidemux_plugins build_pluginsCommon "-DPLUGIN_UI=COMMON -DCMAKE_CXX_COMPILER=${configure.cxx}"
    # build gtk plugins
    #process ${workpath} ${worksrcpath} avidemux_plugins build_pluginsGtk "-DPLUGIN_UI=GTK"
    # build QT plugins
    process ${workpath} ${worksrcpath} avidemux_plugins build_pluginsQt4 "-DPLUGIN_UI=QT4"
    # build cli plugins
    process ${workpath} ${worksrcpath} avidemux_plugins build_pluginsCli "-DPLUGIN_UI=CLI"
}

# destroot is handled by build
destroot {}

variant aac description {Support for faac/faad audio codecs} {
    depends_lib-append  port:faac
    depends_lib-append  port:faad2
    configure.args-strsed s/-DFAAC=OFF/-DFAAC=ON/
    configure.args-strsed s/-DFAAD=OFF/-DFAAD=ON/
}
variant amr description {Support for AMR speech audio codec} {
    depends_lib-append  port:opencore-amr
    configure.args-strsed s/-DOPENCORE_AMRNB=OFF/-DOPENCORE_AMRNB=ON/
    configure.args-strsed s/-DOPENCORE_AMRWB=OFF/-DOPENCORE_AMRWB=ON/
}
variant dts description {Support for DTS (libdca) audio codec} {
    depends_lib-append  port:libdca
    configure.args-strsed s/-DDCAENC=OFF/-DDCAENC=ON/
    configure.args-strsed s/-DLIBDCA=OFF/-DLIBDCA=ON/
}
variant esound description {Support for ESD audio device} {
    depends_lib-append  port:esound
    configure.args-strsed s/-DESD=OFF/-DESD=ON/
}
variant fribidi description {Support for FriBidi} {
    depends_lib-append  port:fribidi
    configure.args-strsed s/-DFRIDIBI=OFF/-DFRIDIBI=ON/
}
variant gettext description {Support for gettext} {
    depends_lib-append  port:gettext
    configure.args-strsed s/-DGETTEXT=OFF/-DGETTEXT=ON/
}
variant jack description {Support for Jack audio device} {
    depends_lib-append  port:jack
    configure.args-strsed s/-DJACK=OFF/-DJACK=ON/
}
variant lame description {Support for LAME audio codec} {
    depends_lib-append  port:lame
    configure.args-strsed s/-DLAME=OFF/-DLAME=ON/
}
variant sqlite description {Support for SQLite3} {
    depends_lib-append  port:sqlite3
}
variant truetype description {Support for FreeType2} {
    depends_lib-append  port:freetype
    depends_lib-append  port:fontconfig
    configure.args-strsed s/-DFREETYPE2=OFF/-DFREETYPE2=ON/
    configure.args-strsed s/-DFONTCONFIG=OFF/-DFONTCONFIG=ON/
}
variant twolame description {Support for TwoLAME audio codec} {
    depends_lib-append  port:twolame
    configure.args-strsed s/-DTWOLAME=OFF/-DTWOLAME=ON/
}
variant vorbis description {Support for Vorbis audio codec} {
    depends_lib-append  port:libvorbis
    configure.args-strsed s/-DVORBIS=OFF/-DVORBIS=ON/
    configure.args-strsed s/-DLIBVORBIS=OFF/-DLIBVORBIS=ON/
}
variant vpx description {Support for VP8 video codec} {
    depends_lib-append  port:libvpx
    configure.args-strsed s/-DVPXDEC=OFF/-DVPXDEC=ON/
}
variant x264 description {Support for x264 video codec} {
    depends_lib-append  port:x264
    configure.args-strsed s/-DX264=OFF/-DX264=ON/
}
variant xvid description {Support for XviD MPEG-4 video codec} {
    depends_lib-append  port:XviD
    configure.args-strsed s/-DXVID=OFF/-DXVID=ON/
}

# .app stuff
app.name        Avidemux
app.executable  avidemux
app.icon        avidemux_icon.png
