OSDN Git Service

Another try at making plpython autoconfiguration work correctly. Use a
[pg-rex/syncrep.git] / config / python.m4
1 #
2 # Autoconf macros for configuring the build of Python extension modules
3 #
4 # $PostgreSQL: pgsql/config/python.m4,v 1.11 2004/10/11 19:32:16 tgl Exp $
5 #
6
7 # PGAC_PATH_PYTHON
8 # ----------------
9 # Look for Python and set the output variable 'PYTHON'
10 # to 'python' if found, empty otherwise.
11 AC_DEFUN([PGAC_PATH_PYTHON],
12 [AC_PATH_PROG(PYTHON, python)
13 if test x"$PYTHON" = x""; then
14   AC_MSG_ERROR([Python not found])
15 fi
16 ])
17
18
19 # _PGAC_CHECK_PYTHON_DIRS
20 # -----------------------
21 # Determine the name of various directories of a given Python installation.
22 AC_DEFUN([_PGAC_CHECK_PYTHON_DIRS],
23 [AC_REQUIRE([PGAC_PATH_PYTHON])
24 AC_MSG_CHECKING([for Python distutils module])
25 if "${PYTHON}" 2>&- -c 'import distutils'
26 then
27     AC_MSG_RESULT(yes)
28 else
29     AC_MSG_RESULT(no)
30     AC_MSG_ERROR([distutils module not found])
31 fi
32 AC_MSG_CHECKING([Python configuration directory])
33 python_version=`${PYTHON} -c "import sys; print sys.version[[:3]]"`
34 python_configdir=`${PYTHON} -c "from distutils.sysconfig import get_python_lib as f; import os; print os.path.join(f(plat_specific=1,standard_lib=1),'config')"`
35 python_includespec=`${PYTHON} -c "import distutils.sysconfig; print '-I'+distutils.sysconfig.get_python_inc()"`
36
37 AC_SUBST(python_version)[]dnl
38 AC_SUBST(python_configdir)[]dnl
39 AC_SUBST(python_includespec)[]dnl
40 # This should be enough of a message.
41 AC_MSG_RESULT([$python_configdir])
42 ])# _PGAC_CHECK_PYTHON_DIRS
43
44
45 # PGAC_CHECK_PYTHON_EMBED_SETUP
46 # -----------------------------
47 #
48 # Note: selecting libpython from python_configdir works in all Python
49 # releases, but it generally finds a non-shared library, which means
50 # that we are binding the python interpreter right into libplpython.so.
51 # In Python 2.3 and up there should be a shared library available in
52 # the main library location.
53 AC_DEFUN([PGAC_CHECK_PYTHON_EMBED_SETUP],
54 [AC_REQUIRE([_PGAC_CHECK_PYTHON_DIRS])
55 AC_MSG_CHECKING([how to link an embedded Python application])
56
57 python_libdir=`${PYTHON} -c "import distutils.sysconfig,string; print string.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR')))"`
58 python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig,string; print string.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY')))"`
59 python_so=`${PYTHON} -c "import distutils.sysconfig,string; print string.join(filter(None,distutils.sysconfig.get_config_vars('SO')))"`
60 ldlibrary=`echo "${python_ldlibrary}" | sed "s/${python_so}$//"`
61
62 if test x"${python_libdir}" != x"" -a x"${python_ldlibrary}" != x"" -a x"${python_ldlibrary}" != x"${ldlibrary}"
63 then
64         # New way: use the official shared library
65         ldlibrary=`echo "${ldlibrary}" | sed "s/^lib//"`
66         python_libspec="-L${python_libdir} -l${ldlibrary}"
67 else
68         # Old way: use libpython from python_configdir
69         python_libdir="${python_configdir}"
70         python_libspec="-L${python_libdir} -lpython${python_version}"
71 fi
72
73 python_additional_libs=`${PYTHON} -c "import distutils.sysconfig,string; print string.join(filter(None,distutils.sysconfig.get_config_vars('LIBS','LIBC','LIBM','LOCALMODLIBS','BASEMODLIBS')))"`
74
75 AC_MSG_RESULT([${python_libspec} ${python_additional_libs}])
76
77 AC_SUBST(python_libdir)[]dnl
78 AC_SUBST(python_libspec)[]dnl
79 AC_SUBST(python_additional_libs)[]dnl
80 ])# PGAC_CHECK_PYTHON_EMBED_SETUP