[vsipl++] patch: python bindings prototype
Jules Bergmann
jules at codesourcery.com
Thu Oct 5 04:57:26 UTC 2006
Stefan,
How does this behave when python isn't present on the system? It looks
like configure will run python even if scripting isn't enabled.
Can you gate the python bindings with --enable-scripting? If the user
doesn't explicitly '--enable-scripting', then configure shouldn't try to
run python.
Also, what is the story with shared libraries? That is only for the
scripting, right?
-- Jules
Stefan Seefeld wrote:
> I just checked in the attached patch, which provides a prototype
> for python bindings for VSIPL++, using boost.python.
> This is really more a proof-of-concept than a complete binding,
> since most functions are still missing.
> However, I'm able to use it to create vectors and run simple
> functions, as well as ffts and convolutions on them.
>
> Regards,
> Stefan
>
>
>
> ------------------------------------------------------------------------
>
> +}
> Index: configure.ac
> ===================================================================
> --- configure.ac (revision 150667)
> +++ configure.ac (working copy)
> @@ -333,6 +333,28 @@
>
> AC_SUBST(QMTEST, $with_qmtest)
>
> +AC_ARG_ENABLE(scripting,
> + [ --enable-scripting Specify whether or not to build the python bindings.],,
> + [enable_scripting="no"])
> +
> +AC_ARG_WITH(python,
> + [ --with-python=PATH Specify the Python interpreter.],
> + PYTHON="$with_python",
> + PYTHON="python"
> +)
> +
> +AC_ARG_WITH(boost-prefix,
> + [ --with-boost-prefix=PATH Specify the boost installation prefix.],
> + BOOST_PREFIX="$with_boost_prefix",
> + BOOST_PREFIX="/usr"
> +)
> +
> +AC_ARG_WITH(boost-version,
> + [ --with-boost-version=VERSION Specify the boost version.],
> + BOOST_VERSION="$with_boost_version",
> + BOOST_VERSION="1.33"
> +)
> +
> #
> # Put libs directory int INT_LDFLAGS:
> #
> @@ -1329,7 +1351,6 @@
> # Copy libg2c into libdir, if requested.
> #
> if test "x$with_g2c_copy" != "x"; then
> - mkdir -p lib
> cp $with_g2c_copy lib
> curdir=`pwd`
> G2C_LDFLAGS="-L$curdir/lib"
> @@ -2009,6 +2030,76 @@
> AC_SUBST(INT_CPPFLAGS)
>
> #
> +# Python frontend
> +#
> +echo "PYTHON $PYTHON"
> +if test -n "$PYTHON" -a "$PYTHON" != yes; then
Why is this code comment out? Either explain why it is commented out,
our delete it.
> +dnl AC_CHECK_FILE($PYTHON,,AC_MSG_ERROR([Cannot find Python interpreter]))
> +dnl else
> + AC_PATH_PROG(PYTHON, python2 python, python)
> +fi
> +PYTHON_INCLUDE=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_inc()"`
> +PYTHON_EXT=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_config_var('SO')"`
> +
> +case $build in
> +CYGWIN*)
> + if test `$PYTHON -c "import os; print os.name"` = posix; then
> + PYTHON_PREFIX=`$PYTHON -c "import sys; print sys.prefix"`
> + PYTHON_VERSION=`$PYTHON -c "import sys; print '%d.%d'%(sys.version_info[[0]],sys.version_info[[1]])"`
> + PYTHON_LIBS="-L $PYTHON_PREFIX/lib/python$PYTHON_VERSION/config -lpython$PYTHON_VERSION"
This sounds like a FIXME.
Let's just document what we do:
"Cygwin doesn't have a -lutil, but some version of distutils tell us to
use it anyway. This has been tested for cygwin versions UMPTY-UMP."
and add an issue for the check each library thing if it is important to
fix later.
> +dnl Cygwin doesn't have an -lutil, but some versions of distutils tell us to use it anyway.
> +dnl It would be better to check for each library it tells us to use with AC_CHECK_LIB, but
> +dnl to do that, we need the name of a function in each one, so we'll just hack -lutil out
> +dnl of the list.
> + PYTHON_DEP_LIBS=`$PYTHON -c "from distutils import sysconfig; import re; print re.sub(r'\\s*-lutil', '', sysconfig.get_config_var('LIBS') or '')"`
> + else dnl this is 'nt'
> + if test "$CXX" = "g++"; then
> + CFLAGS="-mno-cygwin $CFLAGS"
> + CXXFLAGS="-mno-cygwin $CXXFLAGS"
> + LDFLAGS="-mno-cygwin $LDFLAGS"
> + PYTHON_PREFIX=`$PYTHON -c "import sys; print sys.prefix"`
> + PYTHON_VERSION=`$PYTHON -c "import sys; print '%d%d'%(sys.version_info[[0]],sys.version_info[[1]])"`
> + PYTHON_LIBS="-L `cygpath -a $PYTHON_PREFIX`/Libs -lpython$PYTHON_VERSION"
> + fi
> + PYTHON_INCLUDE=`cygpath -a $PYTHON_INCLUDE`
> + PYTHON_DEP_LIBS=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_config_var('LIBS') or ''"`
> + fi
> + LDSHARED="$CXX -shared"
> + PYTHON_LIBS="$PYTHON_LIBS $PYTHON_DEP_LIBS"
> + ;;
> +*)
> + LDSHARED="$CXX -shared"
> + ;;
> +esac
> +
> +PYTHON_LIBS="$PYTHON_LIBS $PYTHON_DEP_LIBS"
> +
> +AC_SUBST(PYTHON)
> +AC_SUBST(PYTHON_CPP, "-I $PYTHON_INCLUDE")
> +AC_SUBST(PYTHON_LIBS)
> +AC_SUBST(PYTHON_EXT)
> +
> +AC_SUBST(LDSHARED)
> +
Whats the AC_LANG(C++) for? We should have set it to C++ at the top of
configure.
> +AC_LANG(C++)
> +if test "$enable_scripting" == "yes"; then
> + AC_SUBST(enable_scripting, 1)
> + if test -n "$with_boost_prefix"; then
> + BOOST_CPPFLAGS="-I$with_boost_prefix/include"
> + BOOST_LDFLAGS="-L$with_boost_prefix/lib"
> + fi
> + save_CPPFLAGS=$CPPFLAGS
> + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS $PYTHON_CPP"
> + AC_CHECK_HEADER([boost/python.hpp], [],
> + [AC_MSG_ERROR([boost.python could not be found])])
> + CPPFLAGS="$save_CPPFLAGS"
Likewise, why is this dnl?
> +dnl save_LIBS=$LIBS
> +dnl LIBS="$LIBS $BOOST_LDFLAGS -lboost_wave"
> +dnl AC_CHECK_LIB(boost_wave, boost::wave::wave_init)
> + AC_SUBST(BOOST_CPPFLAGS)
> + AC_SUBST(BOOST_LDFLAGS)
> +fi
> +#
> # Print summary.
> #
> AC_MSG_NOTICE(Summary)
> @@ -2032,10 +2123,14 @@
> AC_MSG_RESULT([Complex storage format: interleaved])
> fi
> AC_MSG_RESULT([Timer: ${enable_timer}])
> +AC_MSG_RESULT([With Python bindings: ${enable_scripting}])
>
> #
> # Done.
> #
> +mkdir -p bin
> +mkdir -p lib
> +mkdir -p lib/python/site-packages/vsip
> mkdir -p src/vsip/impl/sal
> mkdir -p src/vsip/impl/ipp
> mkdir -p src/vsip/impl/fftw3
--
Jules Bergmann
CodeSourcery
jules at codesourcery.com
(650) 331-3385 x705
More information about the vsipl++
mailing list