From af851c8032f8dd4e65edf9664700c2c8b35906a3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 17 Feb 2008 03:44:47 +0000 Subject: Check for Python properly before attempting to build bindings. Preliminary scheme (chicken/mzscheme) bindings (not working). git-svn-id: http://svn.drobilla.net/lad/slv2@1146 a436a847-0d15-0410-975c-d299462d15a1 --- Makefile.am | 2 +- configure.ac | 12 ++- m4/ac_python_devel.m4 | 268 ++++++++++++++++++++++++++++++++++++++++++++++++++ swig/Makefile.am | 29 +++++- swig/slv2.i | 54 +++++----- swig/slv2.setup | 2 + 6 files changed, 333 insertions(+), 34 deletions(-) create mode 100644 m4/ac_python_devel.m4 create mode 100644 swig/slv2.setup diff --git a/Makefile.am b/Makefile.am index a256646..e61026e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,7 +14,7 @@ dist-check-doxygen: endif SUBDIRS = src slv2 utils hosts $(DOC_DIR) swig debian -DIST_SUBDIRS = src slv2 utils hosts doc swig debian +DIST_SUBDIRS = src slv2 utils hosts doc swig debian m4 pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = slv2.pc diff --git a/configure.ac b/configure.ac index 79ac998..05a425a 100644 --- a/configure.ac +++ b/configure.ac @@ -96,9 +96,9 @@ if test "$strict" = "yes"; then fi # SWIG bindings -bindings="yes" +bindings="no" AC_ARG_ENABLE(bindings, - [AS_HELP_STRING(--enable-bindings, [Build language bindings via SWIG (true if available)])], + [AS_HELP_STRING(--enable-bindings, [Build language bindings via SWIG (false)])], [bindings="$enableval"]) if test "$bindings" = "yes"; then AC_CHECK_PROGS(SWIG, "swig swig-1.3") @@ -108,11 +108,17 @@ if test "$bindings" = "yes"; then fi AM_CONDITIONAL(WITH_SWIG, [test "$bindings" = "yes"]) -python="no" +# Check for binding languages +mzscheme="no" +chicken="no" if test "$bindings" = "yes"; then AC_PYTHON_DEVEL([>= '2.3.0']) + AC_CHECK_HEADER([plt/escheme.h], [mzscheme="yes"], [mzscheme="no"]) + AC_CHECK_HEADER([chicken.h], [chicken="yes"], [chicken="no"]) fi AM_CONDITIONAL(WITH_PYTHON, [test ! "$PYTHON_VERSION" = "yes"]) +AM_CONDITIONAL(WITH_MZSCHEME, [test "$mzscheme" = "yes"]) +AM_CONDITIONAL(WITH_CHICKEN, [test "$chicken" = "yes"]) # Check for Redland build_redland="no" diff --git a/m4/ac_python_devel.m4 b/m4/ac_python_devel.m4 new file mode 100644 index 0000000..e39678f --- /dev/null +++ b/m4/ac_python_devel.m4 @@ -0,0 +1,268 @@ +##### http://autoconf-archive.cryp.to/ac_python_devel.html +# +# SYNOPSIS +# +# AC_PYTHON_DEVEL([version]) +# +# DESCRIPTION +# +# Note: Defines as a precious variable "PYTHON_VERSION". Don't +# override it in your configure.ac. +# +# This macro checks for Python and tries to get the include path to +# 'Python.h'. It provides the $(PYTHON_CPPFLAGS) and +# $(PYTHON_LDFLAGS) output variables. It also exports +# $(PYTHON_EXTRA_LIBS) and $(PYTHON_EXTRA_LDFLAGS) for embedding +# Python in your code. +# +# You can search for some particular version of Python by passing a +# parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". +# Please note that you *have* to pass also an operator along with the +# version to match, and pay special attention to the single quotes +# surrounding the version number. Don't use "PYTHON_VERSION" for +# this: that environment variable is declared as precious and thus +# reserved for the end-user. +# +# This macro should work for all versions of Python >= 2.1.0. As an +# end user, you can disable the check for the python version by +# setting the PYTHON_NOVERSIONCHECK environment variable to something +# else than the empty string. +# +# If you need to use this macro for an older Python version, please +# contact the authors. We're always open for feedback. +# +# LAST MODIFICATION +# +# 2007-07-31 +# +# COPYLEFT +# +# Copyright (c) 2007 Sebastian Huber +# Copyright (c) 2007 Alan W. Irwin +# Copyright (c) 2007 Rafael Laboissiere +# Copyright (c) 2007 Andrew Collier +# Copyright (c) 2007 Matteo Settenvini +# Copyright (c) 2007 Horst Knorr +# +# 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 3 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 +# . +# +# 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([AC_PYTHON_DEVEL],[ + # + # Allow the use of a (user set) custom python version + # + AC_ARG_VAR([PYTHON_VERSION],[The installed Python + version to use, for example '2.3'. This string + will be appended to the Python interpreter + canonical name.]) + + AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]]) + if test -z "$PYTHON"; then + AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path]) + PYTHON_VERSION="" + fi + + # + # Check for a version of Python >= 2.1.0 + # + AC_MSG_CHECKING([for a version of Python >= '2.1.0']) + ac_supports_python_ver=`$PYTHON -c "import sys, string; \ + ver = string.split(sys.version)[[0]]; \ + print ver >= '2.1.0'"` + if test "$ac_supports_python_ver" != "True"; then + if test -z "$PYTHON_NOVERSIONCHECK"; then + AC_MSG_RESULT([no]) + AC_MSG_FAILURE([ +This version of the AC@&t@_PYTHON_DEVEL macro +doesn't work properly with versions of Python before +2.1.0. You may need to re-run configure, setting the +variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG, +PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand. +Moreover, to disable this check, set PYTHON_NOVERSIONCHECK +to something else than an empty string. +]) + else + AC_MSG_RESULT([skip at user request]) + fi + else + AC_MSG_RESULT([yes]) + fi + + # + # if the macro parameter ``version'' is set, honour it + # + if test -n "$1"; then + AC_MSG_CHECKING([for a version of Python $1]) + ac_supports_python_ver=`$PYTHON -c "import sys, string; \ + ver = string.split(sys.version)[[0]]; \ + print ver $1"` + if test "$ac_supports_python_ver" = "True"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + AC_MSG_ERROR([this package requires Python $1. +If you have it installed, but it isn't the default Python +interpreter in your system path, please pass the PYTHON_VERSION +variable to configure. See ``configure --help'' for reference. +]) + PYTHON_VERSION="" + fi + fi + + # + # Check if you have distutils, else fail + # + AC_MSG_CHECKING([for the distutils Python package]) + ac_distutils_result=`$PYTHON -c "import distutils" 2>&1` + if test -z "$ac_distutils_result"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + AC_MSG_ERROR([cannot import Python module "distutils". +Please check your Python installation. The error was: +$ac_distutils_result]) + PYTHON_VERSION="" + fi + + # + # Check for Python include path + # + AC_MSG_CHECKING([for Python include path]) + if test -z "$PYTHON_CPPFLAGS"; then + python_path=`$PYTHON -c "import distutils.sysconfig; \ + print distutils.sysconfig.get_python_inc();"` + if test -n "${python_path}"; then + python_path="-I$python_path" + fi + PYTHON_CPPFLAGS=$python_path + fi + AC_MSG_RESULT([$PYTHON_CPPFLAGS]) + AC_SUBST([PYTHON_CPPFLAGS]) + + # + # Check for Python library path + # + AC_MSG_CHECKING([for Python library path]) + if test -z "$PYTHON_LDFLAGS"; then + # (makes two attempts to ensure we've got a version number + # from the interpreter) + py_version=`$PYTHON -c "from distutils.sysconfig import *; \ + from string import join; \ + print join(get_config_vars('VERSION'))"` + if test "$py_version" == "[None]"; then + if test -n "$PYTHON_VERSION"; then + py_version=$PYTHON_VERSION + else + py_version=`$PYTHON -c "import sys; \ + print sys.version[[:3]]"` + fi + fi + + PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \ + from string import join; \ + print '-L' + get_python_lib(0,1), \ + '-lpython';"`$py_version + fi + AC_MSG_RESULT([$PYTHON_LDFLAGS]) + AC_SUBST([PYTHON_LDFLAGS]) + + # + # Check for site packages + # + AC_MSG_CHECKING([for Python site-packages path]) + if test -z "$PYTHON_SITE_PKG"; then + PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \ + print distutils.sysconfig.get_python_lib(0,0);"` + fi + AC_MSG_RESULT([$PYTHON_SITE_PKG]) + AC_SUBST([PYTHON_SITE_PKG]) + + # + # libraries which must be linked in when embedding + # + AC_MSG_CHECKING(python extra libraries) + if test -z "$PYTHON_EXTRA_LIBS"; then + PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \ + conf = distutils.sysconfig.get_config_var; \ + print conf('LOCALMODLIBS'), conf('LIBS')"` + fi + AC_MSG_RESULT([$PYTHON_EXTRA_LIBS]) + AC_SUBST(PYTHON_EXTRA_LIBS) + + # + # linking flags needed when embedding + # + AC_MSG_CHECKING(python extra linking flags) + if test -z "$PYTHON_EXTRA_LDFLAGS"; then + PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \ + conf = distutils.sysconfig.get_config_var; \ + print conf('LINKFORSHARED')"` + fi + AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS]) + AC_SUBST(PYTHON_EXTRA_LDFLAGS) + + # + # final check to see if everything compiles alright + # + AC_MSG_CHECKING([consistency of all components of python development environment]) + AC_LANG_PUSH([C]) + # save current global flags + LIBS="$ac_save_LIBS $PYTHON_LDFLAGS" + CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS" + AC_TRY_LINK([ + #include + ],[ + Py_Initialize(); + ],[pythonexists=yes],[pythonexists=no]) + + AC_MSG_RESULT([$pythonexists]) + + if test ! "$pythonexists" = "yes"; then + AC_MSG_ERROR([ + Could not link test program to Python. Maybe the main Python library has been + installed in some non-standard library path. If so, pass it to configure, + via the LDFLAGS environment variable. + Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib" + ============================================================================ + ERROR! + You probably have to install the development version of the Python package + for your distribution. The exact name of this package varies among them. + ============================================================================ + ]) + PYTHON_VERSION="" + fi + AC_LANG_POP + # turn back to default flags + CPPFLAGS="$ac_save_CPPFLAGS" + LIBS="$ac_save_LIBS" + + # + # all done! + # +]) diff --git a/swig/Makefile.am b/swig/Makefile.am index b6c5564..9ac6d84 100644 --- a/swig/Makefile.am +++ b/swig/Makefile.am @@ -1,15 +1,36 @@ -EXTRA_DIST = slv2.i lv2_list.py +EXTRA_DIST = slv2.i lv2_list.py slv2.setup if WITH_SWIG +all: python mzscheme chicken + if WITH_PYTHON -all: - swig -Wall -python slv2.i +python: + swig -DPYTHON -Wall -python -I.. -o slv2_python.c -oh slv2_python.h slv2.i gcc -fPIC -shared $(PYTHON_CPPFLAGS) $(PYTHON_EXTRA_LDFLAGS) \ $(PYTHON_EXTRA_LIBS) $(PYTHON_EXTRA_LDFLAGS) \ - -I/usr/include/python2.4 slv2_wrap.c ../src/.libs/libslv2.so -o _slv2.so + slv2_python.c ../src/.libs/libslv2.so -o _slv2.so +else +python: + endif # WITH_PYTHON +if WITH_MZSCHEME +mzscheme: + swig -DMZSCHEME -Wall -mzscheme -I.. -o slv2_mzscheme.c -oh slv2_mzscheme.h slv2.i + gcc -fPIC -shared -Iplt \ + -I/usr/include/plt slv2_mzscheme.c ../src/.libs/libslv2.so -o libslv2_mzscheme.so +endif # WITH_MZSCHEME + +if WITH_CHICKEN +chicken: + rm -rf eggs + mkdir -p eggs + swig -DCHICKEN -Wall -chicken -proxy -nounit -I.. -o slv2_wrap.c -oh slv2_wrap.h slv2.i + tar -czf eggs/slv2.egg slv2.setup slv2.scm slv2_wrap.c + rm -f slv2.scm slv2_wrap.c +endif # WITH_CHICKEN + endif # WITH_SWIG clean-local: diff --git a/swig/slv2.i b/swig/slv2.i index 593411e..210da6e 100644 --- a/swig/slv2.i +++ b/swig/slv2.i @@ -1,37 +1,37 @@ %module slv2 %{ -#include "../slv2/plugin.h" -#include "../slv2/pluginclass.h" -#include "../slv2/pluginclasses.h" -#include "../slv2/plugininstance.h" -#include "../slv2/plugins.h" -#include "../slv2/port.h" -#include "../slv2/slv2.h" -#include "../slv2/types.h" -#include "../slv2/value.h" -#include "../slv2/values.h" -#include "../slv2/world.h" +#include "slv2/plugin.h" +#include "slv2/pluginclass.h" +#include "slv2/pluginclasses.h" +#include "slv2/plugininstance.h" +#include "slv2/plugins.h" +#include "slv2/port.h" +#include "slv2/slv2.h" +#include "slv2/types.h" +#include "slv2/value.h" +#include "slv2/values.h" +#include "slv2/world.h" typedef struct { SLV2World me; } World; typedef struct { SLV2World world; SLV2Plugins me; } Plugins; typedef struct { SLV2World world; SLV2Plugin me; } Plugin; %} -%include "../slv2/plugin.h" -%include "../slv2/pluginclass.h" -%include "../slv2/pluginclasses.h" -%include "../slv2/plugininstance.h" -%include "../slv2/plugins.h" -%include "../slv2/port.h" -%include "../slv2/slv2.h" -%include "../slv2/types.h" -%include "../slv2/value.h" -%include "../slv2/values.h" -%include "../slv2/world.h" +%include "slv2/plugin.h" +%include "slv2/pluginclass.h" +%include "slv2/pluginclasses.h" +%include "slv2/plugininstance.h" +%include "slv2/plugins.h" +%include "slv2/port.h" +%include "slv2/slv2.h" +%include "slv2/types.h" +%include "slv2/value.h" +%include "slv2/values.h" +%include "slv2/world.h" typedef struct { SLV2Plugin me; } Plugin; %extend Plugin { Plugin(SLV2Plugin p) { - Plugin* ret = malloc(sizeof(Plugin)); + Plugin* ret = (Plugin*)malloc(sizeof(Plugin)); ret->me = p; return ret; } @@ -55,7 +55,7 @@ typedef struct { SLV2Plugin me; } Plugin; typedef struct { SLV2World world; SLV2Plugins me; } Plugins; %extend Plugins { Plugins(SLV2World w, SLV2Plugins p) { - Plugins* ret = malloc(sizeof(Plugins)); + Plugins* ret = (Plugins*)malloc(sizeof(Plugins)); ret->world = w; ret->me = p; return ret; @@ -76,6 +76,7 @@ typedef struct { SLV2World world; SLV2Plugins me; } Plugins; return NULL; } +#ifdef PYTHON %pythoncode %{ def __iter__(self): class Iterator(object): @@ -92,12 +93,13 @@ typedef struct { SLV2World world; SLV2Plugins me; } Plugins; return Iterator(self) %} +#endif }; typedef struct { SLV2World me; } World; %extend World { World() { - World* ret = malloc(sizeof(World)); + World* ret = (World*)malloc(sizeof(World)); ret->me = slv2_world_new(); return ret; } @@ -109,7 +111,7 @@ typedef struct { SLV2World me; } World; void load_all() { slv2_world_load_all($self->me); } void load_bundle(const char* uri) { - SLV2Value bundle_uri = slv2_value_new_uri($self->me, (const unsigned char*)uri); + SLV2Value bundle_uri = slv2_value_new_uri($self->me, uri); slv2_world_load_bundle($self->me, bundle_uri); slv2_value_free(bundle_uri); } diff --git a/swig/slv2.setup b/swig/slv2.setup new file mode 100644 index 0000000..4a8fbb4 --- /dev/null +++ b/swig/slv2.setup @@ -0,0 +1,2 @@ +(run (csc -s -o slv2.so slv2.scm slv2_wrap.c)) +(install-extension 'slv2 '("slv2.so")) -- cgit v1.2.1