doc: clarify wording about phantom reads
[pgsql.git] / config / python.m4
blobe500873ff3ce4f777daf0901a5d4623744c21ef2
2 # Autoconf macros for configuring the build of Python extension modules
4 # config/python.m4
7 # PGAC_PATH_PYTHON
8 # ----------------
9 # Look for Python and set the output variable 'PYTHON' if found,
10 # fail otherwise.
12 # Since we are supporting only Python 3.x, prefer python3 to plain python.  If
13 # the latter exists at all, it very possibly points to python2.
15 # As the Python 3 transition happens and PEP 394 isn't updated, we
16 # need to cater to systems that don't have unversioned "python" by
17 # default.  Some systems ship with "python3" by default and perhaps
18 # have "python" in an optional package.  Some systems only have
19 # "python2" and "python3", in which case it's reasonable to prefer the
20 # newer version.
21 AC_DEFUN([PGAC_PATH_PYTHON],
22 [PGAC_PATH_PROGS(PYTHON, [python3 python])
23 AC_ARG_VAR(PYTHON, [Python program])dnl
24 if test x"$PYTHON" = x""; then
25   AC_MSG_ERROR([Python not found])
30 # _PGAC_CHECK_PYTHON_DIRS
31 # -----------------------
32 # Determine the name of various directories of a given Python installation,
33 # as well as the Python version.
34 AC_DEFUN([_PGAC_CHECK_PYTHON_DIRS],
35 [AC_REQUIRE([PGAC_PATH_PYTHON])
36 python_fullversion=`${PYTHON} -c "import sys; print(sys.version)" | sed q`
37 AC_MSG_NOTICE([using python $python_fullversion])
38 # python_fullversion is typically n.n.n plus some trailing junk
39 python_majorversion=`echo "$python_fullversion" | sed '[s/^\([0-9]*\).*/\1/]'`
40 python_minorversion=`echo "$python_fullversion" | sed '[s/^[0-9]*\.\([0-9]*\).*/\1/]'`
41 python_version=`echo "$python_fullversion" | sed '[s/^\([0-9]*\.[0-9]*\).*/\1/]'`
42 # Reject unsupported Python versions as soon as practical.
43 if test "$python_majorversion" -lt 3; then
44   AC_MSG_ERROR([Python version $python_version is too old (version 3 or later is required)])
47 AC_MSG_CHECKING([for Python sysconfig module])
48 if "${PYTHON}" -c 'import sysconfig' 2>&AS_MESSAGE_LOG_FD
49 then
50     AC_MSG_RESULT(yes)
51 else
52     AC_MSG_RESULT(no)
53     AC_MSG_ERROR([sysconfig module not found])
56 AC_MSG_CHECKING([Python configuration directory])
57 python_configdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBPL'))))"`
58 AC_MSG_RESULT([$python_configdir])
60 AC_MSG_CHECKING([Python include directory])
61 python_includespec=`${PYTHON} -c "import sysconfig; print('-I' + sysconfig.get_config_var('INCLUDEPY'))"`
62 if test "$PORTNAME" = win32 ; then
63     python_includespec=`echo $python_includespec | sed 's,[[\]],/,g'`
65 AC_MSG_RESULT([$python_includespec])
67 AC_SUBST(python_majorversion)[]dnl
68 AC_SUBST(python_version)[]dnl
69 AC_SUBST(python_includespec)[]dnl
70 ])# _PGAC_CHECK_PYTHON_DIRS
73 # PGAC_CHECK_PYTHON_EMBED_SETUP
74 # -----------------------------
76 # Set python_libdir to the path of the directory containing the Python shared
77 # library.  Set python_libspec to the -L/-l linker switches needed to link it.
78 # Set python_additional_libs to contain any additional linker switches needed
79 # for subsidiary libraries.
81 # In modern, well-configured Python installations, LIBDIR gives the correct
82 # directory name and LDLIBRARY is the file name of the shlib.  But in older
83 # installations LDLIBRARY is frequently a useless path fragment, and it's also
84 # possible that the shlib is in a standard library directory such as /usr/lib
85 # so that LIBDIR is irrelevant.  Also, some packagers put the .so symlink for
86 # the shlib in ${python_configdir} even though Python itself never does.
87 # We must also check that what we found is a shared library not a plain
88 # library, which we do by checking its extension.  (We used to rely on
89 # Py_ENABLE_SHARED, but that only tells us that a shlib exists, not that
90 # we found it.)
91 AC_DEFUN([PGAC_CHECK_PYTHON_EMBED_SETUP],
92 [AC_REQUIRE([_PGAC_CHECK_PYTHON_DIRS])
93 AC_MSG_CHECKING([how to link an embedded Python application])
95 python_libdir=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBDIR'))))"`
96 python_ldlibrary=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDLIBRARY'))))"`
98 # If LDLIBRARY exists and has a shlib extension, use it verbatim.
99 ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'`
100 if test -e "${python_libdir}/${python_ldlibrary}" -a x"${python_ldlibrary}" != x"${ldlibrary}"
101 then
102         ldlibrary=`echo "${ldlibrary}" | sed "s/^lib//"`
103         found_shlib=1
104 else
105         # Otherwise, guess the base name of the shlib.
106         # LDVERSION was added in Python 3.2, before that use VERSION,
107         # or failing that, $python_version from _PGAC_CHECK_PYTHON_DIRS.
108         python_ldversion=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LDVERSION'))))"`
109         if test x"${python_ldversion}" != x""; then
110                 ldlibrary="python${python_ldversion}"
111         else
112                 python_version_var=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('VERSION'))))"`
113                 if test x"${python_version_var}" != x""; then
114                         ldlibrary="python${python_version_var}"
115                 else
116                         ldlibrary="python${python_version}"
117                 fi
118         fi
119         # Search for a likely-looking file.
120         found_shlib=0
121         for d in "${python_libdir}" "${python_configdir}" /usr/lib64 /usr/lib
122         do
123                 # Note: DLSUFFIX is for loadable modules, not shared
124                 # libraries, so cannot be used here portably.  Just
125                 # check all known possibilities.
126                 for e in .so .dll .dylib .sl; do
127                         if test -e "$d/lib${ldlibrary}$e"; then
128                                 python_libdir="$d"
129                                 found_shlib=1
130                                 break 2
131                         fi
132                 done
133         done
134         # Some platforms (OpenBSD) require us to accept a bare versioned shlib
135         # (".so.n.n") as well. However, check this only after failing to find
136         # ".so" anywhere, because yet other platforms (Debian) put the .so
137         # symlink in a different directory from the underlying versioned shlib.
138         if test "$found_shlib" != 1; then
139                 for d in "${python_libdir}" "${python_configdir}" /usr/lib64 /usr/lib
140                 do
141                         for f in "$d/lib${ldlibrary}.so."* ; do
142                                 if test -e "$f"; then
143                                         python_libdir="$d"
144                                         found_shlib=1
145                                         break 2
146                                 fi
147                         done
148                 done
149         fi
150         # As usual, Windows has its own ideas.  Possible default library
151         # locations include c:/Windows/System32 and (for Cygwin) /usr/bin,
152         # and the "lib" prefix might not be there.
153         if test "$found_shlib" != 1 -a \( "$PORTNAME" = win32 -o "$PORTNAME" = cygwin \); then
154                 for d in "${python_libdir}" "${python_configdir}" c:/Windows/System32 /usr/bin
155                 do
156                         for f in "$d/lib${ldlibrary}.dll" "$d/${ldlibrary}.dll" ; do
157                                 if test -e "$f"; then
158                                         python_libdir="$d"
159                                         found_shlib=1
160                                         break 2
161                                 fi
162                         done
163                 done
164         fi
166 if test "$found_shlib" != 1; then
167         AC_MSG_ERROR([could not find shared library for Python
168 You might have to rebuild your Python installation.  Refer to the
169 documentation for details.  Use --without-python to disable building
170 PL/Python.])
172 python_libspec="-L${python_libdir} -l${ldlibrary}"
174 python_additional_libs=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
176 AC_MSG_RESULT([${python_libspec} ${python_additional_libs}])
178 AC_SUBST(python_libdir)[]dnl
179 AC_SUBST(python_libspec)[]dnl
180 AC_SUBST(python_additional_libs)[]dnl
182 ])# PGAC_CHECK_PYTHON_EMBED_SETUP