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

name                doxygen-launcher
# should match doxygen version
version             1.9.1
categories          aqua textproc devel
platforms           {darwin any}
license             GPL-2
maintainers         {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
description         Doxygen.app application bundle
long_description    {*}${description}
homepage            http://www.doxygen.org/
master_sites        http://doxygen.nl/files/

distfiles           Doxygen-${version}.dmg

checksums           rmd160  6d0e30e2f09062e67fb993229d3e4633165d8d6c \
                    sha256  df9c647f2d9cad1cd271f00a7662400b3f73e4569abfa231e350b5daaa97fe67 \
                    size    90840684

use_configure       no
supported_archs     noarch
installs_libs       no

use_dmg             yes

depends_lib-append  path:bin/doxygen:doxygen

pre-configure {
    if { ![file exists ${prefix}/bin/doxywizard] } {
        ui_error "doxygen port must be installed with either the +qt4 or +qt5 variant"
        return -code error "doxywizard not found"
    }
}

post-extract {
    delete ${worksrcpath}/Doxygen.app/Contents/Frameworks
    delete ${worksrcpath}/Doxygen.app/Contents/PlugIns
    foreach file {doxygen doxyindexer doxysearch.cgi qt.conf} {
        delete ${worksrcpath}/Doxygen.app/Contents/Resources/${file}
    }
    delete ${worksrcpath}/Doxygen.app/Contents/MacOS/Doxywizard
}

build {
    set values "
        NSPrincipalClass string NSApplication
    "

    foreach {key type value} ${values} {
        #system -W "${worksrcpath}/Doxygen.app/Contents" "/usr/libexec/PlistBuddy -c \"Add :${key} ${type} ${value}\" Info.plist"
    }

    # have Info.plist be human readable
    #system "/usr/bin/plutil -convert xml1 ${worksrcpath}/Doxygen.app/Contents/Info.plist"

    # conversion by plutil set verys limited permissions
    #system "/bin/chmod 0644 ${worksrcpath}/Doxygen.app/Contents/Info.plist"

    ln -s ${prefix}/bin/doxywizard ${worksrcpath}/Doxygen.app/Contents/MacOS/Doxywizard
}

destroot {
    copy ${worksrcpath}/Doxygen.app ${destroot}${applications_dir}
}

variant qt5 conflicts qt4 description {Use doxygen wizard based on Qt5} {
    require_active_variants doxygen qt5
}

variant qt4 conflicts qt5 description {Use doxygen wizard based on Qt4} {
    require_active_variants doxygen qt4
}

if {![variant_isset qt4] && ![variant_isset qt5]} {
    default_variants-append +qt5
}

if {![variant_isset qt4] && ![variant_isset qt5]} {
    pre-fetch {
        ui_error "${name} must be installed with either the +qt4 or +qt5 variant"
        return -code error "Qt variant required"
    }
}

livecheck.url       https://github.com/macports/macports-ports/blob/master/textproc/doxygen/Portfile
livecheck.regex     {version +(\d+(?:\.\d+)*)}
