summaryrefslogtreecommitdiffstats
path: root/src/modules/rlm_python/configure.ac
blob: 5129b951dac354f003d1e55a636fd92c72ff7f20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
AC_PREREQ([2.68])
AC_INIT(rlm_python.c)
AC_REVISION($Revision$)
FR_INIT_MODULE([rlm_python], [support for embedded Python2])

if test x$with_[]modname != xno; then

	AC_PROG_CC
	AC_PROG_CPP

	dnl extra argument: --with-rlm-python-bin
	PYTHON_BIN=
	AC_ARG_WITH(rlm-python-bin,
	[  --with-rlm-python-bin=PATH   Path to python binary []],
	[ case "$withval" in
	    no)
		AC_MSG_ERROR(Need rlm-python-bin)
		;;
	    yes)
		;;
	    *)
		PYTHON_BIN="$withval"
		;;
	  esac ]
	)

	if test "x$PYTHON_BIN" = x; then
		AC_CHECK_PROGS(PYTHON_BIN, [ python2.7 python2.6 python ], not-found, [${PATH}:/usr/bin:/usr/local/bin])
	fi

	if test "x$PYTHON_BIN" = "xnot-found"; then
		fail="python-binary"
	fi

	dnl extra argument: --with-rlm-python-lib-dir
	PY_LIB_DIR=
	AC_ARG_WITH(rlm-python-lib-dir,
	[  --with-rlm-python-lib-dir=DIR       Directory for Python library files []],
	[ case "$withval" in
	    no)
		AC_MSG_ERROR(Need rlm-python-lib-dir)
		;;
	    yes)
		;;
	    *)
		PY_LIB_DIR="$withval"
		;;
	  esac ]
	)

	dnl extra argument: --with-rlm-python-include-dir
	PY_INC_DIR=
	AC_ARG_WITH(rlm-python-include-dir,
	[  --with-rlm-python-include-dir=DIR   Directory for Python include files []],
	[ case "$withval" in
	    no)
		AC_MSG_ERROR(Need rlm-python-include-dir)
		;;
	    yes)
		;;
	    *)
		PY_INC_DIR="$withval"
		;;
	  esac ]
	)

	if test x$fail = x; then
		PY_MAJOR_VER=`${PYTHON_BIN} -x 'import sys ; print(sys.version[[0]])'`
		if test $PY_MAJOR_VER -ne 2; then
			fail="not-python2"
		fi
	fi

	if test x$fail = x; then
		PY_PREFIX=`${PYTHON_BIN} -c 'import sys ; print(sys.prefix)'`
		AC_MSG_NOTICE([Python sys.prefix \"${PY_PREFIX}\"])

		PY_EXEC_PREFIX=`${PYTHON_BIN} -c 'import sys ; print(sys.exec_prefix)'`
		AC_MSG_NOTICE([Python sys.exec_prefix \"${PY_EXEC_PREFIX}\"])

		PY_SYS_VERSION=`${PYTHON_BIN} -c 'import sys ; print(sys.version[[0:3]])'`
		AC_MSG_NOTICE([Python sys.version \"${PY_SYS_VERSION}\"])

		if test "x$PY_LIB_DIR" = "x"; then
			PY_LIB_DIR="$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config"
			PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config"
		fi

		PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config/Makefile"
		if test -f ${PY_MAKEFILE}; then
			PY_LOCAL_MOD_LIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/^ *//;s/ *$//'`
			AC_MSG_NOTICE([Python local_mod_libs \"${PY_LOCAL_MOD_LIBS}\"])

			PY_BASE_MOD_LIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/^ *//;s/ *$//'`
			AC_MSG_NOTICE([Python base_mod_libs \"${PY_BASE_MOD_LIBS}\"])

			PY_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/  / /g;s/^ *//;s/ *$//'`
			PY_OTHER_LDFLAGS=`sed -n -e 's/^LINKFORSHARED=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/  / /g;s/^ *//;s/ *$//'`
			AC_MSG_NOTICE([Python other_libs \"${PY_OTHER_LDFLAGS} ${PY_OTHER_LIBS}\"])
		fi
		PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASE_MOD_LIBS $PY_OTHER_LIBS"

		old_CFLAGS=$CFLAGS
		CFLAGS="$CFLAGS $PY_CFLAGS"
		smart_try_dir="$PY_PREFIX/include/python$PY_SYS_VERSION"
		FR_SMART_CHECK_INCLUDE(Python.h)
		CFLAGS=$old_CFLAGS

		if test "x$ac_cv_header_Python_h" = "xyes"; then
			mod_cflags="$SMART_CPPFLAGS"
		else
			fail="$fail Python.h"
			targetname=
		fi

		old_LIBS=$LIBS
		LIBS="$LIBS $PY_LIB_LOC $PY_EXTRA_LIBS -lm"
		smart_try_dir=$PY_LIB_DIR
		FR_SMART_CHECK_LIB(python${PY_SYS_VERSION}, Py_Initialize)
		LIBS=$old_LIBS

		eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
		if test "x$t" = "xyes"; then
			mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
			targetname=modname
		else
			FR_SMART_CHECK_LIB(python${PY_SYS_VERSION}m, Py_Initialize)
			eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
			if test "x$t" = "xyes"; then
				mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
				targetname=modname
			else
				targetname=
				fail="$fail libpython$PY_SYS_VERSION"
			fi
		fi
	fi

	AC_CHECK_FUNCS([dl_iterate_phdr])
else
	targetname=
	echo \*\*\* module modname is disabled.
fi

if test x"$fail" != x""; then
	if test x"${enable_strict_dependencies}" = x"yes"; then
		AC_MSG_ERROR([set --without-]modname[ to disable it explicitly.])
	else
		AC_MSG_WARN([silently not building ]modname[.])
		AC_MSG_WARN([FAILURE: ]modname[ requires: $fail.]);
		targetname=""
	fi
fi

AC_CONFIG_HEADER(config.h)
AC_SUBST(mod_ldflags)
AC_SUBST(mod_cflags)
AC_SUBST(targetname)
AC_OUTPUT(all.mk)