# -*- 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 119466 2014-04-26 19:06:18Z rowue@macports.org $

PortSystem          1.0

name                gwyddion
version             2.36
categories          science x11
platforms           darwin
license             gpl-2
# revision            1
maintainers         rowue gwyddion.net:yeti
description         Software for SPM Analysis

long_description \
    Gwyddion is a modular program for SPM (scanning probe microscopy) data \
    visualization and analysis. It uses gtk2 for the user interface.

homepage            http://gwyddion.net
# master_sites        sourceforge
master_sites        sourceforge:project/gwyddion/gwyddion/${version}
use_xz              yes
use_parallel_build  yes

checksums           sha256  98baf72eeed4b5d1ab6012aedd426d157cd9352d9cf8dbfcd35377b9eef9bda3 \
                    rmd160  ca4f0167384eb0c33dea0fdafa8303548880ac61

depends_build       port:pkgconfig

depends_lib         port:gtk2 \
                    port:icu \
                    port:libxml2 \
                    port:fftw-3 \
                    port:gtkglext

configure.args      --disable-desktop-file-update \
                    --x-include=${prefix}/include \
                    --x-lib=${prefix}/lib

variant quartz description { Build gwyddion with quartz gl support } {
    depends_lib-append    port:gtk-osx-application
}

variant pygwy description { Build gwyddion with python support } {
    ui_msg "For console python support you have to set DYLD_FALLBACK_LIBRARY_PATH to $prefix/lib"
    set python.prefix     ${frameworks_dir}/Python.framework/Versions/2.7
    configure.pkg_config_path ${python.prefix}/lib/pkgconfig
    depends_lib-append    port:py-pygtk \
                          port:python27
    configure.cflags-append -I${python.prefix}/include
    patchfiles-append      patch-modules-pygwy-gwy.c.diff
}

# remove after october 2014
variant no_x11 requires quartz description { Legacy compatibility variant } {}

variant debug description { Enable debugging } {
    configure.cflags-append "-O0 -g"
}

post-destroot {
    xinstall -m 755 -d ${destroot}${applications_dir}/gwyddion.app/Contents/MacOS
    if {[variant_isset quartz]} {
        xinstall ${filespath}/gwyddion.quartz ${destroot}${applications_dir}/gwyddion.app/Contents/MacOS/gwyddion
        reinplace "s|@PREFIX@|${prefix}|" ${destroot}${applications_dir}/gwyddion.app/Contents/MacOS/gwyddion
    } else {
        xinstall ${filespath}/gwyddion ${destroot}${applications_dir}/gwyddion.app/Contents/MacOS
        reinplace "s|@APPDIR@|${applications_dir}|" ${destroot}${applications_dir}/gwyddion.app/Contents/MacOS/gwyddion
        reinplace "s|@PREFIX@|${prefix}|" ${destroot}${applications_dir}/gwyddion.app/Contents/MacOS/gwyddion
    }
    if {[variant_isset pygwy]} {
    	set python.prefix   ${frameworks_dir}/Python.framework/Versions/2.7
    	set python.site_packages    ${python.prefix}/lib/python2.7/site-packages/
        xinstall -m 755 -d ${destroot}${python.site_packages}
        move ${destroot}${prefix}/lib/python2.7/site-packages/gwy.so ${destroot}${python.site_packages}
        move ${destroot}${prefix}/lib/python2.7/site-packages/gwy.la ${destroot}${python.site_packages}
    }
    xinstall -m 755 -d ${destroot}${applications_dir}/gwyddion.app/Contents/Resources
    xinstall -m 0644 ${filespath}/gwyddion.icns ${destroot}${applications_dir}/gwyddion.app/Contents/Resources
    xinstall -m 0644 ${filespath}/Info.plist ${destroot}${applications_dir}/gwyddion.app/Contents/
    reinplace "s|@VERSION@|${version}|" ${destroot}${applications_dir}/gwyddion.app/Contents/Info.plist
    system "echo 'APPL????' > ${destroot}${applications_dir}/gwyddion.app/Contents/PkgInfo"
}

post-activate {
        system "${prefix}/bin/update-mime-database ${prefix}/share/mime ; true"
}

platform darwin 8 {
	post-activate {
		if {[file exists ${prefix}/lib/pkgconfig/gl.pc]} {
            if {![variant_isset quartz]} {
			    ui_msg "openGL support currently requires you to use MacPorts' X11 server (xorg-server) rather than Apple's."
            }
		}
	}
}
