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

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    PortGroup       qmake 1.0

    # Please do not upgrade unless these are fixed:
    # https://github.com/communi/libcommuni/issues/117
    # https://github.com/communi/libcommuni/issues/118
    github.setup    communi libcommuni 3.6.0 v
    revision        1
    checksums       rmd160  e689974400c25446a94280e5805f14f88a49c37e \
                    sha256  c598e4ec23211f58bcb8dd3a9905a45d38c02f4c5c17cfc27cf724cd7b3edb9c \
                    size    472634

    # For w/e reason, clang pre-processor cannot handle this:
    if {[string match *clang* ${configure.compiler}]} {
        patchfiles-append patch-irccore_p.h.diff
    }

    pre-configure {
        system -W ${worksrcpath} "${qt_lrelease_cmd} ${name}.pro"
    }

    set communiplugin_dir   ${qt_imports_dir}

} else {
    PortGroup       qmake5 1.0

    github.setup    communi libcommuni 3.7.0 v
    revision        0
    checksums       rmd160  26a03135c661d05a31737788586c42271c7974fa \
                    sha256  28f315992d90c2f915d7a41da313050d1f74fc7a98cce265ee2722e3775e3675 \
                    size    475364

    qt5.depends_component   qtdeclarative

    set communiplugin_dir   ${qt_qml_dir}
}

categories          devel net irc
license             BSD
maintainers         nomaintainer

description         Cross-platform IRC framework for Qt
long_description    {*}${description}
homepage            https://communi.github.io

github.tarball_from archive

depends_lib-append  port:uchardet

# Install normal dylibs:
configure.args-append \
                    -config qt_no_framework

compiler.cxx_standard 2011

post-destroot {
    # Fix libs:
    foreach dylib [exec find ${destroot}${qt_libs_dir} -name "\*.dylib"] {
        regsub ":$" ${dylib} "" destroot_dylib_path
        regsub ${destroot} ${destroot_dylib_path} "" dylib_path
        system "install_name_tool -id ${dylib_path} ${destroot_dylib_path}"
        system "install_name_tool -change libIrcCore.3.dylib ${qt_libs_dir}/libIrcCore.3.dylib \
            ${destroot_dylib_path}"
        system "install_name_tool -change libIrcModel.3.dylib ${qt_libs_dir}/libIrcModel.3.dylib \
            ${destroot_dylib_path}"
        system "install_name_tool -change libIrcUtil.3.dylib ${qt_libs_dir}/libIrcUtil.3.dylib \
            ${destroot_dylib_path}"
    }

    # Fix the plugin:
    system "install_name_tool -id ${communiplugin_dir}/Communi/libcommuniplugin.dylib \
            ${destroot}${communiplugin_dir}/Communi/libcommuniplugin.dylib"
    foreach irclib [list libIrcCore.3.dylib libIrcModel.3.dylib libIrcUtil.3.dylib] {
        system "install_name_tool -change ${irclib} ${qt_libs_dir}/${irclib} \
            ${destroot}${communiplugin_dir}/Communi/libcommuniplugin.dylib"
    }
}
