From 17137804eea30b7b8edc82db768e1a27f280abc2 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 19 Feb 2015 19:31:53 -0500 Subject: [PATCH] Fix out-of-tree build for Python bindings + doc MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- bindings/python/Makefile.am | 27 ++++++++++--------- configure.ac | 6 ++--- doc/bindings/python/Makefile.am | 40 +++++++++++++++++------------ doc/bindings/python/sphinx-build.py | 11 ++++++++ m4/check_sphinx.m4 | 32 +++++++++++++++++++++++ 5 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 doc/bindings/python/sphinx-build.py create mode 100644 m4/check_sphinx.m4 diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am index ffea7a1d..7f3ada3e 100644 --- a/bindings/python/Makefile.am +++ b/bindings/python/Makefile.am @@ -1,31 +1,34 @@ -all-local: __init__.py +NATIVEBT_PY = nativebt.py +NATIVEBT_WRAP_C = nativebt_wrap.c +INIT_PY = __init__.py +INIT_PY_IN = $(srcdir)/$(INIT_PY).in +NATIVEBT_I = $(srcdir)/nativebt.i -__init__.py: __init__.py.in +all-local: $(INIT_PY) + +$(INIT_PY): $(INIT_PY_IN) sed "s/BABELTRACE_VERSION_STR/$(PACKAGE_VERSION)/g" < $< > $@ AM_CFLAGS = $(PYTHON_INCLUDE) -I$(top_srcdir)/include/ -EXTRA_DIST = __init__.py.in nativebt.i common.py reader.py writer.py -nodist_btpackage_PYTHON = __init__.py nativebt.py common.py reader.py writer.py +EXTRA_DIST = common.py reader.py writer.py $(INIT_PY_IN) $(NATIVEBT_I) +nodist_btpackage_PYTHON = $(INIT_PY) $(NATIVEBT_PY) common.py reader.py writer.py nativebtlib_LTLIBRARIES = _nativebt.la btpackagedir = $(pythondir)/babeltrace nativebtlibdir = $(btpackagedir) -MAINTAINERCLEANFILES = nativebt_wrap.c nativebt.py +MAINTAINERCLEANFILES = $(NATIVEBT_PY) $(NATIVEBT_WRAP_C) -nodist__nativebt_la_SOURCES = nativebt_wrap.c +nodist__nativebt_la_SOURCES = $(NATIVEBT_WRAP_C) _nativebt_la_SOURCES = python-complements.h python-complements.c _nativebt_la_LDFLAGS = -module - _nativebt_la_CFLAGS = $(GLIB_CFLAGS) $(AM_CFLAGS) - _nativebt_la_LIBS = $(GLIB_LIBS) - _nativebt_la_LIBADD = $(top_builddir)/formats/ctf/libbabeltrace-ctf.la # SWIG 'warning md variable unused' fixed after SWIG build: -nativebt_wrap.c: nativebt.i - $(SWIG) -python -Wall -I. -I$(top_srcdir)/include $< +$(NATIVEBT_WRAP_C): $(NATIVEBT_I) + $(SWIG) -python -Wall -I$(srcdir) -I$(top_srcdir)/include -outcurrentdir $< -CLEANFILES = nativebt.py nativebt_wrap.c __init__.py +CLEANFILES = $(NATIVEBT_PY) $(NATIVEBT_WRAP_C) $(INIT_PY) diff --git a/configure.ac b/configure.ac index 934bf030..be36423d 100644 --- a/configure.ac +++ b/configure.ac @@ -161,9 +161,9 @@ else fi if test "x${enable_python_bindings_doc:-yes}" = xyes; then - AC_CHECK_PROGS([SPHINXBUILD], [sphinx-build sphinx-build3 sphinx-build2], [no]) - AS_IF([test "x$SPHINXBUILD" = xno], - AC_MSG_ERROR([sphinx-build is required to build Python bindings documentation]) + AM_CHECK_PYTHON_SPHINX([PYTHON]) + AS_IF([test "x$PYTHON_SPHINX_EXISTS" = xno], + AC_MSG_ERROR([The Sphinx package for Python 3 is required to build Python bindings documentation]) ) fi diff --git a/doc/bindings/python/Makefile.am b/doc/bindings/python/Makefile.am index 8e4fff7e..2d7dac3b 100644 --- a/doc/bindings/python/Makefile.am +++ b/doc/bindings/python/Makefile.am @@ -1,32 +1,40 @@ -EXTRA_DIST = source +SPHINX_SOURCE_DIR = $(srcdir)/source +SPHINX_BUILD_DIR = build +SPHINX_BUILD_HTML_DIR = $(SPHINX_BUILD_DIR)/html +SPHINX_BUILD_DIRHTML_DIR = $(SPHINX_BUILD_DIR)/dirhtml -SPHINX_HTML_TARGET = build/html/index.html -SPHINX_DIRHTML_TARGET = build/dirhtml/index.html +SPHINX_HTML_TARGET = $(SPHINX_BUILD_HTML_DIR)/index.html +SPHINX_DIRHTML_TARGET = $(SPHINX_BUILD_DIRHTML_DIR)/index.html + +EXTRA_DIST = $(srcdir)/source all-local: $(SPHINX_HTML_TARGET) $(SPHINX_DIRHTML_TARGET) -PP = $(top_srcdir)/doc/bindings/python:$(top_srcdir)/doc/bindings/python/swig-libs +PP = .:swig-libs LLP = $(top_builddir)/formats/ctf/.libs:$(top_builddir)/lib/.libs -LOCAL_SPHINXBUILD = PYTHONPATH="$(PP)" LD_LIBRARY_PATH="$(LLP)" $(SPHINXBUILD) - -SPHINX_SRC = $(wildcard source/*.rst) +LOCAL_SPHINXBUILD = PYTHONPATH="$(PP)" LD_LIBRARY_PATH="$(LLP)" $(PYTHON) $(srcdir)/sphinx-build.py -$(SPHINX_HTML_TARGET): $(SPHINX_SRC) babeltrace-python-deps - $(LOCAL_SPHINXBUILD) -b dirhtml -E source build/dirhtml +SPHINX_SRC = $(wildcard $(SPHINX_SOURCE_DIR)/*.rst) -$(SPHINX_DIRHTML_TARGET): $(SPHINX_SRC) babeltrace-python-deps - $(LOCAL_SPHINXBUILD) -b html -E source build/html +BABELTRACE_PYTHON_DEPS = babeltrace swig-libs -.PHONY: babeltrace-python-deps +$(SPHINX_HTML_TARGET): $(SPHINX_SRC) $(BABELTRACE_PYTHON_DEPS) + $(LOCAL_SPHINXBUILD) -b html -E $(SPHINX_SOURCE_DIR) $(SPHINX_BUILD_HTML_DIR) -babeltrace-python-deps: babeltrace swig-libs +$(SPHINX_DIRHTML_TARGET): $(SPHINX_SRC) $(BABELTRACE_PYTHON_DEPS) + $(LOCAL_SPHINXBUILD) -b dirhtml -E $(SPHINX_SOURCE_DIR) $(SPHINX_BUILD_DIRHTML_DIR) swig-libs: - $(LN_S) $(top_builddir)/bindings/python/.libs $@ + $(LN_S) $(abs_top_builddir)/bindings/python/.libs $@ babeltrace: - $(LN_S) $(top_srcdir)/bindings/python $@ + $(mkdir_p) $@ + $(LN_S) $(abs_top_builddir)/bindings/python/__init__.py $@/__init__.py + $(LN_S) $(abs_top_srcdir)/bindings/python/common.py $@/common.py + $(LN_S) $(abs_top_srcdir)/bindings/python/reader.py $@/reader.py + $(LN_S) $(abs_top_srcdir)/bindings/python/writer.py $@/writer.py + $(LN_S) $(abs_top_builddir)/bindings/python/nativebt.py $@/nativebt.py clean-local: - rm -rf build swig-libs babeltrace + rm -rf $(SPHINX_BUILD_DIR) swig-libs babeltrace diff --git a/doc/bindings/python/sphinx-build.py b/doc/bindings/python/sphinx-build.py new file mode 100644 index 00000000..0ab57336 --- /dev/null +++ b/doc/bindings/python/sphinx-build.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python +import sys + + +if __name__ == '__main__': + from sphinx import main, make_main + + if sys.argv[1:2] == ['-M']: + sys.exit(make_main(sys.argv)) + else: + sys.exit(main(sys.argv)) diff --git a/m4/check_sphinx.m4 b/m4/check_sphinx.m4 new file mode 100644 index 00000000..5e9dcbc1 --- /dev/null +++ b/m4/check_sphinx.m4 @@ -0,0 +1,32 @@ +# check_sphinx.m4 -- check for Sphinx Python package +# +# Copyright (C) 2015 - Philippe Proulx +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# Sphinx ships with a script named "sphinx-build", which is usually +# installed in "/usr/bin". Unfortunately, this script uses +# "/usr/bin/python" as its interpreter. Since "/usr/bin/python" can +# be either Python 2 or Python 3, depending on the distribution, and +# since we absolutely need the Python 3 Sphinx package for Babeltrace +# because it needs to import our bindings for autodocumentation, +# there's no way to tell if "sphinx-build" is actually using Python 2 +# or Python 3. +# +# This macro checks if the Sphinx package ("sphinx") is installed +# and visible from the interpreter designated by the PYTHON variable. +# It sets PYTHON_SPHINX_EXISTS to "yes" if Sphinx is found for the +# given Python interpreter, otherwise "no". + +# AM_CHECK_PYTHON_SPHINX(PYTHON) +# --------------------------------------------------------------------------- +AC_DEFUN([AM_CHECK_PYTHON_SPHINX], + [prog=" +try: + import sphinx + print('yes') +except ImportError: + print('no')" + PYTHON_SPHINX_EXISTS=`${$1} -c "$prog"`]) -- 2.34.1