# $Id: Portfile 62446 2010-01-08 11:18:53Z ryandesign@macports.org $

PortSystem 1.0

name                cgnslib
version             2.5.4
revision            1
set branch          [join [lrange [split ${version} .] 0 1] .]
set minor           [lindex [split ${version} .] end]
categories          science
maintainers         cerfacs.fr:dechaume
license             zlib

description         Computational fluid dynamics data container.
long_description    The CFD General Notation System (CGNS) provides a general, \
portable, and extensible standard for the storage and retrieval of \
computational fluid dynamics (CFD) analysis data. It consists of a collection \
of conventions, and free and open software implementing those conventions. It \
is self-descriptive, machine-independent, well-documented, and administered by \
an international steering committee.

homepage            http://cgns.sourceforge.net/
platforms           darwin
distname            ${name}_${branch}-${minor}
master_sites        sourceforge:cgns

checksums           md5 42063efdf726c81300a51c3495d3224e \
                    sha1 d5f99f6df7409d923d8703fc3732b13bd1d89b20

worksrcdir          ${name}_${branch}

configure.args-append --enable-lfs

# cgns tools
post-build {
    system "cd ${worksrcpath}/tools && make"
}

destroot.destdir    INCLUDEDIR=${destroot}${prefix}/include \
                    LIBDIR=${destroot}${prefix}/lib

post-destroot {
    xinstall -m 755 -W ${worksrcpath}/tools \
        cgnsversion \
        cgnspack \
        cgnsdiff \
        cgnscheck \
        cgnslist \
        ${destroot}${prefix}/bin
    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    xinstall -m 644 -W ${worksrcpath} \
        LICENSE \
        README \
        ${docdir}
}

post-install {
    # cgnslib 2.5.4_0 installed items directly in ${prefix}; remove them if found
    foreach file {include/cgnslib.h include/cgnslib_f.h include/cgnswin_f.h lib/libcgns.a} {
        set filepath ${prefix}/${file}
        if {[file exists ${filepath}]} {
            if {[catch {delete ${filepath}}]} {
                ui_warn "Cannot delete ${filepath}; please remove it manually"
            }
        }
    }
}
