]> granicus.if.org Git - postgresql/blob - config/python.m4
Fix query cancellation.
[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 # Set python_libdir to the path of the directory containing the Python shared
62 # library.  Set python_libspec to the -L/-l linker switches needed to link it.
63 # Set python_additional_libs to contain any additional linker switches needed
64 # for subsidiary libraries.
65 #
66 # In modern, well-configured Python installations, LIBDIR gives the correct
67 # directory name and LDLIBRARY is the file name of the shlib.  But in older
68 # installations LDLIBRARY is frequently a useless path fragment, and it's also
69 # possible that the shlib is in a standard library directory such as /usr/lib
70 # so that LIBDIR is irrelevant.  Also, some packagers put the .so symlink for
71 # the shlib in ${python_configdir} even though Python itself never does.
72 # We must also check that what we found is a shared library not a plain
73 # library, which we do by checking its extension.  (We used to rely on
74 # Py_ENABLE_SHARED, but that only tells us that a shlib exists, not that
75 # we found it.)
76 AC_DEFUN([PGAC_CHECK_PYTHON_EMBED_SETUP],
77 [AC_REQUIRE([_PGAC_CHECK_PYTHON_DIRS])
78 AC_MSG_CHECKING([how to link an embedded Python application])
79
80 python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"`
81 python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY'))))"`
82
83 # If LDLIBRARY exists and has a shlib extension, use it verbatim.
84 ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'`
85 if test -e "${python_libdir}/${python_ldlibrary}" -a x"${python_ldlibrary}" != x"${ldlibrary}"
86 then
87         ldlibrary=`echo "${ldlibrary}" | sed "s/^lib//"`
88         found_shlib=1
89 else
90         # Otherwise, guess the base name of the shlib.
91         # LDVERSION was added in Python 3.2, before that use VERSION,
92         # or failing that, $python_version from _PGAC_CHECK_PYTHON_DIRS.
93         python_ldversion=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDVERSION'))))"`
94         if test x"${python_ldversion}" != x""; then
95                 ldlibrary="python${python_ldversion}"
96         else
97                 python_version_var=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('VERSION'))))"`
98                 if test x"${python_version_var}" != x""; then
99                         ldlibrary="python${python_version_var}"
100                 else
101                         ldlibrary="python${python_version}"
102                 fi
103         fi
104         # Search for a likely-looking file.
105         found_shlib=0
106         for d in "${python_libdir}" "${python_configdir}" /usr/lib64 /usr/lib
107         do
108                 # We don't know the platform DLSUFFIX here, so check 'em all.
109                 for e in .so .dll .dylib .sl; do
110                         if test -e "$d/lib${ldlibrary}$e"; then
111                                 python_libdir="$d"
112                                 found_shlib=1
113                                 break 2
114                         fi
115                 done
116         done
117         # Some platforms (OpenBSD) require us to accept a bare versioned shlib
118         # (".so.n.n") as well. However, check this only after failing to find
119         # ".so" anywhere, because yet other platforms (Debian) put the .so
120         # symlink in a different directory from the underlying versioned shlib.
121         if test "$found_shlib" != 1; then
122                 for d in "${python_libdir}" "${python_configdir}" /usr/lib64 /usr/lib
123                 do
124                         for f in "$d/lib${ldlibrary}.so."* ; do
125                                 if test -e "$f"; then
126                                         python_libdir="$d"
127                                         found_shlib=1
128                                         break 2
129                                 fi
130                         done
131                 done
132         fi
133         # As usual, Windows has its own ideas.  Possible default library
134         # locations include c:/Windows/System32 and (for Cygwin) /usr/bin,
135         # and the "lib" prefix might not be there.
136         if test "$found_shlib" != 1 -a \( "$PORTNAME" = win32 -o "$PORTNAME" = cygwin \); then
137                 for d in "${python_libdir}" "${python_configdir}" c:/Windows/System32 /usr/bin
138                 do
139                         for f in "$d/lib${ldlibrary}.dll" "$d/${ldlibrary}.dll" ; do
140                                 if test -e "$f"; then
141                                         python_libdir="$d"
142                                         found_shlib=1
143                                         break 2
144                                 fi
145                         done
146                 done
147         fi
148 fi
149 if test "$found_shlib" != 1; then
150         AC_MSG_ERROR([could not find shared library for Python
151 You might have to rebuild your Python installation.  Refer to the
152 documentation for details.  Use --without-python to disable building
153 PL/Python.])
154 fi
155 python_libspec="-L${python_libdir} -l${ldlibrary}"
156
157 python_additional_libs=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
158
159 AC_MSG_RESULT([${python_libspec} ${python_additional_libs}])
160
161 AC_SUBST(python_libdir)[]dnl
162 AC_SUBST(python_libspec)[]dnl
163 AC_SUBST(python_additional_libs)[]dnl
164
165 ])# PGAC_CHECK_PYTHON_EMBED_SETUP