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

github.setup        anthonygelibert QLColorCode 4.1.0 release-
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            1
worksrcdir          ${github.author}-${name}-749f674
categories          sysutils aqua

license             {GPL-3 MIT}
maintainers         nomaintainer

description         Quick Look plugin that renders source code with syntax highlighting.
long_description    {*}${description}

set lua_version         e2ea3b31c94bb3e1da27c233661cb2a16699c685
set highlight_version   ecf5d4aa1341908a6b191a47d67e735197dc430d

master_sites        ${github.homepage}/tarball/${git.branch}:QLColorCode \
                    https://github.com/lua/lua/archive:lua \
                    https://gitlab.com/saalen/highlight/-/archive/${highlight_version}:highlight

distfiles           ${name}-${git.branch}.tar.gz:QLColorCode \
                    ${lua_version}.tar.gz:lua \
                    highlight-${highlight_version}.tar.gz:highlight

checksums           QLColorCode-release-4.1.0.tar.gz \
                    rmd160  b45817626018c2cd7d5df4b4430c760e6a18e0d3 \
                    sha256  d6d878ddbcb5b1f7d9f1656e96e1ab0d5cce2f4208e1e7a6f5a190ff2a6f878a \
                    size    44683 \
                    e2ea3b31c94bb3e1da27c233661cb2a16699c685.tar.gz \
                    rmd160  972fcc46049cf60a780a4dc7bef6a273167dab78 \
                    sha256  a2e01036021d319fd41e16dfe12cc5fabc7db1337df8605a884ac0b424932d9b \
                    size    444643 \
                    highlight-ecf5d4aa1341908a6b191a47d67e735197dc430d.tar.gz \
                    rmd160  5fe1ca6acbd700138c3f20fbd6bedfcd8faa0e0d \
                    sha256  770ce8dd4b269963711038748e2505945bee29ed1807ef9c473846717e4500a3 \
                    size    1589913

depends_build       port:boost

destroot.violate_mtree  yes
xcode.build.settings \
    CODE_SIGN_IDENTITY=- \
    CODE_SIGN_STYLE=Manual \
    ENABLE_HARDENED_RUNTIME=NO

# remove build phase that copies to the user's home directory
patchfiles-append   patch-xcode.diff \
                    patch-include-path.diff

post-extract {
    reinplace -W ${worksrcpath} "s,open \$PROJECT_DIR/release,," QLColorCode.xcodeproj/project.pbxproj
}

post-patch {
    reinplace -W ${worksrcpath} "s/-j9/-j${build.jobs}/g" QLColorCode.xcodeproj/project.pbxproj
    delete ${worksrcpath}/hl/lua ${worksrcpath}/hl/highlight
    move ${worksrcpath}/../lua-${lua_version} ${worksrcpath}/hl/lua
    move ${worksrcpath}/../highlight-${highlight_version} ${worksrcpath}/hl/highlight
}

destroot {
    xinstall -d ${destroot}/Library/QuickLook
    file copy ${worksrcpath}/build/Release/${name}.qlgenerator ${destroot}/Library/QuickLook
}

# force quicklook to reload plugins
post-activate {
    system "qlmanage -r"
}

post-deactivate {
    system "qlmanage -r"
}
