Skip to content

Commit

Permalink
Autoconf support for Python bindings
Browse files Browse the repository at this point in the history
Binding itself is coming with next commits


git-svn-id: https://iksemel.googlecode.com/svn/trunk@31 6ddeccfd-2234-0410-8ab0-45b763562eda
  • Loading branch information
[email protected] committed Oct 7, 2011
1 parent ebdd1ba commit 4028bd9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
## Process this file with automake to produce Makefile.in
##

SUBDIRS = include src tools test doc
if DO_PYTHON
python_d = python
endif

SUBDIRS = include src tools $(python_d) test doc

EXTRA_DIST = HACKING iksemel.pc.in

Expand Down
51 changes: 46 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ AC_SEARCH_LIBS(recv,socket)
AC_CHECK_FUNCS(getopt_long)
AC_CHECK_FUNCS(getaddrinfo)

dnl Check -Wall flag of GCC
if test "x$GCC" = "xyes"; then
if test -z "`echo "$CFLAGS" | grep "\-Wall" 2> /dev/null`" ; then
CFLAGS="$CFLAGS -Wall"
fi
fi

dnl Options for overriding TLS checks
AC_ARG_WITH([openssl],
AS_HELP_STRING([--without-openssl],[disable checking for openssl]),
Expand Down Expand Up @@ -84,12 +91,45 @@ if test "x$with_gnutls" = "xyes"; then
fi
fi

dnl Check -Wall flag of GCC
if test "x$GCC" = "xyes"; then
if test -z "`echo "$CFLAGS" | grep "\-Wall" 2> /dev/null`" ; then
CFLAGS="$CFLAGS -Wall"
fi
dnl Option for overriding Python check
AC_ARG_ENABLE([python],
AS_HELP_STRING([--disable-python],[disable checking for Python bindings]),
[with_python=$enableval],
[with_python=yes]
)

dnl a macro to check for ability to create python extensions
dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
dnl function also defines PYTHON_INCLUDES
AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
[AC_REQUIRE([AM_PATH_PYTHON])
AC_MSG_CHECKING(for headers required to compile python extensions)
dnl deduce PYTHON_INCLUDES
py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
if test "$py_prefix" != "$py_exec_prefix"; then
PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
fi
AC_SUBST(PYTHON_INCLUDES)
dnl check if the headers exist:
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
AC_TRY_CPP([#include <Python.h>],dnl
[AC_MSG_RESULT(found)
$1],dnl
[AC_MSG_RESULT(not found)
$2])
CPPFLAGS="$save_CPPFLAGS"
])

dnl Check Python for binding
if test "x$with_python" = "xyes"; then
with_python=no
AM_PATH_PYTHON([2.2], , [:])
AM_CHECK_PYTHON_HEADERS(with_python=yes,[AC_MSG_ERROR(could not find Python headers)])
fi
AM_CONDITIONAL([DO_PYTHON], [test "x$with_python" = "xyes"])

dnl Generating makefiles
AC_CONFIG_FILES([
Expand All @@ -98,6 +138,7 @@ iksemel.pc
src/Makefile
include/Makefile
tools/Makefile
python/Makefile
test/Makefile
doc/Makefile
])
Expand Down
11 changes: 11 additions & 0 deletions python/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
##
## Process this file with automake to produce Makefile.in
##

INCLUDES = -I$(top_srcdir)/include $(PYTHON_INCLUDES)

pyexec_LTLIBRARIES = iksemel.la

iksemel_la_LIBADD = $(top_builddir)/src/libiksemel.la
iksemel_la_SOURCES = xml.c
iksemel_la_LDFLAGS = -avoid-version -module -export-symbols-regex initiksemel
23 changes: 23 additions & 0 deletions python/xml.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* iksemel (XML parser for Jabber)
** Copyright (C) 2011 Gurer Ozen
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
*/

#include <Python.h>
#include "iksemel.h"

PyObject *iksemel_module;

static PyMethodDef methods[] = {
{ NULL, NULL, 0, NULL }
};

PyMODINIT_FUNC
initiksemel(void)
{
PyObject *m;

m = Py_InitModule("iksemel", methods);
iksemel_module = m;
}

0 comments on commit 4028bd9

Please sign in to comment.