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

github.setup        facebookresearch fastText 0.9.2 v
revision            2
name                [string tolower ${github.project}]

categories-append   textproc
license             MIT
maintainers         nomaintainer

description         Library for fast text representation and classification.

long_description    fastText is a library for efficient learning of \
                    word representations and sentence classification.

checksums           rmd160  ff9c900c945c5b5075a55b7625a4d119c38f8473 \
                    sha256  7ea4edcdb64bfc6faaaec193ef181bdc108ee62bb6a04e48b2e80b639a99e27e \
                    size    4036722
github.tarball_from archive

patchfiles          no-march-native.patch

# args.cc:468:3: error: 'uint64_t' was not declared in this scope
patchfiles-append   patch-cstdint.diff

post-patch {
    if {${os.platform} eq "darwin" && ${configure.cxx_stdlib} ne "libc++"} {
        reinplace "s|@CXXFLAG@|-D_GLIBCXX_USE_CXX11_ABI=0|" ${worksrcpath}/CMakeLists.txt ${worksrcpath}/setup.py
    } else {
        reinplace "s|@CXXFLAG@||" ${worksrcpath}/CMakeLists.txt ${worksrcpath}/setup.py
    }
}

compiler.cxx_standard   2011

# Undefined symbols: "___atomic_fetch_add_8"
if {[string match *gcc* ${configure.compiler}]} {
    configure.ldflags-append \
                    -latomic
}

if {${name} eq ${subport}} {
    PortGroup       cmake 1.1
}

post-destroot {
    set docdir ${prefix}/share/doc/${subport}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} LICENSE README.md \
        ${destroot}${docdir}
}

# create Python subports
set python_versions {39}

# Python modules
foreach v ${python_versions} {
    subport py${v}-${name} {
        PortGroup   python 1.0

        description Python bindings for ${name}
        long_description \
                    {*}${description}

        python.default_version  ${v}
    }
}

# common settings for all Python ports
if {[string match "py*" ${subport}]} {
    depends_build-append \
                    port:py${python.version}-pybind11 \
                    port:py${python.version}-setuptools

    depends_run-append \
                    port:py${python.version}-numpy

    pre-test {
        test.env-append \
            PYTHONPATH=[glob -nocomplain ${worksrcpath}/build/lib*]
    }

    test.run        yes
    test.cmd        ${python.bin}
    test.target     runtests.py
    test.args       --unit-tests

    livecheck.type  none
}
