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

if {${os.platform} ne "darwin" || ${os.major} > 10} {
    PortGroup           qmake5 1.0

    github.setup        texstudio-org texstudio 4.8.1
    revision            0
    checksums           rmd160  b998a4970001c1ba74df86d974f1f53ead056313 \
                        sha256  2d024c4af9304265bdb1dd57b0af382e2d7ce9e4ce368e01b2d9751916d5be99 \
                        size    116026662

    qt5.depends_component \
                        qtscript qtsvg qttools

    patchfiles          patch-texstudio.pro.diff

    depends_lib-append  port:poppler-qt5

    compiler.cxx_standard   2017

    # https://github.com/texstudio-org/texstudio/issues/3706
    compiler.blacklist-append \
                        {clang}

    # https://github.com/texstudio-org/texstudio/issues/3707
    # Temporary fix:
    configure.args-append \
                        NO_POPPLER_PREVIEW=1
} else {
    # This is a fallback version for legacy systems.
    PortGroup           qmake 1.0

    github.setup        texstudio-org texstudio 2.12.22
    revision            0
    checksums           rmd160  c0b6a73f27339089151b66af4e4d436e7dc4d291 \
                        sha256  a2bfb3caacdfde68dfbe59cc43c2cd4b32ce44c48aeb925f49c52f5a303a6da7 \
                        size    35964755

    patchfiles-append   patch-texstudio.pro-qt4.diff \
                        patch-pdfviewer.pri-qt4.diff

    post-patch {
        reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/texstudio.pro \
                        ${worksrcpath}/src/pdfviewer/pdfviewer.pri
    }

    depends_lib-append  port:poppler-qt4-mac

    compiler.cxx_standard   2011
}

categories              editors
license                 GPL-2+
maintainers             nomaintainer

description             TeX editor

long_description        TeXstudio is a TeX editor forked off Texmaker.

homepage                https://www.texstudio.org

depends_lib-append      port:hunspell \
                        port:quazip

# dvipng is used to preview math equations, etc.
depends_run-append      port:dvipng

pre-patch {
    # DOS to UNIX line endings so we can patch
    reinplace "s|\r||g" ${worksrcpath}/texstudio.pro
}

configure.args-append   USE_SYSTEM_QUAZIP=1 USE_SYSTEM_HUNSPELL=1

universal_variant       no

destroot {
    copy ${worksrcpath}/texstudio.app ${destroot}${applications_dir}
    ln -s ${applications_dir}/texstudio.app/Contents/MacOS/texstudio ${destroot}${prefix}/bin/texstudio
}
