Convert range_in and multirange_in to report errors softly.
[pgsql.git] / config / python.m4
blobb295ad3d3a4515dee35a9df1b8add0e311c750cc
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                 if test -e "$d/lib${ldlibrary}${DLSUFFIX}"; then
124                         python_libdir="$d"
125                         found_shlib=1
126                         break 2
127                 fi
128         done
129         # Some platforms (OpenBSD) require us to accept a bare versioned shlib
130         # (".so.n.n") as well. However, check this only after failing to find
131         # ".so" anywhere, because yet other platforms (Debian) put the .so
132         # symlink in a different directory from the underlying versioned shlib.
133         if test "$found_shlib" != 1; then
134                 for d in "${python_libdir}" "${python_configdir}" /usr/lib64 /usr/lib
135                 do
136                         for f in "$d/lib${ldlibrary}.so."* ; do
137                                 if test -e "$f"; then
138                                         python_libdir="$d"
139                                         found_shlib=1
140                                         break 2
141                                 fi
142                         done
143                 done
144         fi
145         # As usual, Windows has its own ideas.  Possible default library
146         # locations include c:/Windows/System32 and (for Cygwin) /usr/bin,
147         # and the "lib" prefix might not be there.
148         if test "$found_shlib" != 1 -a \( "$PORTNAME" = win32 -o "$PORTNAME" = cygwin \); then
149                 for d in "${python_libdir}" "${python_configdir}" c:/Windows/System32 /usr/bin
150                 do
151                         for f in "$d/lib${ldlibrary}.dll" "$d/${ldlibrary}.dll" ; do
152                                 if test -e "$f"; then
153                                         python_libdir="$d"
154                                         found_shlib=1
155                                         break 2
156                                 fi
157                         done
158                 done
159         fi
161 if test "$found_shlib" != 1; then
162         AC_MSG_ERROR([could not find shared library for Python
163 You might have to rebuild your Python installation.  Refer to the
164 documentation for details.  Use --without-python to disable building
165 PL/Python.])
167 python_libspec="-L${python_libdir} -l${ldlibrary}"
169 python_additional_libs=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
171 AC_MSG_RESULT([${python_libspec} ${python_additional_libs}])
173 AC_SUBST(python_libdir)[]dnl
174 AC_SUBST(python_libspec)[]dnl
175 AC_SUBST(python_additional_libs)[]dnl
177 ])# PGAC_CHECK_PYTHON_EMBED_SETUP