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