# -*- 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: Portfile 66905 2010-04-25 16:20:55Z ram@macports.org $

PortSystem				1.0
PortGroup python26		1.0

name					py26-scipy
version					0.7.2
categories				python
platforms				darwin
maintainers				jmr ram openmaintainer
description				An opensource library of scientific tools for Python
long_description		${description}.

homepage				http://www.scipy.org/
master_sites			sourceforge:scipy
distname				scipy-${version}

checksums				md5 33f883f5ea4227de7097c47d70d5402a \
						sha1 c3223df023008ee339cf1d3fad74d4566af69c8a \
						rmd160 456e4ab9d69f9d4056bca6b52474b72bea37b122

depends_lib-append		port:py26-numpy \
						port:py26-nose \
						port:SuiteSparse \
						port:swig-python \
						port:atlas

worksrcdir				${distname}

build.env-append		CCFLAGS="-I${prefix}/include -L${prefix}/lib" \
						ATLAS=${prefix}/lib \
						LAPACK=${prefix}/lib \
						BLAS=${prefix}/lib \
						CC="${filespath}/c-wrapper" \
						CXX="${filespath}/c++-wrapper" \

destroot.env-append		CCFLAGS="-I${prefix}/include -L${prefix}/lib" \
						ATLAS=${prefix}/lib \
						LAPACK=${prefix}/lib \
						BLAS=${prefix}/lib \
						CC="${filespath}/c-wrapper" \
						CXX="${filespath}/c++-wrapper" \

ui_debug ("Generating wrappers")
file copy -force ${filespath}/wrapper ${filespath}/c-wrapper
file copy -force ${filespath}/wrapper ${filespath}/c++-wrapper
file copy -force ${filespath}/wrapper ${filespath}/f-wrapper

reinplace "s|+++|\\\\.c|" ${filespath}/c-wrapper
reinplace "s/+++/(\\\\.cxx|\\\\.C|\\\\.cc)/" ${filespath}/c++-wrapper
reinplace "s|+++|\\\\.f|" ${filespath}/f-wrapper

reinplace "s|___|${prefix}|" ${filespath}/c-wrapper
reinplace "s|___|${prefix}|" ${filespath}/c++-wrapper
reinplace "s|___|${prefix}|" ${filespath}/f-wrapper

# Variants

if {![variant_isset gcc42] && ![variant_isset gcc43] && ![variant_isset gcc44]\
	 && ![variant_isset gcc45]} {
  default_variants      +gcc44
}

variant no_atlas description {"Do not use macports atlas libraries"} {
	depends_lib-delete		port:atlas

	build.env-delete		ATLAS=${prefix}/lib \
							LAPACK=${prefix}/lib \
							BLAS=${prefix}/lib

	destroot.env-delete		ATLAS=${prefix}/lib \
							LAPACK=${prefix}/lib \
							BLAS=${prefix}/lib
}

variant gcc45 conflicts gcc42 gcc43 gcc44 description "Use gcc-mp 4.5" {
	depends_lib-append		port:gcc45
	set fc_options			"config_fc --fcompiler gnu95 \
							--f77exec ${filespath}/f-wrapper \
							--f90exec ${filespath}/f-wrapper "
	set config_options		"config --cc ${filespath}/c-wrapper \
							--include-dirs ${prefix}/include \
							--library-dirs ${prefix}/lib"

	if {[variant_isset universal]} {
		append fc_options	"--f77flags '${configure.universal_cflags}' \
							 --f90flags '${configure.universal_cflags}'"
	}

	build.cmd-append      ${fc_options} ${config_options}
	destroot.cmd-append   ${fc_options} ${config_options}

	reinplace "s|@@@|gcc-mp-4.5|" ${filespath}/c-wrapper
	reinplace "s|@@@|g++-mp-4.5|" ${filespath}/c++-wrapper
	reinplace "s|@@@|gfortran-mp-4.5|" ${filespath}/f-wrapper
}

variant gcc44 conflicts gcc45 gcc43 gcc42 description "Use gcc-mp 4.4" {
	depends_lib-append		port:gcc44
	set fc_options			"config_fc --fcompiler gnu95 \
							--f77exec ${filespath}/f-wrapper \
							--f90exec ${filespath}/f-wrapper "
	set config_options		"config --cc ${filespath}/c-wrapper \
							--include-dirs ${prefix}/include \
							--library-dirs ${prefix}/lib"

	if {[variant_isset universal]} {
		append fc_options	"--f77flags '${configure.universal_cflags}' \
							 --f90flags '${configure.universal_cflags}'"
	}

	build.cmd-append      ${fc_options} ${config_options}
	destroot.cmd-append   ${fc_options} ${config_options}

	reinplace "s|@@@|gcc-mp-4.4|" ${filespath}/c-wrapper
	reinplace "s|@@@|g++-mp-4.4|" ${filespath}/c++-wrapper
	reinplace "s|@@@|gfortran-mp-4.4|" ${filespath}/f-wrapper
}

variant gcc43 conflicts gcc45 gcc44 gcc42 description "Use gcc-mp 4.3" {
	depends_lib-append		port:gcc43
	set fc_options			"config_fc --fcompiler gnu95 \
							--f77exec ${filespath}/f-wrapper \
							--f90exec ${filespath}/f-wrapper "
	set config_options		"config --cc ${filespath}/c-wrapper \
							--include-dirs ${prefix}/include \
							--library-dirs ${prefix}/lib"

	if {[variant_isset universal]} {
		append fc_options	"--f77flags '${configure.universal_cflags}' \
							 --f90flags '${configure.universal_cflags}'"
	}

	build.cmd-append      ${fc_options} ${config_options}
	destroot.cmd-append   ${fc_options} ${config_options}

	reinplace "s|@@@|gcc-mp-4.3|" ${filespath}/c-wrapper
	reinplace "s|@@@|g++-mp-4.3|" ${filespath}/c++-wrapper
	reinplace "s|@@@|gfortran-mp-4.3|" ${filespath}/f-wrapper
}

variant gcc42 conflicts gcc45 gcc44 gcc43 description "Use gcc-mp 4.2" {
	ui_warn ("Use of gcc/gfortran 4.2 is obsolete and not recommended")
	depends_lib-append		port:gcc42
	set fc_options			"config_fc --fcompiler gnu95 \
							--f77exec ${filespath}/f-wrapper \
							--f90exec ${filespath}/f-wrapper "
	set config_options		"config --cc ${filespath}/c-wrapper \
							--include-dirs ${prefix}/include \
							--library-dirs ${prefix}/lib"

	if {[variant_isset universal]} {
		append fc_options	"--f77flags '${configure.universal_cflags}' \
							 --f90flags '${configure.universal_cflags}'"
	}

	build.cmd-append      ${fc_options} ${config_options}
	destroot.cmd-append   ${fc_options} ${config_options}

	reinplace "s|@@@|gcc-mp-4.2|" ${filespath}/c-wrapper
	reinplace "s|@@@|g++-mp-4.2|" ${filespath}/c++-wrapper
	reinplace "s|@@@|gfortran-mp-4.2|" ${filespath}/f-wrapper
}

post-patch {
	reinplace \
	"s|include <\\(umfpack\.*.h\\)>|include <${prefix}/include/ufsparse/\\1>|g" ${worksrcpath}/scipy/sparse/linalg/dsolve/umfpack/umfpack.i
}

post-destroot {
	file delete -force ${filespath}/c-wrapper
	file delete -force ${filespath}/c++-wrapper
	file delete -force ${filespath}/f-wrapper
}

livecheck.type          regex
livecheck.url           http://sourceforge.net/projects/scipy/files/
livecheck.regex         "files\/scipy\/(\\d+(?:\\.\\d+)*)\/scipy"
