# -*- 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 90190 2012-02-25 19:42:39Z rmstonecipher@macports.org $

PortSystem      1.0
PortGroup       python 1.0

name            HandBrake
version         0.9.5
platforms       macosx
categories      aqua multimedia
maintainers     nomaintainer
description     DVD to MPEG4 converter
long_description        HandBrake is a GPL'd multi-platform, heavily \
                        multithreaded DVD to MPEG-4 converter. \
                        - Can encode directly from DVDs (even encrypted ones) \
                        - Outputs MP4, AVI or OGM files \
                        - Outputs AAC, MP3 or Vorbis audio \
                        - Supports 2-pass encoding \
                        - Supports encoding of two audio tracks \
                        - Includes a bitrate calculator \
                        - Supports picture cropping and scaling
homepage        http://handbrake.fr/

use_bzip2 yes
master_sites    http://handbrake.fr/rotation.php?file=${distname}${extract.suffix}&dummy=:src \
                http://download.handbrake.fr/handbrake/contrib/:contrib
distfiles       ${distname}${extract.suffix}:src \
                a52dec-0.7.4.tar.gz:contrib \
                faac-1.28.tar.gz:contrib \
                faad2-2.7.tar.gz:contrib \
                ffmpeg-r25689.tar.bz2:contrib \
                fontconfig-2.8.0.tar.gz:contrib \
                freetype-2.3.9.tar.gz:contrib \
                lame-3.98.tar.gz:contrib \
                libass-0.9.9.tar.bz2:contrib \
                libbluray-0.0.1-pre-16-g1aab213.tar.gz:contrib \
                libdca-r81-strapped.tar.gz:contrib \
                libdvdnav-svn1168.tar.gz:contrib \
                libdvdread-svn1168.tar.gz:contrib \
                libmkv-0.6.4.1-0-ga80e593.tar.bz2:contrib \
                libogg-1.1.3.tar.gz:contrib \
                libsamplerate-0.1.4.tar.gz:contrib \
                libtheora-1.1.0.tar.bz2:contrib \
                libvorbis-aotuv_b5.tar.gz:contrib \
                libxml2-2.7.7.tar.gz:contrib \
                mp4v2-trunk-r355.tar.bz2:contrib \
                mpeg2dec-0.5.1.tar.gz:contrib \
                x264-r1834-a51816a.tar.gz:contrib
extract.only    ${distname}${extract.suffix}

checksums       ${distname}${extract.suffix} \
                    md5     e17d3663fc36a985fe43e188695e3196 \
                    sha1    6db599fe96a640e5355f1c92b8915f11c7cb45ad \
                    rmd160  7de96b74e93c9fb7c3fe83a425a7d512e9e811e0 \
                a52dec-0.7.4.tar.gz sha1 7c406b9b5351cdec56279b6d02f3f556711424d2 \
                faac-1.28.tar.gz sha1 d00b023a3642f81bb1fb13d962a65079121396ee \
                faad2-2.7.tar.gz sha1 80eaaa5cc576c35dd28863767b795c50cbcc0511 \
                ffmpeg-r25689.tar.bz2 sha1 0bf31c93575b8f0bd4b38592261bce4f9b9b8d8e \
                fontconfig-2.8.0.tar.gz sha1 570fb55eb14f2c92a7b470b941e9d35dbfafa716 \
                freetype-2.3.9.tar.gz sha1 2c82a4f87b076c13d878129c8651645803585ff4 \
                lame-3.98.tar.gz sha1 2908edcf0628512c407aadad317866826c6df5c7 \
                libass-0.9.9.tar.bz2 sha1 e95923d7833f9ec8aa4f826a6fe113ea30404ad5 \
                libbluray-0.0.1-pre-16-g1aab213.tar.gz sha1 571150392d95f283e4c5e6ea8bdc77218ea962cc \
                libdca-r81-strapped.tar.gz sha1 aace1f940184fad9ec033de48f7d1efc3d0c0ffa \
                libdvdnav-svn1168.tar.gz sha1 2e0b1cb2e215f231fcf7b94f8be6a4a4a6643e94 \
                libdvdread-svn1168.tar.gz sha1 f6db5b9b5cce837e0c3dfd34f9c434b243bfc6fa \
                libmkv-0.6.4.1-0-ga80e593.tar.bz2 sha1 c709548804ea697069d7156d0f9391f86d5da6a5 \
                libogg-1.1.3.tar.gz sha1 9ce317cfe225e121deee68cd81db39f15b602caa \
                libsamplerate-0.1.4.tar.gz sha1 d6974129497ba141d43c36826a23deb6c0b3e5d8 \
                libtheora-1.1.0.tar.bz2 sha1 fb1686a8318d79f889f248ff774265d0ec4c6430 \
                libvorbis-aotuv_b5.tar.gz sha1 ec446e9d2c480210ec8c5a02e479e52336450e3d \
                libxml2-2.7.7.tar.gz sha1 8592824a2788574a172cbddcdc72f734ff87abe3 \
                mp4v2-trunk-r355.tar.bz2 sha1 18a10807c5a05e0361e77d126599f8717ad7c8f5 \
                mpeg2dec-0.5.1.tar.gz sha1 c39a95d18e133cd81e890fd7672f592ed41fadfc \
                x264-r1834-a51816a.tar.gz sha1 33028199108ed71cb4f1b5ae755ef8a2e5f6e7d3

variant python26 conflicts python27 description {Use Python 2.6} {
    python.default_version 26
}

variant python27 conflicts python26 description {Use Python 2.7} {
    python.default_version 27
}

if {![variant_isset python26] && ![variant_isset python27]} {
    default_variants +python27
}

depends_build   bin:curl:curl \
                port:yasm

post-extract {
    file mkdir ${worksrcpath}/download
    file copy \
        ${distpath}/a52dec-0.7.4.tar.gz \
        ${distpath}/faac-1.28.tar.gz \
        ${distpath}/faad2-2.7.tar.gz \
        ${distpath}/ffmpeg-r25689.tar.bz2 \
        ${distpath}/fontconfig-2.8.0.tar.gz \
        ${distpath}/freetype-2.3.9.tar.gz \
        ${distpath}/lame-3.98.tar.gz \
        ${distpath}/libass-0.9.9.tar.bz2 \
        ${distpath}/libbluray-0.0.1-pre-16-g1aab213.tar.gz \
        ${distpath}/libdca-r81-strapped.tar.gz \
        ${distpath}/libdvdnav-svn1168.tar.gz \
        ${distpath}/libdvdread-svn1168.tar.gz \
        ${distpath}/libmkv-0.6.4.1-0-ga80e593.tar.bz2 \
        ${distpath}/libogg-1.1.3.tar.gz \
        ${distpath}/libsamplerate-0.1.4.tar.gz \
        ${distpath}/libtheora-1.1.0.tar.bz2 \
        ${distpath}/libvorbis-aotuv_b5.tar.gz \
        ${distpath}/libxml2-2.7.7.tar.gz \
        ${distpath}/mp4v2-trunk-r355.tar.bz2 \
        ${distpath}/mpeg2dec-0.5.1.tar.gz \
        ${distpath}/x264-r1834-a51816a.tar.gz \
        ${worksrcpath}/download
}

post-extract {
    # make mp4v2 build with clang, see http://code.google.com/p/mp4v2/issues/detail?id=80
    file copy ${filespath}/mp4v2-r355-clang-compatibility-src-bmff-typebmff.cpp.patch \
        ${worksrcpath}/contrib/mp4v2/A01-clang-compatibility.patch
    file copy ${filespath}/mp4v2-r355-clang-compatibility-src-itmf-type.cpp.patch \
        ${worksrcpath}/contrib/mp4v2/A02-clang-compatibility.patch
    # make ffmpeg build with jack support on OS X, see http://ffmpeg.org/trac/ffmpeg/ticket/43
    file copy ${filespath}/ffmpeg-jack-osx.patch \
        ${worksrcpath}/contrib/ffmpeg/A06-jack-osx.patch
}

if {${configure.compiler} == "llvm-gcc-4.2"} {
    configure.compiler gcc-4.2
} elseif {${configure.compiler} == "clang"} {
    depends_build-append port:apple-gcc42
    configure.compiler apple-gcc-4.2
    # base (as of 2.0.3) doesn't set cxx for apple-gcc-4.2
    configure.cxx ${prefix}/bin/g++-apple-4.2
}

# the Python PortGroup disables configure, we still want to use it, though
use_configure       yes
pre-configure {
    # this needs to be set in a phase, since setting it without a phase will not
    # give the correct python version selected by the variants
    configure.cmd   ${python.bin} make/configure.py
}
configure.pre_args
configure.args      --fetch=curl --arch=${configure.build_arch} --gcc=${configure.cc}

# +universal would be possible, but not implemented yet
# see ${worksrcpath}/doc/BUILD-Mac for details
universal_variant   no

build.cmd [portbuild::build_getmaketype]
build.dir ${worksrcpath}/build
build.target

destroot {
    file copy ${worksrcpath}/build/${name}.app ${destroot}${applications_dir}/${name}.app
}
