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

name                enchant
version             1.6.0
revision            6
categories          textproc devel
license             LGPL-2.1+
maintainers         nomaintainer

description         Spellchecker wrapping library
long_description \
    On the surface, Enchant appears to be a generic spell checking library. \
    You can request dictionaries from it, ask if a word is correctly spelled, \
    get corrections for a misspelled word, etc. but all it really does is to \
    provide a uniform wrapper over several popular spell checking libraries \
    including aspell, ispell and AppleSpell.

homepage            https://www.abisource.com/enchant/
master_sites        https://www.abisource.com/downloads/${name}/${version}/

checksums           rmd160  a992034355bb36b9acabdbd400c9f4a3b996cce6 \
                    sha256  2fac9e7be7e9424b2c5570d8affe568db39f7572c10ed48d4e13cddf03f7097f \
                    size    607018

patch.pre_args-replace  -p0 -p1

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

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

use_autoreconf      yes
autoreconf.args     -fvi

configure.args      --disable-ispell \
                    --disable-myspell \
                    --disable-aspell \
                    --disable-voikko \
                    --disable-uspell \
                    --disable-hspell \
                    --disable-zemberek \
                    --with-myspell-dir=${prefix}/share/hunspell

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

variant ispell description {Enable ispell backend} {
    configure.args-replace --disable-ispell --enable-ispell
}

variant aspell description {Enable aspell backend} {
    configure.args-replace --disable-aspell --enable-aspell
    depends_lib-append  port:aspell
    depends_run         port:aspell-dict-en
}

variant myspell description {Enable myspell backend, using hunspell} {
    configure.args-replace --disable-myspell --enable-myspell
    depends_lib-append  port:hunspell
    depends_run-append  port:hunspell-en_US
}

variant applespell description {Enable AppleSpell backend, using system-wide macOS spell checker} {
    # the AppleSpell backend will always be built with this patch,
    # no configure flags required
    patchfiles-append   patch-applespell.diff \
                        patch-applespell-ordering.diff
}

if {[variant_isset ispell] || [variant_isset aspell] || [variant_isset myspell]} {
    notes {
        enchant 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 aspell, myspell, ispell, AppleSpell from highest to lowest\
        preference.

        $ man enchant
    }
}

livecheck.type      regex
livecheck.url       https://www.abisource.com/downloads/${name}/
livecheck.regex     {"(\d+(?:\.\d+)*)/"}
