# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; truncate-lines: t -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 91968 2012-04-14 09:59:50Z raimue@macports.org $

PortSystem 1.0
PortGroup  qt4 1.0

name            stellarium
version         0.11.2
categories      science
platforms       darwin
maintainers     raimue \
                michaelld

description     Stellarium is a free open source planetarium for your computer.
long_description \
    Stellarium is a free open source planetarium for your computer. \
    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.
homepage        http://stellarium.org/

master_sites    sourceforge
checksums       rmd160  b36bb6d709c4c67e1483630523b8c423622eea20 \
                sha256  85a413ec8aff8774952c32ff6fbf61ba7f1d1d38a224ff51c65750f5803662e2

depends_build-append port:cmake
depends_lib-append \
                port:freetype \
                port:libiconv \
                port:openssl

post-patch {
    reinplace "s:SET(CMAKE_INSTALL_PREFIX \"\$\{PROJECT_BINARY_DIR\}/:SET(CMAKE_INSTALL_PREFIX \"${applications_dir}/:" ${worksrcpath}/CMakeLists.txt

    # Determine which archs to build
    if {[variant_isset universal]} {
        set archs ${configure.universal_archs}
    } else {
        set archs ${configure.build_arch}
    }
    reinplace "s:SET(CMAKE_OSX_ARCHITECTURES \"i386;ppc\"):SET(CMAKE_OSX_ARCHITECTURES \"${archs}\"):" ${worksrcpath}/CMakeLists.txt
}

platform darwin 9 {
    # Upgrade MacOSX SDK version to 10.5, for compatibility with qt4-mac
    post-patch {
        reinplace "s:-mmacosx-version-min=10.4:-mmacosx-version-min=10.5:" ${worksrcpath}/CMakeLists.txt
        reinplace "s:SET(CMAKE_OSX_DEPLOYMENT_TARGET \"10.4\"):SET(CMAKE_OSX_DEPLOYMENT_TARGET \"10.5\"):" ${worksrcpath}/CMakeLists.txt
        reinplace "s:MacOSX10.4u.sdk:MacOSX10.5.sdk:" ${worksrcpath}/CMakeLists.txt
    }
}

platform darwin 10 {
    # Upgrade MacOSX SDK version to 10.6, for compatibility with qt4-mac
    post-patch {
        reinplace "s:-mmacosx-version-min=10.4:-mmacosx-version-min=10.6:" ${worksrcpath}/CMakeLists.txt
        reinplace "s:SET(CMAKE_OSX_DEPLOYMENT_TARGET \"10.4\"):SET(CMAKE_OSX_DEPLOYMENT_TARGET \"10.6\"):" ${worksrcpath}/CMakeLists.txt
        reinplace "s:MacOSX10.4u.sdk:MacOSX10.6.sdk:" ${worksrcpath}/CMakeLists.txt
    }
}

configure.cmd       cmake
# specify MacPorts' dependencies to cmake
configure.pre_args  -DFreeType2_INCLUDE_DIR:PATH=${prefix}/include/freetype2 \
                    -DFreeType2_LIBRARIES:FILEPATH=${prefix}/lib/libfreetype.dylib \
                    -DZLIB_INCLUDE_DIR:PATH=${prefix}/include \
                    -DZLIB_LIBRARY:FILEPATH=${prefix}/lib/libz.dylib \
                    -DICONV_INCLUDE_DIR:PATH=${prefix}/include \
                    -DICONV_LIBRARIES:FILEPATH=${prefix}/lib/libiconv.dylib \
                    -DOPENSSL_CRYPTO_LIBRARIES:FILEPATH=${prefix}/lib/libcrypto.dylib \
                    -DOPENSSL_INCLUDE_DIR:PATH=${prefix}/include/openssl \
                    -DOPENSSL_SSL_LIBRARIES:FILEPATH=${prefix}/lib/libssl.dylib \
                    ${qt_cmake_defines}

configure.args      .

# 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 ${appdir}/bin ${appdir}/MacOS
    move ${appdir}/share ${appdir}/Resources
    eval move [glob ${appdir}/Resources/stellarium/*] ${appdir}/Resources/
    delete ${appdir}/Resources/stellarium

    # copy .app-specific files
    copy ${worksrcpath}/data/Info.plist ${appdir}
    copy ${worksrcpath}/data/PkgInfo ${appdir}
    copy ${worksrcpath}/data/Icon.icns ${appdir}/Resources/

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

# Supports universal builds through cmake, archs are set in post-patch
variant universal {}

livecheck.url http://sourceforge.net/projects/stellarium/files/
livecheck.regex "Stellarium-sources/.*/stellarium-(.*)[quotemeta ${extract.suffix}]"
