# $Id: Portfile 102485 2013-02-04 16:02:38Z raimue@macports.org $

PortSystem 1.0

name            valgrind
conflicts       valgrind-devel
version         3.8.1
revision        1
categories      devel
platforms       darwin
supported_archs i386 x86_64
license         GPL-2
maintainers     raimue

description     A powerful open-source memory debugger
long_description \
    Valgrind is a powerful open-source memory debugger. When valgrind is \
    attached to a program, it intercepts calls to malloc/new/free/delete and \
    all memory operations are checked for invalid read or write.

homepage        http://valgrind.org
master_sites    http://valgrind.org/downloads/
use_bzip2 yes

checksums       md5     288758010b271119a0ffc0183f1d6e38 \
                sha1    aa7a3b0b9903f59a11ae518874852e8ccb12751c \
                sha256  473be00576bed311a662b277a2bfbe97d9cca4058e68619a0e420c9fc19958db

# Avoid conflict of faq.html and FAQ.html, #30541
extract.post_args-append --exclude=${distname}/docs/html/FAQ.html

pre-configure {
    if {"darwin" == ${os.platform} && (${os.major} < 9 || ${os.major} > 12)} {
        ui_error "${name} ${version} is only compatible with Mac OS X 10.5, 10.6, 10.7 and 10.8"
        return -code error "incompatible Mac OS X version"
    }
}

depends_build   bin:perl:perl5
# Ignore trace reports about boost, Qt and OpenMP
# as they are only used for tests

patchfiles      link_tool_exe_darwin-ccache.diff

configure.args  --mandir=${prefix}/share/man \
                --without-mpicc

if {$build_arch == "i386"} {
    configure.args-append --enable-only32bit
} elseif {$build_arch == "x86_64"} {
    configure.args-append --enable-only64bit
}

# valgrind sets up -arch by itself, adding our own interferes with the build
configure.cc_archflags {}
configure.ld_archflags {}

variant universal {
    configure.args-delete --enable-only32bit --enable-only64bit
    configure.universal_cflags {}
    configure.universal_cxxflags {}
    configure.universal_ldflags {}

    pre-configure {
        if {$build_arch == "i386"} {
            # See #25684 and https://bugs.kde.org/show_bug.cgi?id=243362
            ui_error "valgrind does not build +universal on a 32-bit only CPU!"
            return -code error "unsupported CPU"
        }
    }
}

variant mpich2 requires mpich description {Compatibility variant, renamed to +mpich} {}
variant mpich description {Use mpich for MPI support} conflicts universal {
    depends_lib-append path:bin/mpicc:mpich
    configure.args-delete --without-mpicc
    configure.args-append --with-mpicc=${prefix}/bin/mpicc
}

variant openmpi description {Use openmpi for MPI support} conflicts universal {
    depends_lib-append port:openmpi
    configure.args-delete --without-mpicc
    configure.args-append --with-mpicc=${prefix}/bin/openmpicc
}

livecheck.type  regex
livecheck.url ${homepage}
livecheck.regex ${name}-(\\d(?:\\.\\d)+)
