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

PortSystem          1.0
PortGroup           muniversal 1.0
PortGroup           xcodeversion 1.0
PortGroup           xcode_workaround 1.0

name                x264
version             20191217
categories          multimedia
license             GPL-2+
platforms           darwin
maintainers         {devans @dbevans} 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            https://www.videolan.org/x264.html
master_sites        https://download.videolan.org/pub/videolan/x264/snapshots/

dist_subdir         x264
distname            ${name}-snapshot-${version}-2245-stable

use_bzip2           yes

checksums           rmd160  6a204dfd1d56faf2d9c0ff2b90642507112f291d \
                    sha256  b2495c8f2930167d470994b1ce02b0f4bfb24b3317ba36ba7f112e9809264160 \
                    size    770169

minimum_xcodeversions {9 3.1}

depends_build       port:nasm

# as of 20190313 the PPC assembly uses VSX, which is Power7+ only. We could disable asm, but
# instead we can use the previous ppc assembly,  which does compile and provides the same functions
patchfiles-append   patch-x264-older-ppc-code.diff \
                    patch-x264-apple-silicon.diff

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

# as of build 148 asm optimizations are believed to work with x86_64 Snow Leopard and up
# 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" && ${configure.build_arch} ne "" && (!${universal_possible} || ![variant_isset universal])} {
    if {${configure.build_arch} eq "i386"} {
        configure.args-append   --host=i686-apple-darwin${os.major} \
                                --disable-asm
    } else {
        configure.args-append   --host=${configure.build_arch}-apple-darwin${os.major}
    }
    configure.ldflags-append {*}${configure.cc_archflags}
}

foreach arch ${configure.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 {${configure.build_arch} eq "i386" && (!${universal_possible} || ![variant_isset universal])} {
        configure.cflags-append -msse2
    }
    set merger_configure_cflags(i386) -msse2

    depends_build-append port:gmake
    build.cmd            gmake
}

# 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

livecheck.type      none
