# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           cmake 1.1

github.setup        fontforge fontforge 20230101
revision            1
checksums           rmd160  bd104bd30dd9b6673b2f91c6ea45649a4b8be220 \
                    sha256  ca82ec4c060c4dda70ace5478a41b5e7b95eb035fe1c4cf85c48f996d35c60f8 \
                    size    13761728

categories          graphics fonts
maintainers         nomaintainer
license             BSD

description         Outline and bitmap font editor/converter for many formats

long_description    FontForge allows you to edit outline and bitmap fonts.  You may create \
                    new ones or modify old ones.  It is also a format converter and can \
                    interconvert between PostScript (ascii & binary Type1, some Type3, \
                    some Type0), TrueType, OpenType (Type2), CID, SVG.  Previously known as \
                    pfaedit.

homepage            https://fontforge.org

# https://github.com/fontforge/fontforge/issues/5276
if {(${os.major} eq "darwin" && ${os.major} < 9) || \
    ${configure.build_arch} ni [list arm64 ppc64 x86_64]} {
    github.setup    fontforge fontforge 20201107
    revision        1

    checksums       rmd160  25ef811489661aa66200c3d49a5e6f8951129d9c \
                    sha256  68bcba8f602819eddc29cd356ee13fafbad7a80d19b652d354c6791343476c78 \
                    size    14163424

    # fix 32-bit builds by masking an old Carbon call to GetTime
    patchfiles-append \
                    patch-fontforge-carbon-gettime-namecollision.diff

    # use older noerr macros
    platform darwin {
        if {${os.major} <= 10} {
            patchfiles-append \
                    patch-fontforge-startui-require-noerr.diff
        }
    }

    # the date command on Tiger is too old for this port, use gnu coreutils dates instead
    platform darwin 8 {
        depends_build-append path:libexec/coreutils/libstdbuf.so:coreutils
        configure.env-append PATH=${prefix}/libexec/gnubin/:$env(PATH)

        # add SRefCon definition, which is missing in the Tiger SDK
        patchfiles-append \
                    patch-fontforge-startui-SRefCon-tiger.diff
    }
} else {
    patchfiles-append \
                    stdlib.patch
}

github.tarball_from releases
use_xz              yes

depends_build-append \
                    port:pkgconfig

depends_lib         path:lib/pkgconfig/cairo.pc:cairo \
                    port:readline \
                    port:freetype \
                    port:gettext \
                    port:giflib \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libiconv \
                    port:libpng \
                    port:libspiro \
                    port:libuninameslist \
                    port:libxml2 \
                    path:lib/pkgconfig/pango.pc:pango \
                    port:potrace \
                    port:tiff \
                    port:woff2 \
                    port:zlib

post-patch {
    # https://github.com/fontforge/fontforge/issues/5251#issuecomment-1614365162
    reinplace -q {s/\(%[^%[:space:]]*\)hs/\1s/g} \
        ${worksrcpath}/fontforgeexe/searchview.c \
        {*}[glob ${worksrcpath}/po/*.po]
}

compiler.c_standard 2011

configure.args-append -DENABLE_GUI=False \
                      -DENABLE_LIBGIF=True \
                      -DENABLE_LIBJPEG=True \
                      -DENABLE_LIBPNG=True \
                      -DENABLE_LIBREADLINE=True \
                      -DENABLE_LIBSPIRO=True \
                      -DENABLE_LIBTIFF=True \
                      -DENABLE_UNINAMELIST=True \
                      -DENABLE_PYTHON_SCRIPTING=False \
                      -DENABLE_PYTHON_EXTENSION=False \
                      -DENABLE_WOFF2=True \
                      -DENABLE_WRITE_PFM=False \
                      -DENABLE_X11=False

variant python38 conflicts python39 python310 python311 python312 description {Enable Python support (Python 3.8)} {
    depends_lib-append      port:python38
    configure.args-replace  -DENABLE_PYTHON_EXTENSION=False \
                            -DENABLE_PYTHON_EXTENSION=True
    configure.args-replace  -DENABLE_PYTHON_SCRIPTING=False \
                            -DENABLE_PYTHON_SCRIPTING=True
    configure.args-append   -DPython3_EXECUTABLE="${prefix}/bin/python3.8" \
                            -DPYHOOK_INSTALL_DIR="${frameworks_dir}/Python.framework/Versions/3.8/lib/python3.8/site-packages"
    configure.pkg_config_path \
                            "${frameworks_dir}/Python.framework/Versions/3.8/lib/pkgconfig"
}

variant python39 conflicts python38 python310 python311 python312 description {Enable Python support (Python 3.9)} {
    depends_lib-append      port:python39
    configure.args-replace  -DENABLE_PYTHON_EXTENSION=False \
                            -DENABLE_PYTHON_EXTENSION=True
    configure.args-replace  -DENABLE_PYTHON_SCRIPTING=False \
                            -DENABLE_PYTHON_SCRIPTING=True
    configure.args-append   -DPython3_EXECUTABLE="${prefix}/bin/python3.9" \
                            -DPYHOOK_INSTALL_DIR="${frameworks_dir}/Python.framework/Versions/3.9/lib/python3.9/site-packages"
    configure.pkg_config_path \
                            "${frameworks_dir}/Python.framework/Versions/3.9/lib/pkgconfig"
}

variant python310 conflicts python38 python39 python311 python312 description {Enable Python support (Python 3.10)} {
    depends_lib-append      port:python310
    configure.args-replace  -DENABLE_PYTHON_EXTENSION=False \
                            -DENABLE_PYTHON_EXTENSION=True
    configure.args-replace  -DENABLE_PYTHON_SCRIPTING=False \
                            -DENABLE_PYTHON_SCRIPTING=True
    configure.args-append   -DPython3_EXECUTABLE="${prefix}/bin/python3.10" \
                            -DPYHOOK_INSTALL_DIR="${frameworks_dir}/Python.framework/Versions/3.10/lib/python3.10/site-packages"
    configure.pkg_config_path \
                            "${frameworks_dir}/Python.framework/Versions/3.10/lib/pkgconfig"
}

variant python311 conflicts python38 python39 python310 python312 description {Enable Python support (Python 3.11)} {
    depends_lib-append      port:python311
    configure.args-replace  -DENABLE_PYTHON_EXTENSION=False \
                            -DENABLE_PYTHON_EXTENSION=True
    configure.args-replace  -DENABLE_PYTHON_SCRIPTING=False \
                            -DENABLE_PYTHON_SCRIPTING=True
    configure.args-append   -DPython3_EXECUTABLE="${prefix}/bin/python3.11" \
                            -DPYHOOK_INSTALL_DIR="${frameworks_dir}/Python.framework/Versions/3.11/lib/python3.11/site-packages"
    configure.pkg_config_path \
                            "${frameworks_dir}/Python.framework/Versions/3.11/lib/pkgconfig"
}

variant python312 conflicts python38 python39 python310 python311 description {Enable Python support (Python 3.12)} {
    depends_lib-append      port:python312
    configure.args-replace  -DENABLE_PYTHON_EXTENSION=False \
                            -DENABLE_PYTHON_EXTENSION=True
    configure.args-replace  -DENABLE_PYTHON_SCRIPTING=False \
                            -DENABLE_PYTHON_SCRIPTING=True
    configure.args-append   -DPython3_EXECUTABLE="${prefix}/bin/python3.12" \
                            -DPYHOOK_INSTALL_DIR="${frameworks_dir}/Python.framework/Versions/3.12/lib/python3.12/site-packages"
    configure.pkg_config_path \
                            "${frameworks_dir}/Python.framework/Versions/3.12/lib/pkgconfig"
}

variant gui description {Enable GUI support} {
    PortGroup               app 1.0

    depends_lib-append      path:lib/pkgconfig/gtk+-3.0.pc:gtk3
    configure.args-replace  -DENABLE_GUI=False -DENABLE_GUI=True
    app.name                FontForge
    app.icon                ${worksrcpath}/osx/FontForge.app/Contents/Resources/FontForge.icns
}

default_variants    +gui
if {![variant_isset python38] && ![variant_isset python39] && ![variant_isset python310] && ![variant_isset python311] && ![variant_isset python312]} {
    default_variants-append +python312
}
