Mercurial > pytave
changeset 83:8145ecfecfb9 task
Configuration changes. Detect numpy in ./configure.
author | David Grundberg <c04dgg@cs.umu.se> |
---|---|
date | Sat, 12 Sep 2009 14:52:14 +0200 |
parents | f6e8abc9a8cf |
children | 8ee00dc40ae5 0495ad9db223 |
files | Jamfile.in Makefile.am configure.ac m4/ax_octave.m4 m4/ax_python_numpy.m4 pytave.cc setup.py.in |
diffstat | 7 files changed, 163 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/Jamfile.in Mon Aug 24 11:02:29 2009 +0200 +++ b/Jamfile.in Sat Sep 12 14:52:14 2009 +0200 @@ -6,7 +6,7 @@ <library>@JAM_LIBOCTAVE@ <library>@JAM_LIBCRUFT@ <library>@JAM_LIBOCTINTERP@ -# <include>@PYTHON_INCLUDE_DIR@ +# <include>@PYTHON_INCLUDE_DIR@ # FIXME <include>@OCTAVE_INCLUDEDIR@ <include>@abs_srcdir@ <include>@abs_builddir@
--- a/Makefile.am Mon Aug 24 11:02:29 2009 +0200 +++ b/Makefile.am Sat Sep 12 14:52:14 2009 +0200 @@ -4,7 +4,7 @@ package/__init__.py package/pytave.py EXTRA_libdir = @PYTAVE_MODULE_INSTALL_PATH@ -_pytave_la_CPPFLAGS = @OCTAVE_CPPFLAGS@ @PYTHON_CPPFLAGS@ +_pytave_la_CPPFLAGS = @OCTAVE_CPPFLAGS@ @PYTHON_CPPFLAGS@ -I@NUMPY_INCLUDEDIR@ # Having -module in LDFLAGS lets us use a non-standard library name # (e.g. _pytave instead of libpytave)
--- a/configure.ac Mon Aug 24 11:02:29 2009 +0200 +++ b/configure.ac Sat Sep 12 14:52:14 2009 +0200 @@ -20,21 +20,30 @@ AC_ARG_ENABLE(numpy, [AS_HELP_STRING([--enable-numpy], [use NumPy module (experimental) - @<:@default=no@:>@])], + @<:@default=check@:>@])], [pytave_enable_numpy="$enableval"], - [pytave_enable_numpy=no]) dnl TODO: Check? + [pytave_enable_numpy=check]) -if test "$pytave_enable_numpy" == "yes" ; then - AC_DEFINE([HAVE_NUMPY], 1, [Define if using NumPy]) -fi - pytave_libs_ok= -AX_OCTAVE([], [], [pytave_libs_ok=no]) +AX_OCTAVE([OCTAVE_CONFIG], [], [pytave_libs_ok=no]) # Pick a Python library to use AX_PYTHON_DEVEL([], [], [pytave_libs_ok=no]) +AS_IF(test "x$pytave_enable_numpy" != "xno", +[ + AX_PYTHON_NUMPY( + [ + AC_DEFINE([HAVE_NUMPY], 1, [Define if using NumPy]) + pytave_enable_numpy=yes + ], + [ + AS_IF(test "x$pytave_enable_numpy" == "xyes", [pytave_libs_ok=no]) + pytave_enable_numpy='not found' + ]) +]) + # Look for boost::python pytave_old_libs="$LIBS" pytave_old_ldflags="$LDFLAGS" @@ -49,17 +58,6 @@ LDFLAGS="$pytave_old_ldflags" CPPFLAGS="$pytave_old_cppflags" -# Now check the libs, if they have problems, halt. -AS_IF(test -n "$pytave_libs_ok", -[ - AC_MSG_ERROR([ -======================================================================== -One or more library dependencies could not be resolved. - -Configuration failed. Halt. -========================================================================]) -]) - # Do some more initializations AM_INIT_AUTOMAKE() @@ -107,7 +105,6 @@ PYTAVE_OCTAVE_RPATH="$OCTAVE_LIBRARYDIR" AC_SUBST(PYTAVE_OCTAVE_RPATH) AC_SUBST(PYTAVE_MODULE_INSTALL_PATH) -AC_SUBST(pytave_enable_numpy) # Substitutes for the Jamfile. XXX: Replace lib*.so with OS independent name. AC_SUBST(JAM_LIBOCTAVE, $OCTAVE_LIBRARYDIR/liboctave.so) @@ -117,14 +114,22 @@ # setup.py AC_SUBST(PYTHON) +msg='One or more library dependencies could not be resolved. + +Configuration failed. Halt.' + +AS_IF(test -z "$pytave_libs_ok", +[ # Substitute in these files, copy project-root.jam to VPATH too AC_OUTPUT([Makefile Jamfile setup.py project-root.jam]) chmod u+x "setup.py" +msg='Pytave is configured with the following setup' +]) AC_MSG_NOTICE([ ======================================================================== -Pytave now configured with the following setup: +$msg Dependencies Octave ............. $OCTAVE_INCLUDEDIR @@ -136,3 +141,8 @@ uselocale .......... $pytave_have_uselocale ========================================================================]) + +AS_IF(test -n "$pytave_libs_ok", +[ + AC_MSG_ERROR([[Configuration failure. Halt.]]) +]) \ No newline at end of file
--- a/m4/ax_octave.m4 Mon Aug 24 11:02:29 2009 +0200 +++ b/m4/ax_octave.m4 Sat Sep 12 14:52:14 2009 +0200 @@ -77,7 +77,7 @@ OCTAVE_CPPFLAGS= OCTAVE_INCLUDEDIR= OCTAVE_LIBRARYDIR= - ax_octave_config="$1" + ax_octave_config="[$]$1" ax_octave_ok= AC_MSG_CHECKING([for octave-config filename])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m4/ax_python_numpy.m4 Sat Sep 12 14:52:14 2009 +0200 @@ -0,0 +1,121 @@ +# =========================================================================== +# +# =========================================================================== +# +# SYNOPSIS +# +# AX_PYTHON_NUMPY([ACTION_IF_FOUND], [ACTION_IF_NOT_FOUND]) +# +# DESCRIPTION +# +# +# LAST MODIFICATION +# +# 2009-08024 +# +# COPYING +# +# Copyright (c) 2009 David Grundberg +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see <http://www.gnu.org/licenses/>. +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Macro Archive. When you make and +# distribute a modified version of the Autoconf Macro, you may extend this +# special exception to the GPL to apply to your modified version as well. + +AC_DEFUN([AX_PYTHON_NUMPY],[ + NUMPY_INCLUDEDIR= + + AC_MSG_CHECKING([for python]) + AS_IF([test -z "$PYTHON"], [ + AC_MSG_RESULT([unknown]) + ],[ + AC_MSG_RESULT([$PYTHON]) + ]) + + AC_MSG_CHECKING([for numpy includedir]) + AS_IF([test -z "$PYTHON"], [ + AC_MSG_RESULT([no (python unknown)]) + ],[ + NUMPY_INCLUDEDIR=`$PYTHON -c ' +try: + from numpy import get_include + print get_include() +except: + pass +'` + AC_MSG_RESULT([$NUMPY_INCLUDEDIR]) + ]) + + AS_IF([test -n "$NUMPY_INCLUDEDIR"], [ + + AC_CACHE_CHECK([whether linking to numpy library works], [ax_python_numpy_cv_check], + [ + ax_python_numpy_cv_check=no + + AC_LANG_PUSH([C++]) + + ax_python_numpy_cppflags="$CPPFLAGS" + ax_python_numpy_ldflags="$LDFLAGS" + CPPFLAGS="$CPPFLAGS -I$NUMPY_INCLUDEDIR $PYTHON_CPPFLAGS" + LDFLAGS="$LDFLAGS $PYTHON_LDFLAGS" + + AC_LANG_ASSERT(C++) + AC_LINK_IFELSE( + AC_LANG_PROGRAM( + [[ +#define PY_ARRAY_UNIQUE_SYMBOL my_array_symbol +#include <Python.h> +#include <numpy/oldnumeric.h> +#include <numpy/old_defines.h> +]], + [[ &PyArray_FromDims; ]]), + [ax_python_numpy_cv_check=yes], + [ax_python_numpy_cv_check=no]) + CPPFLAGS="$ax_python_numpy_old_cppflags" + LDFLAGS="$ax_python_numpy_ldflags" + + AC_LANG_POP([C++]) + ]) + ]) + + AS_IF([test "x$ax_python_numpy_cv_check" != "xyes"], [ + NUMPY_INCLUDEDIR= + + AC_MSG_WARN([[ +======================================================================== +Can not link with Numpy. + +Make sure the Numpy development package is installed. +========================================================================]]) + ]) + + AC_SUBST([NUMPY_INCLUDEDIR]) + + # Execute ACTION_IF_FOUND or ACTION_IF_NOT_FOUND + if test "x$ax_python_numpy_cv_check" == "xyes" ; then + m4_ifvaln([$1],[$1],[:])dnl + m4_ifvaln([$2],[else $2])dnl + fi + +])
--- a/pytave.cc Mon Aug 24 11:02:29 2009 +0200 +++ b/pytave.cc Sat Sep 12 14:52:14 2009 +0200 @@ -103,6 +103,7 @@ // occurs, e.g. Numeric Array not installed, an exception is set. import_array() #ifdef HAVE_NUMPY + // Let boost use numpy numeric::array::set_module_and_type ("numpy", "ndarray"); #endif }
--- a/setup.py.in Mon Aug 24 11:02:29 2009 +0200 +++ b/setup.py.in Sat Sep 12 14:52:14 2009 +0200 @@ -2,19 +2,7 @@ # -*- coding: utf-8; c-basic-offset: 3; indent-tabs-mode: nil; tab-width: 3; -*- # @configure_input@ -from distutils.core import setup, Extension, DistutilsModuleError - -include_dirs = ['/usr/local/include/octave-3.1.55', - '/home/hajek/devel/pytave-repo/pytave', '.'] # Python always included. - -# check for numpy. If it exists, define the path. - -if '@pytave_enable_numpy@' == 'yes': - try: - from numpy import get_include - include_dirs.append(get_include()) - except ImportError: - raise DistutilsModuleError("could not found numpy") +from distutils.core import setup, Extension setup( name = 'pytave', @@ -41,10 +29,15 @@ '@srcdir@/python_to_octave.h' ], + # Python always included, so don't bother. # TODO: Check whether paths work on Windows or not. # The file separator might be wrong. (Must be / in setup.cfg) - include_dirs = include_dirs, - define_macros = [('HAVE_CONFIG_H', '1')], + include_dirs = ['@OCTAVE_INCLUDEDIR@', + '@NUMPY_INCLUDEDIR@', + '@abs_builddir@', + '@srcdir@', + ], + define_macros = [('HAVE_CONFIG_H', '1')], library_dirs = ['@OCTAVE_LIBRARYDIR@'], runtime_library_dirs = ['@PYTAVE_OCTAVE_RPATH@'], libraries = ['octinterp', 'octave', 'cruft', '@BOOST_PYTHON_LIB@']