# -*- 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$

PortSystem          1.0

name                libcudd
version             2.5.0
categories          devel
platforms           darwin
maintainers         caltech.edu:SCL openmaintainer

description         An efficient library for manipulating decision diagrams

long_description    The CUDD package provides functions to manipulate Binary \
                    Decision Diagrams (BDDs), Algebraic Decision Diagrams (ADDs), \
                    and Zero-suppressed Binary Decision Diagrams (ZDDs). It's \
                    been written by Fabio Somenzi at the University of Colorado, \
                    Boulder.

homepage            http://vlsi.colorado.edu/~fabio/CUDD/
master_sites        ftp://vlsi.colorado.edu/pub/
distname            cudd-${version}

checksums           rmd160  2f7b1dc3118925de268a1f1396ba4e66b65c54e4 \
                    sha256  4f3bc49b35564af94b17135d8cb8c4063fb049cfaa442f80dc40ba73c6345a85

patchfiles          patch-Makefile.diff \
                    patch-cudd-cudd.h.diff \
                    patch-dddmp-Makefile.diff \
                    patch-epd-Makefile.diff \
                    patch-mtr-mtr.h.diff \
                    patch-nanotrav-Makefile.diff \
                    patch-st-Makefile.diff \
                    patch-util-util.h.diff

use_configure       no

variant universal {}

pre-build {
    system -W ${worksrcpath} "make distclean"
    system -W ${worksrcpath}/obj "make distclean"
}

build.target        build
build.args          CC="${configure.cc} [get_canonical_archflags cc]" \
                    CXX="${configure.cxx} [get_canonical_archflags cxx]"

post-build {
    # generate dylib for C interface
    system -W ${worksrcpath} "${configure.cc} ${configure.optflags} [get_canonical_archflags cc] -dynamiclib -install_name ${prefix}/lib/cudd/libcudd.dylib -o libcudd.dylib `find cudd dddmp epd mtr st util -name '*.o'` ${configure.ldflags}"

    # compile the additional C++ interface
    system -W ${worksrcpath}/obj "make distclean && make [join ${build.args}]"
    # generate dylib for C++ interface
    system -W ${worksrcpath} "${configure.cxx} ${configure.optflags} [get_canonical_archflags cxx] -dynamiclib -install_name ${prefix}/lib/cudd/libcuddobj.dylib -L. -lcudd -o libcuddobj.dylib obj/cuddObj.o ${configure.ldflags}"
}

destroot {
    # install header files
    xinstall -m 755 -d ${destroot}${prefix}/include/cudd
    xinstall -m 644 -W ${worksrcpath}/include cudd.h cuddInt.h cuddObj.hh \
                    dddmp.h epd.h mtr.h st.h util.h \
                ${destroot}${prefix}/include/cudd
    # install libraries
    xinstall -m 755 -d ${destroot}${prefix}/lib/cudd
    xinstall -m 644 -W ${worksrcpath} libcudd.dylib libcuddobj.dylib ${destroot}${prefix}/lib/cudd
    # TODO: install documentation ...
}

notes "
To compile against the CUDD dynamic library, use\
'-I${prefix}/include/cudd -L${prefix}/lib/cudd -lcudd' for the C interface, or\
'-I${prefix}/include/cudd -L${prefix}/lib/cudd -lcudd -lcuddobj' for the C++ interface.
"

livecheck.type      regex
livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     cudd-(\[0-9.\]+)${extract.suffix}