# -*- 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 117612 2014-03-05 19:40:10Z devans@macports.org $

PortSystem      1.0
PortGroup       muniversal 1.0
PortGroup       xcodeversion 1.0

name            x264
version         20140124
revision        1
set git_branch  956c8d8c2a3c2fb1f2f17807532321e492c75efc
categories      multimedia
license         GPL-2+
platforms       darwin
maintainers     devans openmaintainer
description     x264 - a free h264/avc encoder
long_description \
                x264 is a free library for encoding H264/AVC video streams. \
                The code is written by Laurent Aimar, Eric Petit(OS X), Min \
                Chen (vfw/nasm), Justin Clay(vfw), Måns Rullgård and Loren \
                Merritt from scratch. It is released under the terms of the \
                GPL license.
homepage        http://www.videolan.org/x264.html
master_sites    "http://git.videolan.org/gitweb.cgi?p=x264.git;a=snapshot;h=${git_branch};sf=tgz;dummy="

dist_subdir     x264

if {[string length "${git_branch}"] >= 7} {
    set filetag [string range "${git_branch}" 0 6]
    distname ${name}-${filetag}
} else {
    error "git branch hash must be at least 7 characters long."
}

checksums        rmd160  a8d693295ea3f84cdc23b29874d79dd729441e5d \
                 sha256  ef2ff1c71659dca4712c4a789c3313fa656b413818a00849057fc69e53655b38

minimum_xcodeversions {9 3.1}

depends_build    port:yasm

configure.args   --enable-pic \
                 --enable-shared \
                 --enable-static \
                 --disable-avs \
                 --disable-swscale \
                 --disable-lavf \
                 --disable-ffms \
                 --disable-gpac

# as of this build (142) asm optimizations are believed to work with x86_64 Snow Leopard and up including Mavericks
# please file a ticket if you have evidence to the contrary
# i386 clang build issues remain which break i386 build when asm optimizations are enabled
# assert configure option --disable-asm for all i386 builds
# see https://mailman.videolan.org/pipermail/x264-devel/2014-February/010371.html, #42672.

if {${os.platform} eq "darwin" && ${build_arch} ne "" && ![variant_isset universal]} {
    if {${build_arch} eq "i386"} {
        configure.args-append   --host=i686-apple-darwin${os.major} \
                                --disable-asm
    } else {
        configure.args-append   --host=${build_arch}-apple-darwin${os.major}
    }
    eval configure.ldflags-append ${configure.cc_archflags}
}

foreach arch ${universal_archs} {
    if {${arch} eq "i386"} {
        set merger_configure_args(${arch}) "--host=i686-apple-darwin${os.major} --disable-asm"
    } else {
        set merger_configure_args(${arch}) --host=${arch}-apple-darwin${os.major}
    }
}

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

platform darwin 8 {
    # https://trac.macports.org/ticket/24893
    if {${build_arch} eq "i386" && ![variant_isset universal]} {
        configure.cflags-append -msse2
    }
    set merger_configure_cflags(i386) -msse2
}

# sets its own optflags
configure.optflags
configure.cflags-append -I. -fno-common -read_only_relocs suppress

destroot.args   DIR_INSTALL=${destroot}${prefix}

build.target    default

post-patch {
    if {[string match "*clang*" ${configure.compiler}]} {
        reinplace "s|-falign-loops=16||g" ${worksrcpath}/configure
    }
}

livecheck.type  none
