]> granicus.if.org Git - postgresql/blob - config/python.m4
Let compiler handle size calculation of bool types.
[postgresql] / config / python.m4
1 #
2 # Autoconf macros for configuring the build of Python extension modules
3 #
4 # config/python.m4
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}" -c 'import distutils' 2>&AS_MESSAGE_LOG_FD
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_majorversion=`${PYTHON} -c "import sys; print(sys.version[[0]])"`
34 python_version=`${PYTHON} -c "import sys; print(sys.version[[:3]])"`
35 python_configdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBPL'))))"`
36 AC_MSG_RESULT([$python_configdir])
37
38 AC_MSG_CHECKING([Python include directories])
39 python_includespec=`${PYTHON} -c "
40 import distutils.sysconfig
41 a = '-I' + distutils.sysconfig.get_python_inc(False)
42 b = '-I' + distutils.sysconfig.get_python_inc(True)
43 if a == b:
44     print(a)
45 else:
46     print(a + ' ' + b)"`
47 if test "$PORTNAME" = win32 ; then
48     python_includespec=`echo $python_includespec | sed 's,[[\]],/,g'`
49 fi
50 AC_MSG_RESULT([$python_includespec])
51
52 AC_SUBST(python_majorversion)[]dnl
53 AC_SUBST(python_version)[]dnl
54 AC_SUBST(python_includespec)[]dnl
55 ])# _PGAC_CHECK_PYTHON_DIRS
56
57
58 # PGAC_CHECK_PYTHON_EMBED_SETUP
59 # -----------------------------
60 #
61 # Note: selecting libpython from python_configdir works in all Python
62 # releases, but it generally finds a non-shared library, which means
63 # that we are binding the python interpreter right into libplpython.so.
64 # In Python 2.3 and up there should be a shared library available in
65 # the main library location.
66 AC_DEFUN([PGAC_CHECK_PYTHON_EMBED_SETUP],
67 [AC_REQUIRE([_PGAC_CHECK_PYTHON_DIRS])
68 AC_MSG_CHECKING([how to link an embedded Python application])
69
70 python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"`
71 python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY'))))"`
72 python_so=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('SO'))))"`
73 ldlibrary=`echo "${python_ldlibrary}" | sed "s/${python_so}$//"`
74 python_enable_shared=`${PYTHON} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_vars().get('Py_ENABLE_SHARED',0))"`
75
76 if test x"${python_libdir}" != x"" -a x"${python_ldlibrary}" != x"" -a x"${python_ldlibrary}" != x"${ldlibrary}"
77 then
78         # New way: use the official shared library
79         ldlibrary=`echo "${ldlibrary}" | sed "s/^lib//"`
80         python_libspec="-L${python_libdir} -l${ldlibrary}"
81 else
82         # Old way: use libpython from python_configdir
83         python_libdir="${python_configdir}"
84         # LDVERSION was introduced in Python 3.2.
85         python_ldversion=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDVERSION'))))"`
86         if test x"${python_ldversion}" = x""; then
87                 python_ldversion=$python_version
88         fi
89         python_libspec="-L${python_libdir} -lpython${python_ldversion}"
90 fi
91
92 python_additional_libs=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
93
94 AC_MSG_RESULT([${python_libspec} ${python_additional_libs}])
95
96 AC_SUBST(python_libdir)[]dnl
97 AC_SUBST(python_libspec)[]dnl
98 AC_SUBST(python_additional_libs)[]dnl
99
100 ])# PGAC_CHECK_PYTHON_EMBED_SETUP