# -*- 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$

PortSystem          1.0
PortGroup           compiler_blacklist_versions 1.0
PortGroup           muniversal 1.0

# Since libvpx installs a static library only, increase the revision of
# dependents when updating libvpx to a new version so they'll be rebuilt.
name                libvpx
version             1.4.0
categories          multimedia
maintainers         devans openmaintainer
platforms           darwin
license             Permissive

description         WebM VP8/VP9 Codec SDK
long_description    The WebM VP8/VP9 codecs are being developed \
                    specifically to meet the demand for the consumption \
                    of video over the Internet, including professionally \
                    and amateur produced video-on-demand and conversational \
                    video content. VP9 is an evolution of the VP8 video \
                    codec and includes a number of enhancements and new \
                    coding tools that have been added to improve coding efficiency. \
                    The VP9 encoder in this release is not, as yet, feature complete.

homepage            http://webmproject.org
master_sites        http://storage.googleapis.com/downloads.webmproject.org/releases/webm/
use_bzip2           yes

checksums           rmd160  272b1a9f1687a80337d79ccbada2a344c96d1bf1 \
                    sha256  f582d9b2d60a592a4a3d8c32965ca2d2167e9ade38c6c30bac8801ff66a118e4

if {[string match "*86*" [get_canonical_archs]]} {
    depends_build-append port:yasm
}

patchfiles          patch-build-make-configure.sh.diff \
                    patch-configure.diff \
                    patch-Makefile.diff

# clang 425.0.28 with libvpx-1.4.0:
# vp9/common/x86/vp9_subpixel_8t_intrin_avx2.c:77:16: error: assigning to '__m256i' from incompatible type 'int'
#  filtersReg32 = MM256_BROADCASTSI128_SI256(filtersReg);
#               ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compiler.blacklist  {clang < 500}

# As of 1.3.0: 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-vp9 \
                    --enable-internal-stats \
                    --enable-pic \
                    --enable-postproc \
                    --enable-multithread \
                    --enable-runtime-cpu-detect \
                    --disable-install-docs \
                    --disable-debug-libs \
                    --disable-examples \
                    --disable-unit-tests

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

destroot.args       verbose=1

# Build fix for MacPorts clang-3.5 and later:
#
# This is an intentional change to Clang. It now parses the assembly output by default even when emitting assembly so that the diagnostics are consistent between "clang -c" and "clang -S".
# The solution is either to pass -fno-integrated-as to the compiler, or change the assembly produced (& probably the script that processes it) so that it's valid. Note that commenting out the line won't work: comments get stripped by the same process.
# Current Xcode versions of clang > 602 corresponding to Xcode 6.3 or greater also need this fix

if {[string match "macports-clang-3.\[5-9\]" ${configure.compiler}] ||
    (${configure.compiler} eq "clang" && [compiler_blacklist_versions._get_compiler_version ${configure.compiler}] > 602)} {
        build.args-append CFLAGS_S=-fno-integrated-as
}

configure.universal_args-delete --disable-dependency-tracking

set my_targets(ppc)     ppc32
set my_targets(ppc64)   ppc64
set my_targets(i386)    x86
set my_targets(x86_64)  x86_64

# We must specify the target, otherwise the configure script will guess,
# and that may not match what the user requested in macports.conf.
foreach my_arch {ppc ppc64 i386 x86_64} {
    set merger_host(${my_arch}) ""
    if {[info exists my_targets(${my_arch})]} {
        set merger_configure_args(${my_arch}) --target=$my_targets(${my_arch})-${os.platform}-gcc
    }
}
if {![variant_isset universal]} {
    if {[info exists merger_configure_args(${build_arch})]} {
        configure.args-append $merger_configure_args(${build_arch})
    } else {
        configure.args-append --target=${os.arch}-${os.platform}-gcc
    }
}

livecheck.type  regex
livecheck.url   http://downloads.webmproject.org/releases/webm/index.html
livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
