Commit | Line | Data |
---|---|---|
34e49164 C |
1 | dnl Process this file with autoconf to produce a configure script. |
2 | AC_INIT(pycaml_ml.c) | |
3 | ||
4 | dnl Checks for programs. | |
5 | ||
6 | dnl Checks for libraries. | |
7 | dnl Replace `main' with a function in -lpython: | |
8 | AC_CHECK_LIB(python, main) | |
9 | ||
10 | dnl Checks for header files. | |
11 | AC_CHECK_HEADERS(unistd.h) | |
12 | ||
13 | dnl Checks for typedefs, structures, and compiler characteristics. | |
14 | AC_C_CONST | |
15 | ||
16 | dnl Checks for library functions. | |
17 | AC_HEADER_STDC | |
18 | ||
19 | dnl ******************** | |
20 | dnl Check for Python. | |
21 | dnl ******************** | |
22 | ||
23 | AM_PATH_PYTHON() | |
24 | ||
25 | dnl Find Python executable | |
26 | AC_PATH_PROGS(PYPACKAGE, python) | |
27 | ||
28 | dnl Extract the version using Python, check against 1.5+ | |
29 | ||
30 | changequote(<<, >>) | |
31 | PY_PREFIX=`$PYPACKAGE getprefix.py` | |
32 | PY_VERSION=`$PYPACKAGE getversion.py` | |
33 | changequote([, ]) | |
34 | ||
35 | if test `echo $PY_VERSION | tr -d .` -lt 15; then | |
36 | echo "Sorry, you need to have Python 1.5+ installed - update your version!" | |
37 | AC_MSG_ERROR([*** Python 1.5 or better required]) | |
38 | fi | |
39 | ||
40 | dnl Find the Python.h header file | |
41 | ||
42 | AC_MSG_CHECKING(for Python header files) | |
43 | changequote(<<, >>) | |
44 | PY_INCLUDE=`$PYPACKAGE -c 'import sys ; print "%s/include/python%s" % (sys.prefix, sys.version[:3])'` | |
45 | changequote([, ]) | |
46 | ||
47 | if test -r "$PY_INCLUDE/Python.h"; then | |
48 | PY_CFLAGS="-I$PY_INCLUDE" | |
49 | else | |
50 | AC_MSG_ERROR([Could not find Python.h in $PY_INCLUDE]) | |
51 | fi | |
52 | AC_MSG_RESULT(found) | |
53 | ||
54 | dnl Find the Python library | |
55 | ||
56 | AC_MSG_CHECKING(for Python library) | |
57 | PYLIB="" | |
58 | changequote(<<, >>) | |
59 | PY_PREFIX=`$PYPACKAGE -c 'import sys; print sys.prefix'` | |
60 | PYLIBVER=`$PYPACKAGE -c 'import sys; print sys.version[:3]'` | |
61 | changequote([, ]) | |
62 | ||
63 | py_paths="$PY_PREFIX/lib/python$PYLIBVER/config $PYPREFIX/lib" | |
64 | py_suffix="$PYLIBVER.so $PYLIBVER.a .so .a" | |
65 | ||
66 | dnl Try for specific version first, then the generic version, then panic | |
67 | ||
68 | for ppath in $py_paths ; do | |
69 | if test -r "$ppath/libpython$PYLIBVER.so" -o \ | |
70 | -r "$ppath/libpython$PYLIBVER.a"; then | |
71 | PYLIB="-cclib -L$ppath -cclib -lpython$PYLIBVER" | |
72 | break | |
73 | fi | |
74 | ||
75 | if test -r "$ppath/libpython.so" -o \ | |
76 | -r "$ppath/libpython.a"; then | |
77 | PYLIB="-cclib -L$ppath -cclib -lpython" | |
78 | break | |
79 | fi | |
80 | done | |
81 | ||
82 | if test "x$PYLIB" != x ; then | |
83 | PY_LIBS="$PYLIB $PY_LIBS" | |
84 | AC_MSG_RESULT(found) | |
85 | else | |
86 | AC_MSG_ERROR([*** Python library not found]) | |
87 | fi | |
88 | ||
89 | dnl Get the libraries that python depends on | |
90 | ||
91 | AC_PATH_PROG(haveldd, ldd) | |
92 | AC_MSG_CHECKING(for Python's dependencies) | |
93 | ||
94 | if test x$haveldd != x ; then | |
95 | changequote(<<, >>) | |
96 | py_deps=`ldd $PYPACKAGE | sed 's/\( *lib\([^\/]*\)\.so.*=.*$\)/-cclib\ \"-l\2\"/p; d'` | |
97 | for py_lib in $py_deps ; do | |
98 | if test "$py_lib" != "-lm" && test "$py_lib" != "-lc" ; then | |
99 | PY_DEPS="$PY_DEPS $py_lib" | |
100 | fi | |
101 | done | |
102 | changequote([, ]) | |
103 | fi | |
104 | ||
105 | dnl only GNU ld seems to know -E flag | |
106 | ||
107 | if $LD -v 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then | |
108 | PY_LIBS="-Wl,-E $PY_LIBS $PY_DEPS" | |
109 | else | |
110 | PY_LIBS="$PY_LIBS $PY_DEPS" | |
111 | fi | |
112 | ||
113 | export PY_LIBS | |
114 | export PY_VERSION | |
115 | export PY_PREFIX | |
116 | ||
117 | AC_SUBST(PY_LIBS) | |
118 | AC_SUBST(PY_VERSION) | |
119 | AC_SUBST(PY_PREFIX) | |
120 | ||
121 | AC_OUTPUT(Makefile) |