Commit cc40fd79 authored by Ashley Whetter's avatar Ashley Whetter

Autotools can now build the host python module

pyenergy.so is built into .host/.libs.
Can be built with python 2 or 3.
--with-python option added to configure script, which should point to the python
binary that should be used to build the module.
parent 36a8870e
bin_PROGRAMS=host_receiver
lib_LTLIBRARIES=pyenergy.la
host_receiver_SOURCES=helper.cpp dataprocessor.cpp libusbinterface.cpp host_receiver.cpp
pyenergy_la_SOURCES=pymodule.cpp
host_receiver_CPPFLAGS = $(BOOST_CPPFLAGS)
host_receiver_LDADD = $(BOOST_REGEX_LIBS) $(BOOST_THREAD_LIBS) $(BOOST_SYSTEM_LIBS)
host_receiver_LDFLAGS = $(BOOST_REGEX_LDFLAGS) $(BOOST_THREAD_LDFLAGS) $(BOOST_SYSTEM_LDFLAGS)
pyenergy_la_CPPFLAGS = $(PYTHON_CPPFLAGS)
pyenergy_la_LIBADD = $(BOOST_PYTHON_LIBS) $(BOOST_PYTHON3_LIBS) $(PYTHON_LIBS)
pyenergy_la_LDFLAGS = $(BOOST_PYTHON_LDFLAGS) $(BOOST_PYTHON3_LDFLAGS) -module -shared -avoid-version
ACLOCAL_AMFLAGS=-Im4
This diff is collapsed.
......@@ -3,6 +3,9 @@
/* Defined if the requested minimum BOOST version is satisfied */
#undef HAVE_BOOST
/* Define to 1 if you have <boost/python.hpp> */
#undef HAVE_BOOST_PYTHON_HPP
/* Define to 1 if you have <boost/regex.hpp> */
#undef HAVE_BOOST_REGEX_HPP
......
This diff is collapsed.
......@@ -6,7 +6,7 @@ AC_INIT([stm32-host-receiver], [0.0.1], [BUG-REPORT-ADDRESS])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE
AC_PROG_LIBTOOL
LT_INIT
AC_CONFIG_SRCDIR([host_receiver.cpp])
AC_CONFIG_HEADERS([config.h])
......@@ -28,6 +28,87 @@ BOOST_SYSTEM([n])
AC_CHECK_LIB([readline], [main],, [AC_MSG_ERROR([Cannot find readline library. Please install it.])])
AC_CHECK_LIB([usb-1.0], [main],, [AC_MSG_ERROR([Cannot find usb-1.0 library. Please install it.])])
# Python checking adapted from gdb's configure.ac
# It's license, and original code can be obtained from
# http://ftp.gnu.org/gnu/gdb/gdb-7.6.tar.bz2
AC_DEFUN([AC_TRY_LIBPYTHON],
[
version=$1
define([have_libpython_var],$2)
new_CPPFLAGS=$3
new_LIBS=$4
save_CPPFLAGS=$CPPFLAGS
save_LIBS=$LIBS
CPPFLAGS="$CPPFLAGS $new_CPPFLAGS"
LIBS="$LIBS $new_LIBS"
case $version in
python3*)
BOOST_FIND_LIB([python3], [n], [boost/python.hpp],
[], [BOOST_PYTHON_MODULE(empty) {}])
;;
*)
BOOST_PYTHON([n])
;;
esac
found_usable_python=no
AC_MSG_CHECKING([for ${version}])
AC_LINK_IFELSE(AC_LANG_PROGRAM([[#include "Python.h"]],
[[Py_Initialize ();]]),
[have_libpython_var=${version}
found_usable_python=yes
PYTHON_CPPFLAGS=$new_CPPFLAGS
PYTHON_LIBS=$new_LIBS])
CPPFLAGS=$save_CPPFLAGS
LIBS=$save_LIBS
AC_MSG_RESULT([${found_usable_python}])
])
AC_ARG_WITH(python,
AS_HELP_STRING([--with-python=PYTHON], [also build host receiver as a python module (/path/to/python)]),
[],
[with_python=no])
AC_MSG_CHECKING([whether to use python])
AC_MSG_RESULT([$with_python])
if test "${with_python}" = no; then
AC_MSG_WARN([python module will not be compiled])
else
python_bin="${with_python}"
if test ! -f "${python_bin}"; then
AC_MSG_ERROR(unable to find python program ${python_bin})
else
python_includes=`${python_bin}-config --includes`
if test $? != 0; then
AC_MSG_ERROR(failure running python-config --includes)
fi
python_libs=`${python_bin}-config --ldflags`
if test $? != 0; then
AC_MSG_ERROR(failure running python-config --ldflags)
fi
have_libpython=no
python_version=`echo " ${python_libs} " \
| sed -e 's,^.* -l\(python[[0-9]]*[[\.]]*[[0-9]]*\).*$,\1,'`
case "${python_version}" in
python*)
AC_TRY_LIBPYTHON(${python_version}, have_libpython,
${python_includes}, ${python_libs})
;;
*)
AC_MSG_ERROR([unable to determine python version from ${python_libs}])
;;
esac
if test "${have_libpython}" = no; then
AC_MSG_ERROR([no usable python found at ${with_python}])
fi
fi
fi
AC_SUBST(PYTHON_CPPFLAGS)
AC_SUBST(PYTHON_LIBS)
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
......
#include <python.h>
#include <boost/python.hpp>
#include <libusb-1.0/libusb.h>
#include <readline/readline.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment