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

github.setup        springer13 hptt 942538649b51ff14403a0c73a35d9825eab2d7de
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             1.0.5
revision            1

checksums           rmd160  7cbc53545b2841eb7c8f59126c315805e39bdc3b \
                    sha256  26ff7b4661ecfde7fb44b13154679c589bd9a87010f0bcba13ef56641a0cf7ee \
                    size    635723

categories          math
license             BSD
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         High-Performance Tensor Transpose library
long_description    {*}${description}

patch.pre_args-replace  -p0 -p1
patchfiles          0001-CMakeLists-add-PPC-support-unbreak-build-on-Darwin.patch \
                    0002-CMakeLists-fix-install-path-for-headers.patch \
                    0003-Add-hptt.pc-config-file.patch

compiler.cxx_standard   2011

# Fix builds with clang
#   https://github.com/springer13/hptt/issues/21
#   https://github.com/springer13/hptt/pull/32
# Remove once above is in a new release
patchfiles-append   0004-Fix-Build-With-Clang.patch

configure.args-append \
                    -DENABLE_ARM=OFF \
                    -DENABLE_AVX=OFF \
                    -DENABLE_IBM=OFF \
                    -DENABLE_PPC=OFF

post-patch {
    reinplace "s,@PREFIX@,${prefix}," ${worksrcpath}/misc/hptt.pc
    reinplace "s,@VERSION@,${version}," ${worksrcpath}/misc/hptt.pc
}

platform powerpc {
    if {${os.platform} eq "darwin"} {
        # Needed only for Rosetta, has no effect on native PPC:
        post-patch {
            reinplace "s,-march=native,," ${worksrcpath}/CMakeLists.txt
        }
        configure.args-replace \
                    -DENABLE_PPC=OFF -DENABLE_PPC=ON
    } else {
        # On non-Apple OSs this is likely a correct choice:
        configure.args-replace \
                    -DENABLE_IBM=OFF -DENABLE_IBM=ON
    }
}

post-destroot {
    xinstall -d ${destroot}/lib/pkgconfig/
    copy ${worksrcpath}/misc/hptt.pc ${destroot}${prefix}/lib/pkgconfig/
}
