# -*- 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        rrthomas enchant 2.8.12 v
revision            0
checksums           rmd160  9095fc0e180c34aa9081647c5ee1ec0421cbcb4d \
                    sha256  20e5fab2ca0f95ba9d1ef5052fe5b028e3e1d66d4cdea6b9adfcbd3e524c2a09 \
                    size    1254492

name                enchant2
categories          textproc devel
maintainers         {ryandesign @ryandesign} openmaintainer
license             LGPL-2.1+

description         Generic spell checking library

long_description    Enchant aims to provide a simple but comprehensive abstraction for dealing \
                    with different spell checking libraries in a consistent way. Installs in \
                    parallel with legacy Enchant 1.x versions without conflict.

homepage            https://rrthomas.github.io/enchant/
github.tarball_from releases

depends_build-append \
                    bin:groff:groff \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  path:lib/pkgconfig/glib-2.0.pc:glib2

compiler.c_standard 1999
compiler.cxx_standard   2011

# https://trac.macports.org/wiki/WimplicitFunctionDeclaration#strchr
configure.checks.implicit_function_declaration.whitelist-append strchr

configure.args      --without-hunspell \
                    --without-applespell \
                    --without-aspell \
                    --without-voikko \
                    --without-hspell \
                    --without-nuspell \
                    --without-zemberek \
                    --disable-silent-rules \
                    --disable-gcc-warnings

# to allow parallel install with enchant 1.x
build.cmd-append    pkgdatadir=${prefix}/share/enchant-2

# https://trac.macports.org/ticket/51287
# https://trac.macports.org/ticket/56222
if {${os.platform} eq "darwin" &&  ${os.major} >= 15} {
    # users most likely have AppleSpell already set up for their language
    default_variants    +applespell
} else {
    default_variants    +aspell
}

variant aspell description {Enable aspell backend} {
    configure.args-replace --without-aspell --with-aspell
    configure.args-append  --with-aspell-dir=${prefix}/share/aspell
    depends_lib-append  port:aspell
    depends_run         port:aspell-dict-en
}

variant hunspell description {Enable hunspell backend} {
    configure.args-replace --without-hunspell --with-hunspell
    configure.args-append  --with-hunspell-dir=${prefix}/share/hunspell
    depends_lib-append  port:hunspell
    depends_run-append  port:hunspell-en_US
}

variant nuspell description {Enable nuspell backend} {
    configure.args-replace --without-nuspell --with-nuspell
    configure.args-append  --with-nuspell-dir=${prefix}/share/hunspell
    depends_lib-append  port:nuspell
    depends_run-append  port:hunspell-en_US
}

variant applespell description {Enable AppleSpell backend, using system-wide macOS spell checker} {
    configure.args-replace --without-applespell --with-applespell
}

if {[variant_isset aspell] || [variant_isset hunspell]} {
    notes {
        enchant2 will use the first backend that provides a dictionary for the\
        requested language. If you prefer a specific backend, please see the\
        man page how you can change the lookup order. By default, the backend\
        order is hunspell, aspell, AppleSpell from highest to lowest\
        preference.

        $ man enchant-2
    }
}

variant test {
    depends_build-append \
                    port:unittest-cpp

    configure.args-append \
                    --enable-relocatable

    test.run        yes
    test.target     check
}
