# -*- 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 91751 2012-04-09 18:51:34Z jeremyhu@macports.org $

PortSystem      1.0
PortGroup       muniversal 1.0

name            libvpx
version         1.0.0
categories      multimedia
maintainers     nomaintainer
platforms       darwin
license         BSD

description     VP8 video codec
long_description \
    VP8 is a highly efficient video compression technology.

homepage        http://webmproject.org
master_sites    googlecode:webm
use_bzip2       yes
distname        ${name}-v${version}

checksums           rmd160  2ee5a2e7f4cb2f126c6d0d9a36e8636455f42915 \
                    sha256  07cedb0a19a44e6d81d75f52eea864f59ef10c6c725cb860431bec6641eafe21

depends_build   port:yasm

# patches for: 10.6; correct "universal" arch default selection; 'sed' scripts.
patchfiles      patch-build-make-configure.sh.diff \
                patch-configure.diff

post-patch {
    if {[vercmp $xcodeversion 4.3] < 0} {
        set sdks_dir "${developer_dir}/SDKs"
    } else {
        set sdks_dir "${developer_dir}/Platforms/MacOSX.platform/Developer/SDKs"
    }
    reinplace "s|@SDK_DIR@|${sdks_dir}|g" ${worksrcpath}/build/make/configure.sh
}

# As of 0.9.1: doesn't handle shared libraries or debug properly on darwin;
# doesn't install docs or examples correctly, so disable them.
configure.args  --enable-vp8 \
                --enable-internal-stats \
                --enable-pic \
                --enable-postproc \
                --enable-multithread \
                --enable-runtime-cpu-detect \
                --disable-install-docs \
                --disable-debug-libs \
                --disable-examples

configure.env   LD="${configure.cc}"

# add in when docs are installed correctly
#variant docs description {Build documentation} {
#    depends_build-append path:bin/php:php5 port:doxygen
#    configure.args-delete --disable-install-docs
#    configure.args-append --enable-install-docs
#}

platform darwin 8 {
    # Tiger's make 3.80 experiences "virtual memory exhausted" during destroot
    depends_build-append port:gmake
    build.cmd ${prefix}/bin/gmake
}

build.target
build.args      verbose=1

# set configure parameters depending on if universal or not
set my_targets(ppc)     ppc32
set my_targets(ppc64)   ppc64
set my_targets(i386)    x86
set my_targets(x86_64)  x86_64
if {[variant_isset universal]} {
    # clear universal flags; configure will determine them.
    configure.universal_cppflags
    configure.universal_cflags
    configure.universal_cxxflags
    configure.universal_ldflags
    configure.universal_args-delete --disable-dependency-tracking
    foreach my_arch ${configure.universal_archs} {
        set merger_host(${my_arch}) ""
        set merger_configure_args(${my_arch}) --target=$my_targets(${my_arch})-${os.platform}${os.major}-gcc
    }
} else {
    # specify only the single target, otherwise 'configure' will try
    # for a universal install.
    configure.args-append --target=$my_targets(${build_arch})-${os.platform}${os.major}-gcc
}
