1# SPDX-License-Identifier: FSFAP 2# -*- Autoconf -*- 3# 4# ax_check_python_modules.m4 - Macros to locate python modules. 5# 6# Author: Dodji Seketeli <dodji@seketeli.org> 7# 8 9#-------------------------------------------------------------------------------- 10# 11# SYNOPSIS 12# 13# AX_CHECK_PYTHON_MODULE(MODNAME, 14# PYTHON, 15# ACTION-IF-FOUND, 16# ACTION-IF-NOT-FOUND) 17# 18# DESCRIPTION 19# 20# Check that a python module is present on the system. 21# 22# MODNAME is the name of the python module to check for. 23# 24# PYTHON is either python2 or python3. It's the python interpreter 25# to use. By default, this is python3. 26# 27# If the module MODNAME is found, the shell variable 28# HAVE_PYMOD_MODNAME is set to 'yes' and ACTION-IF_FOUND is 29# evaluated. Otherwise the shell variable HAVE_PYMOD_MODNAME is set 30# to 'no' and ACTION-IF-NOT-FOUND is evaluated. 31# 32# Note that this macro was inspired from the ax_python_module.m4 33# at 34# http://www.gnu.org/software/autoconf-archive/ax_python_module.html. 35# 36#---------------------------------------------------------------------------------- 37AU_ALIAS([AC_CHECK_PYTHON_MODULE], [AX_CHECK_PYTHON_MODULE]) 38AC_DEFUN([AX_CHECK_PYTHON_MODULE],[ 39 if test -z $PYTHON; then 40 if test -z "$2"; then 41 PYTHON="python3" 42 else 43 PYTHON="$2" 44 fi 45 fi 46 PYTHON_NAME=`basename $PYTHON` 47 AC_MSG_CHECKING($PYTHON_NAME module: $1) 48 $PYTHON -c "import $1" 2>/dev/null 49 if test $? -eq 0; then 50 AC_MSG_RESULT(yes) 51 eval AS_TR_CPP(HAVE_PYMOD_$1)=yes 52 $3 53 # 54 else 55 AC_MSG_RESULT(no) 56 eval AS_TR_CPP(HAVE_PYMOD_$1)=no 57 $4 58 # 59 fi 60]) 61 62#-------------------------------------------------------------------------------- 63# 64# SYNOPSIS 65# 66# AX_CHECK_PYTHON_MODULES(MODLIST, 67# PYTHON, 68# ACTION-IF-FOUND, 69# ACTION-IF-NOT-FOUND) 70# 71# DESCRIPTION 72# 73# Checks that a set of Python modules are present on the system. 74# 75# MODLIST is a white space separated list of python modules to check 76# for. 77# 78# PYTHON is either python2 or python3. It's the name of the python 79# interpreter to use to perform the checking. By default, uses 80# python3. 81# 82# If there is a module from MODLIST that is not found the execution 83# of the test stops and ACTION-IF-NOT-FOUND is evaluated. 84# Otherwise, if all modules are found, ACTION-IF-FOUND is evaluated. 85# 86#-------------------------------------------------------------------------------- 87AU_ALIAS([AC_CHECK_PYTHON_MODULES], [AX_CHECK_PYTHON_MODULES]) 88AC_DEFUN([AX_CHECK_PYTHON_MODULES], [ 89 ax_python_modules_are_ok__=yes 90 for m in $1; do 91 AX_CHECK_PYTHON_MODULE([$m], 92 $2, 93 [ax_python_module_FOUND__=yes], 94 [ax_python_module_FOUND__=no]) 95 if test x$ax_python_module_FOUND__ = xno; then 96 MISSING_PYTHON_MODULES="$MISSING_PYTHON_MODULES $m" 97 ax_python_modules_are_ok__=no 98 fi 99 done 100 101 if test x$ax_python_modules_are_ok__ = xyes; then 102 $3 103 # 104 else 105 $4 106 # 107 fi 108]) 109