# -*- 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
PortGroup           xcode 1.0

categories          aqua
platforms           macosx
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             MIT

description         小麥注音輸入法
long_description    OpenVanilla McBopomofo 小麥注音輸入法 – input method for Traditional Chinese.

homepage            https://mcbopomofo.openvanilla.org/

if {${os.major} > 11} {
    github.setup    openvanilla McBopomofo 0.9.11
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    checksums       rmd160  c201c4c176f0ee205c3587cf93b441128ca241ab \
                    sha256  203c925e72990c41b45bc948214becc20f6410ec00dd8caa6abc0bbcb58e2d7a \
                    size    2868560
} elseif {${os.major} == 11} {
    github.setup    openvanilla McBopomofo 0.9.10
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    checksums       rmd160  04ecfcc546ca4e5cdf615d91a626cdef7ad7ebb1 \
                    sha256  23f37e1de13b2a14a770d1bdef16b7dc3e1cc953d2fc420f2436867ba6c20ac5 \
                    size    2866643
} elseif {${os.major} == 10 && ${configure.build_arch} ne "ppc"} {
    github.setup    openvanilla McBopomofo 0.9.9
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    checksums       rmd160  66e855dd7dcf13aa785d037270f6a72953373ee5 \
                    sha256  ff4972a51a78134b6b8e036a345253656044f1538ef237f6a342b5ec5cd701f3 \
                    size    2871281
} elseif {${os.major} < 10 || (${os.major} == 10 && ${configure.build_arch} eq "ppc")} {
    # https://github.com/openvanilla/McBopomofo/issues/349
    github.setup    openvanilla McBopomofo 4c239a2a5fe10610d63473727a71f9b30077667c
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    version         0.9.9.1
    checksums       rmd160  f0459b10993f3afae4450f0781f664e9eb974f10 \
                    sha256  20428feaaa43749377d4b931c5190c9dc317843cc839d8ac694cc30d384e2d1c \
                    size    3174055
    macosx_deployment_target 10.5
}

patchfiles          patch-includes.diff

if {${os.major} > 9 && ${configure.build_arch} ne "ppc"} {
    # Not needed on leopard-support branch since already implemented with upstream:
    patchfiles-append \
                    patch-no-werror.diff
}

# Don't build McBopomofoInstaller
xcode.target        Data McBopomofo

destroot.violate_mtree yes

destroot.pre_args   -IDECustomDerivedDataLocation=${worksrcpath}/DerivedData

if {[vercmp ${xcodeversion} 10.0] >= 0} {
    destroot.pre_args-append \
                    -UseNewBuildSystem=NO
}

depends_build-append \
                    port:python311
configure.python    ${prefix}/bin/python3.11
post-patch {
    fs-traverse f ${worksrcpath}/Source/Data/bin {
        if {[string match *.py ${f}]} {
            reinplace -q "s|/usr/bin/env python$|${configure.python}|" ${f}
        }
    }
}

post-destroot {
    xinstall -d "${destroot}/Library/Input Methods"
    if {[vercmp $xcodeversion 4.2] >= 0} {
        move "${destroot}${applications_dir}/McBopomofo.app" \
            "${destroot}/Library/Input Methods/McBopomofo.app"
    } else {
        copy "${worksrcpath}/build/UninstalledProducts/McBopomofo.app" \
            "${destroot}/Library/Input Methods/McBopomofo.app"
    }
}
