configure.ac 4.06 KB
Newer Older
1 2 3 4
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
5
AC_INIT([stm32f4-energy-monitor], [1.0], [james.pallister@embecosm.com])
6 7 8
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE
9
AC_PROG_LIBTOOL
10
LT_INIT
11
AC_CONFIG_SRCDIR([src/host/host_receiver.cpp])
12 13 14 15 16 17 18
AC_CONFIG_HEADERS([config.h])

AC_LANG([C++])

AC_PROG_CXX
AC_PROG_CC

19 20 21 22 23 24
AC_PROG_CC([arm-none-eabi-gcc])

# TODO check if a suitable arm compiler exists
# Check to see if it can compile code for cortex-m4f
# Check to see if libopencm3 is available

25 26 27 28 29 30 31 32 33
# Check for compiler flags.
AX_CXX_COMPILE_STDCXX_11([noext],[mandatory])

# Checks for libraries.
BOOST_REQUIRE([1.49.0])
BOOST_REGEX([n])
BOOST_THREADS([n])
BOOST_SYSTEM([n])

34 35 36 37 38
# Save libraries (don't want to compile energy_monitor with them)
save_LIBS="$LIBS"
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.])])
LIBS="$save_LIBS"
39

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
# 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}])
65 66 67 68 69 70 71 72
    AC_LINK_IFELSE([AC_LANG_SOURCE([AC_LANG_PROGRAM(
                    [[
                        #include "Python.h"
                    ]],

                    [[
                        Py_Initialize ();
                    ]])])],
73 74 75 76 77 78 79 80 81 82 83 84
                   [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)]),
            [],
85 86 87 88
            [with_python=`which python`])
AC_ARG_WITH(python,
            [AS_HELP_STRING([--without-python],[disable building of host receiver as a python module])],
            [],
89
            [with_python=no])
90

91 92 93 94 95
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])
96
    have_libpython=no
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
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)
132
AM_CONDITIONAL([BUILD_PYMODULE], [test x$have_libpython != xno])
133

134

135
AC_CONFIG_FILES([Makefile src/host/Makefile src/firmware/Makefile])
136
AC_OUTPUT