Skip to content

Commit

Permalink
Support py2 and py3 at the same time
Browse files Browse the repository at this point in the history
This patch reworks the build system so that we use the same sources to
build both a python2 loader and a python3 loader. The python 2 one
keeps the same name for backward compatibility, while the python 3 one
is explicitely called "python3".
Supporting py2 and py3 in the same build is tricky since the existing
autotools support is limited, so we make some assumptions:
 - there are separate --enable-python2 and --enable-python3 flags,
   --enable-python has been removed
 - the py3 loader is in a separate dir but compliles the files from the
   py2 loader
 - for py2 we only check the binary and the python2-config tool, while
   for py3 we use the proper AM_PATH_PYTHON macro
 - for py2 we manually detect pyexecdir, hopefully with the same logic
   used by the AM_PATH_PYTHON macro
 - we do not check for Python.h header anymore since it is not strictly
   needed and autoconf caching makes it difficult
 - for we build the demos only for python3 (unit tests instead are
   replicated for both)

https://bugzilla.gnome.org/show_bug.cgi?id=691081
  • Loading branch information
pbor committed Jan 5, 2013
1 parent 519d9eb commit 590b5e1
Show file tree
Hide file tree
Showing 17 changed files with 324 additions and 71 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Expand Up @@ -76,6 +76,7 @@ Makefile.in
/tests/libpeas/extension-c
/tests/libpeas/extension-gjs
/tests/libpeas/extension-python
/tests/libpeas/extension-python3
/tests/libpeas/extension-seed
/tests/libpeas/extension-set
/tests/libpeas/plugin-info
Expand All @@ -85,6 +86,12 @@ Makefile.in
/tests/libpeas/plugins/extension-js/extension-seed.gschema.xml
/tests/libpeas/plugins/extension-js/extension-seed.js
/tests/libpeas/plugins/extension-js/extension-seed.plugin
/tests/libpeas/plugins/extension-python/extension-python.gschema.xml
/tests/libpeas/plugins/extension-python/extension-python.plugin
/tests/libpeas/plugins/extension-python/extension-python.py
/tests/libpeas/plugins/extension-python/extension-python3.gschema.xml
/tests/libpeas/plugins/extension-python/extension-python3.plugin
/tests/libpeas/plugins/extension-python/extension-python3.py
/tests/libpeas-gtk/plugin-manager
/tests/libpeas-gtk/plugin-manager-store
/tests/libpeas-gtk/plugin-manager-view
Expand Down
134 changes: 87 additions & 47 deletions configure.ac
Expand Up @@ -311,68 +311,106 @@ dnl ================================================================
dnl Python
dnl ================================================================

PYTHON_REQUIRED=2.5.2
PYTHON2_REQUIRED=2.5.2
PYTHON3_REQUIRED=3.2.0

dnl Used by the Python loader to check the PyGObject version at runtime
PYGOBJECT_MAJOR_VERSION=3
PYGOBJECT_MINOR_VERSION=0
PYGOBJECT_MICRO_VERSION=0
PYGOBJECT_REQUIRED=$PYGOBJECT_MAJOR_VERSION.$PYGOBJECT_MINOR_VERSION.$PYGOBJECT_MICRO_VERSION
AC_DEFINE_UNQUOTED(PYGOBJECT_MAJOR_VERSION,[$PYGOBJECT_MAJOR_VERSION], [PyGObject major version.])
AC_DEFINE_UNQUOTED(PYGOBJECT_MINOR_VERSION,[$PYGOBJECT_MINOR_VERSION], [PyGObject minor version.])
AC_DEFINE_UNQUOTED(PYGOBJECT_MICRO_VERSION,[$PYGOBJECT_MICRO_VERSION], [PyGObject micro version.])

AC_ARG_ENABLE(python,
AS_HELP_STRING([--enable-python],[Enable Python support]),
[enable_python=$enableval],
[enable_python=auto])
AC_MSG_CHECKING([for Python 2 availability.])

if test "$enable_python" = "no"; then
found_python="no (disabled, use --enable-python to enable)"
AC_ARG_ENABLE(python2,
AS_HELP_STRING([--enable-python2],[Enable Python 2 support]),
[enable_python2=$enableval],
[enable_python2=auto])

if test "x$enable_python2" = "xno"; then
found_python2="no (disabled, use --enable-python2 to enable)"
else
AM_PATH_PYTHON($PYTHON_REQUIRED,
[found_python=yes],
[found_python="no (python interpretor >= ${PYTHON_REQUIRED} not found"])

if test "$found_python" = "yes"; then
AC_PATH_TOOL(PYTHON_CONFIG, "python${PYTHON_VERSION}-config")
if test -z "$PYTHON_CONFIG"; then
AC_PATH_TOOL(PYTHON_CONFIG, "python-config-${PYTHON_VERSION}")
if test -z "$PYTHON_CONFIG"; then
found_python="no (python${PYTHON_VERSION}-config not found)"
fi
fi
fi

if test "$found_python" = "yes"; then
save_CPPFLAGS="${CPPFLAGS}"
CPPFLAGS="$CPPFLAGS `$PYTHON_CONFIG --includes`"
AC_CHECK_HEADER(Python.h,,[found_python="no (Python headers not found)"])
CPPFLAGS="${save_CPPFLAGS}"
fi

AC_MSG_CHECKING([for PyGObject availability.])
if test "$found_python" = "yes"; then
PKG_CHECK_EXISTS([pygobject-3.0 >= $PYGOBJECT_REQUIRED],,
[found_python="no (pygobject >= $PYGOBJECT_REQUIRED not found)"])
fi
AC_MSG_RESULT([$found_python])
dnl NOTE: we do not use AM_PATH_PYTHON, since it does not allow
dnl to call it twice for py2 and py3, so we just check the prog
AC_PATH_PROGS(PYTHON2, [python2 python2.7 python2.6 python2.5])
if test -z "${PYTHON2}"; then
found_python2="no (python2 not found)"
else
AM_PYTHON_CHECK_VERSION($PYTHON2, $PYTHON2_REQUIRED, [
AC_PATH_TOOL(PYTHON2_CONFIG, "python2-config")
if test -n "${PYTHON2_CONFIG}"; then
PKG_CHECK_MODULES(PYGOBJECT, pygobject-3.0 >= $PYGOBJECT_REQUIRED, [
found_python2=yes
PYTHON2_CFLAGS=`${PYTHON2_CONFIG} --includes`
PYTHON2_LIBS=`${PYTHON2_CONFIG} --libs`
pyexecdir=`$PYTHON2 -c "import sys; from distutils import sysconfig; print sysconfig.get_python_lib(True, prefix='')"`
PYTHON2_PYEXECDIR="\${exec_prefix}/${pyexecdir}"
AC_SUBST(PYTHON2_CFLAGS)
AC_SUBST(PYTHON2_LIBS)
AC_SUBST(PYTHON2_PYEXECDIR)
AC_DEFINE(ENABLE_PYTHON2, 1, [Define to compile with Python 2 support])
], [
found_python2="no (PyGObject not found)"
])
else
found_python2="no (python2-config not found)"
fi
], [
found_python2="no (python2 version too old)"
])
fi
fi

if test "$enable_python" = "yes" -a "$found_python" != "yes"; then
AC_MSG_ERROR([$found_python])
if test "x$enable_python2" = "xyes" -a "x$found_python2" != "xyes"; then
AC_MSG_ERROR([You need to have Python 2 and PyGobject installed to build libpeas])
fi
AC_MSG_RESULT([$found_python2])

AM_CONDITIONAL([ENABLE_PYTHON2],[test "x$found_python2" = "xyes"])


AC_MSG_CHECKING([for Python 3 availability.])

AC_ARG_ENABLE(python3,
AS_HELP_STRING([--enable-python3],[Enable Python 3 support]),
[enable_python3=$enableval],
[enable_python3=auto])

if test "$found_python" = "yes"; then
PYTHON_CFLAGS="`$PKG_CONFIG --cflags pygobject-3.0` `$PYTHON_CONFIG --includes`"
PYTHON_LIBS="`$PKG_CONFIG --libs pygobject-3.0` `$PYTHON_CONFIG --libs`"
AC_SUBST(PYTHON_CFLAGS)
AC_SUBST(PYTHON_LIBS)
if test "x$enable_python3" = "xno"; then
found_python3="no (disabled, use --enable-python3 to enable)"
else
AM_PATH_PYTHON($PYTHON3_REQUIRED, [
AC_PATH_TOOL(PYTHON3_CONFIG, "python3-config")
if test -n "${PYTHON3_CONFIG}"; then
PKG_CHECK_MODULES(PYGOBJECT, pygobject-3.0 >= $PYGOBJECT_REQUIRED, [
found_python3=yes
PYTHON3_CFLAGS=`${PYTHON3_CONFIG} --includes`
PYTHON3_LIBS=`${PYTHON3_CONFIG} --libs`
PYTHON3_PYEXECDIR="${pyexecdir}"
AC_SUBST(PYTHON3_CFLAGS)
AC_SUBST(PYTHON3_LIBS)
AC_SUBST(PYTHON3_PYEXECDIR)
AC_DEFINE(ENABLE_PYTHON3, 1, [Define to compile with Python 3 support])
], [
found_python3="no (PyGObject not found)"
])
else
found_python3="no (python3-config not found)"
fi
], [
found_python3="no (python3 not found)"
])
fi

AC_DEFINE_UNQUOTED(PYGOBJECT_MAJOR_VERSION,[$PYGOBJECT_MAJOR_VERSION], [PyGObject major version.])
AC_DEFINE_UNQUOTED(PYGOBJECT_MINOR_VERSION,[$PYGOBJECT_MINOR_VERSION], [PyGObject minor version.])
AC_DEFINE_UNQUOTED(PYGOBJECT_MICRO_VERSION,[$PYGOBJECT_MICRO_VERSION], [PyGObject micro version.])
AC_DEFINE(ENABLE_PYTHON,1,[Define to compile with Python support])
if test "x$enable_python3" = "xyes" -a "x$found_python3" != "xyes"; then
AC_MSG_ERROR([You need to have Python 3 and PyGObject installed to build libpeas])
fi
AC_MSG_RESULT([$found_python3])

AM_CONDITIONAL([ENABLE_PYTHON],[test "$found_python" = "yes"])
AM_CONDITIONAL([ENABLE_PYTHON3],[test "x$found_python3" = "xyes"])

dnl ================================================================
dnl Documentation
Expand Down Expand Up @@ -436,6 +474,7 @@ libpeas-gtk/Makefile
loaders/Makefile
loaders/gjs/Makefile
loaders/python/Makefile
loaders/python3/Makefile
loaders/seed/Makefile
data/Makefile
data/glade/Makefile
Expand Down Expand Up @@ -488,7 +527,8 @@ Configuration:

Languages support:

Python support : ${found_python}
Python 2 support : ${found_python2}
Python 3 support : ${found_python3}
Javascript support (Seed) : ${found_seed}
Javascript support (GJS) : ${found_gjs}
"
6 changes: 5 additions & 1 deletion loaders/Makefile.am
Expand Up @@ -4,10 +4,14 @@ if ENABLE_GJS
SUBDIRS += gjs
endif

if ENABLE_PYTHON
if ENABLE_PYTHON2
SUBDIRS += python
endif

if ENABLE_PYTHON3
SUBDIRS += python3
endif

if ENABLE_SEED
SUBDIRS += seed
endif
Expand Down
8 changes: 5 additions & 3 deletions loaders/python/Makefile.am
Expand Up @@ -8,8 +8,9 @@ INCLUDES = \
$(GCOV_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED) \
$(PYTHON_CFLAGS) \
-DPEAS_PYEXECDIR=\""$(pyexecdir)"\" \
$(PYGOBJECT_CFLAGS) \
$(PYTHON2_CFLAGS) \
-DPEAS_PYEXECDIR=\""$(PYTHON2_PYEXECDIR)"\" \
-DPEAS_LOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\"

loader_LTLIBRARIES = libpythonloader.la
Expand All @@ -26,7 +27,8 @@ libpythonloader_la_LDFLAGS = \

libpythonloader_la_LIBADD = \
$(PEAS_LIBS) \
$(PYTHON_LIBS)
$(PYGOBJECT_LIBS) \
$(PYTHON2_LIBS)

gcov_sources = $(libpythonloader_la_SOURCES)
include $(top_srcdir)/Makefile.gcov
34 changes: 34 additions & 0 deletions loaders/python3/Makefile.am
@@ -0,0 +1,34 @@
# Python 3 plugin loader

loaderdir = $(libdir)/libpeas-1.0/loaders

INCLUDES = \
-I$(top_srcdir) \
$(PEAS_CFLAGS) \
$(GCOV_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED) \
$(PYGOBJECT_CFLAGS) \
$(PYTHON3_CFLAGS) \
-DPEAS_PYEXECDIR=\""$(PYTHON3_PYEXECDIR)"\" \
-DPEAS_LOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\"

loader_LTLIBRARIES = libpython3loader.la

libpython3loader_la_SOURCES = \
$(top_srcdir)/loaders/python/peas-extension-python.c \
$(top_srcdir)/loaders/python/peas-extension-python.h \
$(top_srcdir)/loaders/python/peas-plugin-loader-python.c \
$(top_srcdir)/loaders/python/peas-plugin-loader-python.h

libpython3loader_la_LDFLAGS = \
$(LOADER_LIBTOOL_FLAGS) \
$(GCOV_LDFLAGS)

libpython3loader_la_LIBADD = \
$(PEAS_LIBS) \
$(PYGOBJECT_LIBS) \
$(PYTHON3_LIBS)

gcov_sources = $(libpython3loader_la_SOURCES)
include $(top_srcdir)/Makefile.gcov
2 changes: 1 addition & 1 deletion peas-demo/plugins/Makefile.am
Expand Up @@ -4,7 +4,7 @@ if ENABLE_GJS
SUBDIRS += gjshello
endif

if ENABLE_PYTHON
if ENABLE_PYTHON3
SUBDIRS += pythonhello
endif

Expand Down
2 changes: 1 addition & 1 deletion peas-demo/plugins/pythonhello/pythonhello.plugin
@@ -1,6 +1,6 @@
[Plugin]
Module=pythonhello
Loader=python
Loader=python3
Name=Python Says Hello
Description=Inserts a box containing "Python Says Hello" in every windows.
Authors=Steve Frécinaux <code@istique.net>
Expand Down
13 changes: 10 additions & 3 deletions tests/libpeas/Makefile.am
Expand Up @@ -35,11 +35,18 @@ extension_gjs_CFLAGS = $(GJS_CFLAGS)
extension_gjs_LDADD = $(progs_ldadd) $(GJS_LIBS)
endif

if ENABLE_PYTHON
if ENABLE_PYTHON2
TEST_PROGS += extension-python
extension_python_SOURCES = extension-python.c
extension_python_CFLAGS = $(PYTHON_CFLAGS)
extension_python_LDADD = $(progs_ldadd) $(PYTHON_LIBS)
extension_python_CFLAGS = $(PYGOBJECT_CFLAGS) $(PYTHON2_CFLAGS)
extension_python_LDADD = $(progs_ldadd) $(PYGOBJECT_LIBS) $(PYTHON2_LIBS)
endif

if ENABLE_PYTHON3
TEST_PROGS += extension-python3
extension_python3_SOURCES = extension-python3.c
extension_python3_CFLAGS = $(PYGOBJECT_CFLAGS) $(PYTHON3_CFLAGS)
extension_python3_LDADD = $(progs_ldadd) $(PYGOBJECT_LIBS) $(PYTHON3_LIBS)
endif

if ENABLE_SEED
Expand Down

0 comments on commit 590b5e1

Please sign in to comment.