58b2d8028674620d821f1250487c0200a1341dec
[freeradius.git] / src / modules / rlm_python / configure.ac
1 AC_PREREQ([2.53])
2 AC_INIT(rlm_python.c)
3 AC_REVISION($Revision$)
4 AC_DEFUN(modname,[rlm_python])
5
6 if test x$with_[]modname != xno; then
7
8         AC_PROG_CC
9         AC_PROG_CPP
10
11         AC_CHECK_PROGS(PYTHONBIN, [ python2.7 python2.6 python2.5 python2.4 python ], not-found, [${PATH}:/usr/bin:/usr/local/bin])
12
13         if test x$PYTHONBIN = xnot-found; then
14                 fail="python-binary"
15         fi
16
17         dnl extra argument: --with-rlm-python-lib-dir
18         PY_LIB_DIR=
19         AC_ARG_WITH(rlm-python-lib-dir,
20         [  --with-rlm-python-lib-dir=DIR       Directory for Python library files []],
21         [ case "$withval" in
22             no)
23                 AC_MSG_ERROR(Need rlm-python-lib-dir)
24                 ;;
25             yes)
26                 ;;
27             *)
28                 PY_LIB_DIR="$withval"
29                 ;;
30           esac ]
31         )
32
33         dnl extra argument: --with-rlm-python-include-dir
34         PY_INC_DIR=
35         AC_ARG_WITH(rlm-python-include-dir,
36         [  --with-rlm-python-include-dir=DIR   Directory for Python include files []],
37         [ case "$withval" in
38             no)
39                 AC_MSG_ERROR(Need rlm-python-include-dir)
40                 ;;
41             yes)
42                 ;;
43             *)
44                 PY_INC_DIR="$withval"
45                 ;;
46           esac ]
47         )
48
49         if test x$fail = x; then
50
51                 PY_PREFIX=`${PYTHONBIN} -c 'import sys ; print(sys.prefix)'`
52                 PY_EXEC_PREFIX=`${PYTHONBIN} -c 'import sys ; print(sys.exec_prefix)'`
53                 changequote(<<, >>)dnl
54                 PY_VERSION=`${PYTHONBIN} -c 'import sys ; print(sys.version[0:3])'`
55                 changequote([, ])dnl
56                 PY_LIBS="-lpython$PY_VERSION"
57                 PY_LIB_DIR="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
58                 PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
59                 PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config/Makefile"
60                 if test -f ${PY_MAKEFILE}; then
61                         PY_LOCALMODLIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
62                         PY_BASEMODLIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
63                         PY_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE`
64                         PY_OTHER_LDFLAGS=`sed -n -e 's/^LINKFORSHARED=\(.*\)/\1/p' $PY_MAKEFILE`
65                 fi
66                 PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASEMODLIBS $PY_OTHER_LIBS"
67
68                 old_CFLAGS=$CFLAGS
69                 CFLAGS="$CFLAGS $PY_CFLAGS"
70                 smart_try_dir="$PY_PREFIX/include/python$PY_VERSION"
71                 FR_SMART_CHECK_INCLUDE(Python.h)
72                 CFLAGS=$old_CFLAGS
73
74                 if test "x$ac_cv_header_Python_h" = "xyes"; then
75                         mod_cflags="$SMART_CPPFLAGS"
76                 else
77                         fail="$fail Python.h"
78                         targetname=
79                 fi
80
81                 old_LIBS=$LIBS
82                 LIBS="$LIBS $PY_LIB_LOC $PY_EXTRA_LIBS -lm"
83                 smart_try_dir=$PY_LIB_DIR
84                 FR_SMART_CHECK_LIB(python${PY_VERSION}, Py_Initialize)
85                 LIBS=$old_LIBS
86
87                 eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
88                 if test "x$t" = "xyes"; then
89                         mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
90                         targetname=modname
91                 else
92                         FR_SMART_CHECK_LIB(python${PY_VERSION}m, Py_Initialize)
93                         eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
94                         if test "x$t" = "xyes"; then
95                                 mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
96                                 targetname=modname
97                         else
98                                 targetname=
99                                 fail="$fail libpython$PY_VERSION"
100                         fi
101                 fi
102         fi
103 else
104         targetname=
105         echo \*\*\* module modname is disabled.
106 fi
107
108 if test x"$fail" != x""; then
109         if test x"${enable_strict_dependencies}" = x"yes"; then
110                 AC_MSG_ERROR([set --without-]modname[ to disable it explicitly.])
111         else
112                 AC_MSG_WARN([silently not building ]modname[.])
113                 AC_MSG_WARN([FAILURE: ]modname[ requires: $fail.]);
114                 targetname=""
115         fi
116 fi
117
118 AC_SUBST(mod_ldflags)
119 AC_SUBST(mod_cflags)
120 AC_SUBST(targetname)
121 AC_OUTPUT(all.mk)