# -*- 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
# $Id: Portfile 63935 2010-02-18 18:25:50Z macsforever2000@macports.org $

PortSystem  1.0

name                qtiplot
version             0.9.7.9
revision            1
categories          aqua science
maintainers         jonas openmaintainer

description         Data Analysis and Scientific Plotting
long_description    Similar to Origin or SigmaPlot, QtiPlot can be used to \
                    present 2D and 3D data and has various data analysis functions \
                    like curve fitting. Plotting of 3D data can be rendered using \
                    OpenGL using the Qwt3D libraries.\
                    It's a full-featured data analysis and plotting package available \
                    on Linux, Windows and Mac OS X platforms that supports python scripting.

platforms           darwin
homepage            http://soft.proindependent.com/qtiplot.html
master_sites        http://download.berlios.de/qtiplot/
use_bzip2           yes

depends_lib         path:bin/qmake-mac:qt4-mac \
                    port:muparser \
                    port:boost \
                    port:gsl \
                    port:libpng \
                    port:zlib

checksums           md5     08e4943cadd5ee39e28e4ce0d61d475a \
                    sha1    ad83187af31172794771012072b57a67f9288628 \
                    rmd160  cd6cbef46b3474989bede96af04d1cef52dd6f48

patchfiles          patch-qtiplot-qtiplot.pro \
                    patch-qtiplot-src-scripting-scripting.pri

use_parallel_build  yes

pre-configure {
    # don't step into the manual dir, we don't have all the tools to build it
    reinplace "/manual/d" ${worksrcpath}/qtiplot.pro

    # create the configuration, see build.conf.example which comes with the package
    set confFD [open ${worksrcpath}/build.conf "w"]
    puts $confFD "SYS_INCLUDEPATH = ${prefix}/include"
    # snow leopard seems to need zlib explicitly, see #23272
    puts $confFD "SYS_LIBS = -L${prefix}/lib -lz"
    puts $confFD "MUPARSER_LIBS = -lmuparser"
    puts $confFD "GSL_LIBS = -lgsl -lgslcblas"
    puts $confFD "BOOST_LIBS = -lboost_date_time-mt -lboost_thread-mt"
    # till upstream catches up, we use a local copy of qwt
    puts $confFD "QWT_INCLUDEPATH = \$\$QTI_ROOT/3rdparty/qwt/src"
    puts $confFD "QWT_LIBS = \$\$QTI_ROOT/3rdparty/qwt/lib/libqwt.a"
    puts $confFD "LIBPNG_LIBS = -lpng"
    # target specific configuration
    puts $confFD "contains( TARGET, qtiplot ) \{"
    puts $confFD "SCRIPTING_LANGS += muParser"; # currently you can't build without
    if {[variant_isset python25]} {
        puts $confFD "SCRIPTING_LANGS += Python"
    }
    puts $confFD "DEFINES += SCRIPTING_CONSOLE"
    puts $confFD "DEFINES += SCRIPTING_DIALOG"
    puts $confFD "CONFIG += release"
    puts $confFD "\}"
    close $confFD    

    # fix a bug in the python init script
    # append the current path *before* import __main__, else __file__ points to math.so after the import if this module
    reinplace "/import __main__/ i\\
    import sys, os.path\\
    sys.path.append(os.path.dirname(__file__))
    " ${worksrcpath}/qtiplot/qtiplotrc.py
}

configure.pre_args  "PREFIX=${prefix}"
configure.cmd   "LOCALSOFT=${prefix} ${prefix}/libexec/qt4-mac/bin/qmake"
destroot.destdir INSTALL_ROOT=${destroot}

destroot {
    # install the application bundle and create a symlink for cli invocation
    xinstall -d ${destroot}${applications_dir}
    copy "${worksrcpath}/qtiplot/qtiplot.app" ${destroot}${applications_dir}
    # in this dir python tries to store .pyc files, so it has to be writable
    file attributes ${destroot}${applications_dir}/qtiplot.app/Contents/MacOS -permissions ugo+w
    ln -s ${applications_dir}/qtiplot.app/Contents/MacOS/qtiplot ${destroot}${prefix}/bin/qtiplot
    # install some resources
    xinstall -W ${worksrcpath}/qtiplot/ \
        qti_wordlist.txt \
        qtiUtil.py \
        qtiplotrc.py \
        ${destroot}${applications_dir}/qtiplot.app/Contents/MacOS/
    # install the fitting plugins
    set plugin_dir ${destroot}${applications_dir}/qtiplot.app/Contents/fitPlugins/
    file mkdir ${plugin_dir}
    xinstall -W ${worksrcpath}/fitPlugins/ \
        libexp_saturation.dylib \
        libexplin.dylib \
        libfitRational0.dylib \
        libfitRational1.dylib \
        libplanck_wavelength.dylib \
        ${plugin_dir}
}

variant python25 description "add support for python scripting" {
    depends_lib-append port:python25 \
                       port:py25-sip \
                       port:py25-pyqt4
}

