# -*- 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
PortSystem          1.0
PortGroup           conflicts_build 1.0
PortGroup           legacysupport 1.1

# requires clock_gettime()
legacysupport.newest_darwin_requires_legacy 15

name                OpenIPMI
version             2.0.37
revision            0
set branch          [join [lrange [split ${version} .] 0 1] .]
license             {GPL-2 LGPL-2}
categories          sysutils
platforms           darwin
maintainers         {eborisch @eborisch} \
                    openmaintainer

description         OpenIPMI provides a full-function IPMI interface.

long_description    The Open IPMI project aims to develop an open code base to\
                    allow access to platform information using Intelligent\
                    Platform Management Interface (IPMI).

homepage            http://openipmi.sourceforge.net/
master_sites        sourceforge:project/openipmi/OpenIPMI%20${branch}%20Library

universal_variant   no
use_parallel_build  no

checksums           rmd160  0b3b93d792d620934620ad5e448eb1e4f7c42ed3 \
                    sha256  c62d38f5da7df4299ac3a652508e959537752440181e34c76b2aecebd7f301b9 \
                    size    2929014
patchfiles          disable-lanserv.patch \
                    unix_posix_thread_os_hnd.c.patch \
                    unix_selector.c.patch \
                    include_OpenIPMI_selector.h.patch

# Grabs old headers from installed version during build...
conflicts_build     ${name}

depends_build       port:gsed

depends_lib         path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:net-snmp \
                    port:popt \
                    path:lib/libssl.dylib:openssl

configure.args      --with-poptlibs=-lpopt \
                    --with-swig=no \
                    --with-python=no \
                    --with-perl=no

variant python description "Build python bindings" {
    configure.args-delete --with-swig=no --with-python=no
    depends_lib-append      port:swig-python \
                            port:py27-tkinter \
                            port:tix
}

variant perl description "Build perl bindings" {
    configure.args-delete --with-swig=no --with-perl=no
    depends_lib-append      port:swig-perl \
                            port:perl5
}

platform darwin {
    post-extract {
        system -W ${worksrcpath} \
            "find . -name 'Makefile*' | xargs sed -i '' -e 's/Map/map/g'"
        system -W ${worksrcpath} \
            "grep -R 'rdynamic' -l * | xargs sed -i '' -e 's/-rdynamic//g'"
        set REPLSTR "s/LD_PRELOAD=/DYLD_INSERT_LIBRARIES=/g"
        system -W ${worksrcpath} \
            "grep -R 'LD_PRELOAD' -l * | xargs sed -i '' -e '${REPLSTR}'"
    }

    use_autoreconf  yes

    post-configure {
        set REPLSTR "s/lib(\[^ :\/\]*)\.so/lib\\1.dylib/g"
        system -W ${worksrcpath} \
            "find . -name 'Makefile' | xargs sed -E -i '' -e '${REPLSTR}'"

        if {[variant_isset python]} {
            set LIBPATH \
"../../../unix/.libs:../../../lib/.libs:../../../utils/.libs:../../../cmdlang/.libs:../../../tcl/.libs:../../../swig/python/.libs"
            reinplace "s|DYLD_\[^ \]*|DYLD_LIBRARY_PATH=${LIBPATH}|g" \
                swig/python/openipmigui/Makefile
        }
    }
}

livecheck.type      sourceforge
livecheck.regex     ${name}-(\[0-9.\]+)${extract.suffix}
