# -*- 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           cmake 1.1
PortGroup           xcode_workaround 1.0
PortGroup           github 1.0

# https://trac.macports.org/ticket/59875
PortGroup           legacysupport 1.0

legacysupport.newest_darwin_requires_legacy 9

github.setup        videolan x265 3.4
revision            1

checksums           rmd160  e614c4a03134a67e79efe8d3dd64d54c3990b99a \
                    sha256  544d147bf146f8994a7bf8521ed878c93067ea1c7c6e93ab602389be3117eaaf \
                    size    1530200

categories          multimedia
license             GPL-2+
maintainers         nomaintainer

# exclude pre-release versions
github.livecheck.regex  {([0-9.]+)}

description         H.265 encoder
long_description    x265 is a free software library and application for \
                    encoding video streams into the H.265/MPEG-H HEVC \
                    compression format, and is released under the terms of the \
                    GNU GPL.
homepage            https://www.videolan.org/developers/x265.html
github.tarball_from archive
worksrcdir          ${name}-${version}/source

# allow overriding system processor detection
patchfiles          patch-cmakelists-override-processor.diff

# Altivec uses instructions unsupported on Darwin: https://trac.macports.org/ticket/64781
patchfiles-append   patch-ppc.diff

depends_build-append port:gmake

compiler.blacklist-append *llvm-gcc-4.2

# https://trac.macports.org/ticket/59246
xcode_workaround.fixed_xcode_version 11.2

platform darwin 10 {
    # Rosetta build has to override CMAKE_SYSTEM_PROCESSOR: https://trac.macports.org/ticket/64528
    if {${build_arch} eq "ppc"} {
        configure.args-append -DOVERRIDE_SYSTEM_PROCESSOR="ppc"
    }
}

if {${universal_possible} && [variant_isset universal] && ![variant_isset highdepth]} {

    if {"x86_64" in ${configure.universal_archs} || "i386" in ${configure.universal_archs}} {
        depends_build-append port:nasm
        set merger_configure_env(i386)      NASM_EXECUTABLE=${prefix}/bin/nasm
        set merger_configure_env(x86_64)    NASM_EXECUTABLE=${prefix}/bin/nasm
    }

    # error: illegal text-relocation to '_x265_pw_1'
    lappend merger_configure_ldflags(i386) -Wl,-read_only_relocs,suppress

    foreach uarch {arm64 i386 ppc ppc64 x86_64} {
        set merger_configure_args(${uarch}) -DOVERRIDE_SYSTEM_PROCESSOR=${uarch}
    }

    configure.env-append CONFIGURE=${configure.cmd} BUILD=${build.cmd}
    build.env-append     BUILD=${build.cmd}
    foreach arch ${configure.universal_archs} {
        lappend merger_configure_env(${arch}) ARCH=${arch}
        lappend merger_build_env(${arch}) ARCH=${arch}
    }
} else {

    if {${configure.build_arch} in {i386 x86_64}} {
        depends_build-append port:nasm
        configure.env       NASM_EXECUTABLE=${prefix}/bin/nasm
    }

    if {${configure.build_arch} eq "i386"} {
        # error: illegal text-relocation to '_x265_pw_1'
        configure.ldflags-append -Wl,-read_only_relocs,suppress
    }
    configure.env-append CONFIGURE=${configure.cmd} BUILD=${build.cmd} ARCH='${build_arch}'
    build.env-append BUILD=${build.cmd} ARCH='${build_arch}'
}

destroot.env-append  BUILD=${build.cmd} ARCH=none
configure.cmd        ${portpath}/${filesdir}/configure.sh
build.cmd            ${portpath}/${filesdir}/build.sh
