build: fix cross-compilation of python bindings
authorBartosz Golaszewski <bartekgola@gmail.com>
Fri, 20 Apr 2018 09:54:51 +0000 (11:54 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Fri, 20 Apr 2018 12:10:09 +0000 (14:10 +0200)
AX_PYTHON_DEVEL macro from the autoconf-archive collection doesn't work
when we're trying to cross-compile python bindings in environments such
as buildroot or yocto. It can't properly detect the location of python
headers.

Let's use AM_PATH_PYTHON to detect the python3 interpreter and then
either take the PYTHON_CPPFLAGS and PYTHON_LIBS variables from the
environment (so that cross-compiling build systems can pass their
custom locations to autotools) or try to detect them ourselves using
the python3-config tool.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
bindings/python/Makefile.am
configure.ac

index e14191bb8a7f95cff96c665f3118254b134aaed7..506b7335a5352208de1c95d6d27d9688b550cd55 100644 (file)
@@ -12,7 +12,7 @@ pyexec_LTLIBRARIES = gpiod.la
 
 gpiod_la_SOURCES = gpiodmodule.c
 
-gpiod_la_CFLAGS = -I$(top_srcdir)/include/ -include $(top_builddir)/config.h
-gpiod_la_CFLAGS += $(PYTHON_CPPFLAGS) -Wall -Wextra -g
+gpiod_la_CFLAGS = -I$(top_srcdir)/include/
+gpiod_la_CFLAGS += -Wall -Wextra -g $(PYTHON_CPPFLAGS)
 gpiod_la_LDFLAGS = -module -avoid-version
-gpiod_la_LIBADD = $(top_builddir)/src/lib/libgpiod.la
+gpiod_la_LIBADD = $(top_builddir)/src/lib/libgpiod.la $(PYTHON_LIBS)
index bc4b70316394dba6def5ac6288d55afe8fa1adce..487778f8bd98662f6f51cea83fcb0f8f6a60ea23 100644 (file)
@@ -41,6 +41,11 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 m4_pattern_forbid([^AX_],
        [Unexpanded AX_ macro found. Please install GNU autoconf-archive.])
 
+AC_ARG_VAR([PYTHON_CPPFLAGS],
+       [Compiler flags to find Python headers [default: auto-detect]])
+AC_ARG_VAR([PYTHON_LIBS],
+       [Libraries to link into Python extensions [default: auto-detect]])
+
 AC_CONFIG_SRCDIR([src])
 AC_CONFIG_HEADER([config.h])
 
@@ -169,13 +174,12 @@ AM_CONDITIONAL([WITH_BINDINGS_PYTHON], [test "x$with_bindings_python" = xtrue])
 
 if test "x$with_bindings_python" = xtrue
 then
-       AX_PYTHON_DEVEL([>= '3.0.0'])
-       AM_PATH_PYTHON([3.0])
-       AC_CHECK_PROG([has_python3], [python3], [true], [false])
-       if test "X$has_python3" = xfalse
-       then
-               AC_MSG_ERROR([python3 not found - needed for python bindings], [1])
-       fi
+       AM_PATH_PYTHON([3.0], [],
+               [AC_MSG_ERROR([python3 not found - needed for python bindings])])
+       AS_IF([test -z "$PYTHON_CPPFLAGS"],
+               [AC_SUBST(PYTHON_CPPFLAGS, [`$PYTHON-config --includes`])])
+       AS_IF([test -z "$PYTHON_LIBS"],
+               [AC_SUBST(PYTHON_LIBS, [`$PYTHON-config --libs`])])
 fi
 
 AC_CHECK_PROG([has_doxygen], [doxygen], [true], [false])