use -export-dynamic when linking libpython.a
[mikachu/openbox.git] / m4 / python.m4
1 # PYTHON_DEVEL()
2 #
3 # Checks for Python and tries to get the include path to 'Python.h', and
4 # the libpython library.
5 # It provides the $(PYTHON_CFLAGS) $(PYTHON_LIBS) $(PYTHON_LDFLAGS) output
6 # variables.
7 AC_DEFUN([PYTHON_DEVEL],
8 [
9   AC_REQUIRE([AM_PATH_PYTHON])
10
11   python_prefix=${PYTHON%/bin*}
12
13   # Check for Python include path
14   AC_MSG_CHECKING([for python include path])
15   for i in "$python_prefix/include/python$PYTHON_VERSION/" \
16            "$python_prefix/include/python/" "$python_prefix/"
17   do
18     python_path=`find $i -type f -name Python.h -print 2> /dev/null`
19     test "$python_path" && break
20   done
21   for i in $python_path
22   do
23     python_path=${python_path%/Python.h}
24     break
25   done
26   if test "$python_path"
27   then
28     AC_MSG_RESULT([$python_path])
29   else
30     AC_MSG_ERROR([cannot find python include path])
31   fi
32   AC_SUBST([PYTHON_CFLAGS], [-I$python_path])
33
34   # Check for a Python library
35   AC_MSG_CHECKING([for python library])
36   PYLIB=""
37   for i in "$python_prefix/lib" \
38            "$python_prefix/lib/python$PYTHON_VERSION/config" \
39            "$python_prefix/lib/python$PYTHON_VERSION/lib" \
40            "$python_prefix/lib/python/lib"
41   do
42     if test -r "$i/libpython$PYTHON_VERSION.so"; then
43       PYLIB="$i/libpython$PYTHON_VERSION.so"
44       PYTHON_LIBS="-L$i -lpython$PYTHON_VERSION"
45       PYTHON_LDFLAGS=""
46       break
47     else
48       if test -r "$i/libpython$PYTHON_VERSION.a"; then
49         PYLIB="$i/libpython$PYTHON_VERSION.a"
50         PYTHON_LIBS="-L$i -lpython$PYTHON_VERSION -lpthread -ldl -lutil -lm"
51         PYTHON_LDFLAGS="-export-dynamic"
52         break
53       else
54         # look for really old versions
55         if test -r "$i/libPython.a"; then
56           PYLIB="$i/libPython.a"
57           PYTHON_LIBS="-L$i -lModules -lPython -lObjects -lParser"
58           PYTHON_LDFLAGS="-export-dynamic"
59           break
60         fi
61       fi
62     fi
63   done
64   if test "$PYLIB"
65   then
66     AC_MSG_RESULT([$PYLIB])
67   else
68     AC_MSG_ERROR([cannot find python library])
69   fi
70   AC_SUBST([PYTHON_LIBS])
71   AC_SUBST([PYTHON_LDFLAGS])
72 ])