# $Id: Portfile 80864 2011-07-19 21:06:43Z eborisch@macports.org $

PortSystem          1.0

name                eigen3
version             3.0.1
revision            2
license             {{GPL-2+} {LGPL-3+}}
categories          math science
maintainers         eborisch \
                    openmaintainer
description         A C++ template library for linear algebra: vectors, matrices, and related algorithms.
long_description    ${description}
homepage            http://eigen.tuxfamily.org/
platforms           darwin

master_sites        http://bitbucket.org/eigen/eigen/get/
distname            ${version}

# 3.0.1 was stealth updated; see #30241
dist_subdir         ${name}/${version}_30241

use_bzip2           yes

checksums           md5     542f0b304b42aade9b8bdd70e824328b \
                    sha1    53d557f52c277fdc481902521b2a7c71f8331863 \
                    rmd160  acbeccb97a764b3f23e4dca18fde486713417d40

universal_variant   yes
configure.universal_args  ""

# Install via CMake by default. Slower than a header-only install, but makes other CMake-based builds happy
default_variants     +cmake

# Variants
variant gcc44 description {Use MacPorts' gcc44 compilers} conflicts gcc45 {
  configure.compiler  macports-gcc-4.4
}

variant gcc45 description {Use MacPorts' gcc45 compilers} conflicts gcc44 {
  configure.compiler  macports-gcc-4.5
}

variant doc description {Place local documentation into <prefix>/share/doc/eigen3/html} requires cmake {
  depends_build-append port:doxygen port:texlive-latex
  build.target-append doc
}

variant blas description {Build eigen-based blas (libeigen_blas*)} requires cmake {
  if {![variant_isset gcc44] && ![variant_isset gcc45]} {
    ui_error "eigen3: ##### +blas needs either +gcc44 or +gcc45 enabled #####"
    return -code error
  } else {
    build.target-append blas
  }
}

variant cmake description {CMake-based install: Disabling removes CMake support} {
  PortGroup           muniversal 1.0
  # Not using cmake portgroup as it sets -DCMAKE_OSX_ARCHITECTURES
  # in a way we don't seem to be able disable.
  set cmake_share_module_dir ${prefix}/share/cmake/modules

  depends_build-append port:cmake

  configure.cmd       cmake

  configure.pre_args  -DCMAKE_INSTALL_PREFIX=${prefix}

  configure.args      -DCMAKE_VERBOSE_MAKEFILE=ON \
                      -DCMAKE_COLOR_MAKEFILE=ON \
                      -DCMAKE_BUILD_TYPE=Release \
                      -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
                      -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib \
                      -DCMAKE_SYSTEM_PREFIX_PATH=\"${prefix}\;/usr\" \
                      -DCMAKE_MODULE_PATH=${cmake_share_module_dir} \
                      -Wno-dev
 
  # Out of source build
  configure.args-append ../eigen_src

  # Enable test cases if we've actually configured
  test.run            yes
  test.target         check
  test.env-append     EIGEN_MAKE_ARGS=-j{build.jobs} \
                      EIGEN_CTEST_ARGS=-j{build.jobs}

  # Enable parallel builds
  build.env-append    EIGEN_MAKE_ARGS=-j{build.jobs}
}

# Conditional phase modifications
# Are we doing a header-only or cmake (for 'port test' or +doc/+blas) build?
if {![variant_isset cmake]} {
  # We can skip everything and just copy the headers -- fast!
  use_configure       no
  build {}
  destroot {
    set incldir ${destroot}${prefix}/include/${name}
    xinstall -d ${incldir}
    file copy ${workpath}/eigen_src/Eigen ${incldir}
    file copy ${workpath}/eigen_src/unsupported ${incldir}
  }

  # Fail with message if user tries to test
  test.run            yes
  test {
    ui_error "!!! TESTING IS UNSUPPORTED WITHOUT +cmake VARIANT !!!"
  }
}

# Phase modifications
# Move source into eigen_src; configure & build (out-of-source) in ${worksrcpath}
post-extract {
  move ${workpath}/eigen-eigen-599fc4f7c736 ${workpath}/eigen_src
  file mkdir ${worksrcpath}
}

# Install licenses and documentation (if +doc)
pre-destroot {
  set build_suffix {}
  if {![info exists universal_archs_to_use]} {
    lappend build_suffix ""
  } else {
    set dash "-"
    foreach arch ${universal_archs_to_use} {
      lappend build_suffix ${dash}${arch}
    }
  }

  foreach sfx ${build_suffix} {
    set docdir ${destroot}${sfx}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    xinstall -m 644 -W ${workpath}/eigen_src COPYING.GPL COPYING.LGPL ${docdir}
   
    # Install documentation if requested
    if {[variant_isset doc]} {
      file copy ${worksrcpath}${sfx}/doc/html ${docdir}
    }

    if {[variant_isset blas]} {
        set libdir ${destroot}${sfx}${prefix}/lib
        xinstall -d ${libdir}
        eval file copy [glob ${worksrcpath}${sfx}/blas/libeigen_blas*] ${libdir}
    }
  }
}

livecheck.type        regex
livecheck.url         ${homepage}index.php?title=ChangeLog
livecheck.regex       {Eigen (\d+(?:\.\d+)*)}

