# -*- 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 50094 2009-04-25 07:11:56Z jonas@macports.org $

PortSystem  1.0

name                qtiplot
version             0.9.7.6
categories          aqua science
maintainers         fs.ei.tum.de: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         port:qt4-mac \
                    port:muparser \
                    port:boost \
                    port:gsl \
                    port:libpng \
                    port:qwt52 \
                    port:python25 \
                    port:py25-sip \
                    port:py25-pyqt4
                    # TODO variants to build without python or other python version

checksums           md5     a9b9b2fbd3044022a7afa3a89ec5c47d \
                    sha1    eb29800b614e8552add1ca8c435d56acec712ee5 \
                    rmd160  1b5fd62872250169f80b6f135c7586b610c3be9a

pre-configure {
    # don't step into the manual dir, there is no "make all"
    reinplace "/manual/d" ${worksrcpath}/qtiplot.pro
    # fix include paths
    reinplace "/INCLUDEPATH.*muparser/d" ${worksrcpath}/qtiplot/qtiplot.pro
    reinplace "/INCLUDEPATH.*boost/d" ${worksrcpath}/qtiplot/qtiplot.pro
    reinplace "/INCLUDEPATH.*png/d" ${worksrcpath}/qtiplot/qtiplot.pro
    reinplace "/INCLUDEPATH.*gsl/d" ${worksrcpath}/qtiplot/qtiplot.pro \
                                    ${worksrcpath}/fitPlugins/explin/explin.pro \
                                    ${worksrcpath}/fitPlugins/exp_saturation/exp_saturation.pro \
                                    ${worksrcpath}/fitPlugins/fitRational0/fitRational0.pro \
                                    ${worksrcpath}/fitPlugins/fitRational1/fitRational1.pro
    # fix lib paths
    reinplace "/LIBS.*3rdparty.*gsl/d" ${worksrcpath}/qtiplot/qtiplot.pro \
                                       ${worksrcpath}/fitPlugins/explin/explin.pro \
                                       ${worksrcpath}/fitPlugins/exp_saturation/exp_saturation.pro \
                                       ${worksrcpath}/fitPlugins/fitRational0/fitRational0.pro \
                                       ${worksrcpath}/fitPlugins/fitRational1/fitRational1.pro
    reinplace "/LIBS.*3rdparty.*muparser/d" ${worksrcpath}/qtiplot/qtiplot.pro
    reinplace "/LIBS.*3rdparty.*boost/d" ${worksrcpath}/qtiplot/qtiplot.pro
    reinplace "/LIBS.*3rdparty.*png/d" ${worksrcpath}/qtiplot/qtiplot.pro
    reinplace "/LIBS.*3rdparty.*libqwt.a/d" ${worksrcpath}/qtiplot/qtiplot.pro \
                                            ${worksrcpath}/qtiplot/src/lib/qti.pro

    # 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.args  "'INCLUDEPATH += ${prefix}/include' 'LIBS += -L${prefix}/lib -lqwt -lpng -lgsl -lgslcblas -lmuparser -lboost_date_time-mt -lboost_thread-mt'"
configure.cmd   "LOCALSOFT=${prefix} ${prefix}/libexec/qt4-mac/bin/qmake"
destroot.destdir INSTALL_ROOT=${destroot}

post-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/
}

