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

name            stellarium
categories      science
platforms       darwin
license         GPL-2+
maintainers     {michaelld @michaelld} openmaintainer

description     Stellarium is a free open source planetarium for your computer.
long_description ${description} \
    It shows a realistic sky in 3D, just like what you see with the naked eye, \
    binoculars or a telescope. It is being used in planetarium projectors. Just \
    set your coordinates and go.

subport stellarium-devel {}

if {${name} eq ${subport}} {

    # release

    conflicts    stellarium-devel stellarium-qt4
    github.setup Stellarium stellarium 0.19.2 v
    checksums    rmd160 bfc9fbe67b8f6f574175f29154b0224794bea6fd \
                 sha256 06668190d4df5dad351a92ac3466dc3723946bb9bcbc5f908a30d1022bbc1570 \
                 size   318695000
    revision     0

    # temporary fix for the gpsd API changes
    patchfiles-append patch-fix-gpsd-api.release.diff

} else {

    # devel

    long_description  ${long_description}: \
        This port is kept up with the Stellarium GIT master branch, which is typically updated daily to weekly.

    conflicts    stellarium stellarium-qt4
    github.setup Stellarium stellarium 7603b928329565e946dc31f77754ee0eb04570ce
    version   20191110-[string range ${github.version} 0 7]
    checksums rmd160 e1242083b47d7c601364d669603a2abb3efeb857 \
              sha256 9d3a8c046f8c2aa628588872722e521ee0147b8b44447f0eeb9e868de8f153e7 \
              size   319237569
    revision  0

    # temporary fix for the gpsd API changes
    patchfiles-append patch-fix-gpsd-api.devel.diff

}

homepage        http://stellarium.org/

# builds as 64-bit only, according to its top-level CMakeLists.txt file
universal_variant no

qt5.depends_component qtlocation qtmultimedia qtscript qtserialport qttools

depends_lib-append \
    port:zlib \
    path:lib/libgps.dylib:gpsd \
    port:gettext \
    port:doxygen \
    port:python27

# for libqcocoa.dylib (if not above)

depends_lib-append \
    path:lib/pkgconfig/glib-2.0.pc:glib2 \
    port:fontconfig \
    port:freetype

# fix the install prefix for MP use only
patchfiles-append patch-CMakeLists.txt.diff

# do VPATH (out of source tree) build

cmake.out_of_source yes

# prevent opportunistic use of ccache
if {![tbool configure.ccache]} {
    configure.args-append -DCCACHE_PROGRAM=""
}

# special args for our needs

configure.args-append \
    -DMP_APPLICATIONS_DIR=${applications_dir} \
    -DPYTHON_EXECUTABLE=${prefix}/bin/python2.7

# This post-destroot phase is similar to the 'make macosx_bundle' target,
# but it does not copy libraries into the bundle and does not require perl as
# another dependency
post-destroot {
    set appdir ${destroot}${applications_dir}/Stellarium.app/Contents

    # move App parts around internally
    move ${appdir}/share ${appdir}/Resources

    # copy other useful file(s)
    copy ${worksrcpath}/util/qt.conf ${appdir}/Resources/

    # copy the required qcocoa plugin
    xinstall -m 755 -d ${appdir}/plugins/platforms
    copy ${qt_plugins_dir}/platforms/libqcocoa.dylib \
        ${appdir}/plugins/platforms
}