Fix out-of-tree build for Python bindings + doc
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 20 Feb 2015 00:31:53 +0000 (19:31 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 10 Mar 2015 02:45:38 +0000 (22:45 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bindings/python/Makefile.am
configure.ac
doc/bindings/python/Makefile.am
doc/bindings/python/sphinx-build.py [new file with mode: 0644]
m4/check_sphinx.m4 [new file with mode: 0644]

index ffea7a1d95acdbc3f14813cd087ce573ffbf0eae..7f3ada3e39b5e11a55490b8c7230f1404dad024b 100644 (file)
@@ -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)
index 934bf030dceaebafc3c1c94590108764d073b51b..be36423dcc94c39a7210bc9cc2487490f4f10a40 100644 (file)
@@ -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
 
index 8e4fff7ed94d236e5dae158c5a5b195b8f80d56c..2d7dac3b2add920a179b376a977972ee97c1581a 100644 (file)
@@ -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 (file)
index 0000000..0ab5733
--- /dev/null
@@ -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 (file)
index 0000000..5e9dcbc
--- /dev/null
@@ -0,0 +1,32 @@
+# check_sphinx.m4 -- check for Sphinx Python package
+#
+# Copyright (C) 2015 - Philippe Proulx <pproulx@efficios.com>
+#
+# 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"`])
This page took 0.031873 seconds and 4 git commands to generate.