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

github.setup            dvorka mindforger 2.0.0
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
revision                0

homepage                https://www.mindforger.com

description             Thinking notebook and Markdown editor

long_description        MindForger is an open, free, well-performing Markdown \
                        editor which respects your privacy and enables \
                        security.  It is actually more than an editor or IDE \
                        - it's a human mind -inspired personal knowledge \
                        management tool.

categories              editors office
installs_libs           no
license                 GPL-2
maintainers             {gmail.com:herby.gillot @herbygillot} \
                        openmaintainer

fetch.type              git

set qmake_bin           ${prefix}/libexec/qt5/bin/qmake

depends_build-append    port:pkgconfig

# mindforger is a Qt5 project, but one of its dependencies, cmark-gfm, uses
# CMake.  The qmake5/qt5 portgroups do not mix very well with the cmake
# portgroup, so we use only cmake-1.1 and specify Qt5 dependencies directly:
depends_lib-append      port:qt5-qtbase \
                        port:qt5-qtwebengine \
                        port:zlib

# Since cmark-gfm is built with CMake, set CMake's source dir to where
# cmark-gfm lives.
cmake.source_dir        ${worksrcpath}/deps/cmark-gfm

configure.args-append   -DCMARK_TESTS=OFF \
                        -DCMARK_SHARED=OFF

post-extract {
    # mindforger's dependencies are provided as git submodules
    system -W ${worksrcpath} "git submodule update --init --recursive"
}

pre-configure {
    # Prepare the mindforger make process from its Qt5 project file.
    system -W ${worksrcpath} \
        "${qmake_bin} CONFIG+=mfnoccache -r ./mindforger.pro"
}

post-build {
    # CMake builds cmark-gfm out of source.  We symlink the external build
    # directory back into the cfmark-gfm dir so that the main mindforger
    # Makefile can find resources within it when building mindforger itself.
    ln -s ${cmake.build_dir} ${cmake.source_dir}/build

    # Build mindforger itself
    system -W ${worksrcpath} "make"
}

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