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