Python and Autoconf

Glen Starchman glen at enabledventures.com
Tue May 22 14:15:44 EDT 2001


I have been working on a gigantic project that uses a combination of
Python, Jython, Java, and C and have recently converted all of my
Makefiles over to Autoconf. I was very pleased with Autoconf (after
several nights of head scratching with the New Rider's Autoconf book in
my hands) except for the fact that there is no native support for things
python. For example, there is no built in way to check if a module
exists, like the AC_CHECK_HEADER macro for C/C++. So, I decided to roll
my own. I am working on integrating autoconf even deeper into my
codebase, for example, having configure create Python scripts on the fly
depending on the module test macros. 

Anyway, hopefully someone finds these macros useful... I will
(eventually) have them added to the autoconf repository.

(for the uninitiated, you have to add these macros to a file called
aclocal.m4 in the same directory as your configure.in script in order to
use them in your configure.in)

Anyone have any more Python-specific autoconf macros? 

--------------------------------------------------------------------------

dnl figure out the path to our python libraries
dnl this macro takes no arguments
AC_DEFUN(AC_PY_LIB_PATH, 
[ac_cv_py_lib_path="`python -c "import sys; import string; print
string.join(sys.path,' ')"`"; 
PY_LIB_PATH=$ac_cv_py_lib_path;
])


dnl param is the name of a python module that should 
dnl exist in the sys.path
dnl note: we do not pass in the extension...
dnl may be used in configure.in like:
dnl
dnl     AC_PY_CHECK_LIB(threading)
dnl 

AC_DEFUN(AC_PY_CHECK_LIB,[ dnl
AC_MSG_CHECKING(Python module $1)
AC_PY_LIB_PATH
ac_cv_py_have_$1=false;
for d in $PY_LIB_PATH
{
    if test -e $d/$1.py; then
    {
        ac_cv_py_have_$1=true;
        break;
    }
    fi;
}
AC_MSG_RESULT($ac_cv_py_have_$1)
HAVE_PY_LIB_$1=$ac_cv_py_have_$1;
])


dnl wrapper for AC_PY_CHECK_LIB 
dnl that aborts the configure if
dnl theAC_DEFUN(AC_PY_CHECK_REQUIRED, [dnl
AC_PY_CHECK_LIB($1)
if [[ $HAVE_PY_LIB_$1 == false ]]; then
{
    echo "$1 is a required module... aborting.";
    exit
}
fi;
])



More information about the Python-list mailing list