]> git.ipfire.org Git - thirdparty/Python/cpython.git/blame - configure.ac
GH-109369: Merge all eval-breaker flags and monitoring version into one word. (GH...
[thirdparty/Python/cpython.git] / configure.ac
CommitLineData
5d6e8c1c
CH
1dnl ***************************************************
2dnl * Please run autoreconf -if to test your changes! *
3dnl ***************************************************
4dnl
8a8ebf2e
EA
5dnl Python's configure script requires autoconf 2.71, autoconf-archive,
6dnl pkgconf's m4 macros.
7dnl
8dnl It is recommended to use a cpython_autoconf container to regenerate the
9dnl configure script:
10dnl
11dnl podman run --rm --pull=always -v $(pwd):/src:Z quay.io/tiran/cpython_autoconf:271
12dnl docker run --rm --pull=always -v $(pwd):/src quay.io/tiran/cpython_autoconf:271
5d6e8c1c 13dnl
88afe666
ML
14
15# Set VERSION so we only need to edit in one place (i.e., here)
2ea34cfb 16m4_define([PYTHON_VERSION], [3.13])
88afe666 17
8a8ebf2e 18AC_PREREQ([2.71])
b89910f4 19
af368a7d 20AC_INIT([python],[PYTHON_VERSION],[https://github.com/python/cpython/issues/])
8c6f88ef 21
5d6e8c1c
CH
22m4_ifdef(
23 [AX_C_FLOAT_WORDS_BIGENDIAN],
24 [],
25 [AC_MSG_ERROR([Please install autoconf-archive package and re-run autoreconf])]
be3cd5c0
CH
26)dnl
27m4_ifdef(
28 [PKG_PROG_PKG_CONFIG],
29 [],
30 [AC_MSG_ERROR([Please install pkgconf's m4 macro package and re-run autoreconf])]
31)dnl
ff5be6e8 32
db2277a1
EEA
33dnl Helpers for saving and restoring environment variables:
34dnl - _SAVE_VAR([VAR]) Helper for SAVE_ENV; stores VAR as save_VAR
35dnl - _RESTORE_VAR([VAR]) Helper for RESTORE_ENV; restores VAR from save_VAR
36dnl - SAVE_ENV Saves CFLAGS, LDFLAGS, LIBS, and CPPFLAGS
37dnl - RESTORE_ENV Restores CFLAGS, LDFLAGS, LIBS, and CPPFLAGS
38dnl - WITH_SAVE_ENV([SCRIPT]) Runs SCRIPT wrapped with SAVE_ENV/RESTORE_ENV
39AC_DEFUN([_SAVE_VAR], [AS_VAR_COPY([save_][$1], [$1])])dnl
40AC_DEFUN([_RESTORE_VAR], [AS_VAR_COPY([$1], [save_][$1])])dnl
41AC_DEFUN([SAVE_ENV],
42[_SAVE_VAR([CFLAGS])]
43[_SAVE_VAR([CPPFLAGS])]
44[_SAVE_VAR([LDFLAGS])]
45[_SAVE_VAR([LIBS])]
46)dnl
47AC_DEFUN([RESTORE_ENV],
48[_RESTORE_VAR([CFLAGS])]
49[_RESTORE_VAR([CPPFLAGS])]
50[_RESTORE_VAR([LDFLAGS])]
51[_RESTORE_VAR([LIBS])]
52)dnl
53AC_DEFUN([WITH_SAVE_ENV],
54[SAVE_ENV]
55[$1]
56[RESTORE_ENV]
57)dnl
58
bb8b9313
CH
59dnl PY_CHECK_FUNC(FUNCTION, [INCLUDES], [AC_DEFINE-VAR])
60AC_DEFUN([PY_CHECK_FUNC],
61[ AS_VAR_PUSHDEF([py_var], [ac_cv_func_$1])
62 AS_VAR_PUSHDEF([py_define], m4_ifblank([$3], [[HAVE_]m4_toupper($1)], [$3]))
63 AC_CACHE_CHECK(
64 [for $1],
65 [py_var],
66 [AC_COMPILE_IFELSE(
67 [AC_LANG_PROGRAM([$2], [void *x=$1])],
68 [AS_VAR_SET([py_var], [yes])],
69 [AS_VAR_SET([py_var], [no])])]
70 )
71 AS_VAR_IF(
72 [py_var],
73 [yes],
74 [AC_DEFINE([py_define], [1], [Define if you have the '$1' function.])])
75 AS_VAR_POPDEF([py_var])
76 AS_VAR_POPDEF([py_define])
77])
78
944ff8c5
CH
79dnl PY_CHECK_LIB(LIBRARY, FUNCTION, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], [OTHER-LIBRARIES])
80dnl Like AC_CHECK_LIB() but does not modify LIBS
81AC_DEFUN([PY_CHECK_LIB],
82[AS_VAR_COPY([py_check_lib_save_LIBS], [LIBS])]
2ea34cfb 83[AC_CHECK_LIB([$1], [$2], [$3], [$4], [$5])]
944ff8c5
CH
84[AS_VAR_COPY([LIBS], [py_check_lib_save_LIBS])]
85)
86
87dnl PY_CHECK_EMSCRIPTEN_PORT(PKG_VAR, [EMPORT_ARGS])
88dnl Use Emscripten port unless user passes ${PKG_VAR}_CFLAGS
89dnl or ${PKG_VAR}_LIBS to configure.
90AC_DEFUN([PY_CHECK_EMSCRIPTEN_PORT], [
91 AS_VAR_PUSHDEF([py_cflags], [$1_CFLAGS])
92 AS_VAR_PUSHDEF([py_libs], [$1_LIBS])
93 AS_IF([test "$ac_sys_system" = "Emscripten" -a -z "$py_cflags" -a -z "$py_libs"], [
94 py_cflags="$2"
95 py_libs="$2"
96 ])
97 AS_VAR_POPDEF([py_cflags])
98 AS_VAR_POPDEF([py_libs])
99])
100
2ea34cfb 101AC_SUBST([BASECPPFLAGS])
c5ee3caa 102if test "$srcdir" != . -a "$srcdir" != "$(pwd)"; then
4d4ec650
TN
103 # If we're building out-of-tree, we need to make sure the following
104 # resources get picked up before their $srcdir counterparts.
105 # Objects/ -> typeslots.inc
94faa072 106 # Include/ -> Python.h
4d4ec650
TN
107 # (A side effect of this is that these resources will automatically be
108 # regenerated when building out-of-tree, regardless of whether or not
109 # the $srcdir counterpart is up-to-date. This is an acceptable trade
110 # off.)
111 BASECPPFLAGS="-IObjects -IInclude -IPython"
112else
113 BASECPPFLAGS=""
114fi
115
2ea34cfb
EA
116AC_SUBST([GITVERSION])
117AC_SUBST([GITTAG])
118AC_SUBST([GITBRANCH])
8c6f88ef 119
5facdbb2 120if test -e $srcdir/.git
8c6f88ef 121then
2ea34cfb 122AC_CHECK_PROG([HAS_GIT], [git], [found], [not-found])
8c6f88ef 123else
5c4b0d06 124HAS_GIT=no-repository
8c6f88ef 125fi
5c4b0d06 126if test $HAS_GIT = found
8c6f88ef 127then
4c855577
XZ
128 GITVERSION="git --git-dir \$(srcdir)/.git rev-parse --short HEAD"
129 GITTAG="git --git-dir \$(srcdir)/.git describe --all --always --dirty"
130 GITBRANCH="git --git-dir \$(srcdir)/.git name-rev --name-only HEAD"
8c6f88ef 131else
5c4b0d06
ND
132 GITVERSION=""
133 GITTAG=""
134 GITBRANCH=""
8c6f88ef
BP
135fi
136
88afe666 137AC_CONFIG_SRCDIR([Include/object.h])
cbab997e 138AC_CONFIG_HEADERS([pyconfig.h])
627b2d7c 139
ca2f6ecf 140AC_CANONICAL_HOST
2ea34cfb
EA
141AC_SUBST([build])
142AC_SUBST([host])
ca2f6ecf 143
992565f7
CH
144AS_VAR_IF([cross_compiling], [maybe],
145 [AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH])]
146)
147
fcbc246e
ND
148# pybuilddir.txt will be created by --generate-posix-vars in the Makefile
149rm -f pybuilddir.txt
150
2ea34cfb 151AC_ARG_WITH([build-python],
992565f7 152 [AS_HELP_STRING([--with-build-python=python]PYTHON_VERSION,
612e59b5 153 [path to build python binary for cross compiling (default: _bootstrap_python or python]PYTHON_VERSION[)])],
992565f7
CH
154 [
155 AC_MSG_CHECKING([for --with-build-python])
156
992565f7 157 AS_VAR_IF([with_build_python], [yes], [with_build_python=python$PACKAGE_VERSION])
612e59b5 158 AS_VAR_IF([with_build_python], [no], [AC_MSG_ERROR([invalid --with-build-python option: expected path or "yes", not "no"])])
992565f7
CH
159
160 if ! $(command -v "$with_build_python" >/dev/null 2>&1); then
161 AC_MSG_ERROR([invalid or missing build python binary "$with_build_python"])
162 fi
163 build_python_ver=$($with_build_python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
164 if test "$build_python_ver" != "$PACKAGE_VERSION"; then
165 AC_MSG_ERROR(["$with_build_python" has incompatible version $build_python_ver (expected: $PACKAGE_VERSION)])
166 fi
84ca1232 167 dnl Build Python interpreter is used for regeneration and freezing.
992565f7 168 ac_cv_prog_PYTHON_FOR_REGEN=$with_build_python
84ca1232 169 PYTHON_FOR_FREEZE="$with_build_python"
992565f7
CH
170 PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) '$with_build_python
171 AC_MSG_RESULT([$with_build_python])
172 ], [
173 AS_VAR_IF([cross_compiling], [yes],
174 [AC_MSG_ERROR([Cross compiling requires --with-build-python])]
175 )
176 PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
84ca1232 177 PYTHON_FOR_FREEZE="./_bootstrap_python"
992565f7
CH
178 ]
179)
180AC_SUBST([PYTHON_FOR_BUILD])
181
84ca1232
CH
182AC_MSG_CHECKING([for Python interpreter freezing])
183AC_MSG_RESULT([$PYTHON_FOR_FREEZE])
184AC_SUBST([PYTHON_FOR_FREEZE])
185
eb483c46
CH
186AS_VAR_IF([cross_compiling], [yes],
187 [
188 dnl external build Python, freezing depends on Programs/_freeze_module.py
189 FREEZE_MODULE_BOOTSTRAP='$(PYTHON_FOR_FREEZE) $(srcdir)/Programs/_freeze_module.py'
190 FREEZE_MODULE_BOOTSTRAP_DEPS='$(srcdir)/Programs/_freeze_module.py'
191 FREEZE_MODULE='$(FREEZE_MODULE_BOOTSTRAP)'
192 FREEZE_MODULE_DEPS='$(FREEZE_MODULE_BOOTSTRAP_DEPS)'
084023cc 193 PYTHON_FOR_BUILD_DEPS=''
eb483c46
CH
194 ],
195 [
196 dnl internal build tools also depend on Programs/_freeze_module and _bootstrap_python.
197 FREEZE_MODULE_BOOTSTRAP='./Programs/_freeze_module'
198 FREEZE_MODULE_BOOTSTRAP_DEPS="Programs/_freeze_module"
199 FREEZE_MODULE='$(PYTHON_FOR_FREEZE) $(srcdir)/Programs/_freeze_module.py'
200 FREEZE_MODULE_DEPS="_bootstrap_python \$(srcdir)/Programs/_freeze_module.py"
084023cc 201 PYTHON_FOR_BUILD_DEPS='$(BUILDPYTHON)'
eb483c46
CH
202 ]
203)
204AC_SUBST([FREEZE_MODULE_BOOTSTRAP])
205AC_SUBST([FREEZE_MODULE_BOOTSTRAP_DEPS])
206AC_SUBST([FREEZE_MODULE])
207AC_SUBST([FREEZE_MODULE_DEPS])
084023cc 208AC_SUBST([PYTHON_FOR_BUILD_DEPS])
eb483c46 209
f840398a 210AC_CHECK_PROGS([PYTHON_FOR_REGEN],
500b0f48 211 [python$PACKAGE_VERSION python3.13 python3.12 python3.11 python3.10 python3 python],
f840398a 212 [python3])
2ea34cfb 213AC_SUBST([PYTHON_FOR_REGEN])
fd0d5939 214
f840398a 215AC_MSG_CHECKING([Python for regen version])
84ca1232 216if command -v "$PYTHON_FOR_REGEN" >/dev/null 2>&1; then
f840398a
CH
217 AC_MSG_RESULT([$($PYTHON_FOR_REGEN -V 2>/dev/null)])
218else
219 AC_MSG_RESULT([missing])
220fi
221
d23f8224
BP
222dnl Ensure that if prefix is specified, it does not end in a slash. If
223dnl it does, we get path names containing '//' which is both ugly and
224dnl can cause trouble.
225
226dnl Last slash shouldn't be stripped if prefix=/
227if test "$prefix" != "/"; then
228 prefix=`echo "$prefix" | sed -e 's/\/$//g'`
1b80b240 229fi
d23f8224 230
8316feb1
ML
231dnl This is for stuff that absolutely must end up in pyconfig.h.
232dnl Please use pyport.h instead, if possible.
bddf5a57
ML
233AH_TOP([
234#ifndef Py_PYCONFIG_H
235#define Py_PYCONFIG_H
236])
1143799d 237AH_BOTTOM([
1143799d
ML
238/* Define the macros needed if on a UnixWare 7.x system. */
239#if defined(__USLC__) && defined(__SCO_VERSION__)
240#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
241#endif
bddf5a57
ML
242
243#endif /*Py_PYCONFIG_H*/
1143799d
ML
244])
245
8316feb1
ML
246# We don't use PACKAGE_ variables, and they cause conflicts
247# with other autoconf-based packages that include Python.h
248grep -v 'define PACKAGE_' <confdefs.h >confdefs.h.new
249rm confdefs.h
250mv confdefs.h.new confdefs.h
251
2ea34cfb 252AC_SUBST([VERSION])
88afe666 253VERSION=PYTHON_VERSION
642b6780 254
de7d8343 255# Version number of Python's own shared library file.
2ea34cfb 256AC_SUBST([SOVERSION])
1142de3f
ML
257SOVERSION=1.0
258
17b16e13 259# The later definition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
bcd93962
ML
260# certain features on NetBSD, so we need _NETBSD_SOURCE to re-enable
261# them.
2ea34cfb
EA
262AC_DEFINE([_NETBSD_SOURCE], [1],
263 [Define on NetBSD to activate all library features])
bcd93962 264
17b16e13 265# The later definition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
abccf41a
AM
266# certain features on FreeBSD, so we need __BSD_VISIBLE to re-enable
267# them.
2ea34cfb
EA
268AC_DEFINE([__BSD_VISIBLE], [1],
269 [Define on FreeBSD to activate all library features])
abccf41a 270
17b16e13 271# The later definition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
fcaf910a
GB
272# certain features on Mac OS X, so we need _DARWIN_C_SOURCE to re-enable
273# them.
2ea34cfb
EA
274AC_DEFINE([_DARWIN_C_SOURCE], [1],
275 [Define on Darwin to activate all library features])
fcaf910a
GB
276
277
e981a4eb 278define_xopen_source=yes
6f18a3c1 279
4edbc2a5 280# Arguments passed to configure.
2ea34cfb 281AC_SUBST([CONFIG_ARGS])
4edbc2a5
NS
282CONFIG_ARGS="$ac_configure_args"
283
fc9b6228 284dnl Allow users to disable pkg-config or require pkg-config
2ea34cfb 285AC_ARG_WITH([pkg-config],
fc9b6228
CH
286 [AS_HELP_STRING([[--with-pkg-config=[yes|no|check]]],
287 [use pkg-config to detect build options (default is check)])],
288 [],
289 [with_pkg_config=check]
290)
291AS_CASE([$with_pkg_config],
292 [yes|check], [
293 if test -z "$PKG_CONFIG"; then
294 dnl invalidate stale config.cache values
295 AS_UNSET([PKG_CONFIG])
296 AS_UNSET([ac_cv_path_ac_pt_PKG_CONFIG])
297 AS_UNSET([ac_cv_prog_ac_ct_PKG_CONFIG])
298 fi
299 PKG_PROG_PKG_CONFIG
300 ],
301 [no], [
302 PKG_CONFIG=''
303 dnl force AX_CHECK_OPENSSL to ignore pkg-config
304 ac_cv_path_ac_pt_PKG_CONFIG=''
305 ac_cv_prog_ac_ct_PKG_CONFIG=''
306 ],
307 [AC_MSG_ERROR([invalid argument --with-pkg-config=$with_pkg_config])]
308)
309if test "$with_pkg_config" = yes -a -z "$PKG_CONFIG"; then
310 AC_MSG_ERROR([pkg-config is required])]
311fi
312
8af24c11 313AC_MSG_CHECKING([for --enable-universalsdk])
2ea34cfb 314AC_ARG_ENABLE([universalsdk],
2de064e6
AS
315 AS_HELP_STRING([--enable-universalsdk@<:@=SDKDIR@:>@],
316 [create a universal binary build.
317 SDKDIR specifies which macOS SDK should be used to perform the build,
318 see Mac/README.rst. (default is no)]),
477c8d5e
TW
319[
320 case $enableval in
321 yes)
b5c246f8 322 # Locate the best usable SDK, see Mac/README for more
cbfb9a56
ND
323 # information
324 enableval="`/usr/bin/xcodebuild -version -sdk macosx Path 2>/dev/null`"
87adb6ef 325 if ! ( echo $enableval | grep -E '\.sdk' 1>/dev/null )
8af24c11 326 then
cbfb9a56
ND
327 enableval=/Developer/SDKs/MacOSX10.4u.sdk
328 if test ! -d "${enableval}"
329 then
330 enableval=/
331 fi
8af24c11 332 fi
477c8d5e
TW
333 ;;
334 esac
335 case $enableval in
336 no)
337 UNIVERSALSDK=
338 enable_universalsdk=
339 ;;
340 *)
341 UNIVERSALSDK=$enableval
8af24c11
RO
342 if test ! -d "${UNIVERSALSDK}"
343 then
344 AC_MSG_ERROR([--enable-universalsdk specifies non-existing SDK: ${UNIVERSALSDK}])
345 fi
477c8d5e
TW
346 ;;
347 esac
1b80b240 348
477c8d5e
TW
349],[
350 UNIVERSALSDK=
351 enable_universalsdk=
352])
8af24c11
RO
353if test -n "${UNIVERSALSDK}"
354then
2ea34cfb 355 AC_MSG_RESULT([${UNIVERSALSDK}])
8af24c11 356else
2ea34cfb 357 AC_MSG_RESULT([no])
8af24c11 358fi
2ea34cfb 359AC_SUBST([UNIVERSALSDK])
477c8d5e 360
2ea34cfb 361AC_SUBST([ARCH_RUN_32BIT])
87adb6ef 362ARCH_RUN_32BIT=""
6794aa3c 363
cbfb9a56
ND
364# For backward compatibility reasons we prefer to select '32-bit' if available,
365# otherwise use 'intel'
fcaf910a 366UNIVERSAL_ARCHS="32-bit"
cbfb9a56
ND
367if test "`uname -s`" = "Darwin"
368then
369 if test -n "${UNIVERSALSDK}"
370 then
87adb6ef 371 if test -z "`/usr/bin/file -L "${UNIVERSALSDK}/usr/lib/libSystem.dylib" | grep ppc`"
cbfb9a56
ND
372 then
373 UNIVERSAL_ARCHS="intel"
374 fi
375 fi
376fi
377
2ea34cfb
EA
378AC_SUBST([LIPO_32BIT_FLAGS])
379AC_SUBST([LIPO_INTEL64_FLAGS])
380AC_MSG_CHECKING([for --with-universal-archs])
381AC_ARG_WITH([universal-archs],
2de064e6 382 AS_HELP_STRING([--with-universal-archs=ARCH],
0cb33da1
ND
383 [specify the kind of macOS universal binary that should be created.
384 This option is only valid when --enable-universalsdk is set; options are:
385 ("universal2", "intel-64", "intel-32", "intel", "32-bit",
386 "64-bit", "3-way", or "all")
2de064e6 387 see Mac/README.rst]),
fcaf910a 388[
fcaf910a
GB
389 UNIVERSAL_ARCHS="$withval"
390],
87adb6ef
ND
391[])
392if test -n "${UNIVERSALSDK}"
393then
2ea34cfb 394 AC_MSG_RESULT([${UNIVERSAL_ARCHS}])
87adb6ef 395else
2ea34cfb 396 AC_MSG_RESULT([no])
87adb6ef 397fi
fcaf910a 398
2ea34cfb 399AC_ARG_WITH([framework-name],
2b8733fb 400 AS_HELP_STRING([--with-framework-name=FRAMEWORK],
2de064e6
AS
401 [specify the name for the python framework on macOS
402 only valid when --enable-framework is set. see Mac/README.rst
403 (default is 'Python')]),
81ee3efe
CH
404[
405 PYTHONFRAMEWORK=${withval}
406 PYTHONFRAMEWORKDIR=${withval}.framework
407 PYTHONFRAMEWORKIDENTIFIER=org.python.`echo $withval | tr '[A-Z]' '[a-z]'`
408 ],[
409 PYTHONFRAMEWORK=Python
410 PYTHONFRAMEWORKDIR=Python.framework
411 PYTHONFRAMEWORKIDENTIFIER=org.python.python
412])
3e2c6326 413dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
2ea34cfb 414AC_ARG_ENABLE([framework],
2de064e6
AS
415 AS_HELP_STRING([--enable-framework@<:@=INSTALLDIR@:>@],
416 [create a Python.framework rather than a traditional Unix install.
417 optional INSTALLDIR specifies the installation path. see Mac/README.rst
418 (default is no)]),
3e2c6326 419[
b6e9cad3 420 case $enableval in
1b80b240 421 yes)
b6e9cad3 422 enableval=/Library/Frameworks
127e56e5
JJ
423 esac
424 case $enableval in
425 no)
426 PYTHONFRAMEWORK=
427 PYTHONFRAMEWORKDIR=no-framework
428 PYTHONFRAMEWORKPREFIX=
429 PYTHONFRAMEWORKINSTALLDIR=
477c8d5e
TW
430 FRAMEWORKINSTALLFIRST=
431 FRAMEWORKINSTALLLAST=
73e5a5b6
TW
432 FRAMEWORKALTINSTALLFIRST=
433 FRAMEWORKALTINSTALLLAST=
b8f944f0 434 FRAMEWORKPYTHONW=
73e5a5b6
TW
435 if test "x${prefix}" = "xNONE"; then
436 FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
437 else
438 FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
439 fi
127e56e5 440 enable_framework=
b6e9cad3
JJ
441 ;;
442 *)
86b33c87 443 PYTHONFRAMEWORKPREFIX="${enableval}"
127e56e5 444 PYTHONFRAMEWORKINSTALLDIR=$PYTHONFRAMEWORKPREFIX/$PYTHONFRAMEWORKDIR
477c8d5e 445 FRAMEWORKINSTALLFIRST="frameworkinstallstructure"
f6ccbf60 446 FRAMEWORKALTINSTALLFIRST="frameworkinstallstructure "
6f6c5624
RO
447 FRAMEWORKINSTALLLAST="frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools"
448 FRAMEWORKALTINSTALLLAST="frameworkinstallmaclib frameworkinstallapps frameworkaltinstallunixtools"
b8f944f0 449 FRAMEWORKPYTHONW="frameworkpythonw"
86b33c87 450 FRAMEWORKINSTALLAPPSPREFIX="/Applications"
fcaf910a 451
73e5a5b6
TW
452 if test "x${prefix}" = "xNONE" ; then
453 FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
86b33c87 454
73e5a5b6
TW
455 else
456 FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
457 fi
86b33c87
RO
458
459 case "${enableval}" in
460 /System*)
461 FRAMEWORKINSTALLAPPSPREFIX="/Applications"
462 if test "${prefix}" = "NONE" ; then
463 # See below
464 FRAMEWORKUNIXTOOLSPREFIX="/usr"
465 fi
466 ;;
467
468 /Library*)
469 FRAMEWORKINSTALLAPPSPREFIX="/Applications"
470 ;;
471
472 */Library/Frameworks)
473 MDIR="`dirname "${enableval}"`"
474 MDIR="`dirname "${MDIR}"`"
475 FRAMEWORKINSTALLAPPSPREFIX="${MDIR}/Applications"
476
477 if test "${prefix}" = "NONE"; then
1b80b240 478 # User hasn't specified the
86b33c87
RO
479 # --prefix option, but wants to install
480 # the framework in a non-default location,
481 # ensure that the compatibility links get
482 # installed relative to that prefix as well
483 # instead of in /usr/local.
484 FRAMEWORKUNIXTOOLSPREFIX="${MDIR}"
485 fi
486 ;;
487
488 *)
489 FRAMEWORKINSTALLAPPSPREFIX="/Applications"
490 ;;
491 esac
492
127e56e5 493 prefix=$PYTHONFRAMEWORKINSTALLDIR/Versions/$VERSION
477c8d5e 494
81ee3efe 495 # Add files for Mac specific code to the list of output
477c8d5e 496 # files:
2ea34cfb
EA
497 AC_CONFIG_FILES([Mac/Makefile])
498 AC_CONFIG_FILES([Mac/PythonLauncher/Makefile])
499 AC_CONFIG_FILES([Mac/Resources/framework/Info.plist])
500 AC_CONFIG_FILES([Mac/Resources/app/Info.plist])
b6e9cad3 501 esac
b6e9cad3
JJ
502 ],[
503 PYTHONFRAMEWORK=
127e56e5 504 PYTHONFRAMEWORKDIR=no-framework
b6e9cad3
JJ
505 PYTHONFRAMEWORKPREFIX=
506 PYTHONFRAMEWORKINSTALLDIR=
477c8d5e
TW
507 FRAMEWORKINSTALLFIRST=
508 FRAMEWORKINSTALLLAST=
73e5a5b6
TW
509 FRAMEWORKALTINSTALLFIRST=
510 FRAMEWORKALTINSTALLLAST=
b8f944f0 511 FRAMEWORKPYTHONW=
73e5a5b6
TW
512 if test "x${prefix}" = "xNONE" ; then
513 FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
514 else
515 FRAMEWORKUNIXTOOLSPREFIX="${prefix}"
516 fi
b6e9cad3 517 enable_framework=
fcaf910a 518
b6e9cad3 519])
2ea34cfb
EA
520AC_SUBST([PYTHONFRAMEWORK])
521AC_SUBST([PYTHONFRAMEWORKIDENTIFIER])
522AC_SUBST([PYTHONFRAMEWORKDIR])
523AC_SUBST([PYTHONFRAMEWORKPREFIX])
524AC_SUBST([PYTHONFRAMEWORKINSTALLDIR])
525AC_SUBST([FRAMEWORKINSTALLFIRST])
526AC_SUBST([FRAMEWORKINSTALLLAST])
527AC_SUBST([FRAMEWORKALTINSTALLFIRST])
528AC_SUBST([FRAMEWORKALTINSTALLLAST])
529AC_SUBST([FRAMEWORKPYTHONW])
530AC_SUBST([FRAMEWORKUNIXTOOLSPREFIX])
531AC_SUBST([FRAMEWORKINSTALLAPPSPREFIX])
b6e9cad3 532
2ea34cfb
EA
533AC_DEFINE_UNQUOTED([_PYTHONFRAMEWORK], ["${PYTHONFRAMEWORK}"],
534 [framework name])
a8f8d5b4 535
b418f89b 536# Set name for machine-dependent library files
eab42bf0 537AC_ARG_VAR([MACHDEP], [name for machine-dependent library files])
2ea34cfb 538AC_MSG_CHECKING([MACHDEP])
b418f89b
GR
539if test -z "$MACHDEP"
540then
df2aecbf
MK
541 # avoid using uname for cross builds
542 if test "$cross_compiling" = yes; then
44bbbdab 543 # ac_sys_system and ac_sys_release are used for setting
544 # a lot of different things including 'define_xopen_source'
545 # in the case statement below.
df2aecbf 546 case "$host" in
2a352b66
XG
547 *-*-linux-android*)
548 ac_sys_system=Linux-android
549 ;;
df2aecbf
MK
550 *-*-linux*)
551 ac_sys_system=Linux
552 ;;
553 *-*-cygwin*)
554 ac_sys_system=Cygwin
555 ;;
32f5fdd7 556 *-*-vxworks*)
557 ac_sys_system=VxWorks
558 ;;
1052a39b
CH
559 *-*-emscripten)
560 ac_sys_system=Emscripten
561 ;;
562 *-*-wasi)
563 ac_sys_system=WASI
564 ;;
df2aecbf
MK
565 *)
566 # for now, limit cross builds to known configurations
567 MACHDEP="unknown"
568 AC_MSG_ERROR([cross build not supported for $host])
569 esac
570 ac_sys_release=
571 else
4b6b5798 572 ac_sys_system=`uname -s`
8719ad5d 573 if test "$ac_sys_system" = "AIX" \
21ee4091 574 -o "$ac_sys_system" = "UnixWare" -o "$ac_sys_system" = "OpenUNIX"; then
4b6b5798 575 ac_sys_release=`uname -v`
b418f89b 576 else
4b6b5798 577 ac_sys_release=`uname -r`
b418f89b 578 fi
df2aecbf
MK
579 fi
580 ac_md_system=`echo $ac_sys_system |
581 tr -d '[/ ]' | tr '[[A-Z]]' '[[a-z]]'`
582 ac_md_release=`echo $ac_sys_release |
583 tr -d '[/ ]' | sed 's/^[[A-Z]]\.//' | sed 's/\..*//'`
584 MACHDEP="$ac_md_system$ac_md_release"
4b6b5798 585
df2aecbf 586 case $MACHDEP in
9d949f77 587 aix*) MACHDEP="aix";;
7209ff2b 588 linux*) MACHDEP="linux";;
5a3e4cb0 589 cygwin*) MACHDEP="cygwin";;
8a97f4a3 590 darwin*) MACHDEP="darwin";;
b97ef176 591 '') MACHDEP="unknown";;
df2aecbf 592 esac
b418f89b 593fi
2ea34cfb 594AC_MSG_RESULT(["$MACHDEP"])
1abe1c5f 595
2ea34cfb 596AC_SUBST([_PYTHON_HOST_PLATFORM])
1abe1c5f 597if test "$cross_compiling" = yes; then
598 case "$host" in
599 *-*-linux*)
600 case "$host_cpu" in
601 arm*)
602 _host_cpu=arm
603 ;;
604 *)
605 _host_cpu=$host_cpu
606 esac
607 ;;
608 *-*-cygwin*)
609 _host_cpu=
610 ;;
32f5fdd7 611 *-*-vxworks*)
612 _host_cpu=$host_cpu
613 ;;
1052a39b
CH
614 wasm32-*-* | wasm64-*-*)
615 _host_cpu=$host_cpu
616 ;;
1abe1c5f 617 *)
618 # for now, limit cross builds to known configurations
619 MACHDEP="unknown"
620 AC_MSG_ERROR([cross build not supported for $host])
621 esac
622 _PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
623fi
d3899c1a 624
e981a4eb
ML
625# Some systems cannot stand _XOPEN_SOURCE being defined at all; they
626# disable features if it is defined, without any means to access these
627# features as extensions. For these systems, we skip the definition of
628# _XOPEN_SOURCE. Before adding a system to the list to gain access to
629# some feature, make sure there is no alternative way to access this
630# feature. Also, when using wildcards, make sure you have verified the
631# need for not defining _XOPEN_SOURCE on all systems matching the
632# wildcard, and that the wildcard does not include future systems
633# (which may remove their limitations).
634dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
635case $ac_sys_system/$ac_sys_release in
636 # On OpenBSD, select(2) is not available if _XOPEN_SOURCE is defined,
637 # even though select is a POSIX function. Reported by J. Ribbens.
76bafc64 638 # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish.
19ed3c8b
ML
639 # In addition, Stefan Krah confirms that issue #1244610 exists through
640 # OpenBSD 4.6, but is fixed in 4.7.
1b80b240 641 OpenBSD/2.* | OpenBSD/3.* | OpenBSD/4.@<:@0123456@:>@)
5b5e81c6
CH
642 define_xopen_source=no
643 # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is
644 # also defined. This can be overridden by defining _BSD_SOURCE
645 # As this has a different meaning on Linux, only define it on OpenBSD
2ea34cfb
EA
646 AC_DEFINE([_BSD_SOURCE], [1],
647 [Define on OpenBSD to activate all library features])
5b5e81c6 648 ;;
54ef40b0 649 OpenBSD/*)
7671efc1
ML
650 # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is
651 # also defined. This can be overridden by defining _BSD_SOURCE
652 # As this has a different meaning on Linux, only define it on OpenBSD
2ea34cfb
EA
653 AC_DEFINE([_BSD_SOURCE], [1],
654 [Define on OpenBSD to activate all library features])
7671efc1 655 ;;
89f507fe
TW
656 # Defining _XOPEN_SOURCE on NetBSD version prior to the introduction of
657 # _NETBSD_SOURCE disables certain features (eg. setgroups). Reported by
658 # Marc Recht
f608c613 659 NetBSD/1.5 | NetBSD/1.5.* | NetBSD/1.6 | NetBSD/1.6.* | NetBSD/1.6@<:@A-S@:>@)
e981a4eb 660 define_xopen_source=no;;
1a415762
ML
661 # From the perspective of Solaris, _XOPEN_SOURCE is not so much a
662 # request to enable features supported by the standard as a request
663 # to disable features not supported by the standard. The best way
664 # for Python to use Solaris is simply to leave _XOPEN_SOURCE out
665 # entirely and define __EXTENSIONS__ instead.
666 SunOS/*)
a9d71420 667 define_xopen_source=no;;
c2409b4f
ML
668 # On UnixWare 7, u_long is never defined with _XOPEN_SOURCE,
669 # but used in /usr/include/netinet/tcp.h. Reported by Tim Rice.
253d1f44
ML
670 # Reconfirmed for 7.1.4 by Martin v. Loewis.
671 OpenUNIX/8.0.0| UnixWare/7.1.@<:@0-4@:>@)
c2409b4f
ML
672 define_xopen_source=no;;
673 # On OpenServer 5, u_short is never defined with _XOPEN_SOURCE,
53e73c36 674 # but used in struct sockaddr.sa_family. Reported by Tim Rice.
c2409b4f 675 SCO_SV/3.2)
53e73c36 676 define_xopen_source=no;;
1b80b240 677 # On MacOS X 10.2, a bug in ncurses.h means that it craps out if
b37509b1
ML
678 # _XOPEN_EXTENDED_SOURCE is defined. Apparently, this is fixed in 10.3, which
679 # identifies itself as Darwin/7.*
680 # On Mac OS X 10.4, defining _POSIX_C_SOURCE or _XOPEN_SOURCE
681 # disables platform specific features beyond repair.
1b80b240 682 # On Mac OS X 10.3, defining _POSIX_C_SOURCE or _XOPEN_SOURCE
b37509b1
ML
683 # has no effect, don't bother defining them
684 Darwin/@<:@6789@:>@.*)
6169c6bc 685 define_xopen_source=no;;
8ea6353f 686 Darwin/@<:@[12]@:>@@<:@0-9@:>@.*)
b8f11a66 687 define_xopen_source=no;;
f78e02b7
GB
688 # On QNX 6.3.2, defining _XOPEN_SOURCE prevents netdb.h from
689 # defining NI_NUMERICHOST.
690 QNX/6.3.2)
691 define_xopen_source=no
692 ;;
32f5fdd7 693 # On VxWorks, defining _XOPEN_SOURCE causes compile failures
694 # in network headers still using system V types.
695 VxWorks/*)
696 define_xopen_source=no
697 ;;
7026a0ae 698
a9edf44a
IN
699 # On HP-UX, defining _XOPEN_SOURCE to 600 or greater hides
700 # chroot() and other functions
701 hp*|HP*)
702 define_xopen_source=no
703 ;;
704
e981a4eb
ML
705esac
706
707if test $define_xopen_source = yes
708then
14d098d3 709 # X/Open 7, incorporating POSIX.1-2008
2ea34cfb
EA
710 AC_DEFINE([_XOPEN_SOURCE], [700],
711 [Define to the level of X/Open that your system supports])
678fc1ee
ML
712
713 # On Tru64 Unix 4.0F, defining _XOPEN_SOURCE also requires
714 # definition of _XOPEN_SOURCE_EXTENDED and _POSIX_C_SOURCE, or else
715 # several APIs are not declared. Since this is also needed in some
716 # cases for HP-UX, we define it globally.
2ea34cfb
EA
717 AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1],
718 [Define to activate Unix95-and-earlier features])
678fc1ee 719
2ea34cfb
EA
720 AC_DEFINE([_POSIX_C_SOURCE], [200809L],
721 [Define to activate features from IEEE Stds 1003.1-2008])
e981a4eb
ML
722fi
723
647cd871
CH
724# On HP-UX mbstate_t requires _INCLUDE__STDC_A1_SOURCE
725case $ac_sys_system in
b02bcae5
CH
726 hp*|HP*)
727 define_stdc_a1=yes;;
728 *)
729 define_stdc_a1=no;;
647cd871
CH
730esac
731
b02bcae5
CH
732if test $define_stdc_a1 = yes
733then
2ea34cfb
EA
734 AC_DEFINE([_INCLUDE__STDC_A1_SOURCE], [1],
735 [Define to include mbstate_t for mbrtowc])
b02bcae5
CH
736fi
737
6b08a404
JJ
738# Record the configure-time value of MACOSX_DEPLOYMENT_TARGET,
739# it may influence the way we can build extensions, so distutils
740# needs to check it
2ea34cfb
EA
741AC_SUBST([CONFIGURE_MACOSX_DEPLOYMENT_TARGET])
742AC_SUBST([EXPORT_MACOSX_DEPLOYMENT_TARGET])
6b08a404 743CONFIGURE_MACOSX_DEPLOYMENT_TARGET=
477c8d5e 744EXPORT_MACOSX_DEPLOYMENT_TARGET='#'
6b08a404 745
627b2d7c 746# checks for alternative programs
decc6a47
SM
747
748# compiler flags are generated in two sets, BASECFLAGS and OPT. OPT is just
749# for debug/optimization stuff. BASECFLAGS is for flags that are required
750# just to get things to compile and link. Users are free to override OPT
751# when running configure or make. The build should not break if they do.
752# BASECFLAGS should generally not be messed with, however.
753
49fd7fa4
TW
754# If the user switches compilers, we can't believe the cache
755if test ! -z "$ac_cv_prog_CC" -a ! -z "$CC" -a "$CC" != "$ac_cv_prog_CC"
756then
757 AC_MSG_ERROR([cached CC is different -- throw away $cache_file
758(it is also a good idea to do 'make clean' before compiling)])
759fi
760
d4fcdb1e
JY
761# Don't let AC_PROG_CC set the default CFLAGS. It normally sets -g -O2
762# when the compiler supports them, but we don't always want -O2, and
763# we set -g later.
764if test -z "$CFLAGS"; then
765 CFLAGS=
df700f07 766fi
cbfb9a56 767
32ac98e8
CH
768dnl Emscripten SDK and WASI SDK default to wasm32.
769dnl On Emscripten use MEMORY64 setting to build target wasm64-emscripten.
770dnl for wasm64.
771AS_CASE([$host],
772 [wasm64-*-emscripten], [
773 AS_VAR_APPEND([CFLAGS], [" -sMEMORY64=1"])
774 AS_VAR_APPEND([LDFLAGS], [" -sMEMORY64=1"])
775 ],
776)
777
cbfb9a56
ND
778if test "$ac_sys_system" = "Darwin"
779then
bb8b9313
CH
780 dnl look for SDKROOT
781 AC_CHECK_PROG([HAS_XCRUN], [xcrun], [yes], [missing])
782 AC_MSG_CHECKING([macOS SDKROOT])
783 if test -z "$SDKROOT"; then
784 dnl SDKROOT not set
785 if test "$HAS_XCRUN" = "yes"; then
786 dnl detect with Xcode
787 SDKROOT=$(xcrun --show-sdk-path)
788 else
789 dnl default to root
790 SDKROOT="/"
791 fi
792 fi
793 AC_MSG_RESULT([$SDKROOT])
794
cbfb9a56 795 # Compiler selection on MacOSX is more complicated than
b5c246f8 796 # AC_PROG_CC can handle, see Mac/README for more
cbfb9a56
ND
797 # information
798 if test -z "${CC}"
799 then
800 found_gcc=
801 found_clang=
802 as_save_IFS=$IFS; IFS=:
803 for as_dir in $PATH
804 do
805 IFS=$as_save_IFS
14aa00b5 806 if test -x "${as_dir}/gcc"; then
cbfb9a56 807 if test -z "${found_gcc}"; then
14aa00b5 808 found_gcc="${as_dir}/gcc"
cbfb9a56
ND
809 fi
810 fi
14aa00b5 811 if test -x "${as_dir}/clang"; then
cbfb9a56 812 if test -z "${found_clang}"; then
14aa00b5 813 found_clang="${as_dir}/clang"
cbfb9a56
ND
814 fi
815 fi
816 done
817 IFS=$as_save_IFS
818
819 if test -n "$found_gcc" -a -n "$found_clang"
820 then
821 if test -n "`"$found_gcc" --version | grep llvm-gcc`"
822 then
823 AC_MSG_NOTICE([Detected llvm-gcc, falling back to clang])
824 CC="$found_clang"
825 CXX="$found_clang++"
826 fi
827
828
829 elif test -z "$found_gcc" -a -n "$found_clang"
830 then
831 AC_MSG_NOTICE([No GCC found, use CLANG])
832 CC="$found_clang"
833 CXX="$found_clang++"
834
835 elif test -z "$found_gcc" -a -z "$found_clang"
836 then
837 found_clang=`/usr/bin/xcrun -find clang 2>/dev/null`
838 if test -n "${found_clang}"
839 then
840 AC_MSG_NOTICE([Using clang from Xcode.app])
841 CC="${found_clang}"
842 CXX="`/usr/bin/xcrun -find clang++`"
843
844 # else: use default behaviour
845 fi
846 fi
847 fi
848fi
d4fcdb1e 849AC_PROG_CC
d3899c1a 850AC_PROG_CPP
851AC_PROG_GREP
a785c87d 852AC_PROG_SED
cbab997e
CH
853AC_PROG_EGREP
854
3124d9a5
CH
855dnl detect compiler name
856dnl check for xlc before clang, newer xlc's can use clang as frontend.
857dnl check for GCC last, other compilers set __GNUC__, too.
858dnl msvc is listed for completeness.
859AC_CACHE_CHECK([for CC compiler name], [ac_cv_cc_name], [
860cat > conftest.c <<EOF
861#if defined(__INTEL_COMPILER) || defined(__ICC)
862 icc
863#elif defined(__ibmxl__) || defined(__xlc__) || defined(__xlC__)
864 xlc
865#elif defined(_MSC_VER)
866 msvc
867#elif defined(__clang__)
868 clang
869#elif defined(__GNUC__)
870 gcc
871#else
872# error unknown compiler
873#endif
874EOF
875
876if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
877 ac_cv_cc_name=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
878else
879 ac_cv_cc_name="unknown"
880fi
881rm -f conftest.c conftest.out
882])
883
cbab997e
CH
884# checks for UNIX variants that set C preprocessor variables
885# may set _GNU_SOURCE, __EXTENSIONS__, _POSIX_PTHREAD_SEMANTICS,
886# _POSIX_SOURCE, _POSIX_1_SOURCE, and more
887AC_USE_SYSTEM_EXTENSIONS
49fd7fa4 888
2ea34cfb 889AC_SUBST([CXX])
537970fe 890
49fd7fa4
TW
891preset_cxx="$CXX"
892if test -z "$CXX"
54241138 893then
49fd7fa4 894 case "$CC" in
2ea34cfb
EA
895 gcc) AC_PATH_TOOL([CXX], [g++], [g++], [notfound]) ;;
896 cc) AC_PATH_TOOL([CXX], [c++], [c++], [notfound]) ;;
897 clang|*/clang) AC_PATH_TOOL([CXX], [clang++], [clang++], [notfound]) ;;
898 icc|*/icc) AC_PATH_TOOL([CXX], [icpc], [icpc], [notfound]) ;;
49fd7fa4
TW
899 esac
900 if test "$CXX" = "notfound"
901 then
902 CXX=""
903 fi
54241138 904fi
49fd7fa4 905if test -z "$CXX"
537970fe 906then
2ea34cfb 907 AC_CHECK_TOOLS([CXX], [$CCC c++ g++ gcc CC cxx cc++ cl], [notfound])
537970fe
ML
908 if test "$CXX" = "notfound"
909 then
49fd7fa4 910 CXX=""
537970fe
ML
911 fi
912fi
49fd7fa4 913if test "$preset_cxx" != "$CXX"
03ad99f0 914then
fe32aec2 915 AC_MSG_NOTICE([
49fd7fa4
TW
916
917 By default, distutils will build C++ extension modules with "$CXX".
918 If this is not intended, then set CXX on the configure command line.
919 ])
03ad99f0
GR
920fi
921
1d5ecb7c 922
d3899c1a 923AC_MSG_CHECKING([for the platform triplet based on compiler characteristics])
c163d7f0
JT
924if $CPP $CPPFLAGS $srcdir/Misc/platform_triplet.c >conftest.out 2>/dev/null; then
925 PLATFORM_TRIPLET=`grep '^PLATFORM_TRIPLET=' conftest.out | tr -d ' '`
926 PLATFORM_TRIPLET="${PLATFORM_TRIPLET@%:@PLATFORM_TRIPLET=}"
d3899c1a 927 AC_MSG_RESULT([$PLATFORM_TRIPLET])
928else
929 AC_MSG_RESULT([none])
930fi
c163d7f0 931rm -f conftest.out
d3899c1a 932
cae55542
CH
933AC_MSG_CHECKING([for multiarch])
934AS_CASE([$ac_sys_system],
935 [Darwin*], [MULTIARCH=""],
936 [FreeBSD*], [MULTIARCH=""],
937 [MULTIARCH=$($CC --print-multiarch 2>/dev/null)]
938)
939AC_SUBST([MULTIARCH])
940AC_MSG_RESULT([$MULTIARCH])
9c476677 941
d3899c1a 942if test x$PLATFORM_TRIPLET != x && test x$MULTIARCH != x; then
943 if test x$PLATFORM_TRIPLET != x$MULTIARCH; then
944 AC_MSG_ERROR([internal configure error for the platform triplet, please file a bug report])
945 fi
75b1cb10 946elif test x$PLATFORM_TRIPLET != x && test x$MULTIARCH = x; then
947 MULTIARCH=$PLATFORM_TRIPLET
1b80b240 948fi
2ea34cfb 949AC_SUBST([PLATFORM_TRIPLET])
cae55542 950
5553231b 951if test x$MULTIARCH != x; then
952 MULTIARCH_CPPFLAGS="-DMULTIARCH=\\\"$MULTIARCH\\\""
953fi
2ea34cfb 954AC_SUBST([MULTIARCH_CPPFLAGS])
d3899c1a 955
3124d9a5
CH
956dnl Support tiers according to https://peps.python.org/pep-0011/
957dnl
958dnl NOTE: Windows support tiers are defined in PC/pyconfig.h.
959dnl
960AC_MSG_CHECKING([for PEP 11 support tier])
961AS_CASE([$host/$ac_cv_cc_name],
962 [x86_64-*-linux-gnu/gcc], [PY_SUPPORT_TIER=1], dnl Linux on AMD64, any vendor, glibc, gcc
963 [x86_64-apple-darwin*/clang], [PY_SUPPORT_TIER=1], dnl macOS on Intel, any version
964 [i686-pc-windows-msvc/msvc], [PY_SUPPORT_TIER=1], dnl 32bit Windows on Intel, MSVC
965 [x86_64-pc-windows-msvc/msvc], [PY_SUPPORT_TIER=1], dnl 64bit Windows on AMD64, MSVC
966
967 [aarch64-apple-darwin*/clang], [PY_SUPPORT_TIER=2], dnl macOS on M1, any version
968 [aarch64-*-linux-gnu/gcc], [PY_SUPPORT_TIER=2], dnl Linux ARM64, glibc, gcc+clang
969 [aarch64-*-linux-gnu/clang], [PY_SUPPORT_TIER=2],
970 [powerpc64le-*-linux-gnu/gcc], [PY_SUPPORT_TIER=2], dnl Linux on PPC64 little endian, glibc, gcc
971 [x86_64-*-linux-gnu/clang], [PY_SUPPORT_TIER=2], dnl Linux on AMD64, any vendor, glibc, clang
972
973 [aarch64-pc-windows-msvc/msvc], [PY_SUPPORT_TIER=3], dnl Windows ARM64, MSVC
974 [armv7l-*-linux-gnueabihf/gcc], [PY_SUPPORT_TIER=3], dnl ARMv7 LE with hardware floats, any vendor, glibc, gcc
975 [powerpc64le-*-linux-gnu/clang], [PY_SUPPORT_TIER=3], dnl Linux on PPC64 little endian, glibc, clang
976 [s390x-*-linux-gnu/gcc], [PY_SUPPORT_TIER=3], dnl Linux on 64bit s390x (big endian), glibc, gcc
daa64d6a
CH
977 [wasm32-unknown-emscripten/clang], [PY_SUPPORT_TIER=3], dnl WebAssembly Emscripten
978 [wasm32-unknown-wasi/clang], [PY_SUPPORT_TIER=3], dnl WebAssembly System Interface
67d208fb 979 [x86_64-*-freebsd*/clang], [PY_SUPPORT_TIER=3], dnl FreeBSD on AMD64
3124d9a5
CH
980 [PY_SUPPORT_TIER=0]
981)
982
983AS_CASE([$PY_SUPPORT_TIER],
984 [1], [AC_MSG_RESULT([$host/$ac_cv_cc_name has tier 1 (supported)])],
985 [2], [AC_MSG_RESULT([$host/$ac_cv_cc_name has tier 2 (supported)])],
986 [3], [AC_MSG_RESULT([$host/$ac_cv_cc_name has tier 3 (partially supported)])],
987 [AC_MSG_WARN([$host/$ac_cv_cc_name is not supported])]
988)
989
990AC_DEFINE_UNQUOTED([PY_SUPPORT_TIER], [$PY_SUPPORT_TIER], [PEP 11 Support tier (1, 2, 3 or 0 for unsupported)])
991
76d14fac
EEA
992AC_CACHE_CHECK([for -Wl,--no-as-needed], [ac_cv_wl_no_as_needed], [
993 save_LDFLAGS="$LDFLAGS"
bb8b9313 994 AS_VAR_APPEND([LDFLAGS], [" -Wl,--no-as-needed"])
76d14fac
EEA
995 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
996 [NO_AS_NEEDED="-Wl,--no-as-needed"
997 ac_cv_wl_no_as_needed=yes],
998 [NO_AS_NEEDED=""
999 ac_cv_wl_no_as_needed=no])
1000 LDFLAGS="$save_LDFLAGS"
1001])
2ea34cfb 1002AC_SUBST([NO_AS_NEEDED])
48e14d3f 1003
95750b1c 1004AC_MSG_CHECKING([for the Android API level])
b1288964 1005cat > conftest.c <<EOF
95750b1c 1006#ifdef __ANDROID__
2a352b66
XG
1007android_api = __ANDROID_API__
1008arm_arch = __ARM_ARCH
95750b1c
XG
1009#else
1010#error not Android
1011#endif
1012EOF
1013
1014if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
2a352b66
XG
1015 ANDROID_API_LEVEL=`sed -n -e '/__ANDROID_API__/d' -e 's/^android_api = //p' conftest.out`
1016 _arm_arch=`sed -n -e '/__ARM_ARCH/d' -e 's/^arm_arch = //p' conftest.out`
95750b1c 1017 AC_MSG_RESULT([$ANDROID_API_LEVEL])
c06c22e9 1018 if test -z "$ANDROID_API_LEVEL"; then
74b23c97 1019 AC_MSG_ERROR([Fatal: you must define __ANDROID_API__])
c06c22e9 1020 fi
2ea34cfb
EA
1021 AC_DEFINE_UNQUOTED([ANDROID_API_LEVEL], [$ANDROID_API_LEVEL],
1022 [The Android API level.])
2a352b66
XG
1023
1024 AC_MSG_CHECKING([for the Android arm ABI])
1025 AC_MSG_RESULT([$_arm_arch])
1026 if test "$_arm_arch" = 7; then
1027 BASECFLAGS="${BASECFLAGS} -mfloat-abi=softfp -mfpu=vfpv3-d16"
1028 LDFLAGS="${LDFLAGS} -march=armv7-a -Wl,--fix-cortex-a8"
1029 fi
95750b1c
XG
1030else
1031 AC_MSG_RESULT([not Android])
1032fi
1033rm -f conftest.c conftest.out
1034
779ffc06 1035# Check for unsupported systems
74b23c97
EEA
1036AS_CASE([$ac_sys_system/$ac_sys_release],
1037 [atheos*|Linux*/1*], [
1038 AC_MSG_ERROR([m4_normalize([
1039 This system \($ac_sys_system/$ac_sys_release\) is no longer supported.
1040 See README for details.
1041 ])])
1042 ]
1043)
779ffc06 1044
43839ba4
CH
1045AC_MSG_CHECKING([for --with-emscripten-target])
1046AC_ARG_WITH([emscripten-target],
1047 [AS_HELP_STRING([--with-emscripten-target=@<:@browser|node@:>@], [Emscripten platform])],
1048[
1049 AS_VAR_IF([ac_sys_system], [Emscripten], [
1050 AS_CASE([$with_emscripten_target],
1051 [browser], [ac_sys_emscripten_target=browser],
1052 [node], [ac_sys_emscripten_target=node],
17245c81
CH
1053dnl Debug builds with source map / dwarf symbols. Py_DEBUG builds easily
1054dnl run out of stack space. Detached sybmols and map prohibit some
1055dnl optimizations and increase file size. Options are undocumented so we
1056dnl are free to remove them in the future.
1057 [browser-debug], [ac_sys_emscripten_target=browser-debug],
1058 [node-debug], [ac_sys_emscripten_target=node-debug],
43839ba4
CH
1059 [AC_MSG_ERROR([Invalid argument: --with-emscripten-target=browser|node])]
1060 )
1061 ], [
1062 AC_MSG_ERROR([--with-emscripten-target only applies to Emscripten])
1063 ])
1064], [
1065 AS_VAR_IF([ac_sys_system], [Emscripten], [ac_sys_emscripten_target=browser])
1066])
1067AC_MSG_RESULT([$ac_sys_emscripten_target])
1068
c9844cb8
CH
1069dnl On Emscripten dlopen() requires -s MAIN_MODULE and -fPIC. The flags
1070dnl disables dead code elimination and increases the size of the WASM module
1071dnl by about 1.5 to 2MB. MAIN_MODULE defines __wasm_mutable_globals__.
1072dnl See https://emscripten.org/docs/compiling/Dynamic-Linking.html
1073AC_MSG_CHECKING([for --enable-wasm-dynamic-linking])
1074AC_ARG_ENABLE([wasm-dynamic-linking],
1075 [AS_HELP_STRING([--enable-wasm-dynamic-linking],
1076 [Enable dynamic linking support for WebAssembly (default is no)])],
1077[
1078 AS_CASE([$ac_sys_system],
1079 [Emscripten], [],
1080 [WASI], [AC_MSG_ERROR([WASI dynamic linking is not implemented yet.])],
1081 [AC_MSG_ERROR([--enable-wasm-dynamic-linking only applies to Emscripten and WASI])]
1082 )
1083], [
2b16a08b 1084 enable_wasm_dynamic_linking=missing
c9844cb8
CH
1085])
1086AC_MSG_RESULT([$enable_wasm_dynamic_linking])
1087
92c1037a
CH
1088AC_MSG_CHECKING([for --enable-wasm-pthreads])
1089AC_ARG_ENABLE([wasm-pthreads],
1090 [AS_HELP_STRING([--enable-wasm-pthreads],
1091 [Enable pthread emulation for WebAssembly (default is no)])],
1092[
1093 AS_CASE([$ac_sys_system],
1094 [Emscripten], [],
d8f87cdf 1095 [WASI], [],
92c1037a
CH
1096 [AC_MSG_ERROR([--enable-wasm-pthreads only applies to Emscripten and WASI])]
1097 )
1098], [
1099 enable_wasm_pthreads=missing
1100])
1101AC_MSG_RESULT([$enable_wasm_pthreads])
1102
6ac3c8a3
CH
1103AC_MSG_CHECKING([for --with-suffix])
1104AC_ARG_WITH([suffix],
1105 [AS_HELP_STRING([--with-suffix=SUFFIX], [set executable suffix to SUFFIX (default is empty, yes is mapped to '.exe')])],
3e2c6326 1106[
6ac3c8a3
CH
1107 AS_CASE([$with_suffix],
1108 [no], [EXEEXT=],
1109 [yes], [EXEEXT=.exe],
1110 [EXEEXT=$with_suffix]
1111 )
1112], [
43839ba4 1113 AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
96e09837 1114 [Emscripten/browser*], [EXEEXT=.js],
17245c81 1115 [Emscripten/node*], [EXEEXT=.js],
a6ca8eee 1116 [WASI/*], [EXEEXT=.wasm],
6ac3c8a3
CH
1117 [EXEEXT=]
1118 )
1119])
1120AC_MSG_RESULT([$EXEEXT])
1999ef49 1121
9a66b6d4
JJ
1122# Test whether we're running on a non-case-sensitive system, in which
1123# case we give a warning if no ext is given
2ea34cfb
EA
1124AC_SUBST([BUILDEXEEXT])
1125AC_MSG_CHECKING([for case-insensitive build directory])
3c2c4334
JJ
1126if test ! -d CaseSensitiveTestDir; then
1127mkdir CaseSensitiveTestDir
1128fi
1129
50ec3453 1130if test -d casesensitivetestdir && test -z "$EXEEXT"
9a66b6d4 1131then
2ea34cfb 1132 AC_MSG_RESULT([yes])
1999ef49
JJ
1133 BUILDEXEEXT=.exe
1134else
2ea34cfb 1135 AC_MSG_RESULT([no])
dd19cf81 1136 BUILDEXEEXT=$EXEEXT
9a66b6d4 1137fi
3c2c4334 1138rmdir CaseSensitiveTestDir
fb84255e 1139
8456161f
GR
1140case $ac_sys_system in
1141hp*|HP*)
1142 case $CC in
cd5ff9f0 1143 cc|*/cc) CC="$CC -Ae";;
8456161f
GR
1144 esac;;
1145esac
1146
2ea34cfb
EA
1147AC_SUBST([LIBRARY])
1148AC_MSG_CHECKING([LIBRARY])
61c51156
NS
1149if test -z "$LIBRARY"
1150then
f040d7de 1151 LIBRARY='libpython$(VERSION)$(ABIFLAGS).a'
61c51156 1152fi
2ea34cfb 1153AC_MSG_RESULT([$LIBRARY])
61c51156 1154
54ecc3d2 1155# LDLIBRARY is the name of the library to link against (as opposed to the
b6e9cad3
JJ
1156# name of the library into which to insert object files). BLDLIBRARY is also
1157# the library to link against, usually. On Mac OS X frameworks, BLDLIBRARY
1158# is blank as the main program is not linked directly against LDLIBRARY.
1159# LDLIBRARYDIR is the path to LDLIBRARY, which is made in a subdirectory. On
1160# systems without shared libraries, LDLIBRARY is the same as LIBRARY
1161# (defined in the Makefiles). On Cygwin LDLIBRARY is the import library,
1162# DLLLIBRARY is the shared (i.e., DLL) library.
1b80b240 1163#
1142de3f
ML
1164# RUNSHARED is used to run shared python without installed libraries
1165#
1166# INSTSONAME is the name of the shared library that will be use to install
1167# on the system - some systems like version suffix, others don't
8cf4eae5
BW
1168#
1169# LDVERSION is the shared library version number, normally the Python version
1170# with the ABI build flags appended.
2ea34cfb
EA
1171AC_SUBST([LDLIBRARY])
1172AC_SUBST([DLLLIBRARY])
1173AC_SUBST([BLDLIBRARY])
1174AC_SUBST([PY3LIBRARY])
1175AC_SUBST([LDLIBRARYDIR])
1176AC_SUBST([INSTSONAME])
1177AC_SUBST([RUNSHARED])
1178AC_SUBST([LDVERSION])
61c51156 1179LDLIBRARY="$LIBRARY"
b6e9cad3 1180BLDLIBRARY='$(LDLIBRARY)'
09bdf72b 1181INSTSONAME='$(LDLIBRARY)'
27552908 1182DLLLIBRARY=''
b6e9cad3 1183LDLIBRARYDIR=''
1142de3f 1184RUNSHARED=''
14d98ac3 1185LDVERSION="$VERSION"
54ecc3d2 1186
fb84255e 1187# LINKCC is the command that links the python executable -- default is $(CC).
b7da67a8
ML
1188# If CXX is set, and if it is needed to link a main function that was
1189# compiled with CXX, LINKCC is CXX instead. Always using CXX is undesirable:
1190# python might then depend on the C++ runtime
2ea34cfb
EA
1191AC_SUBST([LINKCC])
1192AC_MSG_CHECKING([LINKCC])
fb84255e
GR
1193if test -z "$LINKCC"
1194then
398ed84d 1195 LINKCC='$(PURIFY) $(CC)'
fb84255e 1196 case $ac_sys_system in
f78e02b7
GB
1197 QNX*)
1198 # qcc must be used because the other compilers do not
1199 # support -N.
1200 LINKCC=qcc;;
fb84255e
GR
1201 esac
1202fi
2ea34cfb 1203AC_MSG_RESULT([$LINKCC])
fb84255e 1204
e6dcd371
SK
1205# EXPORTSYMS holds the list of exported symbols for AIX.
1206# EXPORTSFROM holds the module name exporting symbols on AIX.
1207EXPORTSYMS=
1208EXPORTSFROM=
2ea34cfb
EA
1209AC_SUBST([EXPORTSYMS])
1210AC_SUBST([EXPORTSFROM])
1211AC_MSG_CHECKING([EXPORTSYMS])
e6dcd371
SK
1212case $ac_sys_system in
1213AIX*)
1214 EXPORTSYMS="Modules/python.exp"
c79667ff 1215 EXPORTSFROM=. # the main executable
e6dcd371
SK
1216 ;;
1217esac
2ea34cfb 1218AC_MSG_RESULT([$EXPORTSYMS])
e6dcd371 1219
be720e03
TZ
1220# GNULD is set to "yes" if the GNU linker is used. If this goes wrong
1221# make sure we default having it set to "no": this is used by
1222# distutils.unixccompiler to know if it should add --enable-new-dtags
1223# to linker command lines, and failing to detect GNU ld simply results
f52d987a 1224# in the same behaviour as before.
2ea34cfb
EA
1225AC_SUBST([GNULD])
1226AC_MSG_CHECKING([for GNU ld])
be720e03
TZ
1227ac_prog=ld
1228if test "$GCC" = yes; then
1229 ac_prog=`$CC -print-prog-name=ld`
1230fi
1231case `"$ac_prog" -V 2>&1 < /dev/null` in
1232 *GNU*)
1233 GNULD=yes;;
1234 *)
1235 GNULD=no;;
1236esac
2ea34cfb 1237AC_MSG_RESULT([$GNULD])
be720e03 1238
2ea34cfb
EA
1239AC_MSG_CHECKING([for --enable-shared])
1240AC_ARG_ENABLE([shared],
2de064e6 1241 AS_HELP_STRING([--enable-shared], [enable building a shared Python library (default is no)]))
54ecc3d2 1242
1142de3f 1243if test -z "$enable_shared"
1b80b240 1244then
b51033d4 1245 case $ac_sys_system in
6103ab1d 1246 CYGWIN*)
b51033d4
ML
1247 enable_shared="yes";;
1248 *)
1249 enable_shared="no";;
1250 esac
1142de3f 1251fi
2ea34cfb 1252AC_MSG_RESULT([$enable_shared])
1142de3f 1253
6be84892
VS
1254# --with-static-libpython
1255STATIC_LIBPYTHON=1
2ea34cfb
EA
1256AC_MSG_CHECKING([for --with-static-libpython])
1257AC_ARG_WITH([static-libpython],
6be84892
VS
1258 AS_HELP_STRING([--without-static-libpython],
1259 [do not build libpythonMAJOR.MINOR.a and do not install python.o (default is yes)]),
1260[
1261if test "$withval" = no
1262then
2ea34cfb 1263 AC_MSG_RESULT([no]);
6be84892
VS
1264 STATIC_LIBPYTHON=0
1265else
2ea34cfb 1266 AC_MSG_RESULT([yes]);
6be84892 1267fi],
2ea34cfb
EA
1268[AC_MSG_RESULT([yes])])
1269AC_SUBST([STATIC_LIBPYTHON])
6be84892 1270
2ea34cfb
EA
1271AC_MSG_CHECKING([for --enable-profiling])
1272AC_ARG_ENABLE([profiling],
2de064e6 1273 AS_HELP_STRING([--enable-profiling], [enable C-level code profiling with gprof (default is no)]))
ba01583e 1274if test "x$enable_profiling" = xyes; then
1275 ac_save_cc="$CC"
615ea1a9 1276 CC="$CC -pg"
e35ca417 1277 AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])],
ba01583e 1278 [],
1279 [enable_profiling=no])
1280 CC="$ac_save_cc"
1281else
1282 enable_profiling=no
1283fi
2ea34cfb 1284AC_MSG_RESULT([$enable_profiling])
ba01583e 1285
1286if test "x$enable_profiling" = xyes; then
1287 BASECFLAGS="-pg $BASECFLAGS"
1288 LDFLAGS="-pg $LDFLAGS"
1289fi
1142de3f 1290
2ea34cfb 1291AC_MSG_CHECKING([LDLIBRARY])
b6e9cad3 1292
b8552160
GR
1293# MacOSX framework builds need more magic. LDLIBRARY is the dynamic
1294# library that we build, but we do not want to link against it (we
1295# will find it with a -framework option). For this reason there is an
1296# extra variable BLDLIBRARY against which Python and the extension
1297# modules are linked, BLDLIBRARY. This is normally the same as
1298# LDLIBRARY, but empty for MacOSX framework builds.
b6e9cad3
JJ
1299if test "$enable_framework"
1300then
1301 LDLIBRARY='$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
e5de66ea 1302 RUNSHARED=DYLD_FRAMEWORK_PATH=`pwd`${DYLD_FRAMEWORK_PATH:+:${DYLD_FRAMEWORK_PATH}}
b6e9cad3
JJ
1303 BLDLIBRARY=''
1304else
1305 BLDLIBRARY='$(LDLIBRARY)'
1b80b240 1306fi
b6e9cad3 1307
1142de3f
ML
1308# Other platforms follow
1309if test $enable_shared = "yes"; then
87421197 1310 PY_ENABLE_SHARED=1
2ea34cfb
EA
1311 AC_DEFINE([Py_ENABLE_SHARED], [1],
1312 [Defined if Python is built as a shared library.])
1142de3f 1313 case $ac_sys_system in
1142de3f 1314 CYGWIN*)
8cf4eae5
BW
1315 LDLIBRARY='libpython$(LDVERSION).dll.a'
1316 DLLLIBRARY='libpython$(LDVERSION).dll'
1142de3f
ML
1317 ;;
1318 SunOS*)
8cf4eae5
BW
1319 LDLIBRARY='libpython$(LDVERSION).so'
1320 BLDLIBRARY='-Wl,-R,$(LIBDIR) -L. -lpython$(LDVERSION)'
e5de66ea 1321 RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
2389c41a 1322 INSTSONAME="$LDLIBRARY".$SOVERSION
9b142aaa 1323 if test "$with_pydebug" != yes
d1fc34d5
ML
1324 then
1325 PY3LIBRARY=libpython3.so
1326 fi
1142de3f 1327 ;;
c117426b 1328 Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*|VxWorks*)
8cf4eae5
BW
1329 LDLIBRARY='libpython$(LDVERSION).so'
1330 BLDLIBRARY='-L. -lpython$(LDVERSION)'
e5de66ea 1331 RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
1142de3f 1332 INSTSONAME="$LDLIBRARY".$SOVERSION
9b142aaa 1333 if test "$with_pydebug" != yes
d1fc34d5
ML
1334 then
1335 PY3LIBRARY=libpython3.so
1336 fi
1142de3f
ML
1337 ;;
1338 hp*|HP*)
477c8d5e
TW
1339 case `uname -m` in
1340 ia64)
8cf4eae5 1341 LDLIBRARY='libpython$(LDVERSION).so'
477c8d5e
TW
1342 ;;
1343 *)
8cf4eae5 1344 LDLIBRARY='libpython$(LDVERSION).sl'
477c8d5e
TW
1345 ;;
1346 esac
8cf4eae5 1347 BLDLIBRARY='-Wl,+b,$(LIBDIR) -L. -lpython$(LDVERSION)'
e5de66ea 1348 RUNSHARED=SHLIB_PATH=`pwd`${SHLIB_PATH:+:${SHLIB_PATH}}
1142de3f 1349 ;;
b1441c7e 1350 Darwin*)
8cf4eae5
BW
1351 LDLIBRARY='libpython$(LDVERSION).dylib'
1352 BLDLIBRARY='-L. -lpython$(LDVERSION)'
e5de66ea 1353 RUNSHARED=DYLD_LIBRARY_PATH=`pwd`${DYLD_LIBRARY_PATH:+:${DYLD_LIBRARY_PATH}}
b1441c7e 1354 ;;
8e6b407d 1355 AIX*)
8cf4eae5 1356 LDLIBRARY='libpython$(LDVERSION).so'
e5de66ea 1357 RUNSHARED=LIBPATH=`pwd`${LIBPATH:+:${LIBPATH}}
8e6b407d 1358 ;;
b1441c7e 1359
1142de3f 1360 esac
3076559e 1361else # shared is disabled
87421197 1362 PY_ENABLE_SHARED=0
3076559e
JT
1363 case $ac_sys_system in
1364 CYGWIN*)
1365 BLDLIBRARY='$(LIBRARY)'
8cf4eae5 1366 LDLIBRARY='libpython$(LDVERSION).dll.a'
3076559e
JT
1367 ;;
1368 esac
1142de3f
ML
1369fi
1370
1abe1c5f 1371if test "$cross_compiling" = yes; then
1372 RUNSHARED=
1373fi
1374
d1de1078 1375AC_ARG_VAR([HOSTRUNNER], [Program to run CPython for the host platform])
d1de1078
ES
1376if test -z "$HOSTRUNNER"
1377then
1378 AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
1379 [Emscripten/node*], [
32ac98e8
CH
1380 AC_PATH_TOOL([NODE], [node], [node])
1381 HOSTRUNNER="$NODE"
8625802d 1382 # bigint for ctypes c_longlong, c_longdouble
32ac98e8
CH
1383 # no longer available in Node 16
1384 AC_CACHE_CHECK([for node --experimental-wasm-bigint], [ac_cv_tool_node_wasm_bigint], [
1385 if $NODE -v --experimental-wasm-bigint > /dev/null 2>&1; then
1386 ac_cv_tool_node_wasm_bigint=yes
1387 else
1388 ac_cv_tool_node_wasm_bigint=no
1389 fi
1390 ])
1391 AS_VAR_IF([ac_cv_tool_node_wasm_bigint], [yes], [
1392 AS_VAR_APPEND([HOSTRUNNER], [" --experimental-wasm-bigint"])
1393 ])
1394
d1de1078 1395 AS_VAR_IF([enable_wasm_pthreads], [yes], [
32ac98e8
CH
1396 AS_VAR_APPEND([HOSTRUNNER], [" --experimental-wasm-threads"])
1397 # no longer available in Node 16
1398 AC_CACHE_CHECK([for node --experimental-wasm-bulk-memory], [ac_cv_tool_node_wasm_bulk_memory], [
1399 if $NODE -v --experimental-wasm-bulk-memory > /dev/null 2>&1; then
1400 ac_cv_tool_node_wasm_bulk_memory=yes
1401 else
1402 ac_cv_tool_node_wasm_bulk_memory=no
1403 fi
1404 ])
1405 AS_VAR_IF([ac_cv_tool_node_wasm_bulk_memory], [yes], [
1406 AS_VAR_APPEND([HOSTRUNNER], [" --experimental-wasm-bulk-memory"])
1407 ])
d1de1078 1408 ])
32ac98e8
CH
1409
1410 AS_VAR_IF([host_cpu], [wasm64], [AS_VAR_APPEND([HOSTRUNNER], [" --experimental-wasm-memory64"])])
d1de1078 1411 ],
22df2e03
CH
1412 dnl TODO: support other WASI runtimes
1413 dnl wasmtime starts the proces with "/" as CWD. For OOT builds add the
1414 dnl directory containing _sysconfigdata to PYTHONPATH.
cd543d0b 1415 [WASI/*], [HOSTRUNNER='wasmtime run --env PYTHONPATH=/$(shell realpath --relative-to $(abs_srcdir) $(abs_builddir))/$(shell cat pybuilddir.txt):/Lib --mapdir /::$(srcdir) --'],
d1de1078
ES
1416 [HOSTRUNNER='']
1417 )
1418fi
1419AC_SUBST([HOSTRUNNER])
32ac98e8 1420AC_MSG_CHECKING([HOSTRUNNER])
d1de1078
ES
1421AC_MSG_RESULT([$HOSTRUNNER])
1422
dc5e02b2
CH
1423if test -n "$HOSTRUNNER"; then
1424 dnl Pass hostrunner variable as env var in order to expand shell expressions.
1425 PYTHON_FOR_BUILD="_PYTHON_HOSTRUNNER='$HOSTRUNNER' $PYTHON_FOR_BUILD"
1426fi
1427
2ea34cfb 1428AC_MSG_RESULT([$LDLIBRARY])
54ecc3d2 1429
6be84892 1430# LIBRARY_DEPS, LINK_PYTHON_OBJS and LINK_PYTHON_DEPS variable
c8319f79 1431AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
6087f491 1432 [Emscripten/browser*], [LIBRARY_DEPS='$(PY3LIBRARY) $(WASM_STDLIB) python.html python.worker.js'],
c8319f79
CH
1433 [LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)']
1434)
6be84892
VS
1435LINK_PYTHON_DEPS='$(LIBRARY_DEPS)'
1436if test "$PY_ENABLE_SHARED" = 1 || test "$enable_framework" ; then
1437 LIBRARY_DEPS="\$(LDLIBRARY) $LIBRARY_DEPS"
1438 if test "$STATIC_LIBPYTHON" = 1; then
1439 LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS"
1440 fi
1441 # Link Python program to the shared library
1442 LINK_PYTHON_OBJS='$(BLDLIBRARY)'
1443else
1444 if test "$STATIC_LIBPYTHON" = 0; then
1445 # Build Python needs object files but don't need to build
1446 # Python static library
1447 LINK_PYTHON_DEPS="$LIBRARY_DEPS \$(LIBRARY_OBJS)"
1448 fi
1449 LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS"
1450 # Link Python program to object files
1451 LINK_PYTHON_OBJS='$(LIBRARY_OBJS)'
1452fi
2ea34cfb
EA
1453AC_SUBST([LIBRARY_DEPS])
1454AC_SUBST([LINK_PYTHON_DEPS])
1455AC_SUBST([LINK_PYTHON_OBJS])
6be84892
VS
1456
1457# ar program
2ea34cfb
EA
1458AC_SUBST([AR])
1459AC_CHECK_TOOLS([AR], [ar aal], [ar])
a42c8271 1460
5662d3e6 1461# tweak ARFLAGS only if the user didn't set it on the command line
2ea34cfb 1462AC_SUBST([ARFLAGS])
5662d3e6
TZ
1463if test -z "$ARFLAGS"
1464then
d15108a4 1465 ARFLAGS="rcs"
5662d3e6
TZ
1466fi
1467
a42c8271 1468case $MACHDEP in
288d1daa
BP
1469hp*|HP*)
1470 # install -d does not work on HP-UX
a42c8271
NS
1471 if test -z "$INSTALL"
1472 then
1473 INSTALL="${srcdir}/install-sh -c"
1474 fi
1475esac
55f0cf33 1476AC_PROG_INSTALL
93a0ef16 1477AC_PROG_MKDIR_P
b418f89b 1478
ec95c7bd 1479# Not every filesystem supports hard links
2ea34cfb 1480AC_SUBST([LN])
ec95c7bd
GR
1481if test -z "$LN" ; then
1482 case $ac_sys_system in
aef734b1 1483 CYGWIN*) LN="ln -s";;
ec95c7bd
GR
1484 *) LN=ln;;
1485 esac
1486fi
1487
35f3a2cb 1488# For calculating the .so ABI tag.
2ea34cfb 1489AC_SUBST([ABIFLAGS])
8cf4eae5 1490ABIFLAGS=""
35f3a2cb 1491
773614e0
SG
1492# Check for --disable-gil
1493# --disable-gil
1494AC_MSG_CHECKING([for --disable-gil])
1495AC_ARG_ENABLE([gil],
1496 [AS_HELP_STRING([--disable-gil], [enable experimental support for running without the GIL (default is no)])],
1497 [AS_VAR_IF([enable_gil], [yes], [disable_gil=no], [disable_gil=yes])], [disable_gil=no]
1498)
1499AC_MSG_RESULT([$disable_gil])
1500
1501if test "$disable_gil" = "yes"
1502then
1503 AC_DEFINE([Py_NOGIL], [1],
1504 [Define if you want to disable the GIL])
1505 # Add "t" for "threaded"
1506 ABIFLAGS="${ABIFLAGS}t"
1507fi
1508
9f71582c 1509# Check for --with-pydebug
2ea34cfb
EA
1510AC_MSG_CHECKING([for --with-pydebug])
1511AC_ARG_WITH([pydebug],
1512 [AS_HELP_STRING([--with-pydebug], [build with Py_DEBUG defined (default is no)]) ],
3e2c6326 1513[
9f71582c 1514if test "$withval" != no
1b80b240 1515then
2ea34cfb 1516 AC_DEFINE([Py_DEBUG], [1],
1b80b240 1517 [Define if you want to build an interpreter with many run-time checks.])
2ea34cfb 1518 AC_MSG_RESULT([yes]);
c45929ec 1519 Py_DEBUG='true'
8cf4eae5 1520 ABIFLAGS="${ABIFLAGS}d"
2ea34cfb 1521else AC_MSG_RESULT([no]); Py_DEBUG='false'
9f71582c 1522fi],
2ea34cfb 1523[AC_MSG_RESULT([no])])
9f71582c 1524
f4e4703e
VS
1525# Check for --with-trace-refs
1526# --with-trace-refs
2ea34cfb
EA
1527AC_MSG_CHECKING([for --with-trace-refs])
1528AC_ARG_WITH([trace-refs],
1529 [AS_HELP_STRING([--with-trace-refs], [enable tracing references for debugging purpose (default is no)])],
1530 [], [with_trace_refs=no]
1531)
1532AC_MSG_RESULT([$with_trace_refs])
f4e4703e
VS
1533
1534if test "$with_trace_refs" = "yes"
1535then
2ea34cfb
EA
1536 AC_DEFINE([Py_TRACE_REFS], [1],
1537 [Define if you want to enable tracing references for debugging purpose])
f4e4703e
VS
1538fi
1539
342b93f9
MS
1540
1541# Check for --enable-pystats
1542AC_MSG_CHECKING([for --enable-pystats])
1543AC_ARG_ENABLE([pystats],
1544 [AS_HELP_STRING(
1545 [--enable-pystats],
2ea34cfb
EA
1546 [enable internal statistics gathering (default is no)]
1547 )],
1548 [], [enable_pystats=no]
342b93f9
MS
1549)
1550AC_MSG_RESULT([$enable_pystats])
1551
1552AS_VAR_IF([enable_pystats], [yes], [
1553 AC_DEFINE([Py_STATS], [1], [Define if you want to enable internal statistics gathering.])
1554])
1555
f4e4703e
VS
1556# Check for --with-assertions.
1557# This allows enabling assertions without Py_DEBUG.
ddbfa2c3 1558assertions='false'
2ea34cfb
EA
1559AC_MSG_CHECKING([for --with-assertions])
1560AC_ARG_WITH([assertions],
2de064e6 1561 AS_HELP_STRING([--with-assertions],[build with C assertions enabled (default is no)]),
ddbfa2c3
W
1562[
1563if test "$withval" != no
1564then
1565 assertions='true'
1566fi],
1567[])
1568if test "$assertions" = 'true'; then
2ea34cfb 1569 AC_MSG_RESULT([yes])
ddbfa2c3
W
1570elif test "$Py_DEBUG" = 'true'; then
1571 assertions='true'
2ea34cfb 1572 AC_MSG_RESULT([implied by --with-pydebug])
ddbfa2c3 1573else
2ea34cfb 1574 AC_MSG_RESULT([no])
ddbfa2c3
W
1575fi
1576
63d98bcd 1577# Enable optimization flags
2ea34cfb
EA
1578AC_SUBST([DEF_MAKE_ALL_RULE])
1579AC_SUBST([DEF_MAKE_RULE])
63d98bcd 1580Py_OPT='false'
2ea34cfb
EA
1581AC_MSG_CHECKING([for --enable-optimizations])
1582AC_ARG_ENABLE([optimizations], AS_HELP_STRING(
2de064e6
AS
1583 [--enable-optimizations],
1584 [enable expensive, stable optimizations (PGO, etc.) (default is no)]),
63d98bcd 1585[
8cea5929 1586if test "$enableval" != no
63d98bcd
BC
1587then
1588 Py_OPT='true'
2ea34cfb 1589 AC_MSG_RESULT([yes]);
63d98bcd
BC
1590else
1591 Py_OPT='false'
2ea34cfb 1592 AC_MSG_RESULT([no]);
63d98bcd 1593fi],
2ea34cfb 1594[AC_MSG_RESULT([no])])
43839ba4 1595
63d98bcd 1596if test "$Py_OPT" = 'true' ; then
14c7f711
GS
1597 # Intentionally not forcing Py_LTO='true' here. Too many toolchains do not
1598 # compile working code using it and both test_distutils and test_gdb are
1d8f755e 1599 # broken when you do manage to get a toolchain that works with it. People
14c7f711 1600 # who want LTO need to use --with-lto themselves.
63d98bcd 1601 DEF_MAKE_ALL_RULE="profile-opt"
799520c9 1602 REQUIRE_PGO="yes"
63d98bcd 1603 DEF_MAKE_RULE="build_all"
b451b0e9
PG
1604 case $CC in
1605 *gcc*)
c6d7e82d 1606 AX_CHECK_COMPILE_FLAG([-fno-semantic-interposition],[
b451b0e9
PG
1607 CFLAGS_NODIST="$CFLAGS_NODIST -fno-semantic-interposition"
1608 LDFLAGS_NODIST="$LDFLAGS_NODIST -fno-semantic-interposition"
c6d7e82d 1609 ])
b451b0e9
PG
1610 ;;
1611 esac
7acedd71 1612elif test "$ac_sys_system" = "Emscripten" -o "$ac_sys_system" = "WASI"; then
43839ba4 1613 dnl Emscripten does not support shared extensions yet. Build
7acedd71
CH
1614 dnl "python.[js,wasm]", "pybuilddir.txt", and "platform" files.
1615 DEF_MAKE_ALL_RULE="build_wasm"
43839ba4
CH
1616 REQUIRE_PGO="no"
1617 DEF_MAKE_RULE="all"
63d98bcd
BC
1618else
1619 DEF_MAKE_ALL_RULE="build_all"
799520c9 1620 REQUIRE_PGO="no"
63d98bcd
BC
1621 DEF_MAKE_RULE="all"
1622fi
1623
2ea34cfb
EA
1624AC_ARG_VAR([PROFILE_TASK], [Python args for PGO generation task])
1625AC_MSG_CHECKING([PROFILE_TASK])
4e16a4a3
NS
1626if test -z "$PROFILE_TASK"
1627then
6790005a 1628 PROFILE_TASK='-m test --pgo --timeout=$(TESTTIMEOUT)'
4e16a4a3 1629fi
2ea34cfb 1630AC_MSG_RESULT([$PROFILE_TASK])
4e16a4a3 1631
83d84e67 1632# Make llvm-related checks work on systems where llvm tools are not installed with their
5ad36f9b 1633# normal names in the default $PATH (ie: Ubuntu). They exist under the
1634# non-suffixed name in their versioned llvm directory.
1635
1636llvm_bin_dir=''
1637llvm_path="${PATH}"
1638if test "${CC}" = "clang"
1639then
1640 clang_bin=`which clang`
1641 # Some systems install clang elsewhere as a symlink to the real path
1642 # which is where the related llvm tools are located.
1643 if test -L "${clang_bin}"
1644 then
1645 clang_dir=`dirname "${clang_bin}"`
1646 clang_bin=`readlink "${clang_bin}"`
1647 llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
1648 llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
1649 fi
1650fi
1651
d82da9f7 1652# Enable LTO flags
2ea34cfb
EA
1653AC_MSG_CHECKING([for --with-lto])
1654AC_ARG_WITH([lto],
1655 [AS_HELP_STRING([--with-lto=@<:@full|thin|no|yes@:>@], [enable Link-Time-Optimization in any build (default is no)])],
d82da9f7 1656[
b2cf2513
DN
1657case "$withval" in
1658 full)
1659 Py_LTO='true'
1660 Py_LTO_POLICY='full'
2ea34cfb 1661 AC_MSG_RESULT([yes])
b2cf2513
DN
1662 ;;
1663 thin)
1664 Py_LTO='true'
1665 Py_LTO_POLICY='thin'
2ea34cfb 1666 AC_MSG_RESULT([yes])
b2cf2513
DN
1667 ;;
1668 yes)
1669 Py_LTO='true'
1670 Py_LTO_POLICY='default'
2ea34cfb 1671 AC_MSG_RESULT([yes])
b2cf2513
DN
1672 ;;
1673 no)
1674 Py_LTO='false'
2ea34cfb 1675 AC_MSG_RESULT([no])
b2cf2513
DN
1676 ;;
1677 *)
1678 Py_LTO='false'
1679 AC_MSG_ERROR([unknown lto option: '$withval'])
1680 ;;
1681esac
1682],
2ea34cfb 1683[AC_MSG_RESULT([no])])
d82da9f7
GS
1684if test "$Py_LTO" = 'true' ; then
1685 case $CC in
1686 *clang*)
84ca1232 1687 LDFLAGS_NOLTO="-fno-lto"
83d84e67
DN
1688 dnl Clang linker requires -flto in order to link objects with LTO information.
1689 dnl Thin LTO is faster and works for object files with full LTO information, too.
1690 AX_CHECK_COMPILE_FLAG([-flto=thin],[LDFLAGS_NOLTO="-flto=thin"],[LDFLAGS_NOLTO="-flto"])
2ea34cfb
EA
1691 AC_SUBST([LLVM_AR])
1692 AC_PATH_TOOL([LLVM_AR], [llvm-ar], [''], [${llvm_path}])
1693 AC_SUBST([LLVM_AR_FOUND])
5ad36f9b 1694 if test -n "${LLVM_AR}" -a -x "${LLVM_AR}"
1695 then
1696 LLVM_AR_FOUND="found"
1697 else
1698 LLVM_AR_FOUND="not-found"
1699 fi
1700 if test "$ac_sys_system" = "Darwin" -a "${LLVM_AR_FOUND}" = "not-found"
1701 then
59acfd4a
ND
1702 # The Apple-supplied ar in Xcode or the Command Line Tools is apparently sufficient
1703 found_llvm_ar=`/usr/bin/xcrun -find ar 2>/dev/null`
5ad36f9b 1704 if test -n "${found_llvm_ar}"
1705 then
59acfd4a 1706 LLVM_AR='/usr/bin/xcrun ar'
5ad36f9b 1707 LLVM_AR_FOUND=found
1708 AC_MSG_NOTICE([llvm-ar found via xcrun: ${LLVM_AR}])
1709 fi
1710 fi
1711 if test $LLVM_AR_FOUND = not-found
1712 then
1713 LLVM_PROFR_ERR=yes
1714 AC_MSG_ERROR([llvm-ar is required for a --with-lto build with clang but could not be found.])
1715 else
1716 LLVM_AR_ERR=no
1717 fi
1718 AR="${LLVM_AR}"
8482ce48
ND
1719 case $ac_sys_system in
1720 Darwin*)
1721 # Any changes made here should be reflected in the GCC+Darwin case below
b2cf2513
DN
1722 if test $Py_LTO_POLICY = default
1723 then
e47b96c4
DN
1724 # Check that ThinLTO is accepted.
1725 AX_CHECK_COMPILE_FLAG([-flto=thin],[
1726 LTOFLAGS="-flto=thin -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
1727 LTOCFLAGS="-flto=thin"
1728 ],[
1729 LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
1730 LTOCFLAGS="-flto"
1731 ]
1732 )
b2cf2513 1733 else
5b070c0d 1734 LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
b2cf2513
DN
1735 LTOCFLAGS="-flto=${Py_LTO_POLICY}"
1736 fi
8482ce48
ND
1737 ;;
1738 *)
b2cf2513
DN
1739 if test $Py_LTO_POLICY = default
1740 then
e47b96c4
DN
1741 # Check that ThinLTO is accepted
1742 AX_CHECK_COMPILE_FLAG([-flto=thin],[LTOFLAGS="-flto=thin"],[LTOFLAGS="-flto"])
b2cf2513
DN
1743 else
1744 LTOFLAGS="-flto=${Py_LTO_POLICY}"
1745 fi
8482ce48
ND
1746 ;;
1747 esac
d82da9f7 1748 ;;
deeaac49
CH
1749 *emcc*)
1750 if test "$Py_LTO_POLICY" != "default"; then
1751 AC_MSG_ERROR([emcc supports only default lto.])
1752 fi
1753 LTOFLAGS="-flto"
1754 LTOCFLAGS="-flto"
1755 ;;
d82da9f7 1756 *gcc*)
b2cf2513
DN
1757 if test $Py_LTO_POLICY = thin
1758 then
1759 AC_MSG_ERROR([thin lto is not supported under gcc compiler.])
1760 fi
84ca1232
CH
1761 dnl flag to disable lto during linking
1762 LDFLAGS_NOLTO="-fno-lto"
d82da9f7
GS
1763 case $ac_sys_system in
1764 Darwin*)
5b070c0d 1765 LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
59acfd4a 1766 LTOCFLAGS="-flto"
d82da9f7
GS
1767 ;;
1768 *)
1769 LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none"
1770 ;;
1771 esac
1772 ;;
1773 esac
06fe77a8
VS
1774
1775 if test "$ac_cv_prog_cc_g" = "yes"
1776 then
1777 # bpo-30345: Add -g to LDFLAGS when compiling with LTO
1778 # to get debug symbols.
1779 LTOFLAGS="$LTOFLAGS -g"
1780 fi
1781
59acfd4a 1782 CFLAGS_NODIST="$CFLAGS_NODIST ${LTOCFLAGS-$LTOFLAGS}"
cf10a750 1783 LDFLAGS_NODIST="$LDFLAGS_NODIST $LTOFLAGS"
d82da9f7
GS
1784fi
1785
7188a3ef 1786# Enable PGO flags.
2ea34cfb
EA
1787AC_SUBST([PGO_PROF_GEN_FLAG])
1788AC_SUBST([PGO_PROF_USE_FLAG])
1789AC_SUBST([LLVM_PROF_MERGER])
1790AC_SUBST([LLVM_PROF_FILE])
1791AC_SUBST([LLVM_PROF_ERR])
1792AC_SUBST([LLVM_PROFDATA])
1793AC_PATH_TOOL([LLVM_PROFDATA], [llvm-profdata], [''], [${llvm_path}])
1794AC_SUBST([LLVM_PROF_FOUND])
799520c9
GS
1795if test -n "${LLVM_PROFDATA}" -a -x "${LLVM_PROFDATA}"
1796then
1797 LLVM_PROF_FOUND="found"
1798else
1799 LLVM_PROF_FOUND="not-found"
1800fi
1801if test "$ac_sys_system" = "Darwin" -a "${LLVM_PROF_FOUND}" = "not-found"
1802then
1803 found_llvm_profdata=`/usr/bin/xcrun -find llvm-profdata 2>/dev/null`
1804 if test -n "${found_llvm_profdata}"
1805 then
1806 # llvm-profdata isn't directly in $PATH in some cases.
1807 # https://apple.stackexchange.com/questions/197053/
1808 LLVM_PROFDATA='/usr/bin/xcrun llvm-profdata'
1809 LLVM_PROF_FOUND=found
1810 AC_MSG_NOTICE([llvm-profdata found via xcrun: ${LLVM_PROFDATA}])
1811 fi
1812fi
7188a3ef 1813LLVM_PROF_ERR=no
fecb9faf
JM
1814
1815# GNU Autoconf recommends the use of expr instead of basename.
1816AS_VAR_SET([CC_BASENAME], [$(expr "//$CC" : '.*/\(.*\)')])
1817case "$CC_BASENAME" in
7188a3ef
BC
1818 *clang*)
1819 # Any changes made here should be reflected in the GCC+Darwin case below
1820 PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
1821 PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd"
799520c9 1822 LLVM_PROF_MERGER="${LLVM_PROFDATA} merge -output=code.profclangd *.profclangr"
7188a3ef
BC
1823 LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\""
1824 if test $LLVM_PROF_FOUND = not-found
1825 then
1826 LLVM_PROF_ERR=yes
799520c9
GS
1827 if test "${REQUIRE_PGO}" = "yes"
1828 then
1016b2ff 1829 AC_MSG_ERROR([llvm-profdata is required for a --enable-optimizations build but could not be found.])
799520c9 1830 fi
7188a3ef
BC
1831 fi
1832 ;;
1833 *gcc*)
1834 case $ac_sys_system in
1835 Darwin*)
1836 PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
1837 PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd"
799520c9 1838 LLVM_PROF_MERGER="${LLVM_PROFDATA} merge -output=code.profclangd *.profclangr"
7188a3ef 1839 LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\""
799520c9 1840 if test "${LLVM_PROF_FOUND}" = "not-found"
7188a3ef
BC
1841 then
1842 LLVM_PROF_ERR=yes
799520c9
GS
1843 if test "${REQUIRE_PGO}" = "yes"
1844 then
1016b2ff 1845 AC_MSG_ERROR([llvm-profdata is required for a --enable-optimizations build but could not be found.])
799520c9 1846 fi
7188a3ef
BC
1847 fi
1848 ;;
1849 *)
1850 PGO_PROF_GEN_FLAG="-fprofile-generate"
1851 PGO_PROF_USE_FLAG="-fprofile-use -fprofile-correction"
1852 LLVM_PROF_MERGER="true"
1853 LLVM_PROF_FILE=""
1854 ;;
1855 esac
1856 ;;
5af85640
ZW
1857 *icc*)
1858 PGO_PROF_GEN_FLAG="-prof-gen"
1859 PGO_PROF_USE_FLAG="-prof-use"
1860 LLVM_PROF_MERGER="true"
1861 LLVM_PROF_FILE=""
1862 ;;
7188a3ef
BC
1863esac
1864
27d8ecd7
GS
1865# BOLT optimization. Always configured after PGO since it always runs after PGO.
1866Py_BOLT='false'
2ea34cfb
EA
1867AC_MSG_CHECKING([for --enable-bolt])
1868AC_ARG_ENABLE([bolt], [AS_HELP_STRING(
27d8ecd7 1869 [--enable-bolt],
2ea34cfb 1870 [enable usage of the llvm-bolt post-link optimizer (default is no)])],
27d8ecd7
GS
1871[
1872if test "$enableval" != no
1873then
1874 Py_BOLT='true'
2ea34cfb 1875 AC_MSG_RESULT([yes]);
27d8ecd7
GS
1876else
1877 Py_BOLT='false'
2ea34cfb 1878 AC_MSG_RESULT([no]);
27d8ecd7 1879fi],
2ea34cfb 1880[AC_MSG_RESULT([no])])
27d8ecd7 1881
2ea34cfb 1882AC_SUBST([PREBOLT_RULE])
27d8ecd7
GS
1883if test "$Py_BOLT" = 'true' ; then
1884 PREBOLT_RULE="${DEF_MAKE_ALL_RULE}"
1885 DEF_MAKE_ALL_RULE="bolt-opt"
1886 DEF_MAKE_RULE="build_all"
1887
27d8ecd7
GS
1888 # -fno-reorder-blocks-and-partition is required for bolt to work.
1889 # Possibly GCC only.
1890 AX_CHECK_COMPILE_FLAG([-fno-reorder-blocks-and-partition],[
1891 CFLAGS_NODIST="$CFLAGS_NODIST -fno-reorder-blocks-and-partition"
1892 ])
1893
1894 # These flags are required for bolt to work:
1895 LDFLAGS_NODIST="$LDFLAGS_NODIST -Wl,--emit-relocs"
1896
1897 # These flags are required to get good performance from bolt:
1898 CFLAGS_NODIST="$CFLAGS_NODIST -fno-pie"
1899 # We want to add these no-pie flags to linking executables but not shared libraries:
1900 LINKCC="$LINKCC -fno-pie -no-pie"
2ea34cfb
EA
1901 AC_SUBST([LLVM_BOLT])
1902 AC_PATH_TOOL([LLVM_BOLT], [llvm-bolt], [''], [${llvm_path}])
27d8ecd7
GS
1903 if test -n "${LLVM_BOLT}" -a -x "${LLVM_BOLT}"
1904 then
2ea34cfb 1905 AC_MSG_RESULT(["Found llvm-bolt"])
27d8ecd7
GS
1906 else
1907 AC_MSG_ERROR([llvm-bolt is required for a --enable-bolt build but could not be found.])
1908 fi
1909
2ea34cfb
EA
1910 AC_SUBST([MERGE_FDATA])
1911 AC_PATH_TOOL([MERGE_FDATA], [merge-fdata], [''], [${llvm_path}])
27d8ecd7
GS
1912 if test -n "${MERGE_FDATA}" -a -x "${MERGE_FDATA}"
1913 then
2ea34cfb 1914 AC_MSG_RESULT(["Found merge-fdata"])
27d8ecd7
GS
1915 else
1916 AC_MSG_ERROR([merge-fdata is required for a --enable-bolt build but could not be found.])
1917 fi
1918fi
1919
5360cb3d 1920dnl Enable BOLT of libpython if built.
2ea34cfb 1921AC_SUBST([BOLT_BINARIES])
5360cb3d
GS
1922BOLT_BINARIES='$(BUILDPYTHON)'
1923AS_VAR_IF([enable_shared], [yes], [
1924 BOLT_BINARIES="${BOLT_BINARIES} \$(INSTSONAME)"
1925])
1926
1927AC_ARG_VAR(
1928 [BOLT_INSTRUMENT_FLAGS],
1929 [Arguments to llvm-bolt when instrumenting binaries]
1930)
1931AC_MSG_CHECKING([BOLT_INSTRUMENT_FLAGS])
1932if test -z "${BOLT_INSTRUMENT_FLAGS}"
1933then
1934 BOLT_INSTRUMENT_FLAGS=
1935fi
1936AC_MSG_RESULT([$BOLT_INSTRUMENT_FLAGS])
1937
1938AC_ARG_VAR(
1939 [BOLT_APPLY_FLAGS],
1940 [Arguments to llvm-bolt when creating a BOLT optimized binary]
1941)
1942AC_MSG_CHECKING([BOLT_APPLY_FLAGS])
1943if test -z "${BOLT_APPLY_FLAGS}"
1944then
1945 AS_VAR_SET(
1946 [BOLT_APPLY_FLAGS],
c4378519
DN
1947 [m4_normalize("
1948 -update-debug-sections
1949 -reorder-blocks=ext-tsp
1950 -reorder-functions=hfsort+
1951 -split-functions
1952 -icf=1
1953 -inline-all
1954 -split-eh
1955 -reorder-functions-use-hot-size
1956 -peepholes=none
1957 -jump-tables=aggressive
1958 -inline-ap
1959 -indirect-call-promotion=all
1960 -dyno-stats
1961 -use-gnu-stack
1962 -frame-opt=hot
1963 ")]
5360cb3d
GS
1964 )
1965fi
1966AC_MSG_RESULT([$BOLT_APPLY_FLAGS])
1967
decc6a47
SM
1968# XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be
1969# merged with this chunk of code?
1970
55f0cf33 1971# Optimizer/debugger flags
decc6a47
SM
1972# ------------------------
1973# (The following bit of code is complicated enough - please keep things
1974# indented properly. Just pretend you're editing Python code. ;-)
1975
1976# There are two parallel sets of case statements below, one that checks to
1977# see if OPT was set and one that does BASECFLAGS setting based upon
1978# compiler and platform. BASECFLAGS tweaks need to be made even if the
1979# user set OPT.
1980
23a683ad
VS
1981case $CC in
1982 *clang*)
1983 cc_is_clang=1
1984 ;;
1985 *)
1986 if $CC --version 2>&1 | grep -q clang
1987 then
1988 cc_is_clang=1
1989 else
1990 cc_is_clang=
1991 fi
1992esac
1993
eff9f439
MG
1994dnl Historically, some of our code assumed that signed integer overflow
1995dnl is defined behaviour via twos-complement.
1996dnl Set STRICT_OVERFLOW_CFLAGS and NO_STRICT_OVERFLOW_CFLAGS depending on compiler support.
1997dnl Pass the latter to modules that depend on such behaviour.
1998_SAVE_VAR([CFLAGS])
1999CFLAGS="-fstrict-overflow -fno-strict-overflow"
2000AC_CACHE_CHECK([if $CC supports -fstrict-overflow and -fno-strict-overflow],
2001 [ac_cv_cc_supports_fstrict_overflow],
2002 AC_COMPILE_IFELSE(
2003 [AC_LANG_PROGRAM([[]], [[]])],
2004 [ac_cv_cc_supports_fstrict_overflow=yes],
2005 [ac_cv_cc_supports_fstrict_overflow=no]
2006 )
2007)
2008_RESTORE_VAR([CFLAGS])
2009
2010AS_VAR_IF([ac_cv_cc_supports_fstrict_overflow], [yes],
2011 [STRICT_OVERFLOW_CFLAGS="-fstrict-overflow"
2012 NO_STRICT_OVERFLOW_CFLAGS="-fno-strict-overflow"],
2013 [STRICT_OVERFLOW_CFLAGS=""
2014 NO_STRICT_OVERFLOW_CFLAGS=""])
2015
2016AC_MSG_CHECKING([for --with-strict-overflow])
2017AC_ARG_WITH([strict-overflow],
2018 AS_HELP_STRING(
2019 [--with-strict-overflow],
2020 [if 'yes', add -fstrict-overflow to CFLAGS, else add -fno-strict-overflow (default is no)]
2021 ),
2022 [
2023 AS_VAR_IF(
2024 [ac_cv_cc_supports_fstrict_overflow], [no],
2025 [AC_MSG_WARN([--with-strict-overflow=yes requires a compiler that supports -fstrict-overflow])],
2026 []
2027 )
2028 ],
2029 [with_strict_overflow=no]
2030)
2031AC_MSG_RESULT([$with_strict_overflow])
2032
0515eafe
VS
2033# Check if CC supports -Og optimization level
2034_SAVE_VAR([CFLAGS])
2035CFLAGS="-Og"
2036AC_CACHE_CHECK([if $CC supports -Og optimization level],
2037 [ac_cv_cc_supports_og],
2038 AC_COMPILE_IFELSE(
2039 [
2040 AC_LANG_PROGRAM([[]], [[]])
2041 ],[
2042 ac_cv_cc_supports_og=yes
2043 ],[
2044 ac_cv_cc_supports_og=no
2045 ])
2046)
2047_RESTORE_VAR([CFLAGS])
2048
2049# Optimization messes up debuggers, so turn it off for
2050# debug builds.
2051PYDEBUG_CFLAGS="-O0"
2052AS_VAR_IF([ac_cv_cc_supports_og], [yes],
2053 [PYDEBUG_CFLAGS="-Og"])
2054
decc6a47
SM
2055# tweak OPT based on compiler and platform, only if the user didn't set
2056# it on the command line
2ea34cfb
EA
2057AC_SUBST([OPT])
2058AC_SUBST([CFLAGS_ALIASING])
65b4ec50 2059if test "${OPT-unset}" = "unset"
b418f89b 2060then
decc6a47
SM
2061 case $GCC in
2062 yes)
35f3d240
VS
2063 if test -n "${cc_is_clang}"
2064 then
826f83f1
VS
2065 # bpo-30104: disable strict aliasing to compile correctly dtoa.c,
2066 # see Makefile.pre.in for more information
2067 CFLAGS_ALIASING="-fno-strict-aliasing"
35f3d240
VS
2068 fi
2069
decc6a47 2070 case $ac_cv_prog_cc_g in
2242f2fb 2071 yes)
9f71582c 2072 if test "$Py_DEBUG" = 'true' ; then
0515eafe 2073 OPT="-g $PYDEBUG_CFLAGS -Wall"
9f71582c 2074 else
eff9f439 2075 OPT="-g -O3 -Wall"
decc6a47
SM
2076 fi
2077 ;;
2242f2fb 2078 *)
28205b20 2079 OPT="-O3 -Wall"
decc6a47 2080 ;;
9f71582c 2081 esac
28205b20 2082
21ee4091 2083 case $ac_sys_system in
decc6a47
SM
2084 SCO_SV*) OPT="$OPT -m486 -DSCO5"
2085 ;;
2086 esac
9f71582c 2087 ;;
decc6a47 2088
2242f2fb 2089 *)
decc6a47
SM
2090 OPT="-O"
2091 ;;
2242f2fb 2092 esac
4e8af445 2093fi
627b2d7c 2094
43839ba4 2095# WASM flags
92c1037a
CH
2096AS_CASE([$ac_sys_system],
2097 [Emscripten], [
2098 dnl build with WASM debug info if either Py_DEBUG is set or the target is
2099 dnl node-debug or browser-debug.
2100 AS_VAR_IF([Py_DEBUG], [yes], [wasm_debug=yes], [wasm_debug=no])
cb04a09d 2101
92c1037a
CH
2102 dnl Start with 20 MB and allow to grow
2103 AS_VAR_APPEND([LDFLAGS_NODIST], [" -sALLOW_MEMORY_GROWTH -sTOTAL_MEMORY=20971520"])
2104
e69306f0
CH
2105 dnl map int64_t and uint64_t to JS bigint
2106 AS_VAR_APPEND([LDFLAGS_NODIST], [" -sWASM_BIGINT"])
2107
92c1037a
CH
2108 dnl Include file system support
2109 AS_VAR_APPEND([LDFLAGS_NODIST], [" -sFORCE_FILESYSTEM -lidbfs.js -lnodefs.js -lproxyfs.js -lworkerfs.js"])
2110
c9844cb8 2111 AS_VAR_IF([enable_wasm_dynamic_linking], [yes], [
7acedd71 2112 AS_VAR_APPEND([LINKFORSHARED], [" -sMAIN_MODULE"])
c9844cb8 2113 ])
92c1037a
CH
2114
2115 AS_VAR_IF([enable_wasm_pthreads], [yes], [
2116 AS_VAR_APPEND([CFLAGS_NODIST], [" -pthread"])
2117 AS_VAR_APPEND([LDFLAGS_NODIST], [" -sUSE_PTHREADS"])
2118 AS_VAR_APPEND([LINKFORSHARED], [" -sPROXY_TO_PTHREAD"])
2119 ])
2120
2121 AS_CASE([$ac_sys_emscripten_target],
2122 [browser*], [
2123 AS_VAR_IF([ac_sys_emscripten_target], [browser-debug], [wasm_debug=yes])
2124 AS_VAR_APPEND([LINKFORSHARED], [" --preload-file=\$(WASM_ASSETS_DIR)"])
2125 WASM_ASSETS_DIR=".\$(prefix)"
2126 WASM_STDLIB="\$(WASM_ASSETS_DIR)/local/lib/python\$(VERSION)/os.py"
2127 dnl separate-dwarf does not seem to work in Chrome DevTools Support.
2128 WASM_LINKFORSHARED_DEBUG="-gsource-map --emit-symbol-map"
2129 ],
2130 [node*], [
2131 AS_VAR_IF([ac_sys_emscripten_target], [node-debug], [wasm_debug=yes])
2132 AS_VAR_APPEND([LDFLAGS_NODIST], [" -sALLOW_MEMORY_GROWTH -sNODERAWFS"])
2133 AS_VAR_APPEND([LINKFORSHARED], [" -sEXIT_RUNTIME"])
2134 WASM_LINKFORSHARED_DEBUG="-gseparate-dwarf --emit-symbol-map"
2135 ]
2136 )
2137
2138 AS_VAR_IF([wasm_debug], [yes], [
2139 AS_VAR_APPEND([LDFLAGS_NODIST], [" -sASSERTIONS"])
2140 AS_VAR_APPEND([LINKFORSHARED], [" $WASM_LINKFORSHARED_DEBUG"])
2141 ], [
2142 AS_VAR_APPEND([LINKFORSHARED], [" -O2 -g0"])
c9844cb8 2143 ])
43839ba4 2144 ],
92c1037a 2145 [WASI], [
a6ca8eee 2146 AC_DEFINE([_WASI_EMULATED_SIGNAL], [1], [Define to 1 if you want to emulate signals on WASI])
4aea656d
CH
2147 AC_DEFINE([_WASI_EMULATED_GETPID], [1], [Define to 1 if you want to emulate getpid() on WASI])
2148 AC_DEFINE([_WASI_EMULATED_PROCESS_CLOCKS], [1], [Define to 1 if you want to emulate process clocks on WASI])
2149 LIBS="$LIBS -lwasi-emulated-signal -lwasi-emulated-getpid -lwasi-emulated-process-clocks"
a6ca8eee 2150 echo "#define _WASI_EMULATED_SIGNAL 1" >> confdefs.h
d81d57e9 2151
d8f87cdf
YT
2152 AS_VAR_IF([enable_wasm_pthreads], [yes], [
2153 # Note: update CFLAGS because ac_compile/ac_link needs this too.
2154 # without this, configure fails to find pthread_create, sem_init,
2155 # etc because they are only available in the sysroot for
2156 # wasm32-wasi-threads.
2157 AS_VAR_APPEND([CFLAGS], [" -target wasm32-wasi-threads -pthread"])
2158 AS_VAR_APPEND([CFLAGS_NODIST], [" -target wasm32-wasi-threads -pthread"])
2159 AS_VAR_APPEND([LDFLAGS_NODIST], [" -target wasm32-wasi-threads -pthread"])
2160 AS_VAR_APPEND([LDFLAGS_NODIST], [" -Wl,--import-memory"])
2161 AS_VAR_APPEND([LDFLAGS_NODIST], [" -Wl,--max-memory=10485760"])
2162 ])
2163
d81d57e9
CH
2164 dnl increase initial memory and stack size, move stack first
2165 dnl https://github.com/WebAssembly/wasi-libc/issues/233
2166 AS_VAR_APPEND([LDFLAGS_NODIST], [" -z stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760"])
a6ca8eee 2167 ]
43839ba4
CH
2168)
2169
c9844cb8
CH
2170AS_CASE([$enable_wasm_dynamic_linking],
2171 [yes], [ac_cv_func_dlopen=yes],
2172 [no], [ac_cv_func_dlopen=no],
2173 [missing], []
2174)
2175
2ea34cfb
EA
2176AC_SUBST([BASECFLAGS])
2177AC_SUBST([CFLAGS_NODIST])
2178AC_SUBST([LDFLAGS_NODIST])
2179AC_SUBST([LDFLAGS_NOLTO])
43839ba4
CH
2180AC_SUBST([WASM_ASSETS_DIR])
2181AC_SUBST([WASM_STDLIB])
fcaf910a 2182
41761933 2183# The -arch flags for universal builds on macOS
fcaf910a 2184UNIVERSAL_ARCH_FLAGS=
2ea34cfb 2185AC_SUBST([UNIVERSAL_ARCH_FLAGS])
fcaf910a 2186
9bd0cf59
EEA
2187dnl PY_CHECK_CC_WARNING(ENABLE, WARNING, [MSG])
2188AC_DEFUN([PY_CHECK_CC_WARNING], [
9bd0cf59 2189 AS_VAR_PUSHDEF([py_var], [ac_cv_$1_]m4_normalize($2)[_warning])
2ea34cfb 2190 AC_CACHE_CHECK([m4_ifblank([$3], [if we can $1 $CC $2 warning], [$3])], [py_var], [
76d14fac
EEA
2191 AS_VAR_COPY([py_cflags], [CFLAGS])
2192 AS_VAR_APPEND([CFLAGS], ["-W$2 -Werror"])
2193 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
2194 [AS_VAR_SET([py_var], [yes])],
2195 [AS_VAR_SET([py_var], [no])])
2196 AS_VAR_COPY([CFLAGS], [py_cflags])
2197 ])
9bd0cf59
EEA
2198 AS_VAR_POPDEF([py_var])
2199])
2200
decc6a47 2201# tweak BASECFLAGS based on compiler and platform
eff9f439
MG
2202AS_VAR_IF([with_strict_overflow], [yes],
2203 [BASECFLAGS="$BASECFLAGS $STRICT_OVERFLOW_CFLAGS"],
2204 [BASECFLAGS="$BASECFLAGS $NO_STRICT_OVERFLOW_CFLAGS"])
2205
decc6a47
SM
2206case $GCC in
2207yes)
aaeea78b 2208 CFLAGS_NODIST="$CFLAGS_NODIST -std=c11"
d1702565 2209
9bd0cf59
EEA
2210 PY_CHECK_CC_WARNING([enable], [extra], [if we can add -Wextra])
2211 AS_VAR_IF([ac_cv_enable_extra_warning], [yes],
2212 [CFLAGS_NODIST="$CFLAGS_NODIST -Wextra"])
ea80ffb8 2213
e6c9d245
BP
2214 # Python doesn't violate C99 aliasing rules, but older versions of
2215 # GCC produce warnings for legal Python code. Enable
2216 # -fno-strict-aliasing on versions of GCC that support but produce
2217 # warnings. See Issue3326
70fedcd5
ML
2218 ac_save_cc="$CC"
2219 CC="$CC -fno-strict-aliasing"
e6c9d245 2220 save_CFLAGS="$CFLAGS"
76d14fac
EEA
2221 AC_CACHE_CHECK([whether $CC accepts and needs -fno-strict-aliasing],
2222 [ac_cv_no_strict_aliasing],
b159a556
MK
2223 AC_COMPILE_IFELSE(
2224 [
8c2b6f1f 2225 AC_LANG_PROGRAM([[]], [[]])
b159a556
MK
2226 ],[
2227 CC="$ac_save_cc -fstrict-aliasing"
2228 CFLAGS="$CFLAGS -Werror -Wstrict-aliasing"
2229 AC_COMPILE_IFELSE(
2230 [
8c2b6f1f
MD
2231 AC_LANG_PROGRAM([[void f(int **x) {}]],
2232 [[double *x; f((int **) &x);]])
b159a556
MK
2233 ],[
2234 ac_cv_no_strict_aliasing=no
2235 ],[
2236 ac_cv_no_strict_aliasing=yes
2237 ])
2238 ],[
2239 ac_cv_no_strict_aliasing=no
2240 ]))
e6c9d245 2241 CFLAGS="$save_CFLAGS"
70fedcd5 2242 CC="$ac_save_cc"
9bd0cf59
EEA
2243 AS_VAR_IF([ac_cv_no_strict_aliasing], [yes],
2244 [BASECFLAGS="$BASECFLAGS -fno-strict-aliasing"])
b0e2b4c5 2245
5af85640
ZW
2246 # ICC doesn't recognize the option, but only emits a warning
2247 ## XXX does it emit an unused result warning and can it be disabled?
fecb9faf 2248 AS_CASE(["$CC_BASENAME"],
9bd0cf59
EEA
2249 [*icc*], [ac_cv_disable_unused_result_warning=no]
2250 [PY_CHECK_CC_WARNING([disable], [unused-result])])
2251 AS_VAR_IF([ac_cv_disable_unused_result_warning], [yes],
2252 [BASECFLAGS="$BASECFLAGS -Wno-unused-result"
2253 CFLAGS_NODIST="$CFLAGS_NODIST -Wno-unused-result"])
2254
2255 PY_CHECK_CC_WARNING([disable], [unused-parameter])
2256 AS_VAR_IF([ac_cv_disable_unused_parameter_warning], [yes],
2257 [CFLAGS_NODIST="$CFLAGS_NODIST -Wno-unused-parameter"])
2258
75c8133e
KD
2259 PY_CHECK_CC_WARNING([disable], [int-conversion])
2260 AS_VAR_IF([ac_cv_disable_int_conversion], [yes],
2261 [CFLAGS_NODIST="$CFLAGS_NODIST -Wno-int-conversion"])
2262
9bd0cf59
EEA
2263 PY_CHECK_CC_WARNING([disable], [missing-field-initializers])
2264 AS_VAR_IF([ac_cv_disable_missing_field_initializers_warning], [yes],
2265 [CFLAGS_NODIST="$CFLAGS_NODIST -Wno-missing-field-initializers"])
2266
2267 PY_CHECK_CC_WARNING([enable], [sign-compare])
2268 AS_VAR_IF([ac_cv_enable_sign_compare_warning], [yes],
2269 [BASECFLAGS="$BASECFLAGS -Wsign-compare"])
2270
2271 PY_CHECK_CC_WARNING([enable], [unreachable-code])
7f9cc935
CFN
2272 # Don't enable unreachable code warning in debug mode, since it usually
2273 # results in non-standard code paths.
bec699e4
ND
2274 # Issue #24324: Unfortunately, the unreachable code warning does not work
2275 # correctly on gcc and has been silently removed from the compiler.
2276 # It is supported on clang but on OS X systems gcc may be an alias
2277 # for clang. Try to determine if the compiler is not really gcc and,
2278 # if so, only then enable the warning.
2279 if test $ac_cv_enable_unreachable_code_warning = yes && \
2280 test "$Py_DEBUG" != "true" && \
2281 test -z "`$CC --version 2>/dev/null | grep 'Free Software Foundation'`"
7f9cc935
CFN
2282 then
2283 BASECFLAGS="$BASECFLAGS -Wunreachable-code"
bec699e4
ND
2284 else
2285 ac_cv_enable_unreachable_code_warning=no
7f9cc935 2286 fi
e3364848 2287
9bd0cf59
EEA
2288 PY_CHECK_CC_WARNING([enable], [strict-prototypes])
2289 AS_VAR_IF([ac_cv_enable_strict_prototypes_warning], [yes],
2290 [CFLAGS_NODIST="$CFLAGS_NODIST -Wstrict-prototypes"])
e3364848 2291
193ee0a0
VS
2292 ac_save_cc="$CC"
2293 CC="$CC -Werror=implicit-function-declaration"
76d14fac
EEA
2294 AC_CACHE_CHECK([if we can make implicit function declaration an error in $CC],
2295 [ac_cv_enable_implicit_function_declaration_error],
193ee0a0
VS
2296 AC_COMPILE_IFELSE(
2297 [
2298 AC_LANG_PROGRAM([[]], [[]])
2299 ],[
2300 ac_cv_enable_implicit_function_declaration_error=yes
2301 ],[
2302 ac_cv_enable_implicit_function_declaration_error=no
2303 ]))
2304 CC="$ac_save_cc"
193ee0a0 2305
9bd0cf59
EEA
2306 AS_VAR_IF([ac_cv_enable_implicit_function_declaration_error], [yes],
2307 [CFLAGS_NODIST="$CFLAGS_NODIST -Werror=implicit-function-declaration"])
193ee0a0 2308
0b60f64e
VS
2309 ac_save_cc="$CC"
2310 CC="$CC -fvisibility=hidden"
76d14fac 2311 AC_CACHE_CHECK([if we can use visibility in $CC], [ac_cv_enable_visibility],
0b60f64e
VS
2312 AC_COMPILE_IFELSE(
2313 [
2314 AC_LANG_PROGRAM([[]], [[]])
2315 ],[
2316 ac_cv_enable_visibility=yes
2317 ],[
2318 ac_cv_enable_visibility=no
2319 ]))
2320 CC="$ac_save_cc"
0b60f64e 2321
9bd0cf59
EEA
2322 AS_VAR_IF([ac_cv_enable_visibility], [yes],
2323 [CFLAGS_NODIST="$CFLAGS_NODIST -fvisibility=hidden"])
0b60f64e 2324
b0e2b4c5
MD
2325 # if using gcc on alpha, use -mieee to get (near) full IEEE 754
2326 # support. Without this, treatment of subnormals doesn't follow
2327 # the standard.
df2aecbf 2328 case $host in
b0e2b4c5
MD
2329 alpha*)
2330 BASECFLAGS="$BASECFLAGS -mieee"
2331 ;;
2332 esac
2333
decc6a47
SM
2334 case $ac_sys_system in
2335 SCO_SV*)
2336 BASECFLAGS="$BASECFLAGS -m486 -DSCO5"
2337 ;;
fcaf910a 2338
87adb6ef
ND
2339 Darwin*)
2340 # -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd
2341 # used to be here, but non-Apple gcc doesn't accept them.
2342 if test "${CC}" = gcc
2343 then
2ea34cfb 2344 AC_MSG_CHECKING([which compiler should be used])
87adb6ef
ND
2345 case "${UNIVERSALSDK}" in
2346 */MacOSX10.4u.sdk)
2347 # Build using 10.4 SDK, force usage of gcc when the
2348 # compiler is gcc, otherwise the user will get very
2349 # confusing error messages when building on OSX 10.6
2350 CC=gcc-4.0
2351 CPP=cpp-4.0
2352 ;;
2353 esac
2ea34cfb 2354 AC_MSG_RESULT([$CC])
87adb6ef 2355 fi
477c8d5e 2356
0cb33da1 2357 LIPO_INTEL64_FLAGS=""
87adb6ef
ND
2358 if test "${enable_universalsdk}"
2359 then
2360 case "$UNIVERSAL_ARCHS" in
2361 32-bit)
2362 UNIVERSAL_ARCH_FLAGS="-arch ppc -arch i386"
2363 LIPO_32BIT_FLAGS=""
2364 ARCH_RUN_32BIT=""
2365 ;;
2366 64-bit)
2367 UNIVERSAL_ARCH_FLAGS="-arch ppc64 -arch x86_64"
2368 LIPO_32BIT_FLAGS=""
2369 ARCH_RUN_32BIT="true"
2370 ;;
2371 all)
2372 UNIVERSAL_ARCH_FLAGS="-arch i386 -arch ppc -arch ppc64 -arch x86_64"
2373 LIPO_32BIT_FLAGS="-extract ppc7400 -extract i386"
2374 ARCH_RUN_32BIT="/usr/bin/arch -i386 -ppc"
2375 ;;
41761933
RO
2376 universal2)
2377 UNIVERSAL_ARCH_FLAGS="-arch arm64 -arch x86_64"
2378 LIPO_32BIT_FLAGS=""
0cb33da1 2379 LIPO_INTEL64_FLAGS="-extract x86_64"
41761933 2380 ARCH_RUN_32BIT="true"
0cb33da1 2381 ;;
87adb6ef
ND
2382 intel)
2383 UNIVERSAL_ARCH_FLAGS="-arch i386 -arch x86_64"
2384 LIPO_32BIT_FLAGS="-extract i386"
2385 ARCH_RUN_32BIT="/usr/bin/arch -i386"
2386 ;;
2387 intel-32)
2388 UNIVERSAL_ARCH_FLAGS="-arch i386"
2389 LIPO_32BIT_FLAGS=""
2390 ARCH_RUN_32BIT=""
2391 ;;
8c9bb72e
ND
2392 intel-64)
2393 UNIVERSAL_ARCH_FLAGS="-arch x86_64"
2394 LIPO_32BIT_FLAGS=""
2395 ARCH_RUN_32BIT="true"
2396 ;;
87adb6ef
ND
2397 3-way)
2398 UNIVERSAL_ARCH_FLAGS="-arch i386 -arch ppc -arch x86_64"
2399 LIPO_32BIT_FLAGS="-extract ppc7400 -extract i386"
2400 ARCH_RUN_32BIT="/usr/bin/arch -i386 -ppc"
2401 ;;
2402 *)
41761933 2403 AC_MSG_ERROR([proper usage is --with-universal-arch=universal2|32-bit|64-bit|all|intel|3-way])
87adb6ef
ND
2404 ;;
2405 esac
2406
87adb6ef
ND
2407 if test "${UNIVERSALSDK}" != "/"
2408 then
8c9bb72e
ND
2409 CFLAGS="${UNIVERSAL_ARCH_FLAGS} -isysroot ${UNIVERSALSDK} ${CFLAGS}"
2410 LDFLAGS="${UNIVERSAL_ARCH_FLAGS} -isysroot ${UNIVERSALSDK} ${LDFLAGS}"
87adb6ef 2411 CPPFLAGS="-isysroot ${UNIVERSALSDK} ${CPPFLAGS}"
8c9bb72e
ND
2412 else
2413 CFLAGS="${UNIVERSAL_ARCH_FLAGS} ${CFLAGS}"
2414 LDFLAGS="${UNIVERSAL_ARCH_FLAGS} ${LDFLAGS}"
87adb6ef
ND
2415 fi
2416 fi
67c38e26 2417
87adb6ef
ND
2418 # Calculate an appropriate deployment target for this build:
2419 # The deployment target value is used explicitly to enable certain
2420 # features are enabled (such as builtin libedit support for readline)
15f44ab0 2421 # through the use of Apple's Availability Macros and is used as a
87adb6ef
ND
2422 # component of the string returned by distutils.get_platform().
2423 #
2424 # Use the value from:
2425 # 1. the MACOSX_DEPLOYMENT_TARGET environment variable if specified
2426 # 2. the operating system version of the build machine if >= 10.6
2427 # 3. If running on OS X 10.3 through 10.5, use the legacy tests
2428 # below to pick either 10.3, 10.4, or 10.5 as the target.
2429 # 4. If we are running on OS X 10.2 or earlier, good luck!
2430
2ea34cfb 2431 AC_MSG_CHECKING([which MACOSX_DEPLOYMENT_TARGET to use])
36820b6e
ND
2432 cur_target_major=`sw_vers -productVersion | \
2433 sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
2434 cur_target_minor=`sw_vers -productVersion | \
2435 sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
2436 cur_target="${cur_target_major}.${cur_target_minor}"
2437 if test ${cur_target_major} -eq 10 && \
2438 test ${cur_target_minor} -ge 3 && \
2439 test ${cur_target_minor} -le 5
87adb6ef 2440 then
36820b6e 2441 # OS X 10.3 through 10.5
87adb6ef
ND
2442 cur_target=10.3
2443 if test ${enable_universalsdk}
2444 then
2445 case "$UNIVERSAL_ARCHS" in
2446 all|3-way|intel|64-bit)
2447 # These configurations were first supported in 10.5
2448 cur_target='10.5'
2449 ;;
2450 esac
2451 else
2452 if test `/usr/bin/arch` = "i386"
2453 then
2454 # 10.4 was the first release to support Intel archs
2455 cur_target="10.4"
2456 fi
2457 fi
2458 fi
2459 CONFIGURE_MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET-${cur_target}}
2460
2461 # Make sure that MACOSX_DEPLOYMENT_TARGET is set in the
2462 # environment with a value that is the same as what we'll use
2463 # in the Makefile to ensure that we'll get the same compiler
2464 # environment during configure and build time.
2465 MACOSX_DEPLOYMENT_TARGET="$CONFIGURE_MACOSX_DEPLOYMENT_TARGET"
2466 export MACOSX_DEPLOYMENT_TARGET
2467 EXPORT_MACOSX_DEPLOYMENT_TARGET=''
2ea34cfb 2468 AC_MSG_RESULT([$MACOSX_DEPLOYMENT_TARGET])
87adb6ef 2469
2ea34cfb 2470 AC_MSG_CHECKING([if specified universal architectures work])
27c68a6d 2471 AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <stdio.h>]], [[printf("%d", 42);]])],
2ea34cfb
EA
2472 [AC_MSG_RESULT([yes])],
2473 [AC_MSG_RESULT([no])
2474 AC_MSG_ERROR([check config.log and use the '--with-universal-archs' option])
0f20bd90
RO
2475 ])
2476
87adb6ef
ND
2477 # end of Darwin* tests
2478 ;;
decc6a47
SM
2479 esac
2480 ;;
2481
2482*)
2483 case $ac_sys_system in
2484 OpenUNIX*|UnixWare*)
2485 BASECFLAGS="$BASECFLAGS -K pentium,host,inline,loop_unroll,alloca "
2486 ;;
2487 SCO_SV*)
2488 BASECFLAGS="$BASECFLAGS -belf -Ki486 -DSCO5"
2489 ;;
2490 esac
2491 ;;
2492esac
2493
fecb9faf 2494case "$CC_BASENAME" in
9a6b2787
LW
2495*mpicc*)
2496 CFLAGS_NODIST="$CFLAGS_NODIST"
2497 ;;
5af85640 2498*icc*)
84a7917b 2499 # ICC needs -fp-model strict or floats behave badly
5af85640
ZW
2500 CFLAGS_NODIST="$CFLAGS_NODIST -fp-model strict"
2501 ;;
84a7917b
SK
2502*xlc*)
2503 CFLAGS_NODIST="$CFLAGS_NODIST -qalias=noansi -qmaxmem=-1"
2504 ;;
5af85640
ZW
2505esac
2506
ddbfa2c3 2507if test "$assertions" = 'true'; then
e1ceaa00
FD
2508 :
2509else
2510 OPT="-DNDEBUG $OPT"
2511fi
2512
6f2260ea 2513if test "$ac_arch_flags"
c5a39034 2514then
decc6a47 2515 BASECFLAGS="$BASECFLAGS $ac_arch_flags"
c5a39034 2516fi
5739e7ec 2517
a5f73f9b
ML
2518# On some compilers, pthreads are available without further options
2519# (e.g. MacOS X). On some of these systems, the compiler will not
2520# complain if unaccepted options are passed (e.g. gcc on Mac OS X).
2521# So we have to see first whether pthreads are available without
2522# options before we can check whether -Kpthread improves anything.
76d14fac
EEA
2523AC_CACHE_CHECK([whether pthreads are available without options],
2524 [ac_cv_pthread_is_default],
b159a556 2525[AC_RUN_IFELSE([AC_LANG_SOURCE([[
7dba5940 2526#include <stdio.h>
a5f73f9b
ML
2527#include <pthread.h>
2528
2529void* routine(void* p){return NULL;}
2530
e35ca417 2531int main(void){
a5f73f9b
ML
2532 pthread_t p;
2533 if(pthread_create(&p,NULL,routine,NULL)!=0)
2534 return 1;
4f8d0549 2535 (void)pthread_detach(p);
a5f73f9b
ML
2536 return 0;
2537}
b159a556 2538]])],[
d8d39a00
SM
2539 ac_cv_pthread_is_default=yes
2540 ac_cv_kthread=no
2541 ac_cv_pthread=no
b159a556 2542],[ac_cv_pthread_is_default=no],[ac_cv_pthread_is_default=no])
a5f73f9b 2543])
a5f73f9b
ML
2544
2545
1b80b240 2546if test $ac_cv_pthread_is_default = yes
a5f73f9b
ML
2547then
2548 ac_cv_kpthread=no
2549else
130fb175
ML
2550# -Kpthread, if available, provides the right #defines
2551# and linker options to make pthread_create available
260aecc8
ML
2552# Some compilers won't report that they do not support -Kpthread,
2553# so we need to run a program to see whether it really made the
2554# function available.
76d14fac 2555AC_CACHE_CHECK([whether $CC accepts -Kpthread], [ac_cv_kpthread],
130fb175
ML
2556[ac_save_cc="$CC"
2557CC="$CC -Kpthread"
b159a556 2558AC_RUN_IFELSE([AC_LANG_SOURCE([[
7dba5940 2559#include <stdio.h>
260aecc8
ML
2560#include <pthread.h>
2561
2562void* routine(void* p){return NULL;}
2563
e35ca417 2564int main(void){
260aecc8
ML
2565 pthread_t p;
2566 if(pthread_create(&p,NULL,routine,NULL)!=0)
2567 return 1;
4f8d0549 2568 (void)pthread_detach(p);
260aecc8
ML
2569 return 0;
2570}
b159a556 2571]])],[ac_cv_kpthread=yes],[ac_cv_kpthread=no],[ac_cv_kpthread=no])
130fb175 2572CC="$ac_save_cc"])
a5f73f9b 2573fi
130fb175 2574
d8d39a00 2575if test $ac_cv_kpthread = no -a $ac_cv_pthread_is_default = no
5f433f0e
ML
2576then
2577# -Kthread, if available, provides the right #defines
2578# and linker options to make pthread_create available
2579# Some compilers won't report that they do not support -Kthread,
2580# so we need to run a program to see whether it really made the
2581# function available.
76d14fac 2582AC_CACHE_CHECK([whether $CC accepts -Kthread], [ac_cv_kthread],
5f433f0e
ML
2583[ac_save_cc="$CC"
2584CC="$CC -Kthread"
b159a556 2585AC_RUN_IFELSE([AC_LANG_SOURCE([[
7dba5940 2586#include <stdio.h>
5f433f0e
ML
2587#include <pthread.h>
2588
2589void* routine(void* p){return NULL;}
2590
e35ca417 2591int main(void){
5f433f0e
ML
2592 pthread_t p;
2593 if(pthread_create(&p,NULL,routine,NULL)!=0)
2594 return 1;
2595 (void)pthread_detach(p);
2596 return 0;
2597}
b159a556 2598]])],[ac_cv_kthread=yes],[ac_cv_kthread=no],[ac_cv_kthread=no])
5f433f0e 2599CC="$ac_save_cc"])
5f433f0e
ML
2600fi
2601
d8d39a00 2602if test $ac_cv_kthread = no -a $ac_cv_pthread_is_default = no
4ee6eef2
ML
2603then
2604# -pthread, if available, provides the right #defines
2605# and linker options to make pthread_create available
2606# Some compilers won't report that they do not support -pthread,
2607# so we need to run a program to see whether it really made the
2608# function available.
76d14fac 2609AC_CACHE_CHECK([whether $CC accepts -pthread], [ac_cv_pthread],
4ee6eef2
ML
2610[ac_save_cc="$CC"
2611CC="$CC -pthread"
b159a556 2612AC_RUN_IFELSE([AC_LANG_SOURCE([[
7dba5940 2613#include <stdio.h>
4ee6eef2
ML
2614#include <pthread.h>
2615
2616void* routine(void* p){return NULL;}
2617
e35ca417 2618int main(void){
4ee6eef2
ML
2619 pthread_t p;
2620 if(pthread_create(&p,NULL,routine,NULL)!=0)
2621 return 1;
2622 (void)pthread_detach(p);
2623 return 0;
2624}
b159a556 2625]])],[ac_cv_pthread=yes],[ac_cv_pthread=no],[ac_cv_pthread=no])
4ee6eef2 2626CC="$ac_save_cc"])
4ee6eef2
ML
2627fi
2628
ab1e5858
ML
2629# If we have set a CC compiler flag for thread support then
2630# check if it works for CXX, too.
ab1e5858
ML
2631if test ! -z "$CXX"
2632then
cc874871
DS
2633AC_CACHE_CHECK([whether $CXX also accepts flags for thread support], [ac_cv_cxx_thread],
2634[ac_save_cxx="$CXX"
ab1e5858
ML
2635
2636if test "$ac_cv_kpthread" = "yes"
2637then
1b80b240 2638 CXX="$CXX -Kpthread"
ab1e5858
ML
2639 ac_cv_cxx_thread=yes
2640elif test "$ac_cv_kthread" = "yes"
2641then
2642 CXX="$CXX -Kthread"
2643 ac_cv_cxx_thread=yes
2644elif test "$ac_cv_pthread" = "yes"
1b80b240 2645then
ab1e5858
ML
2646 CXX="$CXX -pthread"
2647 ac_cv_cxx_thread=yes
cc874871
DS
2648else
2649 ac_cv_cxx_thread=no
ab1e5858
ML
2650fi
2651
2652if test $ac_cv_cxx_thread = yes
2653then
2654 echo 'void foo();int main(){foo();}void foo(){}' > conftest.$ac_ext
2655 $CXX -c conftest.$ac_ext 2>&5
2656 if $CXX -o conftest$ac_exeext conftest.$ac_objext 2>&5 \
2657 && test -s conftest$ac_exeext && ./conftest$ac_exeext
2658 then
2659 ac_cv_cxx_thread=yes
2660 else
2661 ac_cv_cxx_thread=no
ab1e5858
ML
2662 fi
2663 rm -fr conftest*
ab1e5858 2664fi
cc874871
DS
2665CXX="$ac_save_cxx"])
2666else
2667 ac_cv_cxx_thread=no
ab1e5858 2668fi
ab1e5858 2669
ce81d59c
FD
2670dnl # check for ANSI or K&R ("traditional") preprocessor
2671dnl AC_MSG_CHECKING(for C preprocessor type)
b159a556 2672dnl AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
ce81d59c
FD
2673dnl #define spam(name, doc) {#name, &name, #name "() -- " doc}
2674dnl int foo;
2675dnl struct {char *name; int *addr; char *doc;} desc = spam(foo, "something");
b159a556 2676dnl ]], [[;]])],[cpp_type=ansi],[AC_DEFINE(HAVE_OLD_CPP) cpp_type=traditional])
ce81d59c 2677dnl AC_MSG_RESULT($cpp_type)
300fda7a 2678
cbab997e
CH
2679dnl autoconf 2.71 deprecates STDC_HEADERS, keep for backwards compatibility
2680dnl assume C99 compilers provide ANSI C headers
2ea34cfb
EA
2681AC_DEFINE([STDC_HEADERS], [1],
2682 [Define to 1 if you have the ANSI C header files.])
cbab997e 2683
627b2d7c 2684# checks for header files
c1dec954 2685AC_CHECK_HEADERS([ \
e4127eaa 2686 alloca.h asm/types.h bluetooth.h conio.h direct.h dlfcn.h endian.h errno.h fcntl.h grp.h \
4ba18099 2687 io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/fs.h linux/limits.h linux/memfd.h \
d1e2e0e1 2688 linux/random.h linux/soundcard.h \
80c08d1c 2689 linux/tipc.h linux/wait.h netdb.h net/ethernet.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \
a6ca8eee 2690 sched.h setjmp.h shadow.h signal.h spawn.h stropts.h sys/audioio.h sys/bsdtty.h sys/devpoll.h \
c1dec954
EEA
2691 sys/endian.h sys/epoll.h sys/event.h sys/eventfd.h sys/file.h sys/ioctl.h sys/kern_control.h \
2692 sys/loadavg.h sys/lock.h sys/memfd.h sys/mkdev.h sys/mman.h sys/modem.h sys/param.h sys/poll.h \
2693 sys/random.h sys/resource.h sys/select.h sys/sendfile.h sys/socket.h sys/soundcard.h sys/stat.h \
2694 sys/statvfs.h sys/sys_domain.h sys/syscall.h sys/sysmacros.h sys/termio.h sys/time.h sys/times.h \
2695 sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h sys/xattr.h sysexits.h syslog.h \
ae553b35 2696 termios.h util.h utime.h utmp.h \
c1dec954 2697])
76be6eda 2698AC_HEADER_DIRENT
dbe3f762 2699AC_HEADER_MAJOR
627b2d7c 2700
93b2dee8
BP
2701# bluetooth/bluetooth.h has been known to not compile with -std=c99.
2702# http://permalink.gmane.org/gmane.linux.bluez.kernel/22294
2703SAVE_CFLAGS=$CFLAGS
2704CFLAGS="-std=c99 $CFLAGS"
2ea34cfb 2705AC_CHECK_HEADERS([bluetooth/bluetooth.h])
93b2dee8
BP
2706CFLAGS=$SAVE_CFLAGS
2707
3b1f2c35
GS
2708# On Darwin (OS X) net/if.h requires sys/socket.h to be imported first.
2709AC_CHECK_HEADERS([net/if.h], [], [],
2710[#include <stdio.h>
cbab997e
CH
2711#include <stdlib.h>
2712#include <stddef.h>
3b1f2c35
GS
2713#ifdef HAVE_SYS_SOCKET_H
2714# include <sys/socket.h>
2715#endif
2716])
2717
11017b17 2718# On Linux, netlink.h requires asm/types.h
f50c1724
MG
2719# On FreeBSD, netlink.h is located in netlink/netlink.h
2720AC_CHECK_HEADERS([linux/netlink.h netlink/netlink.h], [], [], [
11017b17
ML
2721#ifdef HAVE_ASM_TYPES_H
2722#include <asm/types.h>
2723#endif
2724#ifdef HAVE_SYS_SOCKET_H
2725#include <sys/socket.h>
2726#endif
2727])
2728
bb816517 2729# On Linux, qrtr.h requires asm/types.h
2ea34cfb 2730AC_CHECK_HEADERS([linux/qrtr.h], [], [], [
bb816517
BA
2731#ifdef HAVE_ASM_TYPES_H
2732#include <asm/types.h>
2733#endif
2734#ifdef HAVE_SYS_SOCKET_H
2735#include <sys/socket.h>
2736#endif
2737])
2738
2ea34cfb 2739AC_CHECK_HEADERS([linux/vm_sockets.h], [], [], [
effc12f8 2740#ifdef HAVE_SYS_SOCKET_H
2741#include <sys/socket.h>
2742#endif
2743])
2744
360371f7 2745# On Linux, can.h, can/bcm.h, can/j1939.h, can/raw.h require sys/socket.h
40fcd168 2746# On NetBSD, netcan/can.h requires sys/socket.h
2ea34cfb
EA
2747AC_CHECK_HEADERS(
2748[linux/can.h linux/can/bcm.h linux/can/j1939.h linux/can/raw.h netcan/can.h],
2749[], [], [
47413c11
CFN
2750#ifdef HAVE_SYS_SOCKET_H
2751#include <sys/socket.h>
2752#endif
2753])
2754
627b2d7c 2755# checks for typedefs
57c50c9c
CH
2756AC_CACHE_CHECK([for clock_t in time.h], [ac_cv_clock_t_time_h], [
2757 AC_EGREP_HEADER([clock_t], [time.h], [ac_cv_clock_t_time_h=yes], [ac_cv_clock_t_time_h=no])
2758])
2759dnl checks for "no"
2760AS_VAR_IF([ac_cv_clock_t_time_h], [no], [
2ea34cfb
EA
2761 AC_DEFINE([clock_t], [long],
2762 [Define to 'long' if <time.h> doesn't define.])
c45929ec 2763])
5739e7ec 2764
57c50c9c 2765AC_CACHE_CHECK([for makedev], [ac_cv_func_makedev], [
740f53a6
JC
2766AC_LINK_IFELSE([AC_LANG_PROGRAM([[
2767#if defined(MAJOR_IN_MKDEV)
2768#include <sys/mkdev.h>
2769#elif defined(MAJOR_IN_SYSMACROS)
2770#include <sys/sysmacros.h>
2771#else
2772#include <sys/types.h>
2773#endif
2774]], [[
2775 makedev(0, 0) ]])
57c50c9c
CH
2776],[ac_cv_func_makedev=yes],[ac_cv_func_makedev=no])
2777])
2778
2779AS_VAR_IF([ac_cv_func_makedev], [yes], [
2ea34cfb
EA
2780 AC_DEFINE([HAVE_MAKEDEV], [1],
2781 [Define this if you have the makedev macro.])
57c50c9c 2782])
1169011f 2783
985ecdcf 2784# byte swapping
57c50c9c 2785AC_CACHE_CHECK([for le64toh], [ac_cv_func_le64toh], [
985ecdcf
CH
2786AC_LINK_IFELSE([AC_LANG_PROGRAM([[
2787#ifdef HAVE_ENDIAN_H
2788#include <endian.h>
2789#elif defined(HAVE_SYS_ENDIAN_H)
2790#include <sys/endian.h>
2791#endif
2792]], [[
2793 le64toh(1) ]])
57c50c9c
CH
2794],[ac_cv_func_le64toh=yes],[ac_cv_func_le64toh=no])
2795])
2796
2797AS_VAR_IF([ac_cv_func_le64toh], [yes], [
2ea34cfb
EA
2798 AC_DEFINE([HAVE_HTOLE64], [1],
2799 [Define this if you have le64toh()])
57c50c9c 2800])
985ecdcf 2801
399a6890 2802use_lfs=yes
006a56ce 2803# Don't use largefile support for GNU/Hurd
2804case $ac_sys_system in GNU*)
2805 use_lfs=no
2806esac
2807
399a6890 2808if test "$use_lfs" = "yes"; then
810cc51d
GR
2809# Two defines needed to enable largefile support on various platforms
2810# These may affect some typedefs
216e404b
GB
2811case $ac_sys_system/$ac_sys_release in
2812AIX*)
2ea34cfb 2813 AC_DEFINE([_LARGE_FILES], [1],
216e404b
GB
2814 [This must be defined on AIX systems to enable large file support.])
2815 ;;
2816esac
2ea34cfb 2817AC_DEFINE([_LARGEFILE_SOURCE], [1],
c45929ec 2818[This must be defined on some systems to enable large file support.])
2ea34cfb 2819AC_DEFINE([_FILE_OFFSET_BITS], [64],
c45929ec 2820[This must be set to 64 on some systems to enable large file support.])
399a6890 2821fi
810cc51d 2822
300fda7a
GR
2823# Add some code to confdefs.h so that the test for off_t works on SCO
2824cat >> confdefs.h <<\EOF
2825#if defined(SCO_DS)
2826#undef _OFF_T
2827#endif
2828EOF
2829
ef2255b1 2830# Type availability checks
76be6eda
GR
2831AC_TYPE_MODE_T
2832AC_TYPE_OFF_T
2833AC_TYPE_PID_T
bada4c39 2834AC_DEFINE_UNQUOTED([RETSIGTYPE],[void],[assume C89 semantics that RETSIGTYPE is always void])
76be6eda
GR
2835AC_TYPE_SIZE_T
2836AC_TYPE_UID_T
983bc16c 2837
2ea34cfb
EA
2838AC_CHECK_TYPE([ssize_t],
2839 AC_DEFINE([HAVE_SSIZE_T], [1],
2840 [Define if your compiler provides ssize_t]), [], [])
2841AC_CHECK_TYPE([__uint128_t],
2842 AC_DEFINE([HAVE_GCC_UINT128_T], [1],
2843 [Define if your compiler provides __uint128_t]), [], [])
627b2d7c 2844
dec07575 2845# Sizes and alignments of various common basic types
b9820a3b 2846# ANSI C requires sizeof(char) == 1, so no need to check it
2ea34cfb
EA
2847AC_CHECK_SIZEOF([int], [4])
2848AC_CHECK_SIZEOF([long], [4])
2849AC_CHECK_ALIGNOF([long])
2850AC_CHECK_SIZEOF([long long], [8])
2851AC_CHECK_SIZEOF([void *], [4])
2852AC_CHECK_SIZEOF([short], [2])
2853AC_CHECK_SIZEOF([float], [4])
2854AC_CHECK_SIZEOF([double], [8])
2855AC_CHECK_SIZEOF([fpos_t], [4])
2856AC_CHECK_SIZEOF([size_t], [4])
2857AC_CHECK_ALIGNOF([size_t])
2858AC_CHECK_SIZEOF([pid_t], [4])
2859AC_CHECK_SIZEOF([uintptr_t])
2860AC_CHECK_ALIGNOF([max_align_t])
ac405f6c 2861
3055c947 2862AC_TYPE_LONG_DOUBLE
2ea34cfb 2863AC_CHECK_SIZEOF([long double], [16])
9b30784a 2864
2ea34cfb 2865AC_CHECK_SIZEOF([_Bool], [1])
b213704f 2866
2ea34cfb 2867AC_CHECK_SIZEOF([off_t], [], [
0805b4ac 2868#ifdef HAVE_SYS_TYPES_H
00f0f6ef 2869#include <sys/types.h>
0805b4ac 2870#endif
00f0f6ef 2871])
00f0f6ef 2872
2ea34cfb 2873AC_MSG_CHECKING([whether to enable large file support])
2df5d281 2874if test "$ac_cv_sizeof_off_t" -gt "$ac_cv_sizeof_long" -a \
8bc1dfd2 2875 "$ac_cv_sizeof_long_long" -ge "$ac_cv_sizeof_off_t"; then
96b344c2
CH
2876 have_largefile_support="yes"
2877else
2878 have_largefile_support="no"
2879fi
2880dnl LFS does not work with Emscripten 3.1
2881AS_CASE([$ac_sys_system],
2882 [Emscripten], [have_largefile_support="no"]
2883)
2884AS_VAR_IF([have_largefile_support], [yes], [
2ea34cfb 2885 AC_DEFINE([HAVE_LARGEFILE_SUPPORT], [1],
c45929ec 2886 [Defined to enable large file support when an off_t is bigger than a long
52c1a6a1 2887 and long long is at least as big as an off_t. You may need
c45929ec
ML
2888 to add some flags for configuration and compilation to enable this mode.
2889 (For Solaris and Linux, the necessary defines are already defined.)])
2ea34cfb 2890 AC_MSG_RESULT([yes])
96b344c2 2891], [
2ea34cfb 2892 AC_MSG_RESULT([no])
96b344c2 2893])
00f0f6ef 2894
2ea34cfb 2895AC_CHECK_SIZEOF([time_t], [], [
0805b4ac
AV
2896#ifdef HAVE_SYS_TYPES_H
2897#include <sys/types.h>
2898#endif
2899#ifdef HAVE_TIME_H
a3f6e913 2900#include <time.h>
0805b4ac 2901#endif
a3f6e913 2902])
00f0f6ef 2903
635f6fb0 2904# if have pthread_t then define SIZEOF_PTHREAD_T
123cbd28
ML
2905ac_save_cc="$CC"
2906if test "$ac_cv_kpthread" = "yes"
2907then CC="$CC -Kpthread"
5f433f0e
ML
2908elif test "$ac_cv_kthread" = "yes"
2909then CC="$CC -Kthread"
4ee6eef2
ML
2910elif test "$ac_cv_pthread" = "yes"
2911then CC="$CC -pthread"
123cbd28 2912fi
0805b4ac 2913
57c50c9c 2914AC_CACHE_CHECK([for pthread_t], [ac_cv_have_pthread_t], [
b159a556 2915AC_COMPILE_IFELSE([
27c68a6d 2916 AC_LANG_PROGRAM([[@%:@include <pthread.h>]], [[pthread_t x; x = *(pthread_t*)0;]])
57c50c9c
CH
2917], [ac_cv_have_pthread_t=yes], [ac_cv_have_pthread_t=no])
2918])
2919AS_VAR_IF([ac_cv_have_pthread_t], [yes], [
2ea34cfb 2920 AC_CHECK_SIZEOF([pthread_t], [], [
0805b4ac 2921#ifdef HAVE_PTHREAD_H
6eb37f0e 2922#include <pthread.h>
0805b4ac 2923#endif
635f6fb0 2924 ])
57c50c9c 2925])
731e1890
MY
2926
2927# Issue #25658: POSIX hasn't defined that pthread_key_t is compatible with int.
2928# This checking will be unnecessary after removing deprecated TLS API.
27c68a6d 2929AC_CHECK_SIZEOF([pthread_key_t], [], [[@%:@include <pthread.h>]])
57c50c9c 2930AC_CACHE_CHECK([whether pthread_key_t is compatible with int], [ac_cv_pthread_key_t_is_arithmetic_type], [
731e1890
MY
2931if test "$ac_cv_sizeof_pthread_key_t" -eq "$ac_cv_sizeof_int" ; then
2932 AC_COMPILE_IFELSE(
27c68a6d 2933 [AC_LANG_PROGRAM([[@%:@include <pthread.h>]], [[pthread_key_t k; k * 1;]])],
57c50c9c
CH
2934 [ac_cv_pthread_key_t_is_arithmetic_type=yes],
2935 [ac_cv_pthread_key_t_is_arithmetic_type=no]
731e1890 2936 )
731e1890 2937else
57c50c9c 2938 ac_cv_pthread_key_t_is_arithmetic_type=no
731e1890 2939fi
57c50c9c
CH
2940])
2941AS_VAR_IF([ac_cv_pthread_key_t_is_arithmetic_type], [yes], [
2ea34cfb 2942 AC_DEFINE([PTHREAD_KEY_T_IS_COMPATIBLE_WITH_INT], [1],
57c50c9c
CH
2943 [Define if pthread_key_t is compatible with int.])
2944])
2945
123cbd28 2946CC="$ac_save_cc"
635f6fb0 2947
2ea34cfb 2948AC_MSG_CHECKING([for --enable-framework])
b6e9cad3 2949if test "$enable_framework"
54ecc3d2 2950then
decc6a47 2951 BASECFLAGS="$BASECFLAGS -fno-common -dynamic"
1b80b240 2952 # -F. is needed to allow linking to the framework while
b6e9cad3 2953 # in the build location.
2ea34cfb 2954 AC_DEFINE([WITH_NEXT_FRAMEWORK], [1],
c45929ec
ML
2955 [Define if you want to produce an OpenStep/Rhapsody framework
2956 (shared library plus accessory files).])
2ea34cfb 2957 AC_MSG_RESULT([yes])
99aab651
RO
2958 if test $enable_shared = "yes"
2959 then
2960 AC_MSG_ERROR([Specifying both --enable-shared and --enable-framework is not supported, use only --enable-framework instead])
2961 fi
54ecc3d2 2962else
2ea34cfb 2963 AC_MSG_RESULT([no])
54ecc3d2
GR
2964fi
2965
5b070c0d 2966# Check for --with-dsymutil
2ea34cfb
EA
2967AC_SUBST([DSYMUTIL])
2968AC_SUBST([DSYMUTIL_PATH])
5b070c0d
PGS
2969DSYMUTIL=
2970DSYMUTIL_PATH=
2ea34cfb
EA
2971AC_MSG_CHECKING([for --with-dsymutil])
2972AC_ARG_WITH(
2973 [dsymutil],
2974 [AS_HELP_STRING(
2975 [--with-dsymutil],
2976 [link debug information into final executable with dsymutil in macOS (default is no)]
2977 )],
5b070c0d
PGS
2978[
2979if test "$withval" != no
2980then
2981 if test "$MACHDEP" != "darwin"; then
2982 AC_MSG_ERROR([dsymutil debug linking is only available in macOS.])
2983 fi
2ea34cfb 2984 AC_MSG_RESULT([yes]);
5b070c0d 2985 DSYMUTIL='true'
2ea34cfb 2986else AC_MSG_RESULT([no]); DSYMUTIL=
5b070c0d 2987fi],
2ea34cfb 2988[AC_MSG_RESULT([no])])
5b070c0d
PGS
2989
2990if test "$DSYMUTIL"; then
2ea34cfb 2991 AC_PATH_PROG([DSYMUTIL_PATH], [dsymutil], [not found])
5b070c0d
PGS
2992 if test "$DSYMUTIL_PATH" = "not found"; then
2993 AC_MSG_ERROR([dsymutil command not found on \$PATH])
2994 fi
2995fi
2996
2ea34cfb 2997AC_MSG_CHECKING([for dyld])
9a66b6d4
JJ
2998case $ac_sys_system/$ac_sys_release in
2999 Darwin/*)
2ea34cfb 3000 AC_DEFINE([WITH_DYLD], [1],
c45929ec
ML
3001 [Define if you want to use the new-style (Openstep, Rhapsody, MacOS)
3002 dynamic linker (dyld) instead of the old-style (NextStep) dynamic
3003 linker (rld). Dyld is necessary to support frameworks.])
2ea34cfb 3004 AC_MSG_RESULT([always on for Darwin])
9a66b6d4
JJ
3005 ;;
3006 *)
2ea34cfb 3007 AC_MSG_RESULT([no])
b6e9cad3 3008 ;;
9a66b6d4 3009esac
54ecc3d2 3010
2ea34cfb
EA
3011AC_MSG_CHECKING([for --with-address-sanitizer])
3012AC_ARG_WITH([address_sanitizer],
be9de872
ŁL
3013 AS_HELP_STRING([--with-address-sanitizer],
3014 [enable AddressSanitizer memory error detector, 'asan' (default is no)]),
3015[
2ea34cfb 3016AC_MSG_RESULT([$withval])
be9de872
ŁL
3017BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
3018LDFLAGS="-fsanitize=address $LDFLAGS"
3019# ASan works by controlling memory allocation, our own malloc interferes.
3020with_pymalloc="no"
3021],
2ea34cfb 3022[AC_MSG_RESULT([no])])
be9de872 3023
2ea34cfb
EA
3024AC_MSG_CHECKING([for --with-memory-sanitizer])
3025AC_ARG_WITH(
3026 [memory_sanitizer],
3027 [AS_HELP_STRING(
3028 [--with-memory-sanitizer],
3029 [enable MemorySanitizer allocation error detector, 'msan' (default is no)]
3030 )],
be9de872 3031[
2ea34cfb 3032AC_MSG_RESULT([$withval])
e71c12ef 3033AX_CHECK_COMPILE_FLAG([-fsanitize=memory],[
be9de872
ŁL
3034BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
3035LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
e71c12ef 3036],[AC_MSG_ERROR([The selected compiler doesn't support memory sanitizer])])
be9de872
ŁL
3037# MSan works by controlling memory allocation, our own malloc interferes.
3038with_pymalloc="no"
3039],
2ea34cfb 3040[AC_MSG_RESULT([no])])
be9de872 3041
2ea34cfb
EA
3042AC_MSG_CHECKING([for --with-undefined-behavior-sanitizer])
3043AC_ARG_WITH(
3044 [undefined_behavior_sanitizer],
3045 [AS_HELP_STRING(
3046 [--with-undefined-behavior-sanitizer],
3047 [enable UndefinedBehaviorSanitizer undefined behaviour detector, 'ubsan' (default is no)]
3048 )],
be9de872 3049[
2ea34cfb 3050AC_MSG_RESULT([$withval])
be9de872
ŁL
3051BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
3052LDFLAGS="-fsanitize=undefined $LDFLAGS"
3053with_ubsan="yes"
3054],
3055[
2ea34cfb 3056AC_MSG_RESULT([no])
be9de872
ŁL
3057with_ubsan="no"
3058])
3059
ac405f6c 3060# Set info about shared libraries.
2ea34cfb
EA
3061AC_SUBST([SHLIB_SUFFIX])
3062AC_SUBST([LDSHARED])
3063AC_SUBST([LDCXXSHARED])
3064AC_SUBST([BLDSHARED])
3065AC_SUBST([CCSHARED])
3066AC_SUBST([LINKFORSHARED])
b1441c7e 3067
d5537d07 3068# SHLIB_SUFFIX is the extension of shared libraries `(including the dot!)
3069# -- usually .so, .sl on HP-UX, .dll on Cygwin
2ea34cfb 3070AC_MSG_CHECKING([the extension of shared libraries])
d5537d07 3071if test -z "$SHLIB_SUFFIX"; then
3072 case $ac_sys_system in
3073 hp*|HP*)
3074 case `uname -m` in
3075 ia64) SHLIB_SUFFIX=.so;;
3076 *) SHLIB_SUFFIX=.sl;;
3077 esac
3078 ;;
3079 CYGWIN*) SHLIB_SUFFIX=.dll;;
3080 *) SHLIB_SUFFIX=.so;;
3081 esac
3082fi
2ea34cfb 3083AC_MSG_RESULT([$SHLIB_SUFFIX])
d5537d07 3084
ac405f6c 3085# LDSHARED is the ld *command* used to create shared library
06930631 3086# -- "cc -G" on SunOS 5.x.
54ecc3d2
GR
3087# (Shared libraries in this instance are shared modules to be loaded into
3088# Python, as opposed to building Python itself as a shared library.)
2ea34cfb 3089AC_MSG_CHECKING([LDSHARED])
ac405f6c
GR
3090if test -z "$LDSHARED"
3091then
76be6eda 3092 case $ac_sys_system/$ac_sys_release in
b3531b86 3093 AIX*)
395733d4 3094 BLDSHARED="Modules/ld_so_aix \$(CC) -bI:Modules/python.exp"
5de141f1 3095 LDSHARED="\$(LIBPL)/ld_so_aix \$(CC) -bI:\$(LIBPL)/python.exp"
b3531b86 3096 ;;
1b80b240 3097 SunOS/5*)
03d788dc
TZ
3098 if test "$GCC" = "yes" ; then
3099 LDSHARED='$(CC) -shared'
3100 LDCXXSHARED='$(CXX) -shared'
3101 else
3102 LDSHARED='$(CC) -G'
3103 LDCXXSHARED='$(CXX) -G'
57c9a663 3104 fi ;;
f44b9a1a 3105 hp*|HP*)
03d788dc
TZ
3106 if test "$GCC" = "yes" ; then
3107 LDSHARED='$(CC) -shared'
3108 LDCXXSHARED='$(CXX) -shared'
3109 else
9d25bd11
RB
3110 LDSHARED='$(CC) -b'
3111 LDCXXSHARED='$(CXX) -b'
f44b9a1a 3112 fi ;;
418c3b1e 3113 Darwin/1.3*)
d4958c28
AP
3114 LDSHARED='$(CC) -bundle'
3115 LDCXXSHARED='$(CXX) -bundle'
a3891ea4
JJ
3116 if test "$enable_framework" ; then
3117 # Link against the framework. All externals should be defined.
da49e198
JJ
3118 BLDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
3119 LDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
03d788dc 3120 LDCXXSHARED="$LDCXXSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
a3891ea4
JJ
3121 else
3122 # No framework. Ignore undefined symbols, assuming they come from Python
418c3b1e 3123 LDSHARED="$LDSHARED -undefined suppress"
03d788dc 3124 LDCXXSHARED="$LDCXXSHARED -undefined suppress"
a3891ea4 3125 fi ;;
6b08a404 3126 Darwin/1.4*|Darwin/5.*|Darwin/6.*)
d4958c28
AP
3127 LDSHARED='$(CC) -bundle'
3128 LDCXXSHARED='$(CXX) -bundle'
b6e9cad3
JJ
3129 if test "$enable_framework" ; then
3130 # Link against the framework. All externals should be defined.
da49e198
JJ
3131 BLDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
3132 LDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
03d788dc 3133 LDCXXSHARED="$LDCXXSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
b6e9cad3 3134 else
0c46c0cc
MH
3135 # No framework, use the Python app as bundle-loader
3136 BLDSHARED="$LDSHARED "'-bundle_loader $(BUILDPYTHON)'
c28fc37e 3137 LDSHARED="$LDSHARED "'-bundle_loader $(BINDIR)/python$(VERSION)$(EXE)'
03d788dc 3138 LDCXXSHARED="$LDCXXSHARED "'-bundle_loader $(BINDIR)/python$(VERSION)$(EXE)'
54ecc3d2 3139 fi ;;
6b08a404
JJ
3140 Darwin/*)
3141 # Use -undefined dynamic_lookup whenever possible (10.3 and later).
3142 # This allows an extension to be used in any Python
89d996e5 3143
36820b6e
ND
3144 dep_target_major=`echo ${MACOSX_DEPLOYMENT_TARGET} | \
3145 sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
3146 dep_target_minor=`echo ${MACOSX_DEPLOYMENT_TARGET} | \
3147 sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
3148 if test ${dep_target_major} -eq 10 && \
3149 test ${dep_target_minor} -le 2
6b08a404 3150 then
36820b6e 3151 # building for OS X 10.0 through 10.2
87031782 3152 AC_MSG_ERROR([MACOSX_DEPLOYMENT_TARGET too old ($MACOSX_DEPLOYMENT_TARGET), only 10.3 or later is supported])
36820b6e
ND
3153 else
3154 # building for OS X 10.3 and later
3155 LDSHARED='$(CC) -bundle -undefined dynamic_lookup'
3156 LDCXXSHARED='$(CXX) -bundle -undefined dynamic_lookup'
3157 BLDSHARED="$LDSHARED"
6b08a404
JJ
3158 fi
3159 ;;
9b5ca540
CH
3160 Emscripten|WASI)
3161 LDSHARED='$(CC) -shared'
3162 LDCXXSHARED='$(CXX) -shared';;
5f5b7d0c 3163 Linux*|GNU*|QNX*|VxWorks*|Haiku*)
03d788dc
TZ
3164 LDSHARED='$(CC) -shared'
3165 LDCXXSHARED='$(CXX) -shared';;
1ba5b3b4 3166 FreeBSD*)
4bcc7c51 3167 if [[ "`$CC -dM -E - </dev/null | grep __ELF__`" != "" ]]
0286ae8c 3168 then
d4958c28
AP
3169 LDSHARED='$(CC) -shared'
3170 LDCXXSHARED='$(CXX) -shared'
0286ae8c 3171 else
d4958c28 3172 LDSHARED="ld -Bshareable"
0286ae8c 3173 fi;;
1ba5b3b4
TW
3174 OpenBSD*)
3175 if [[ "`$CC -dM -E - </dev/null | grep __ELF__`" != "" ]]
3176 then
d4958c28
AP
3177 LDSHARED='$(CC) -shared $(CCSHARED)'
3178 LDCXXSHARED='$(CXX) -shared $(CCSHARED)'
1ba5b3b4
TW
3179 else
3180 case `uname -r` in
3181 [[01]].* | 2.[[0-7]] | 2.[[0-7]].*)
3182 LDSHARED="ld -Bshareable ${LDFLAGS}"
3183 ;;
3184 *)
d4958c28
AP
3185 LDSHARED='$(CC) -shared $(CCSHARED)'
3186 LDCXXSHARED='$(CXX) -shared $(CCSHARED)'
1ba5b3b4
TW
3187 ;;
3188 esac
3189 fi;;
03d788dc 3190 NetBSD*|DragonFly*)
ece919eb
AP
3191 LDSHARED='$(CC) -shared'
3192 LDCXXSHARED='$(CXX) -shared';;
25ae43b1 3193 OpenUNIX*|UnixWare*)
03d788dc
TZ
3194 if test "$GCC" = "yes" ; then
3195 LDSHARED='$(CC) -shared'
3196 LDCXXSHARED='$(CXX) -shared'
3197 else
3198 LDSHARED='$(CC) -G'
3199 LDCXXSHARED='$(CXX) -G'
bec1958d 3200 fi;;
03d788dc
TZ
3201 SCO_SV*)
3202 LDSHARED='$(CC) -Wl,-G,-Bexport'
3203 LDCXXSHARED='$(CXX) -Wl,-G,-Bexport';;
c9844cb8
CH
3204 WASI*)
3205 AS_VAR_IF([enable_wasm_dynamic_linking], [yes], [
3206 dnl not iplemented yet
3207 ]);;
03d788dc
TZ
3208 CYGWIN*)
3209 LDSHARED="gcc -shared -Wl,--enable-auto-image-base"
3210 LDCXXSHARED="g++ -shared -Wl,--enable-auto-image-base";;
ac405f6c
GR
3211 *) LDSHARED="ld";;
3212 esac
ac405f6c 3213fi
c9844cb8
CH
3214
3215dnl Emscripten's emconfigure sets LDSHARED. Set BLDSHARED outside the
3216dnl test -z $LDSHARED block to configure BLDSHARED for side module support.
3217if test "$enable_wasm_dynamic_linking" = "yes" -a "$ac_sys_system" = "Emscripten"; then
7acedd71 3218 BLDSHARED='$(CC) -shared -sSIDE_MODULE=1'
c9844cb8
CH
3219fi
3220
2ea34cfb 3221AC_MSG_RESULT([$LDSHARED])
03d788dc 3222LDCXXSHARED=${LDCXXSHARED-$LDSHARED}
c9844cb8
CH
3223
3224AC_MSG_CHECKING([BLDSHARED flags])
b3531b86 3225BLDSHARED=${BLDSHARED-$LDSHARED}
c9844cb8
CH
3226AC_MSG_RESULT([$BLDSHARED])
3227
ac405f6c 3228# CCSHARED are the C *flags* used to create objects to go into a shared
54ecc3d2 3229# library (module) -- this is only needed for a few systems
2ea34cfb 3230AC_MSG_CHECKING([CCSHARED])
ac405f6c
GR
3231if test -z "$CCSHARED"
3232then
6100aaf7 3233 case $ac_sys_system/$ac_sys_release in
66252167 3234 SunOS*) if test "$GCC" = yes;
d8faa365
GR
3235 then CCSHARED="-fPIC";
3236 elif test `uname -p` = sparc;
3237 then CCSHARED="-xcode=pic32";
3238 else CCSHARED="-Kpic";
3239 fi;;
af07a444 3240 hp*|HP*) if test "$GCC" = yes;
703ad705 3241 then CCSHARED="-fPIC";
af07a444
GR
3242 else CCSHARED="+z";
3243 fi;;
2a352b66 3244 Linux-android*) ;;
a6e97580 3245 Linux*|GNU*) CCSHARED="-fPIC";;
c9844cb8
CH
3246 Emscripten*|WASI*)
3247 AS_VAR_IF([enable_wasm_dynamic_linking], [yes], [
3248 CCSHARED="-fPIC"
3249 ]);;
86d66260 3250 FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) CCSHARED="-fPIC";;
5f5b7d0c 3251 Haiku*) CCSHARED="-fPIC";;
25ae43b1 3252 OpenUNIX*|UnixWare*)
bec1958d
ML
3253 if test "$GCC" = "yes"
3254 then CCSHARED="-fPIC"
130fb175 3255 else CCSHARED="-KPIC"
bec1958d 3256 fi;;
21ee4091
ML
3257 SCO_SV*)
3258 if test "$GCC" = "yes"
3259 then CCSHARED="-fPIC"
3260 else CCSHARED="-Kpic -belf"
3261 fi;;
32f5fdd7 3262 VxWorks*)
3263 CCSHARED="-fpic -D__SO_PICABILINUX__ -ftls-model=global-dynamic"
ac405f6c 3264 esac
ac405f6c 3265fi
2ea34cfb 3266AC_MSG_RESULT([$CCSHARED])
ac405f6c 3267# LINKFORSHARED are the flags passed to the $(CC) command that links
b65a48e2 3268# the python executable -- this is only needed for a few systems
2ea34cfb 3269AC_MSG_CHECKING([LINKFORSHARED])
ac405f6c
GR
3270if test -z "$LINKFORSHARED"
3271then
6100aaf7 3272 case $ac_sys_system/$ac_sys_release in
b3531b86 3273 AIX*) LINKFORSHARED='-Wl,-bE:Modules/python.exp -lld';;
5dab3d81 3274 hp*|HP*)
1142de3f
ML
3275 LINKFORSHARED="-Wl,-E -Wl,+s";;
3276# LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";;
2a352b66 3277 Linux-android*) LINKFORSHARED="-pie -Xlinker -export-dynamic";;
a6e97580 3278 Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";;
54ecc3d2 3279 # -u libsys_s pulls in all symbols in libsys
1b80b240 3280 Darwin/*)
9c80cacb 3281 LINKFORSHARED="$extra_undefs -framework CoreFoundation"
5bbbc733
ND
3282
3283 # Issue #18075: the default maximum stack size (8MBytes) is too
3284 # small for the default recursion limit. Increase the stack size
3285 # to ensure that tests don't crash
be9de872 3286 stack_size="1000000" # 16 MB
3d11c1b8 3287 if test "$with_ubsan" = "yes"
be9de872
ŁL
3288 then
3289 # Undefined behavior sanitizer requires an even deeper stack
3290 stack_size="4000000" # 64 MB
3291 fi
3292
3293 LINKFORSHARED="-Wl,-stack_size,$stack_size $LINKFORSHARED"
3294
2ea34cfb
EA
3295 AC_DEFINE_UNQUOTED([THREAD_STACK_SIZE],
3296 [0x$stack_size],
be9de872 3297 [Custom thread stack size depending on chosen sanitizer runtimes.])
5bbbc733 3298
b6e9cad3
JJ
3299 if test "$enable_framework"
3300 then
da49e198 3301 LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
b6e9cad3 3302 fi
ec6eb369 3303 LINKFORSHARED="$LINKFORSHARED";;
25ae43b1 3304 OpenUNIX*|UnixWare*) LINKFORSHARED="-Wl,-Bexport";;
21ee4091 3305 SCO_SV*) LINKFORSHARED="-Wl,-Bexport";;
02706f58 3306 ReliantUNIX*) LINKFORSHARED="-W1 -Blargedynsym";;
1b80b240 3307 FreeBSD*|NetBSD*|OpenBSD*|DragonFly*)
df69365f
GR
3308 if [[ "`$CC -dM -E - </dev/null | grep __ELF__`" != "" ]]
3309 then
3310 LINKFORSHARED="-Wl,--export-dynamic"
3311 fi;;
2b5ca003
GR
3312 SunOS/5*) case $CC in
3313 *gcc*)
a4548576 3314 if $CC -Xlinker --help 2>&1 | grep export-dynamic >/dev/null
8f4ceb16
GR
3315 then
3316 LINKFORSHARED="-Xlinker --export-dynamic"
2b5ca003
GR
3317 fi;;
3318 esac;;
3076559e
JT
3319 CYGWIN*)
3320 if test $enable_shared = "no"
3321 then
3322 LINKFORSHARED='-Wl,--out-implib=$(LDLIBRARY)'
3323 fi;;
f78e02b7
GB
3324 QNX*)
3325 # -Wl,-E causes the symbols to be added to the dynamic
3326 # symbol table so that they can be found when a module
3327 # is loaded. -N 2048K causes the stack size to be set
3328 # to 2048 kilobytes so that the stack doesn't overflow
3329 # when running test_compile.py.
3330 LINKFORSHARED='-Wl,-E -N 2048K';;
32f5fdd7 3331 VxWorks*)
c117426b 3332 LINKFORSHARED='-Wl,-export-dynamic';;
ac405f6c 3333 esac
ac405f6c 3334fi
2ea34cfb 3335AC_MSG_RESULT([$LINKFORSHARED])
ac405f6c 3336
93de216a 3337
2ea34cfb
EA
3338AC_SUBST([CFLAGSFORSHARED])
3339AC_MSG_CHECKING([CFLAGSFORSHARED])
61c51156
NS
3340if test ! "$LIBRARY" = "$LDLIBRARY"
3341then
d9cf41c4
NS
3342 case $ac_sys_system in
3343 CYGWIN*)
3344 # Cygwin needs CCSHARED when building extension DLLs
3345 # but not when building the interpreter DLL.
3346 CFLAGSFORSHARED='';;
3347 *)
3348 CFLAGSFORSHARED='$(CCSHARED)'
3349 esac
61c51156 3350fi
c9844cb8
CH
3351
3352dnl WASM dynamic linking requires -fPIC.
3353AS_VAR_IF([enable_wasm_dynamic_linking], [yes], [
3354 CFLAGSFORSHARED='$(CCSHARED)'
3355])
3356
2ea34cfb 3357AC_MSG_RESULT([$CFLAGSFORSHARED])
61c51156 3358
f90ae203
ML
3359# SHLIBS are libraries (except -lc and -lm) to link to the python shared
3360# library (with --enable-shared).
3361# For platforms on which shared libraries are not allowed to have unresolved
d6359c55
ML
3362# symbols, this must be set to $(LIBS) (expanded by make). We do this even
3363# if it is not required, since it creates a dependency of the shared library
3364# to LIBS. This, in turn, means that applications linking the shared libpython
3365# don't need to link LIBS explicitly. The default should be only changed
3366# on systems where this approach causes problems.
2ea34cfb
EA
3367AC_SUBST([SHLIBS])
3368AC_MSG_CHECKING([SHLIBS])
f90ae203 3369case "$ac_sys_system" in
f90ae203 3370 *)
d6359c55 3371 SHLIBS='$(LIBS)';;
f90ae203 3372esac
2ea34cfb 3373AC_MSG_RESULT([$SHLIBS])
f90ae203 3374
6d791a97
PGS
3375dnl perf trampoline is Linux specific and requires an arch-specific
3376dnl trampoline in asssembly.
3377AC_MSG_CHECKING([perf trampoline])
3378AS_CASE([$PLATFORM_TRIPLET],
3379 [x86_64-linux-gnu], [perf_trampoline=yes],
3380 [aarch64-linux-gnu], [perf_trampoline=yes],
3381 [perf_trampoline=no]
3382)
3383AC_MSG_RESULT([$perf_trampoline])
3384
3385AS_VAR_IF([perf_trampoline], [yes], [
3386 AC_DEFINE([PY_HAVE_PERF_TRAMPOLINE], [1], [Define to 1 if you have the perf trampoline.])
1f737edb 3387 PERF_TRAMPOLINE_OBJ=Python/asm_trampoline.o
6d791a97
PGS
3388
3389 dnl perf needs frame pointers for unwinding, include compiler option in debug builds
3390 AS_VAR_IF([Py_DEBUG], [true], [
3391 AS_VAR_APPEND([BASECFLAGS], [" -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"])
3392 ])
3393])
3394AC_SUBST([PERF_TRAMPOLINE_OBJ])
f90ae203 3395
627b2d7c 3396# checks for libraries
2ea34cfb
EA
3397AC_CHECK_LIB([sendfile], [sendfile])
3398AC_CHECK_LIB([dl], [dlopen]) # Dynamic linking for SunOS/Solaris and SYSV
3399AC_CHECK_LIB([dld], [shl_load]) # Dynamic linking for HP-UX
519adae1 3400
0d3ccb43 3401
8af6481f
CH
3402dnl check for uuid dependencies
3403AH_TEMPLATE([HAVE_UUID_H], [Define to 1 if you have the <uuid.h> header file.])
3404AH_TEMPLATE([HAVE_UUID_UUID_H], [Define to 1 if you have the <uuid/uuid.h> header file.])
3405AH_TEMPLATE([HAVE_UUID_GENERATE_TIME_SAFE], [Define if uuid_generate_time_safe() exists.])
3406have_uuid=missing
3407
3408dnl AIX provides support for RFC4122 (uuid) in libc.a starting with AIX 6.1
3409dnl (anno 2007). FreeBSD and OpenBSD provides support in libc as well.
3410dnl Little-endian FreeBSD, OpenBSD and NetBSD needs encoding into an octet
3411dnl stream in big-endian byte-order
2ea34cfb
EA
3412AC_CHECK_HEADERS([uuid.h],
3413 [AC_CHECK_FUNCS([uuid_create uuid_enc_be],
3414 [have_uuid=yes
0461c68c
CH
3415 LIBUUID_CFLAGS=${LIBUUID_CFLAGS-""}
3416 LIBUUID_LIBS=${LIBUUID_LIBS-""}
8af6481f 3417 ])
57c50c9c 3418])
9a10ff4d 3419
8af6481f
CH
3420AS_VAR_IF([have_uuid], [missing], [
3421 PKG_CHECK_MODULES(
2ea34cfb
EA
3422 [LIBUUID], [uuid >= 2.20],
3423 [dnl linux-util's libuuid has uuid_generate_time_safe() since v2.20 (2011)
8af6481f
CH
3424 dnl and provides <uuid.h>.
3425 have_uuid=yes
3426 AC_DEFINE([HAVE_UUID_H], [1])
3427 AC_DEFINE([HAVE_UUID_GENERATE_TIME_SAFE], [1])
3428 ], [
944ff8c5 3429 WITH_SAVE_ENV([
9af7f87d 3430 CPPFLAGS="$CPPFLAGS $LIBUUID_CFLAGS"
944ff8c5
CH
3431 LDFLAGS="$LDFLAGS $LIBUUID_LIBS"
3432 AC_CHECK_HEADERS([uuid/uuid.h], [
3433 PY_CHECK_LIB([uuid], [uuid_generate_time], [have_uuid=yes])
2ea34cfb
EA
3434 PY_CHECK_LIB([uuid], [uuid_generate_time_safe],
3435 [have_uuid=yes
3436 AC_DEFINE([HAVE_UUID_GENERATE_TIME_SAFE], [1]) ]) ])
0461c68c
CH
3437 AS_VAR_IF([have_uuid], [yes], [
3438 LIBUUID_CFLAGS=${LIBUUID_CFLAGS-""}
3439 LIBUUID_LIBS=${LIBUUID_LIBS-"-luuid"}
3440 ])
8af6481f
CH
3441 ])
3442 ]
3443 )
3444])
17d88303 3445
fc012d80
CH
3446dnl macOS has uuid/uuid.h but uuid_generate_time is in libc
3447AS_VAR_IF([have_uuid], [missing], [
3448 AC_CHECK_HEADERS([uuid/uuid.h], [
3449 AC_CHECK_FUNC([uuid_generate_time], [
3450 have_uuid=yes
0461c68c
CH
3451 LIBUUID_CFLAGS=${LIBUUID_CFLAGS-""}
3452 LIBUUID_LIBS=${LIBUUID_LIBS-""}
fc012d80
CH
3453 ])
3454 ])
3455])
3456
3457AS_VAR_IF([have_uuid], [missing], [have_uuid=no])
3458
9e78dc25
SS
3459# 'Real Time' functions on Solaris
3460# posix4 on Solaris 2.6
3461# pthread (first!) on Linux
2ea34cfb 3462AC_SEARCH_LIBS([sem_init], [pthread rt posix4])
519adae1 3463
19d17348 3464# check if we need libintl for locale functions
2ea34cfb
EA
3465AC_CHECK_LIB([intl], [textdomain],
3466 [AC_DEFINE([WITH_LIBINTL], [1],
c6d936e2
BC
3467 [Define to 1 if libintl is needed for locale functions.])
3468 LIBS="-lintl $LIBS"])
0eefa3fb
GR
3469
3470# checks for system dependent C++ extensions support
3471case "$ac_sys_system" in
2ea34cfb 3472 AIX*) AC_MSG_CHECKING([for genuine AIX C++ extensions support])
b159a556 3473 AC_LINK_IFELSE([
27c68a6d 3474 AC_LANG_PROGRAM([[@%:@include <load.h>]],
b159a556
MK
3475 [[loadAndInit("", 0, "")]])
3476 ],[
2ea34cfb 3477 AC_DEFINE([AIX_GENUINE_CPLUSPLUS], [1],
c45929ec
ML
3478 [Define for AIX if your compiler is a genuine IBM xlC/xlC_r
3479 and you want support for AIX C++ shared extension modules.])
2ea34cfb 3480 AC_MSG_RESULT([yes])
b159a556 3481 ],[
2ea34cfb 3482 AC_MSG_RESULT([no])
39afa2d3
MF
3483 ])
3484dnl The AIX_BUILDDATE is obtained from the kernel fileset - bos.mp64
3485# BUILD_GNU_TYPE + AIX_BUILDDATE are used to construct the platform_tag
3486# of the AIX system used to build/package Python executable. This tag serves
3487# as a baseline for bdist module packages
2ea34cfb 3488 AC_MSG_CHECKING([for the system builddate])
39afa2d3
MF
3489 AIX_BUILDDATE=$(lslpp -Lcq bos.mp64 | awk -F: '{ print $NF }')
3490 AC_DEFINE_UNQUOTED([AIX_BUILDDATE], [$AIX_BUILDDATE],
3491 [BUILD_GNU_TYPE + AIX_BUILDDATE are used to construct the PEP425 tag of the build system.])
2ea34cfb 3492 AC_MSG_RESULT([$AIX_BUILDDATE])
39afa2d3 3493 ;;
0eefa3fb
GR
3494 *) ;;
3495esac
3496
985ecdcf 3497# check for systems that require aligned memory access
76d14fac 3498AC_CACHE_CHECK([aligned memory access is required], [ac_cv_aligned_required],
e4f961be 3499[AC_RUN_IFELSE([AC_LANG_SOURCE([[
e35ca417 3500int main(void)
985ecdcf
CH
3501{
3502 char s[16];
3503 int i, *p1, *p2;
3504 for (i=0; i < 16; i++)
3505 s[i] = i;
3506 p1 = (int*)(s+1);
3507 p2 = (int*)(s+2);
3508 if (*p1 == *p2)
3509 return 1;
3510 return 0;
e4f961be
BP
3511}]])],
3512[ac_cv_aligned_required=no],
3513[ac_cv_aligned_required=yes],
3514[ac_cv_aligned_required=yes])
3515])
e4f961be 3516if test "$ac_cv_aligned_required" = yes ; then
985ecdcf
CH
3517 AC_DEFINE([HAVE_ALIGNED_REQUIRED], [1],
3518 [Define if aligned memory access is required])
3519fi
985ecdcf
CH
3520
3521# str, bytes and memoryview hash algorithm
2ea34cfb 3522AH_TEMPLATE([Py_HASH_ALGORITHM],
985ecdcf 3523 [Define hash algorithm for str, bytes and memoryview.
ad970e86 3524 SipHash24: 1, FNV: 2, SipHash13: 3, externally defined: 0])
985ecdcf 3525
2ea34cfb 3526AC_MSG_CHECKING([for --with-hash-algorithm])
985ecdcf 3527dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
2ea34cfb
EA
3528AC_ARG_WITH(
3529 [hash_algorithm],
3530 [AS_HELP_STRING(
3531 [--with-hash-algorithm=@<:@fnv|siphash13|siphash24@:>@],
3532 [select hash algorithm for use in Python/pyhash.c (default is SipHash13)]
3533 )],
985ecdcf 3534[
2ea34cfb 3535AC_MSG_RESULT([$withval])
985ecdcf 3536case "$withval" in
ad970e86 3537 siphash13)
2ea34cfb 3538 AC_DEFINE([Py_HASH_ALGORITHM], [3])
ad970e86 3539 ;;
985ecdcf 3540 siphash24)
2ea34cfb 3541 AC_DEFINE([Py_HASH_ALGORITHM], [1])
985ecdcf
CH
3542 ;;
3543 fnv)
2ea34cfb 3544 AC_DEFINE([Py_HASH_ALGORITHM], [2])
985ecdcf
CH
3545 ;;
3546 *)
3547 AC_MSG_ERROR([unknown hash algorithm '$withval'])
3548 ;;
3549esac
3550],
2ea34cfb 3551[AC_MSG_RESULT([default])])
985ecdcf 3552
62972d9d 3553validate_tzpath() {
a9e43615 3554 # Checks that each element of the path is an absolute path
62972d9d
PG
3555 if test -z "$1"; then
3556 # Empty string is allowed: it indicates no system TZPATH
3557 return 0
3558 fi
3559
3560 # Bad paths are those that don't start with /
3561 dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
0f66498f 3562 if ( echo $1 | grep '\(^\|:\)\(@<:@^/@:>@\|$\)' > /dev/null); then
62972d9d
PG
3563 AC_MSG_ERROR([--with-tzpath must contain only absolute paths, not $1])
3564 return 1;
3565 fi
3566}
3567
3568TZPATH="/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo"
2ea34cfb
EA
3569AC_MSG_CHECKING([for --with-tzpath])
3570AC_ARG_WITH(
3571 [tzpath],
3572 [AS_HELP_STRING(
3573 [--with-tzpath=<list of absolute paths separated by pathsep>],
3574 [Select the default time zone search path for zoneinfo.TZPATH]
3575 )],
62972d9d
PG
3576[
3577case "$withval" in
3578 yes)
3579 AC_MSG_ERROR([--with-tzpath requires a value])
3580 ;;
3581 *)
3582 validate_tzpath "$withval"
3583 TZPATH="$withval"
2ea34cfb 3584 AC_MSG_RESULT(["$withval"])
62972d9d
PG
3585 ;;
3586esac
3587],
3588[validate_tzpath "$TZPATH"
2ea34cfb
EA
3589 AC_MSG_RESULT(["$TZPATH"])])
3590AC_SUBST([TZPATH])
62972d9d 3591
70c7f48b 3592# Most SVR4 platforms (e.g. Solaris) need -lsocket and -lnsl.
2ea34cfb
EA
3593AC_CHECK_LIB([nsl], [t_open], [LIBS="-lnsl $LIBS"]) # SVR4
3594AC_CHECK_LIB([socket], [socket], [LIBS="-lsocket $LIBS"], [], $LIBS) # SVR4 sockets
b9949dbe 3595
0af08f34
ND
3596case $ac_sys_system/$ac_sys_release in
3597 Haiku*)
2ea34cfb 3598 AC_CHECK_LIB([network], [socket], [LIBS="-lnetwork $LIBS"], [], [$LIBS])
0af08f34
ND
3599 ;;
3600esac
5f5b7d0c 3601
2ea34cfb
EA
3602AC_MSG_CHECKING([for --with-libs])
3603AC_ARG_WITH(
3604 [libs],
3605 [AS_HELP_STRING(
3606 [--with-libs='lib1 ...'],
3607 [link against additional libs (default is no)]
3608 )],
3e2c6326 3609[
2ea34cfb 3610AC_MSG_RESULT([$withval])
c5a39034 3611LIBS="$withval $LIBS"
3e2c6326 3612],
2ea34cfb 3613[AC_MSG_RESULT([no])])
433c8ade 3614
b2d90467 3615# Check for use of the system expat library
2ea34cfb
EA
3616AC_MSG_CHECKING([for --with-system-expat])
3617AC_ARG_WITH(
3618 [system_expat],
3619 [AS_HELP_STRING(
3620 [--with-system-expat],
3621 [build pyexpat module using an installed expat library, see Doc/library/pyexpat.rst (default is no)]
3622 )], [], [with_system_expat="no"])
b2d90467 3623
2ea34cfb 3624AC_MSG_RESULT([$with_system_expat])
b2d90467 3625
464e6616 3626AS_VAR_IF([with_system_expat], [yes], [
0461c68c
CH
3627 LIBEXPAT_CFLAGS=${LIBEXPAT_CFLAGS-""}
3628 LIBEXPAT_LDFLAGS=${LIBEXPAT_LDFLAGS-"-lexpat"}
464e6616
CH
3629 LIBEXPAT_INTERNAL=
3630], [
3631 LIBEXPAT_CFLAGS="-I\$(srcdir)/Modules/expat"
3632 LIBEXPAT_LDFLAGS="-lm \$(LIBEXPAT_A)"
6abec1ca 3633 LIBEXPAT_INTERNAL="\$(LIBEXPAT_HEADERS) \$(LIBEXPAT_A)"
464e6616
CH
3634])
3635
3636AC_SUBST([LIBEXPAT_CFLAGS])
464e6616
CH
3637AC_SUBST([LIBEXPAT_INTERNAL])
3638
bb8b9313
CH
3639dnl detect libffi
3640have_libffi=missing
25590eb5
ZW
3641AS_VAR_IF([ac_sys_system], [Darwin], [
3642 WITH_SAVE_ENV([
3643 CFLAGS="-I${SDKROOT}/usr/include/ffi $CFLAGS"
3644 AC_CHECK_HEADER([ffi.h], [
3645 AC_CHECK_LIB([ffi], [ffi_call], [
3646 dnl use ffi from SDK root
3647 have_libffi=yes
3648 LIBFFI_CFLAGS="-I${SDKROOT}/usr/include/ffi -DUSING_APPLE_OS_LIBFFI=1"
3649 LIBFFI_LIBS="-lffi"
3650 ])
3651 ])
3652 ])
3653])
3654AS_VAR_IF([have_libffi], [missing], [
bb8b9313 3655 PKG_CHECK_MODULES([LIBFFI], [libffi], [have_libffi=yes], [
944ff8c5 3656 WITH_SAVE_ENV([
9af7f87d 3657 CPPFLAGS="$CPPFLAGS $LIBFFI_CFLAGS"
944ff8c5
CH
3658 LDFLAGS="$LDFLAGS $LIBFFI_LIBS"
3659 AC_CHECK_HEADER([ffi.h], [
d6acdc1b
CH
3660 AC_CHECK_LIB([ffi], [ffi_call], [
3661 have_libffi=yes
944ff8c5
CH
3662 LIBFFI_CFLAGS=${LIBFFI_CFLAGS-""}
3663 LIBFFI_LIBS=${LIBFFI_LIBS-"-lffi"}
d6acdc1b 3664 ], [have_libffi=no])
bb8b9313
CH
3665 ])
3666 ])
3667 ])
bb8b9313
CH
3668])
3669
3670AS_VAR_IF([have_libffi], [yes], [
3671 ctypes_malloc_closure=no
3672 AS_CASE([$ac_sys_system],
3673 [Darwin], [
3674 dnl when do we need USING_APPLE_OS_LIBFFI?
bb8b9313
CH
3675 ctypes_malloc_closure=yes
3676 ],
3677 [sunos5], [AS_VAR_APPEND([LIBFFI_LIBS], [" -mimpure-text"])]
3678 )
3679 AS_VAR_IF([ctypes_malloc_closure], [yes], [
3680 MODULE__CTYPES_MALLOC_CLOSURE=_ctypes/malloc_closure.c
3681 AS_VAR_APPEND([LIBFFI_CFLAGS], [" -DUSING_MALLOC_CLOSURE_DOT_C=1"])
3682 ])
3683 AC_SUBST([MODULE__CTYPES_MALLOC_CLOSURE])
3684
3685 dnl HAVE_LIBDL: for dlopen, see gh-76828
3686 AS_VAR_IF([ac_cv_lib_dl_dlopen], [yes], [AS_VAR_APPEND([LIBFFI_LIBS], [" -ldl"])])
3687
3688 WITH_SAVE_ENV([
3689 CFLAGS="$LIBFFI_CFLAGS $CFLAGS"
3690 LDFLAGS="$LIBFFI_LIBS $LDFLAGS"
3691
27c68a6d
EA
3692 PY_CHECK_FUNC([ffi_prep_cif_var], [@%:@include <ffi.h>])
3693 PY_CHECK_FUNC([ffi_prep_closure_loc], [@%:@include <ffi.h>])
3694 PY_CHECK_FUNC([ffi_closure_alloc], [@%:@include <ffi.h>])
bb8b9313
CH
3695 ])
3696])
d78735d8 3697
60187b5e 3698# Check for use of the system libmpdec library
2ea34cfb
EA
3699AC_MSG_CHECKING([for --with-system-libmpdec])
3700AC_ARG_WITH(
3701 [system_libmpdec],
3702 [AS_HELP_STRING(
3703 [--with-system-libmpdec],
3704 [build _decimal module using an installed libmpdec library, see Doc/library/decimal.rst (default is no)]
3705 )],
3706 [],
3707 [with_system_libmpdec="no"])
3708AC_MSG_RESULT([$with_system_libmpdec])
60187b5e 3709
0486570f 3710AS_VAR_IF([with_system_libmpdec], [yes], [
0461c68c
CH
3711 LIBMPDEC_CFLAGS=${LIBMPDEC_CFLAGS-""}
3712 LIBMPDEC_LDFLAGS=${LIBMPDEC_LDFLAGS-"-lmpdec"}
0486570f
CH
3713 LIBMPDEC_INTERNAL=
3714], [
3715 LIBMPDEC_CFLAGS="-I\$(srcdir)/Modules/_decimal/libmpdec"
3716 LIBMPDEC_LDFLAGS="-lm \$(LIBMPDEC_A)"
6abec1ca 3717 LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)"
97b4121f
CH
3718
3719 dnl Disable forced inlining in debug builds, see GH-94847
3720 AS_VAR_IF([with_pydebug], [yes], [
3721 AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DTEST_COVERAGE"])
3722 ])
0486570f
CH
3723])
3724
3725AC_SUBST([LIBMPDEC_CFLAGS])
0486570f
CH
3726AC_SUBST([LIBMPDEC_INTERNAL])
3727
815280eb 3728# Check whether _decimal should use a coroutine-local or thread-local context
2ea34cfb
EA
3729AC_MSG_CHECKING([for --with-decimal-contextvar])
3730AC_ARG_WITH(
3731 [decimal_contextvar],
3732 [AS_HELP_STRING(
3733 [--with-decimal-contextvar],
3734 [build _decimal module using a coroutine-local rather than a thread-local context (default is yes)]
3735 )],
3736 [],
3737 [with_decimal_contextvar="yes"])
815280eb
SK
3738
3739if test "$with_decimal_contextvar" != "no"
3740then
2ea34cfb 3741 AC_DEFINE([WITH_DECIMAL_CONTEXTVAR], [1],
815280eb
SK
3742 [Define if you want build the _decimal module using a coroutine-local rather than a thread-local context])
3743fi
3744
2ea34cfb 3745AC_MSG_RESULT([$with_decimal_contextvar])
815280eb 3746
0486570f 3747# Check for libmpdec machine flavor
2ea34cfb 3748AC_MSG_CHECKING([for decimal libmpdec machine])
0486570f
CH
3749AS_CASE([$ac_sys_system],
3750 [Darwin*], [libmpdec_system=Darwin],
3751 [SunOS*], [libmpdec_system=sunos],
3752 [libmpdec_system=other]
3753)
3754
3755libmpdec_machine=unknown
3756if test "$libmpdec_system" = Darwin; then
ddbab69b
ND
3757 # universal here means: build libmpdec with the same arch options
3758 # the python interpreter was built with
3759 libmpdec_machine=universal
0486570f
CH
3760elif test $ac_cv_sizeof_size_t -eq 8; then
3761 if test "$ac_cv_gcc_asm_for_x64" = yes; then
3762 libmpdec_machine=x64
3763 elif test "$ac_cv_type___uint128_t" = yes; then
3764 libmpdec_machine=uint128
3765 else
3766 libmpdec_machine=ansi64
3767 fi
3768elif test $ac_cv_sizeof_size_t -eq 4; then
3769 if test "$ac_cv_gcc_asm_for_x87" = yes -a "$libmpdec_system" != sunos; then
3770 AS_CASE([$CC],
3771 [*gcc*], [libmpdec_machine=ppro],
3772 [*clang*], [libmpdec_machine=ppro],
3773 [libmpdec_machine=ansi32]
3774 )
3775 else
3776 libmpdec_machine=ansi32
3777 fi
3778fi
3779AC_MSG_RESULT([$libmpdec_machine])
3780
3781AS_CASE([$libmpdec_machine],
3782 [x64], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_64=1 -DASM=1"])],
3783 [uint128], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_64=1 -DANSI=1 -DHAVE_UINT128_T=1"])],
3784 [ansi64], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_64=1 -DANSI=1"])],
3785 [ppro], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_32=1 -DANSI=1 -DASM=1 -Wno-unknown-pragmas"])],
3786 [ansi32], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_32=1 -DANSI=1"])],
3787 [ansi-legacy], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DCONFIG_32=1 -DANSI=1 -DLEGACY_COMPILER=1"])],
3788 [universal], [AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DUNIVERSAL=1"])],
3789 [AC_MSG_ERROR([_decimal: unsupported architecture])]
3790)
3791
3792if test "$have_ipa_pure_const_bug" = yes; then
3793 # Some versions of gcc miscompile inline asm:
3794 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
3795 # https://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
3796 AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -fno-ipa-pure-const"])
3797fi
3798
3799if test "$have_glibc_memmove_bug" = yes; then
3800 # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
3801 # https://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
3802 AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -U_FORTIFY_SOURCE"])
3803fi
3804
c6dec7e2 3805
944ff8c5
CH
3806dnl detect sqlite3 from Emscripten emport
3807PY_CHECK_EMSCRIPTEN_PORT([LIBSQLITE3], [-sUSE_SQLITE3])
3808
29e5874d
EEA
3809dnl Check for SQLite library. Use pkg-config if available.
3810PKG_CHECK_MODULES(
6849acb3 3811 [LIBSQLITE3], [sqlite3 >= 3.15.2], [], [
0461c68c
CH
3812 LIBSQLITE3_CFLAGS=${LIBSQLITE3_CFLAGS-""}
3813 LIBSQLITE3_LIBS=${LIBSQLITE3_LIBS-"-lsqlite3"}
29e5874d
EEA
3814 ]
3815)
3816AS_VAR_APPEND([LIBSQLITE3_CFLAGS], [' -I$(srcdir)/Modules/_sqlite'])
3817
f1606a5b
EEA
3818dnl PY_CHECK_SQLITE_FUNC(FUNCTION, IF-FOUND, IF-NOT-FOUND)
3819AC_DEFUN([PY_CHECK_SQLITE_FUNC], [
3820 AC_CHECK_LIB([sqlite3], [$1], [$2], [
3821 m4_ifblank([$3], [have_supported_sqlite3=no], [$3])
3822 ])
3823])
3824
3825WITH_SAVE_ENV([
29e5874d 3826dnl bpo-45774/GH-29507: The CPP check in AC_CHECK_HEADER can fail on FreeBSD,
db2277a1 3827dnl hence CPPFLAGS instead of CFLAGS.
9af7f87d 3828 CPPFLAGS="$CPPFLAGS $LIBSQLITE3_CFLAGS"
db2277a1
EEA
3829 LDFLAGS="$LIBSQLITE3_LIBS $LDFLAGS"
3830
3831 AC_CHECK_HEADER([sqlite3.h], [
f1606a5b
EEA
3832 have_sqlite3=yes
3833
3834 AC_COMPILE_IFELSE([
3835 AC_LANG_PROGRAM([
3836 #include <sqlite3.h>
6849acb3
EA
3837 #if SQLITE_VERSION_NUMBER < 3015002
3838 # error "SQLite 3.15.2 or higher required"
f1606a5b
EEA
3839 #endif
3840 ], [])
3841 ], [
3842 have_supported_sqlite3=yes
3843 dnl Check that required functions are in place. A lot of stuff may be
3844 dnl omitted with SQLITE_OMIT_* compile time defines.
3845 PY_CHECK_SQLITE_FUNC([sqlite3_bind_double])
3846 PY_CHECK_SQLITE_FUNC([sqlite3_column_decltype])
3847 PY_CHECK_SQLITE_FUNC([sqlite3_column_double])
3848 PY_CHECK_SQLITE_FUNC([sqlite3_complete])
f1606a5b
EEA
3849 PY_CHECK_SQLITE_FUNC([sqlite3_progress_handler])
3850 PY_CHECK_SQLITE_FUNC([sqlite3_result_double])
3851 PY_CHECK_SQLITE_FUNC([sqlite3_set_authorizer])
3852 PY_CHECK_SQLITE_FUNC([sqlite3_trace_v2], [], [
3853 PY_CHECK_SQLITE_FUNC([sqlite3_trace])
3854 ])
3855 PY_CHECK_SQLITE_FUNC([sqlite3_value_double])
3856 AC_CHECK_LIB([sqlite3], [sqlite3_load_extension],
3857 [have_sqlite3_load_extension=yes],
3858 [have_sqlite3_load_extension=no]
3859 )
a7551247
EEA
3860 AC_CHECK_LIB([sqlite3], [sqlite3_serialize], [
3861 AC_DEFINE(
3862 [PY_SQLITE_HAVE_SERIALIZE], [1],
3863 [Define if SQLite was compiled with the serialize API]
3864 )
3865 ])
f1606a5b
EEA
3866 ], [
3867 have_supported_sqlite3=no
3868 ])
db2277a1 3869 ])
e9594f67
CH
3870])
3871
f1606a5b
EEA
3872dnl Check for support for loadable sqlite extensions
3873AC_MSG_CHECKING([for --enable-loadable-sqlite-extensions])
3874AC_ARG_ENABLE([loadable-sqlite-extensions],
3875 AS_HELP_STRING(
3876 [--enable-loadable-sqlite-extensions], [
3877 support loadable extensions in the sqlite3 module, see
3878 Doc/library/sqlite3.rst (default is no)
3879 ]
3880 ), [
3881 AS_VAR_IF([have_sqlite3_load_extension], [no], [
3882 AC_MSG_RESULT([n/a])
3883 AC_MSG_WARN([Your version of SQLite does not support loadable extensions])
3884 ], [
3885 AC_MSG_RESULT([yes])
3886 AC_DEFINE(
3887 [PY_SQLITE_ENABLE_LOAD_EXTENSION], [1],
3888 [Define to 1 to build the sqlite module with loadable extensions support.]
3889 )
3890 ])
3891 ], [
3892 AC_MSG_RESULT([no])
3893 ]
3894)
3895
b36d2221
EEA
3896dnl
3897dnl Detect Tcl/Tk. Use pkg-config if available.
3898dnl
3899found_tcltk=no
3900for _QUERY in \
3901 "tcl >= 8.5.12 tk >= 8.5.12" \
3902 "tcl8.6 tk8.6" \
3903 "tcl86 tk86" \
3904 "tcl8.5 >= 8.5.12 tk8.5 >= 8.5.12" \
3905 "tcl85 >= 8.5.12 tk85 >= 8.5.12" \
3906; do
3907 PKG_CHECK_EXISTS([$_QUERY], [
3908 PKG_CHECK_MODULES([TCLTK], [$_QUERY], [found_tcltk=yes], [found_tcltk=no])
3909 ])
3910 AS_VAR_IF([found_tcltk], [yes], [break])
3911done
3912
3913AS_VAR_IF([found_tcltk], [no], [
3914 TCLTK_CFLAGS=${TCLTK_CFLAGS-""}
3915 TCLTK_LIBS=${TCLTK_LIBS-""}
3916])
3917
3918dnl FreeBSD has an X11 dependency which is not implicitly resolved.
3919AS_CASE([$ac_sys_system],
3920 [FreeBSD*], [
3921 PKG_CHECK_EXISTS([x11], [
3922 PKG_CHECK_MODULES([X11], [x11], [
3923 TCLTK_CFLAGS="$TCLTK_CFLAGS $X11_CFLAGS"
3924 TCLTK_LIBS="$TCLTK_LIBS $X11_LIBS"
3925 ])
3926 ])
3927 ]
3928)
3929
3930WITH_SAVE_ENV([
9af7f87d 3931 CPPFLAGS="$CPPFLAGS $TCLTK_CFLAGS"
b36d2221
EEA
3932 LIBS="$TCLTK_LIBS $LDFLAGS"
3933
3934 AC_LINK_IFELSE([
3935 AC_LANG_PROGRAM([
3936 #include <tcl.h>
3937 #include <tk.h>
3938 #if defined(TK_HEX_VERSION)
3939 # if TK_HEX_VERSION < 0x0805020c
3940 # error "Tk older than 8.5.12 not supported"
3941 # endif
3942 #endif
3943 #if (TCL_MAJOR_VERSION < 8) || \
3944 ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION < 5)) || \
3945 ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION == 5) && (TCL_RELEASE_SERIAL < 12))
3946 # error "Tcl older than 8.5.12 not supported"
3947 #endif
3948 #if (TK_MAJOR_VERSION < 8) || \
3949 ((TK_MAJOR_VERSION == 8) && (TK_MINOR_VERSION < 5)) || \
3950 ((TK_MAJOR_VERSION == 8) && (TK_MINOR_VERSION == 5) && (TK_RELEASE_SERIAL < 12))
3951 # error "Tk older than 8.5.12 not supported"
3952 #endif
3953 ], [
3954 void *x1 = Tcl_Init;
3955 void *x2 = Tk_Init;
3956 ])
3957 ], [
3958 have_tcltk=yes
3959 dnl The X11/xlib.h file bundled in the Tk sources can cause function
3960 dnl prototype warnings from the compiler. Since we cannot easily fix
3961 dnl that, suppress the warnings here instead.
3962 AS_VAR_APPEND([TCLTK_CFLAGS], [" -Wno-strict-prototypes -DWITH_APPINIT=1"])
3963 ], [
3964 have_tcltk=no
3965 ])
3966])
d819b931 3967
9cf5646b
CH
3968dnl check for _gdbmmodule dependencies
3969dnl NOTE: gdbm does not provide a pkgconf file.
3970AC_ARG_VAR([GDBM_CFLAGS], [C compiler flags for gdbm])
3971AC_ARG_VAR([GDBM_LIBS], [additional linker flags for gdbm])
3972WITH_SAVE_ENV([
9af7f87d 3973 CPPFLAGS="$CPPFLAGS $GDBM_CFLAGS"
9cf5646b
CH
3974 LDFLAGS="$GDBM_LIBS $LDFLAGS"
3975 AC_CHECK_HEADERS([gdbm.h], [
3976 AC_CHECK_LIB([gdbm], [gdbm_open], [
3977 have_gdbm=yes
0461c68c 3978 GDBM_LIBS=${GDBM_LIBS-"-lgdbm"}
9cf5646b
CH
3979 ], [have_gdbm=no])
3980 ], [have_gdbm=no])
0a9f6953
CH
3981])
3982
ec5e2535
CH
3983dnl check for _dbmmodule.c dependencies
3984dnl ndbm, gdbm_compat, libdb
0a9f6953 3985AC_CHECK_HEADERS([ndbm.h], [
ec5e2535
CH
3986 WITH_SAVE_ENV([
3987 AC_SEARCH_LIBS([dbm_open], [ndbm gdbm_compat])
3988 ])
0a9f6953
CH
3989])
3990
ec5e2535
CH
3991AC_MSG_CHECKING([for ndbm presence and linker args])
3992AS_CASE([$ac_cv_search_dbm_open],
3993 [*ndbm*|*gdbm_compat*], [
3994 dbm_ndbm="$ac_cv_search_dbm_open"
3995 have_ndbm=yes
3996 ],
3997 [none*], [
3998 dbm_ndbm=""
3999 have_ndbm=yes
4000 ],
4001 [no], [have_ndbm=no]
4002)
4003AC_MSG_RESULT([$have_ndbm ($dbm_ndbm)])
4004
4005dnl "gdbm-ndbm.h" and "gdbm/ndbm.h" are both normalized to "gdbm_ndbm_h"
4006dnl unset ac_cv_header_gdbm_ndbm_h to prevent false positive cache hits.
0a9f6953
CH
4007AS_UNSET([ac_cv_header_gdbm_ndbm_h])
4008AC_CACHE_VAL([ac_cv_header_gdbm_slash_ndbm_h], [
4009 AC_CHECK_HEADER(
4010 [gdbm/ndbm.h],
4011 [ac_cv_header_gdbm_slash_ndbm_h=yes], [ac_cv_header_gdbm_slash_ndbm_h=no]
4012 )
4013])
4014AS_VAR_IF([ac_cv_header_gdbm_slash_ndbm_h], [yes], [
4015 AC_DEFINE([HAVE_GDBM_NDBM_H], [1], [Define to 1 if you have the <gdbm/ndbm.h> header file.])
4016])
4017
4018AS_UNSET([ac_cv_header_gdbm_ndbm_h])
4019AC_CACHE_VAL([ac_cv_header_gdbm_dash_ndbm_h], [
4020 AC_CHECK_HEADER(
4021 [gdbm-ndbm.h],
4022 [ac_cv_header_gdbm_dash_ndbm_h=yes], [ac_cv_header_gdbm_dash_ndbm_h=no]
4023 )
4024])
4025AS_VAR_IF([ac_cv_header_gdbm_dash_ndbm_h], [yes], [
4026 AC_DEFINE([HAVE_GDBM_DASH_NDBM_H], [1], [Define to 1 if you have the <gdbm-ndbm.h> header file.])
4027])
4028AS_UNSET([ac_cv_header_gdbm_ndbm_h])
4029
4030if test "$ac_cv_header_gdbm_slash_ndbm_h" = yes -o "$ac_cv_header_gdbm_dash_ndbm_h" = yes; then
02a72f08 4031 AS_UNSET([ac_cv_search_dbm_open])
ec5e2535 4032 WITH_SAVE_ENV([
02a72f08 4033 AC_SEARCH_LIBS([dbm_open], [gdbm_compat], [have_gdbm_compat=yes], [have_gdbm_compat=no])
ec5e2535 4034 ])
0a9f6953
CH
4035fi
4036
4037# Check for libdb >= 5 with dbm_open()
4038# db.h re-defines the name of the function
4039AC_CHECK_HEADERS([db.h], [
4040 AC_CACHE_CHECK([for libdb], [ac_cv_have_libdb], [
ec5e2535
CH
4041 WITH_SAVE_ENV([
4042 LIBS="$LIBS -ldb"
4043 AC_LINK_IFELSE([AC_LANG_PROGRAM([
4044 #define DB_DBM_HSEARCH 1
4045 #include <db.h>
4046 #if DB_VERSION_MAJOR < 5
4047 #error "dh.h: DB_VERSION_MAJOR < 5 is not supported."
4048 #endif
4049 ], [DBM *dbm = dbm_open(NULL, 0, 0)])
4050 ], [ac_cv_have_libdb=yes], [ac_cv_have_libdb=no])
4051 ])
0a9f6953
CH
4052 ])
4053 AS_VAR_IF([ac_cv_have_libdb], [yes], [
4054 AC_DEFINE([HAVE_LIBDB], [1], [Define to 1 if you have the `db' library (-ldb).])
4055 ])
4056])
4057
55708cce 4058# Check for --with-dbmliborder
ec5e2535 4059AC_MSG_CHECKING([for --with-dbmliborder])
2ea34cfb
EA
4060AC_ARG_WITH(
4061 [dbmliborder],
4062 [AS_HELP_STRING(
4063 [--with-dbmliborder=db1:db2:...],
4064 [override order to check db backends for dbm; a valid value is a colon separated string with the backend names `ndbm', `gdbm' and `bdb'.]
4065 )],
4066 [], [with_dbmliborder=gdbm:ndbm:bdb])
9cf5646b
CH
4067
4068have_gdbm_dbmliborder=no
4069as_save_IFS=$IFS
4070IFS=:
4071for db in $with_dbmliborder; do
4072 AS_CASE([$db],
4073 [ndbm], [],
4074 [gdbm], [have_gdbm_dbmliborder=yes],
4075 [bdb], [],
4076 [with_dbmliborder=error]
4077 )
4078done
4079IFS=$as_save_IFS
4080AS_VAR_IF([with_dbmliborder], [error], [
6c25bf07 4081 AC_MSG_ERROR([proper usage is --with-dbmliborder=db1:db2:... (gdbm:ndbm:bdb)])
9cf5646b 4082])
ec5e2535
CH
4083AC_MSG_RESULT([$with_dbmliborder])
4084
4085AC_MSG_CHECKING([for _dbm module CFLAGS and LIBS])
4086have_dbm=no
4087as_save_IFS=$IFS
4088IFS=:
4089for db in $with_dbmliborder; do
4090 case "$db" in
4091 ndbm)
4092 if test "$have_ndbm" = yes; then
4093 DBM_CFLAGS="-DUSE_NDBM"
4094 DBM_LIBS="$dbm_ndbm"
4095 have_dbm=yes
4096 break
4097 fi
4098 ;;
4099 gdbm)
4100 if test "$have_gdbm_compat" = yes; then
4101 DBM_CFLAGS="-DUSE_GDBM_COMPAT"
4102 DBM_LIBS="-lgdbm_compat"
4103 have_dbm=yes
4104 break
4105 fi
4106 ;;
4107 bdb)
4108 if test "$ac_cv_have_libdb" = yes; then
4109 DBM_CFLAGS="-DUSE_BERKDB"
4110 DBM_LIBS="-ldb"
4111 have_dbm=yes
4112 break
4113 fi
4114 ;;
4115 esac
4116done
4117IFS=$as_save_IFS
4118AC_MSG_RESULT([$DBM_CFLAGS $DBM_LIBS])
55708cce 4119
1143799d
ML
4120# Templates for things AC_DEFINEd more than once.
4121# For a single AC_DEFINE, no template is needed.
2ea34cfb 4122AH_TEMPLATE([_REENTRANT],
1143799d 4123 [Define to force use of thread-safe errno, h_errno, and other functions])
c0d24d8b 4124
a6a4dc81 4125if test "$ac_cv_pthread_is_default" = yes
a5f73f9b 4126then
a5f73f9b 4127 # Defining _REENTRANT on system with POSIX threads should not hurt.
2ea34cfb 4128 AC_DEFINE([_REENTRANT])
a5f73f9b 4129 posix_threads=yes
52d1b86b
JC
4130 if test "$ac_sys_system" = "SunOS"; then
4131 CFLAGS="$CFLAGS -D_REENTRANT"
4132 fi
130fb175
ML
4133elif test "$ac_cv_kpthread" = "yes"
4134then
4135 CC="$CC -Kpthread"
519adae1
ML
4136 if test "$ac_cv_cxx_thread" = "yes"; then
4137 CXX="$CXX -Kpthread"
4138 fi
d0b69ece 4139 posix_threads=yes
5f433f0e
ML
4140elif test "$ac_cv_kthread" = "yes"
4141then
4142 CC="$CC -Kthread"
519adae1
ML
4143 if test "$ac_cv_cxx_thread" = "yes"; then
4144 CXX="$CXX -Kthread"
4145 fi
5f433f0e 4146 posix_threads=yes
4ee6eef2
ML
4147elif test "$ac_cv_pthread" = "yes"
4148then
4149 CC="$CC -pthread"
519adae1
ML
4150 if test "$ac_cv_cxx_thread" = "yes"; then
4151 CXX="$CXX -pthread"
4152 fi
4ee6eef2 4153 posix_threads=yes
c0d24d8b 4154else
130fb175
ML
4155 if test ! -z "$withval" -a -d "$withval"
4156 then LDFLAGS="$LDFLAGS -L$withval"
4157 fi
69c0ff38
ML
4158
4159 # According to the POSIX spec, a pthreads implementation must
a2542bee
MK
4160 # define _POSIX_THREADS in unistd.h. Some apparently don't
4161 # (e.g. gnu pth with pthread emulation)
2ea34cfb
EA
4162 AC_MSG_CHECKING([for _POSIX_THREADS in unistd.h])
4163 AC_EGREP_CPP([yes],
6eb37f0e
NN
4164 [
4165#include <unistd.h>
4166#ifdef _POSIX_THREADS
4167yes
4168#endif
69c0ff38 4169 ], unistd_defines_pthreads=yes, unistd_defines_pthreads=no)
2ea34cfb 4170 AC_MSG_RESULT([$unistd_defines_pthreads])
69c0ff38 4171
2ea34cfb 4172 AC_DEFINE([_REENTRANT])
8158b5ad
ML
4173 # Just looking for pthread_create in libpthread is not enough:
4174 # on HP/UX, pthread.h renames pthread_create to a different symbol name.
4175 # So we really have to include pthread.h, and then link.
4176 _libs=$LIBS
4177 LIBS="$LIBS -lpthread"
4178 AC_MSG_CHECKING([for pthread_create in -lpthread])
7dba5940
SK
4179 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4180#include <stdio.h>
e35ca417 4181#include <stdlib.h>
7dba5940 4182#include <pthread.h>
8158b5ad 4183
b159a556
MK
4184void * start_routine (void *arg) { exit (0); }]], [[
4185pthread_create (NULL, NULL, start_routine, NULL)]])],[
2ea34cfb 4186 AC_MSG_RESULT([yes])
69c0ff38 4187 posix_threads=yes
a6a4dc81 4188 ],[
8158b5ad 4189 LIBS=$_libs
2ea34cfb 4190 AC_CHECK_FUNC([pthread_detach], [
69c0ff38 4191 posix_threads=yes
a6a4dc81 4192 ],[
2ea34cfb 4193 AC_CHECK_LIB([pthreads], [pthread_create], [
d0b69ece 4194 posix_threads=yes
130fb175 4195 LIBS="$LIBS -lpthreads"
a6a4dc81 4196 ], [
2ea34cfb 4197 AC_CHECK_LIB([c_r], [pthread_create], [
d0b69ece 4198 posix_threads=yes
130fb175 4199 LIBS="$LIBS -lc_r"
a6a4dc81 4200 ], [
2ea34cfb 4201 AC_CHECK_LIB([pthread], [__pthread_create_system], [
d0b69ece 4202 posix_threads=yes
130fb175 4203 LIBS="$LIBS -lpthread"
a6a4dc81 4204 ], [
2ea34cfb 4205 AC_CHECK_LIB([cma], [pthread_create], [
d0b69ece 4206 posix_threads=yes
130fb175 4207 LIBS="$LIBS -lcma"
a6a4dc81 4208 ],[
0fe645d6
CH
4209 AS_CASE([$ac_sys_system],
4210 [WASI], [posix_threads=stub],
4211 [AC_MSG_ERROR([could not find pthreads on your system])]
4212 )
4213 ])])])])])])
130fb175 4214
2ea34cfb 4215 AC_CHECK_LIB([mpc], [usconfig], [
4ee6eef2 4216 LIBS="$LIBS -lmpc"
a6a4dc81
AP
4217 ])
4218
4ee6eef2
ML
4219fi
4220
4221if test "$posix_threads" = "yes"; then
69c0ff38 4222 if test "$unistd_defines_pthreads" = "no"; then
2ea34cfb 4223 AC_DEFINE([_POSIX_THREADS], [1],
1b80b240 4224 [Define if you have POSIX threads,
c45929ec 4225 and your system does not define that.])
69c0ff38
ML
4226 fi
4227
dfc33fd8
ML
4228 # Bug 662787: Using semaphores causes unexplicable hangs on Solaris 8.
4229 case $ac_sys_system/$ac_sys_release in
2ea34cfb 4230 SunOS/5.6) AC_DEFINE([HAVE_PTHREAD_DESTRUCTOR], [1],
c80c93f4 4231 [Defined for Solaris 2.6 bug in pthread header.])
4ee6eef2 4232 ;;
2ea34cfb 4233 SunOS/5.8) AC_DEFINE([HAVE_BROKEN_POSIX_SEMAPHORES], [1],
c80c93f4 4234 [Define if the Posix semaphores do not work on your system])
4ee6eef2 4235 ;;
2ea34cfb 4236 AIX/*) AC_DEFINE([HAVE_BROKEN_POSIX_SEMAPHORES], [1],
c80c93f4 4237 [Define if the Posix semaphores do not work on your system])
7b3ce6a1 4238 ;;
2ea34cfb 4239 NetBSD/*) AC_DEFINE([HAVE_BROKEN_POSIX_SEMAPHORES], [1],
60ceedbd
TK
4240 [Define if the Posix semaphores do not work on your system])
4241 ;;
dfc33fd8
ML
4242 esac
4243
76d14fac 4244 AC_CACHE_CHECK([if PTHREAD_SCOPE_SYSTEM is supported], [ac_cv_pthread_system_supported],
7dba5940
SK
4245 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
4246 #include <stdio.h>
4247 #include <pthread.h>
d0b69ece
GR
4248 void *foo(void *parm) {
4249 return NULL;
4250 }
e35ca417 4251 int main(void) {
d0b69ece 4252 pthread_attr_t attr;
a82d3470 4253 pthread_t id;
674fa0a7
JR
4254 if (pthread_attr_init(&attr)) return (-1);
4255 if (pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM)) return (-1);
4256 if (pthread_create(&id, &attr, foo, NULL)) return (-1);
4257 return (0);
b159a556
MK
4258 }]])],
4259 [ac_cv_pthread_system_supported=yes],
4260 [ac_cv_pthread_system_supported=no],
4261 [ac_cv_pthread_system_supported=no])
d0b69ece 4262 ])
d0b69ece 4263 if test "$ac_cv_pthread_system_supported" = "yes"; then
2ea34cfb
EA
4264 AC_DEFINE([PTHREAD_SYSTEM_SCHED_SUPPORTED], [1],
4265 [Defined if PTHREAD_SCOPE_SYSTEM supported.])
d0b69ece 4266 fi
2ea34cfb 4267 AC_CHECK_FUNCS([pthread_sigmask],
fac083d1
JT
4268 [case $ac_sys_system in
4269 CYGWIN*)
2ea34cfb 4270 AC_DEFINE([HAVE_BROKEN_PTHREAD_SIGMASK], [1],
fac083d1
JT
4271 [Define if pthread_sigmask() does not work on your system.])
4272 ;;
4273 esac])
2ea34cfb 4274 AC_CHECK_FUNCS([pthread_getcpuclockid])
627b2d7c 4275fi
433c8ade 4276
0fe645d6
CH
4277AS_VAR_IF([posix_threads], [stub], [
4278 AC_DEFINE([HAVE_PTHREAD_STUBS], [1], [Define if platform requires stubbed pthreads support])
4279])
4280
a2ac6027 4281# Check for enable-ipv6
2ea34cfb 4282AH_TEMPLATE([ENABLE_IPV6], [Define if --enable-ipv6 is specified])
a5f8bb57 4283AC_MSG_CHECKING([if --enable-ipv6 is specified])
2ea34cfb
EA
4284AC_ARG_ENABLE([ipv6],
4285 [AS_HELP_STRING(
4286 [--enable-ipv6],
4287 [enable ipv6 (with ipv4) support, see Doc/library/socket.rst (default is yes if supported)]
4288 )],
a2ac6027
ML
4289[ case "$enableval" in
4290 no)
2ea34cfb 4291 AC_MSG_RESULT([no])
a2ac6027
ML
4292 ipv6=no
4293 ;;
2ea34cfb
EA
4294 *) AC_MSG_RESULT([yes])
4295 AC_DEFINE([ENABLE_IPV6])
a2ac6027
ML
4296 ipv6=yes
4297 ;;
4298 esac ],
4299
a5f8bb57
ML
4300[
4301dnl the check does not work on cross compilation case...
f6fd794f 4302 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ /* AF_INET6 available check */
a2ac6027 4303#include <sys/types.h>
27c68a6d 4304@%:@include <sys/socket.h>]],
f6fd794f 4305[[int domain = AF_INET6;]])],[
b159a556
MK
4306 ipv6=yes
4307],[
b159a556 4308 ipv6=no
b159a556 4309])
a5f8bb57 4310
d81d57e9
CH
4311AS_CASE([$ac_sys_system],
4312 [WASI], [ipv6=no]
4313)
4314
4315AC_MSG_RESULT([$ipv6])
4316
a5f8bb57 4317if test "$ipv6" = "yes"; then
2ea34cfb 4318 AC_MSG_CHECKING([if RFC2553 API is available])
b159a556
MK
4319 AC_COMPILE_IFELSE([
4320 AC_LANG_PROGRAM([[#include <sys/types.h>
27c68a6d 4321@%:@include <netinet/in.h>]],
b159a556
MK
4322 [[struct sockaddr_in6 x;
4323 x.sin6_scope_id;]])
4324 ],[
2ea34cfb 4325 AC_MSG_RESULT([yes])
b159a556
MK
4326 ipv6=yes
4327 ],[
2ea34cfb 4328 AC_MSG_RESULT([no], [IPv6 disabled])
b159a556
MK
4329 ipv6=no
4330 ])
a5f8bb57
ML
4331fi
4332
4333if test "$ipv6" = "yes"; then
2ea34cfb 4334 AC_DEFINE([ENABLE_IPV6])
a5f8bb57
ML
4335fi
4336])
a2ac6027
ML
4337
4338ipv6type=unknown
4339ipv6lib=none
4340ipv6trylibc=no
4341
4342if test "$ipv6" = "yes"; then
4343 AC_MSG_CHECKING([ipv6 stack type])
b8552160
GR
4344 for i in inria kame linux-glibc linux-inet6 solaris toshiba v6d zeta;
4345 do
a2ac6027
ML
4346 case $i in
4347 inria)
4348 dnl http://www.kame.net/
2ea34cfb 4349 AC_EGREP_CPP([yes], [
a2ac6027
ML
4350#include <netinet/in.h>
4351#ifdef IPV6_INRIA_VERSION
4352yes
27c68a6d 4353@%:@endif],
44ddbde3 4354 [ipv6type=$i])
a2ac6027
ML
4355 ;;
4356 kame)
4357 dnl http://www.kame.net/
2ea34cfb 4358 AC_EGREP_CPP([yes], [
a2ac6027
ML
4359#include <netinet/in.h>
4360#ifdef __KAME__
4361yes
27c68a6d 4362@%:@endif],
a2ac6027
ML
4363 [ipv6type=$i;
4364 ipv6lib=inet6
4365 ipv6libdir=/usr/local/v6/lib
44ddbde3 4366 ipv6trylibc=yes])
a2ac6027
ML
4367 ;;
4368 linux-glibc)
4369 dnl http://www.v6.linux.or.jp/
2ea34cfb 4370 AC_EGREP_CPP([yes], [
a2ac6027
ML
4371#include <features.h>
4372#if defined(__GLIBC__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2))
4373yes
27c68a6d 4374@%:@endif],
a2ac6027 4375 [ipv6type=$i;
44ddbde3 4376 ipv6trylibc=yes])
a2ac6027
ML
4377 ;;
4378 linux-inet6)
4379 dnl http://www.v6.linux.or.jp/
4380 if test -d /usr/inet6; then
4381 ipv6type=$i
4382 ipv6lib=inet6
4383 ipv6libdir=/usr/inet6/lib
decc6a47 4384 BASECFLAGS="-I/usr/inet6/include $BASECFLAGS"
a2ac6027
ML
4385 fi
4386 ;;
4387 solaris)
4388 if test -f /etc/netconfig; then
f3fcd9f1 4389 if $GREP -q tcp6 /etc/netconfig; then
a2ac6027
ML
4390 ipv6type=$i
4391 ipv6trylibc=yes
a2ac6027
ML
4392 fi
4393 fi
4394 ;;
4395 toshiba)
2ea34cfb 4396 AC_EGREP_CPP([yes], [
a2ac6027
ML
4397#include <sys/param.h>
4398#ifdef _TOSHIBA_INET6
4399yes
27c68a6d 4400@%:@endif],
a2ac6027
ML
4401 [ipv6type=$i;
4402 ipv6lib=inet6;
44ddbde3 4403 ipv6libdir=/usr/local/v6/lib])
a2ac6027
ML
4404 ;;
4405 v6d)
2ea34cfb 4406 AC_EGREP_CPP([yes], [
a2ac6027
ML
4407#include </usr/local/v6/include/sys/v6config.h>
4408#ifdef __V6D__
4409yes
27c68a6d 4410@%:@endif],
a2ac6027
ML
4411 [ipv6type=$i;
4412 ipv6lib=v6;
4413 ipv6libdir=/usr/local/v6/lib;
decc6a47 4414 BASECFLAGS="-I/usr/local/v6/include $BASECFLAGS"])
a2ac6027
ML
4415 ;;
4416 zeta)
2ea34cfb 4417 AC_EGREP_CPP([yes], [
a2ac6027
ML
4418#include <sys/param.h>
4419#ifdef _ZETA_MINAMI_INET6
4420yes
27c68a6d 4421@%:@endif],
a2ac6027
ML
4422 [ipv6type=$i;
4423 ipv6lib=inet6;
44ddbde3 4424 ipv6libdir=/usr/local/v6/lib])
a2ac6027
ML
4425 ;;
4426 esac
4427 if test "$ipv6type" != "unknown"; then
4428 break
4429 fi
4430 done
2ea34cfb 4431 AC_MSG_RESULT([$ipv6type])
a2ac6027
ML
4432fi
4433
4434if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then
4435 if test -d $ipv6libdir -a -f $ipv6libdir/lib$ipv6lib.a; then
4436 LIBS="-L$ipv6libdir -l$ipv6lib $LIBS"
74b23c97 4437 AC_MSG_NOTICE([using lib$ipv6lib])
a2ac6027 4438 else
74b23c97
EEA
4439 AS_VAR_IF([ipv6trylibc], [yes], [
4440 AC_MSG_NOTICE([using libc])
4441 ], [
4442 AC_MSG_ERROR([m4_normalize([
4443 No $ipv6lib library found; cannot continue.
4444 You need to fetch lib$ipv6lib.a from appropriate
4445 ipv6 kit and compile beforehand.
4446 ])])
4447 ])
a2ac6027
ML
4448 fi
4449fi
4450
57c50c9c
CH
4451
4452AC_CACHE_CHECK([CAN_RAW_FD_FRAMES], [ac_cv_can_raw_fd_frames], [
a6cc5515 4453AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ /* CAN_RAW_FD_FRAMES available check */
27c68a6d 4454@%:@include <linux/can/raw.h>]],
57c50c9c
CH
4455[[int can_raw_fd_frames = CAN_RAW_FD_FRAMES;]])],
4456[ac_cv_can_raw_fd_frames=yes],
4457[ac_cv_can_raw_fd_frames=no])
4458])
4459AS_VAR_IF([ac_cv_can_raw_fd_frames], [yes], [
2ea34cfb
EA
4460 AC_DEFINE([HAVE_LINUX_CAN_RAW_FD_FRAMES], [1],
4461 [Define if compiling using Linux 3.6 or later.])
a6cc5515
LH
4462])
4463
57c50c9c 4464AC_CACHE_CHECK([for CAN_RAW_JOIN_FILTERS], [ac_cv_can_raw_join_filters], [
97e0de04 4465AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
27c68a6d 4466@%:@include <linux/can/raw.h>]],
57c50c9c
CH
4467[[int can_raw_join_filters = CAN_RAW_JOIN_FILTERS;]])],
4468[ac_cv_can_raw_join_filters=yes],
4469[ac_cv_can_raw_join_filters=no])
4470])
4471AS_VAR_IF([ac_cv_can_raw_join_filters], [yes], [
2ea34cfb
EA
4472 AC_DEFINE([HAVE_LINUX_CAN_RAW_JOIN_FILTERS], [1],
4473 [Define if compiling using Linux 4.1 or later.])
97e0de04
ZS
4474])
4475
a3fb4f78 4476# Check for --with-doc-strings
2ea34cfb
EA
4477AC_MSG_CHECKING([for --with-doc-strings])
4478AC_ARG_WITH(
4479 [doc-strings],
4480 [AS_HELP_STRING([--with-doc-strings], [enable documentation strings (default is yes)])])
a3fb4f78
ML
4481
4482if test -z "$with_doc_strings"
4483then with_doc_strings="yes"
4484fi
4485if test "$with_doc_strings" != "no"
4486then
2ea34cfb 4487 AC_DEFINE([WITH_DOC_STRINGS], [1],
a3fb4f78
ML
4488 [Define if you want documentation strings in extension modules])
4489fi
2ea34cfb 4490AC_MSG_RESULT([$with_doc_strings])
a3fb4f78 4491
a35c6880 4492# Check for Python-specific malloc support
2ea34cfb
EA
4493AC_MSG_CHECKING([for --with-pymalloc])
4494AC_ARG_WITH(
4495 [pymalloc],
4496 [AS_HELP_STRING([--with-pymalloc], [enable specialized mallocs (default is yes)])])
16c22976
NS
4497
4498if test -z "$with_pymalloc"
35f3a2cb 4499then
d81d57e9 4500 dnl default to yes except for wasm32-emscripten and wasm32-wasi.
03394348
CH
4501 AS_CASE([$ac_sys_system],
4502 [Emscripten], [with_pymalloc="no"],
d81d57e9 4503 [WASI], [with_pymalloc="no"],
03394348
CH
4504 [with_pymalloc="yes"]
4505 )
16c22976
NS
4506fi
4507if test "$with_pymalloc" != "no"
4508then
2ea34cfb 4509 AC_DEFINE([WITH_PYMALLOC], [1],
c45929ec 4510 [Define if you want to compile in Python-specific mallocs])
16c22976 4511fi
2ea34cfb 4512AC_MSG_RESULT([$with_pymalloc])
a35c6880 4513
9942f42a
CH
4514# Check whether objects such as float, tuple and dict are using
4515# freelists to optimization memory allocation.
2ea34cfb
EA
4516AC_MSG_CHECKING([for --with-freelists])
4517AC_ARG_WITH(
4518 [freelists],
4519 [AS_HELP_STRING([--with-freelists], [enable object freelists (default is yes)])])
9942f42a
CH
4520
4521if test -z "$with_freelists"
4522then
4523 with_freelists="yes"
4524fi
4525if test "$with_freelists" != "no"
4526then
2ea34cfb 4527 AC_DEFINE([WITH_FREELISTS], [1],
9942f42a
CH
4528 [Define if you want to compile in object freelists optimization])
4529fi
2ea34cfb 4530AC_MSG_RESULT([$with_freelists])
9942f42a 4531
6ea4186d 4532# Check for --with-c-locale-coercion
2ea34cfb
EA
4533AC_MSG_CHECKING([for --with-c-locale-coercion])
4534AC_ARG_WITH(
4535 [c-locale-coercion],
4536 [AS_HELP_STRING([--with-c-locale-coercion], [enable C locale coercion to a UTF-8 based locale (default is yes)])])
6ea4186d
NC
4537
4538if test -z "$with_c_locale_coercion"
4539then
4540 with_c_locale_coercion="yes"
4541fi
4542if test "$with_c_locale_coercion" != "no"
4543then
2ea34cfb 4544 AC_DEFINE([PY_COERCE_C_LOCALE], [1],
6ea4186d
NC
4545 [Define if you want to coerce the C locale to a UTF-8 based locale])
4546fi
2ea34cfb 4547AC_MSG_RESULT([$with_c_locale_coercion])
6ea4186d 4548
05159c4a
BP
4549# Check for Valgrind support
4550AC_MSG_CHECKING([for --with-valgrind])
2ea34cfb
EA
4551AC_ARG_WITH(
4552 [valgrind],
4553 [AS_HELP_STRING([--with-valgrind], [enable Valgrind support (default is no)])],
4554 [], [with_valgrind=no]
4555)
05159c4a
BP
4556AC_MSG_RESULT([$with_valgrind])
4557if test "$with_valgrind" != no; then
4558 AC_CHECK_HEADER([valgrind/valgrind.h],
4559 [AC_DEFINE([WITH_VALGRIND], 1, [Define if you want pymalloc to be disabled when running under valgrind])],
4560 [AC_MSG_ERROR([Valgrind support requested but headers not available])]
4561 )
39370830 4562 OPT="-DDYNAMIC_ANNOTATIONS_ENABLED=1 $OPT"
05159c4a
BP
4563fi
4564
a785c87d 4565# Check for DTrace support
2ea34cfb
EA
4566AC_MSG_CHECKING([for --with-dtrace])
4567AC_ARG_WITH(
4568 [dtrace],
4569 [AS_HELP_STRING([--with-dtrace], [enable DTrace support (default is no)])],
4570 [], [with_dtrace=no])
4571AC_MSG_RESULT([$with_dtrace])
4572
4573AC_SUBST([DTRACE])
4574AC_SUBST([DFLAGS])
4575AC_SUBST([DTRACE_HEADERS])
4576AC_SUBST([DTRACE_OBJS])
a785c87d 4577DTRACE=
a785c87d
ŁL
4578DTRACE_HEADERS=
4579DTRACE_OBJS=
4580
4581if test "$with_dtrace" = "yes"
4582then
2ea34cfb 4583 AC_PATH_PROG([DTRACE], [dtrace], [not found])
a785c87d
ŁL
4584 if test "$DTRACE" = "not found"; then
4585 AC_MSG_ERROR([dtrace command not found on \$PATH])
4586 fi
2ea34cfb
EA
4587 AC_DEFINE([WITH_DTRACE], [1],
4588 [Define if you want to compile in DTrace support])
a785c87d
ŁL
4589 DTRACE_HEADERS="Include/pydtrace_probes.h"
4590
4591 # On OS X, DTrace providers do not need to be explicitly compiled and
4592 # linked into the binary. Correspondingly, dtrace(1) is missing the ELF
4593 # generation flag '-G'. We check for presence of this flag, rather than
4594 # hardcoding support by OS, in the interest of robustness.
4595 AC_CACHE_CHECK([whether DTrace probes require linking],
4596 [ac_cv_dtrace_link], [dnl
4597 ac_cv_dtrace_link=no
5c8f5376 4598 echo 'BEGIN{}' > conftest.d
3c97e1e4 4599 "$DTRACE" $DFLAGS -G -s conftest.d -o conftest.o > /dev/null 2>&1 && \
a785c87d
ŁL
4600 ac_cv_dtrace_link=yes
4601 ])
4602 if test "$ac_cv_dtrace_link" = "yes"; then
4603 DTRACE_OBJS="Python/pydtrace.o"
4604 fi
4605fi
4606
087d0fa5
HC
4607dnl Platform-specific C and header files.
4608PLATFORM_HEADERS=
4609PLATFORM_OBJS=
4610
4611AS_CASE([$ac_sys_system],
4612 [Emscripten], [
6b179adb
HC
4613 AS_VAR_APPEND([PLATFORM_OBJS], [' Python/emscripten_signal.o Python/emscripten_trampoline.o'])
4614 AS_VAR_APPEND([PLATFORM_HEADERS], [' $(srcdir)/Include/internal/pycore_emscripten_signal.h $(srcdir)/Include/internal/pycore_emscripten_trampoline.h'])
087d0fa5
HC
4615 ],
4616)
4617AC_SUBST([PLATFORM_HEADERS])
4618AC_SUBST([PLATFORM_OBJS])
4619
68242b5a 4620# -I${DLINCLDIR} is added to the compile rule for importdl.o
2ea34cfb 4621AC_SUBST([DLINCLDIR])
98935bff 4622DLINCLDIR=.
627b2d7c 4623
e97ee181 4624# the dlopen() function means we might want to use dynload_shlib.o. some
c79667ff 4625# platforms have dlopen(), but don't want to use it.
2ea34cfb 4626AC_CHECK_FUNCS([dlopen])
e97ee181
GR
4627
4628# DYNLOADFILE specifies which dynload_*.o file we will use for dynamic
4629# loading of modules.
2ea34cfb
EA
4630AC_SUBST([DYNLOADFILE])
4631AC_MSG_CHECKING([DYNLOADFILE])
e97ee181
GR
4632if test -z "$DYNLOADFILE"
4633then
4634 case $ac_sys_system/$ac_sys_release in
e97ee181 4635 hp*|HP*) DYNLOADFILE="dynload_hpux.o";;
e97ee181
GR
4636 *)
4637 # use dynload_shlib.c and dlopen() if we have it; otherwise stub
4638 # out any dynamic loading
4639 if test "$ac_cv_func_dlopen" = yes
4640 then DYNLOADFILE="dynload_shlib.o"
4641 else DYNLOADFILE="dynload_stub.o"
4642 fi
4643 ;;
4644 esac
4645fi
2ea34cfb 4646AC_MSG_RESULT([$DYNLOADFILE])
e97ee181
GR
4647if test "$DYNLOADFILE" != "dynload_stub.o"
4648then
2ea34cfb 4649 AC_DEFINE([HAVE_DYNAMIC_LOADING], [1],
c45929ec 4650 [Defined when any dynamic module loading is enabled.])
e97ee181
GR
4651fi
4652
c49e5b73
JJ
4653# MACHDEP_OBJS can be set to platform-specific object files needed by Python
4654
2ea34cfb
EA
4655AC_SUBST([MACHDEP_OBJS])
4656AC_MSG_CHECKING([MACHDEP_OBJS])
c49e5b73
JJ
4657if test -z "$MACHDEP_OBJS"
4658then
b6e9cad3
JJ
4659 MACHDEP_OBJS=$extra_machdep_objs
4660else
4661 MACHDEP_OBJS="$MACHDEP_OBJS $extra_machdep_objs"
c49e5b73 4662fi
9c7817e9 4663if test -z "$MACHDEP_OBJS"; then
4664 AC_MSG_RESULT([none])
4665else
4666 AC_MSG_RESULT([$MACHDEP_OBJS])
4667fi
c49e5b73 4668
627b2d7c 4669# checks for library functions
4ebde73b 4670AC_CHECK_FUNCS([ \
a6ca8eee 4671 accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
0d35a59c 4672 copy_file_range ctermid dup dup3 execv explicit_bzero explicit_memset \
4ebde73b
CH
4673 faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
4674 fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
4675 gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \
8b24d60f 4676 getgrnam_r getgrouplist getgroups gethostname getitimer getloadavg getlogin \
4ebde73b 4677 getpeername getpgid getpid getppid getpriority _getpty \
ca9689f8 4678 getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \
4ebde73b
CH
4679 getspnam getuid getwd if_nameindex initgroups kill killpg lchown linkat \
4680 lockf lstat lutimes madvise mbrtowc memrchr mkdirat mkfifo mkfifoat \
4681 mknod mknodat mktime mmap mremap nice openat opendir pathconf pause pipe \
4682 pipe2 plock poll posix_fadvise posix_fallocate posix_spawn posix_spawnp \
4683 pread preadv preadv2 pthread_condattr_setclock pthread_init pthread_kill \
4684 pwrite pwritev pwritev2 readlink readlinkat readv realpath renameat \
4685 rtpSpawn sched_get_priority_max sched_rr_get_interval sched_setaffinity \
4686 sched_setparam sched_setscheduler sem_clockwait sem_getvalue sem_open \
4687 sem_timedwait sem_unlink sendfile setegid seteuid setgid sethostname \
4688 setitimer setlocale setpgid setpgrp setpriority setregid setresgid \
4689 setresuid setreuid setsid setuid setvbuf shutdown sigaction sigaltstack \
4690 sigfillset siginterrupt sigpending sigrelse sigtimedwait sigwait \
4691 sigwaitinfo snprintf splice strftime strlcpy strsignal symlinkat sync \
4692 sysconf system tcgetpgrp tcsetpgrp tempnam timegm times tmpfile \
a6ca8eee 4693 tmpnam tmpnam_r truncate ttyname umask uname unlinkat utimensat utimes vfork \
4ebde73b
CH
4694 wait wait3 wait4 waitid waitpid wcscoll wcsftime wcsxfrm wmemcmp writev \
4695])
00f0f6ef 4696
40caa05f
BP
4697# Force lchmod off for Linux. Linux disallows changing the mode of symbolic
4698# links. Some libc implementations have a stub lchmod implementation that always
4699# returns an error.
4700if test "$MACHDEP" != linux; then
2ea34cfb 4701 AC_CHECK_FUNCS([lchmod])
40caa05f
BP
4702fi
4703
2ea34cfb
EA
4704AC_CHECK_DECL([dirfd],
4705 [AC_DEFINE([HAVE_DIRFD], [1],
4706 [Define if you have the 'dirfd' function or macro.])],
4707 [],
4708 [@%:@include <sys/types.h>
4709 @%:@include <dirent.h>])
df300d50 4710
c8ad7cc5
ML
4711# For some functions, having a definition is not sufficient, since
4712# we want to take their address.
27c68a6d
EA
4713PY_CHECK_FUNC([chroot], [@%:@include <unistd.h>])
4714PY_CHECK_FUNC([link], [@%:@include <unistd.h>])
4715PY_CHECK_FUNC([symlink], [@%:@include <unistd.h>])
4716PY_CHECK_FUNC([fchdir], [@%:@include <unistd.h>])
4717PY_CHECK_FUNC([fsync], [@%:@include <unistd.h>])
4718PY_CHECK_FUNC([fdatasync], [@%:@include <unistd.h>])
4719PY_CHECK_FUNC([epoll_create], [@%:@include <sys/epoll.h>], [HAVE_EPOLL])
4720PY_CHECK_FUNC([epoll_create1], [@%:@include <sys/epoll.h>])
57c50c9c 4721PY_CHECK_FUNC([kqueue],[
4fbc72b4
CH
4722#include <sys/types.h>
4723#include <sys/event.h>
b159a556 4724])
57c50c9c 4725PY_CHECK_FUNC([prlimit], [
b7bd5df8
CH
4726#include <sys/time.h>
4727#include <sys/resource.h>
41761933 4728])
b7bd5df8 4729
27c68a6d 4730PY_CHECK_FUNC([_dyld_shared_cache_contains_path], [@%:@include <mach-o/dyld.h>], [HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH])
57c50c9c
CH
4731
4732PY_CHECK_FUNC([memfd_create], [
43fdbd27
ZS
4733#ifdef HAVE_SYS_MMAN_H
4734#include <sys/mman.h>
4735#endif
4736#ifdef HAVE_SYS_MEMFD_H
4737#include <sys/memfd.h>
4738#endif
43fdbd27
ZS
4739])
4740
57c50c9c 4741PY_CHECK_FUNC([eventfd], [
cd9fed6a
CH
4742#ifdef HAVE_SYS_EVENTFD_H
4743#include <sys/eventfd.h>
4744#endif
cd9fed6a
CH
4745])
4746
d584368d
ML
4747# On some systems (eg. FreeBSD 5), we would find a definition of the
4748# functions ctermid_r, setgroups in the library, but no prototype
4749# (e.g. because we use _XOPEN_SOURCE). See whether we can take their
4750# address to avoid compiler warnings and potential miscompilations
4751# because of the missing prototypes.
4752
27c68a6d 4753PY_CHECK_FUNC([ctermid_r], [@%:@include <stdio.h>])
d584368d 4754
a4e4ae27
AP
4755AC_CACHE_CHECK([for flock declaration], [ac_cv_flock_decl],
4756 [AC_COMPILE_IFELSE(
4757 [AC_LANG_PROGRAM(
27c68a6d 4758 [@%:@include <sys/file.h>],
a4e4ae27
AP
4759 [void* p = flock]
4760 )],
4761 [ac_cv_flock_decl=yes],
4762 [ac_cv_flock_decl=no]
4763 )
b159a556 4764])
5b946cad
EEA
4765dnl Linking with libbsd may be necessary on AIX for flock function.
4766AS_VAR_IF([ac_cv_flock_decl], [yes],
e01c4de3
EA
4767 [AC_CHECK_FUNCS([flock], [],
4768 [AC_CHECK_LIB([bsd], [flock], [FCNTL_LIBS="-lbsd"])])])
f26d63b3 4769
27c68a6d 4770PY_CHECK_FUNC([getpagesize], [@%:@include <unistd.h>])
f26d63b3 4771
57c50c9c
CH
4772AC_CACHE_CHECK([for broken unsetenv], [ac_cv_broken_unsetenv],
4773 [AC_COMPILE_IFELSE(
4774 [AC_LANG_PROGRAM(
27c68a6d 4775 [@%:@include <stdlib.h>],
57c50c9c
CH
4776 [int res = unsetenv("DUMMY")])],
4777 [ac_cv_broken_unsetenv=no],
4778 [ac_cv_broken_unsetenv=yes]
4779 )
4780])
4781AS_VAR_IF([ac_cv_broken_unsetenv], [yes], [
2ea34cfb
EA
4782 AC_DEFINE([HAVE_BROKEN_UNSETENV], [1],
4783 [Define if 'unsetenv' does not return an int.])
984890fc
VS
4784])
4785
4ee6eef2 4786dnl check for true
2ea34cfb 4787AC_CHECK_PROGS([TRUE], [true], [/bin/true])
4ee6eef2 4788
95c419b2
ML
4789dnl On some systems (e.g. Solaris 9), hstrerror and inet_aton are in -lresolv
4790dnl On others, they are in the C library, so we to take no action
2ea34cfb
EA
4791AC_CHECK_LIB([c], [inet_aton], [$ac_cv_prog_TRUE],
4792 AC_CHECK_LIB([resolv], [inet_aton])
95c419b2
ML
4793)
4794
d0764e2b
CH
4795# On Tru64, chflags seems to be present, but calling it will
4796# exit Python
ed68afa8 4797AC_CACHE_CHECK([for chflags], [ac_cv_have_chflags], [dnl
3eb67d58 4798AC_RUN_IFELSE([AC_LANG_SOURCE([[
d0764e2b
CH
4799#include <sys/stat.h>
4800#include <unistd.h>
e35ca417 4801int main(int argc, char *argv[])
d0764e2b
CH
4802{
4803 if(chflags(argv[0], 0) != 0)
4804 return 1;
4805 return 0;
4806}
3eb67d58 4807]])],
b159a556
MK
4808[ac_cv_have_chflags=yes],
4809[ac_cv_have_chflags=no],
4810[ac_cv_have_chflags=cross])
ed68afa8
BP
4811])
4812if test "$ac_cv_have_chflags" = cross ; then
4813 AC_CHECK_FUNC([chflags], [ac_cv_have_chflags="yes"], [ac_cv_have_chflags="no"])
4814fi
4815if test "$ac_cv_have_chflags" = yes ; then
2ea34cfb
EA
4816 AC_DEFINE([HAVE_CHFLAGS], [1],
4817 [Define to 1 if you have the 'chflags' function.])
7b0c1c76 4818fi
d0764e2b 4819
ed68afa8 4820AC_CACHE_CHECK([for lchflags], [ac_cv_have_lchflags], [dnl
3eb67d58 4821AC_RUN_IFELSE([AC_LANG_SOURCE([[
d0764e2b
CH
4822#include <sys/stat.h>
4823#include <unistd.h>
e35ca417 4824int main(int argc, char *argv[])
d0764e2b
CH
4825{
4826 if(lchflags(argv[0], 0) != 0)
4827 return 1;
4828 return 0;
4829}
3eb67d58 4830]])],[ac_cv_have_lchflags=yes],[ac_cv_have_lchflags=no],[ac_cv_have_lchflags=cross])
ed68afa8
BP
4831])
4832if test "$ac_cv_have_lchflags" = cross ; then
4833 AC_CHECK_FUNC([lchflags], [ac_cv_have_lchflags="yes"], [ac_cv_have_lchflags="no"])
4834fi
4835if test "$ac_cv_have_lchflags" = yes ; then
2ea34cfb
EA
4836 AC_DEFINE([HAVE_LCHFLAGS], [1],
4837 [Define to 1 if you have the 'lchflags' function.])
7b0c1c76 4838fi
d0764e2b 4839
5b7c7cb1 4840dnl Check for compression libraries
d9cedabe
CH
4841AH_TEMPLATE([HAVE_ZLIB_COPY], [Define if the zlib library has inflateCopy])
4842
944ff8c5
CH
4843dnl detect zlib from Emscripten emport
4844PY_CHECK_EMSCRIPTEN_PORT([ZLIB], [-sUSE_ZLIB])
4845
d9cedabe
CH
4846PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.0], [
4847 have_zlib=yes
4848 dnl zlib 1.2.0 (2003) added inflateCopy
4849 AC_DEFINE([HAVE_ZLIB_COPY], [1])
4850], [
944ff8c5 4851 WITH_SAVE_ENV([
9af7f87d 4852 CPPFLAGS="$CPPFLAGS $ZLIB_CFLAGS"
944ff8c5
CH
4853 LDFLAGS="$LDFLAGS $ZLIB_LIBS"
4854 AC_CHECK_HEADERS([zlib.h], [
4855 PY_CHECK_LIB([z], [gzread], [have_zlib=yes], [have_zlib=no])
4856 ], [have_zlib=no])
4857 AS_VAR_IF([have_zlib], [yes], [
4858 ZLIB_CFLAGS=${ZLIB_CFLAGS-""}
4859 ZLIB_LIBS=${ZLIB_LIBS-"-lz"}
4860 PY_CHECK_LIB([z], [inflateCopy], [AC_DEFINE([HAVE_ZLIB_COPY], [1])])
d9cedabe 4861 ])
944ff8c5 4862 ])
5b7c7cb1
CH
4863])
4864
d9cedabe
CH
4865dnl binascii can use zlib for optimized crc32.
4866AS_VAR_IF([have_zlib], [yes], [
4867 BINASCII_CFLAGS="-DUSE_ZLIB_CRC32 $ZLIB_CFLAGS"
4868 BINASCII_LIBS="$ZLIB_LIBS"
5b7c7cb1
CH
4869])
4870
944ff8c5
CH
4871dnl detect bzip2 from Emscripten emport
4872PY_CHECK_EMSCRIPTEN_PORT([BZIP2], [-sUSE_BZIP2])
4873
d9cedabe 4874PKG_CHECK_MODULES([BZIP2], [bzip2], [have_bzip2=yes], [
944ff8c5 4875 WITH_SAVE_ENV([
9af7f87d 4876 CPPFLAGS="$CPPFLAGS $BZIP2_CFLAGS"
944ff8c5
CH
4877 LDFLAGS="$LDFLAGS $BZIP2_LIBS"
4878 AC_CHECK_HEADERS([bzlib.h], [
4879 AC_CHECK_LIB([bz2], [BZ2_bzCompress], [have_bzip2=yes], [have_bzip2=no])
4880 ], [have_bzip2=no])
4881 AS_VAR_IF([have_bzip2], [yes], [
4882 BZIP2_CFLAGS=${BZIP2_CFLAGS-""}
4883 BZIP2_LIBS=${BZIP2_LIBS-"-lbz2"}
d9cedabe 4884 ])
944ff8c5 4885 ])
d9cedabe
CH
4886])
4887
4888PKG_CHECK_MODULES([LIBLZMA], [liblzma], [have_liblzma=yes], [
944ff8c5 4889 WITH_SAVE_ENV([
9af7f87d 4890 CPPFLAGS="$CPPFLAGS $LIBLZMA_CFLAGS"
944ff8c5
CH
4891 LDFLAGS="$LDFLAGS $LIBLZMA_LIBS"
4892 AC_CHECK_HEADERS([lzma.h], [
4893 AC_CHECK_LIB([lzma], [lzma_easy_encoder], [have_liblzma=yes], [have_liblzma=no])
4894 ], [have_liblzma=no])
4895 AS_VAR_IF([have_liblzma], [yes], [
4896 LIBLZMA_CFLAGS=${LIBLZMA_CFLAGS-""}
4897 LIBLZMA_LIBS=${LIBLZMA_LIBS-"-llzma"}
d9cedabe 4898 ])
944ff8c5 4899 ])
5b7c7cb1 4900])
0e3f591a 4901
8b24d60f 4902dnl PY_CHECK_NETDB_FUNC(FUNCTION)
27c68a6d 4903AC_DEFUN([PY_CHECK_NETDB_FUNC], [PY_CHECK_FUNC([$1], [@%:@include <netdb.h>])])
e9416176 4904
8b24d60f
CH
4905PY_CHECK_NETDB_FUNC([hstrerror])
4906dnl not available in WASI yet
4907PY_CHECK_NETDB_FUNC([getservbyname])
4908PY_CHECK_NETDB_FUNC([getservbyport])
4909PY_CHECK_NETDB_FUNC([gethostbyname])
4910PY_CHECK_NETDB_FUNC([gethostbyaddr])
4911PY_CHECK_NETDB_FUNC([getprotobyname])
e9416176 4912
8b24d60f
CH
4913dnl PY_CHECK_SOCKET_FUNC(FUNCTION)
4914AC_DEFUN([PY_CHECK_SOCKET_FUNC], [PY_CHECK_FUNC([$1], [
f2e488db 4915#include <sys/types.h>
e9416176
ML
4916#include <sys/socket.h>
4917#include <netinet/in.h>
4918#include <arpa/inet.h>
8b24d60f
CH
4919])])
4920
4921PY_CHECK_SOCKET_FUNC([inet_aton])
4922PY_CHECK_SOCKET_FUNC([inet_ntoa])
4923PY_CHECK_SOCKET_FUNC([inet_pton])
4924dnl not available in WASI yet
4925PY_CHECK_SOCKET_FUNC([getpeername])
4926PY_CHECK_SOCKET_FUNC([getsockname])
4927PY_CHECK_SOCKET_FUNC([accept])
4928PY_CHECK_SOCKET_FUNC([bind])
4929PY_CHECK_SOCKET_FUNC([connect])
4930PY_CHECK_SOCKET_FUNC([listen])
4931PY_CHECK_SOCKET_FUNC([recvfrom])
4932PY_CHECK_SOCKET_FUNC([sendto])
4933PY_CHECK_SOCKET_FUNC([setsockopt])
4934PY_CHECK_SOCKET_FUNC([socket])
e9416176 4935
d6640d4b 4936# On some systems, setgroups is in unistd.h, on others, in grp.h
57c50c9c 4937PY_CHECK_FUNC([setgroups], [
f2e488db 4938#include <unistd.h>
d6640d4b
ML
4939#ifdef HAVE_GRP_H
4940#include <grp.h>
4941#endif
b159a556 4942])
d584368d 4943
ae553b35 4944# check for openpty, login_tty, and forkpty
8cef4cf7 4945
2ea34cfb
EA
4946AC_CHECK_FUNCS([openpty], [],
4947 [AC_CHECK_LIB([util], [openpty],
4948 [AC_DEFINE([HAVE_OPENPTY]) LIBS="$LIBS -lutil"],
4949 [AC_CHECK_LIB([bsd], [openpty],
4950 [AC_DEFINE([HAVE_OPENPTY]) LIBS="$LIBS -lbsd"])])])
ae553b35
SG
4951AC_SEARCH_LIBS([login_tty], [util],
4952 [AC_DEFINE([HAVE_LOGIN_TTY], [1], [Define to 1 if you have the `login_tty' function.])]
4953)
2ea34cfb
EA
4954AC_CHECK_FUNCS([forkpty], [],
4955 [AC_CHECK_LIB([util], [forkpty],
4956 [AC_DEFINE([HAVE_FORKPTY]) LIBS="$LIBS -lutil"],
4957 [AC_CHECK_LIB([bsd], [forkpty],
4958 [AC_DEFINE([HAVE_FORKPTY]) LIBS="$LIBS -lbsd"])])])
8cef4cf7 4959
00f0f6ef 4960# check for long file support functions
2ea34cfb 4961AC_CHECK_FUNCS([fseek64 fseeko fstatvfs ftell64 ftello statvfs])
00f0f6ef 4962
2ea34cfb
EA
4963AC_REPLACE_FUNCS([dup2])
4964AC_CHECK_FUNCS([getpgrp],
4965 [AC_COMPILE_IFELSE(
4966 [AC_LANG_PROGRAM([@%:@include <unistd.h>],
4967 [getpgrp(0);])],
4968 [AC_DEFINE([GETPGRP_HAVE_ARG], [1],
4969 [Define if getpgrp() must be called as getpgrp(0).])],
4970 [])])
4971AC_CHECK_FUNCS([setpgrp],
4972 [AC_COMPILE_IFELSE(
4973 [AC_LANG_PROGRAM([@%:@include <unistd.h>],
4974 [setpgrp(0,0);])],
4975 [AC_DEFINE([SETPGRP_HAVE_ARG], [1],
4976 [Define if setpgrp() must be called as setpgrp(0, 0).])],
4977 [])])
627b2d7c 4978
a371a7e0
NC
4979# check for namespace functions
4980AC_CHECK_FUNCS([setns unshare])
4981
2ea34cfb
EA
4982AC_CHECK_FUNCS([clock_gettime], [], [
4983 AC_CHECK_LIB([rt], [clock_gettime], [
7efb8339 4984 LIBS="$LIBS -lrt"
2ea34cfb
EA
4985 AC_DEFINE([HAVE_CLOCK_GETTIME], [1])
4986 AC_DEFINE([TIMEMODULE_LIB], [rt],
e0be4232
VS
4987 [Library needed by timemodule.c: librt may be needed for clock_gettime()])
4988 ])
4989])
4990
2ea34cfb
EA
4991AC_CHECK_FUNCS([clock_getres], [], [
4992 AC_CHECK_LIB([rt], [clock_getres], [
4993 AC_DEFINE([HAVE_CLOCK_GETRES], [1])
e0be4232
VS
4994 ])
4995])
4996
2ea34cfb
EA
4997AC_CHECK_FUNCS([clock_settime], [], [
4998 AC_CHECK_LIB([rt], [clock_settime], [
4999 AC_DEFINE([HAVE_CLOCK_SETTIME], [1])
37098cd5
BP
5000 ])
5001])
5002
2ea34cfb
EA
5003AC_CHECK_FUNCS([clock_nanosleep], [], [
5004 AC_CHECK_LIB([rt], [clock_nanosleep], [
5005 AC_DEFINE([HAVE_CLOCK_NANOSLEEP], [1])
85a47481
L
5006 ])
5007])
5008
2ea34cfb
EA
5009AC_CHECK_FUNCS([nanosleep], [], [
5010 AC_CHECK_LIB([rt], [nanosleep], [
5011 AC_DEFINE([HAVE_NANOSLEEP], [1])
7834ff26
VS
5012 ])
5013])
5014
57c50c9c 5015AC_CACHE_CHECK([for major, minor, and makedev], [ac_cv_device_macros], [
b159a556 5016AC_LINK_IFELSE([AC_LANG_PROGRAM([[
6eb37f0e
NN
5017#if defined(MAJOR_IN_MKDEV)
5018#include <sys/mkdev.h>
5019#elif defined(MAJOR_IN_SYSMACROS)
5020#include <sys/sysmacros.h>
5021#else
5022#include <sys/types.h>
5023#endif
b159a556 5024]], [[
dbe3f762 5025 makedev(major(0),minor(0));
57c50c9c
CH
5026]])],[ac_cv_device_macros=yes], [ac_cv_device_macros=no])
5027])
5028AS_VAR_IF([ac_cv_device_macros], [yes], [
2ea34cfb 5029 AC_DEFINE([HAVE_DEVICE_MACROS], [1],
dbe3f762 5030 [Define to 1 if you have the device macros.])
dbe3f762 5031])
bdf0d0f0 5032
57c50c9c 5033dnl no longer used, now always defined for backwards compatibility
2ea34cfb 5034AC_DEFINE([SYS_SELECT_WITH_SYS_TIME], [1],
57c50c9c
CH
5035 [Define if you can safely include both <sys/select.h> and <sys/time.h>
5036 (which you can't on SCO ODT 3.0).])
5037
861a65bc 5038# On OSF/1 V5.1, getaddrinfo is available, but a define
1b80b240 5039# for [no]getaddrinfo in netdb.h.
57c50c9c 5040AC_CACHE_CHECK([for getaddrinfo], [ac_cv_func_getaddrinfo], [
b159a556 5041AC_LINK_IFELSE([AC_LANG_PROGRAM([[
c010b6d9 5042#include <sys/types.h>
861a65bc
ML
5043#include <sys/socket.h>
5044#include <netdb.h>
c010b6d9 5045#include <stdio.h>
b159a556 5046]], [[getaddrinfo(NULL, NULL, NULL, NULL);]])],
57c50c9c
CH
5047[ac_cv_func_getaddrinfo=yes],
5048[ac_cv_func_getaddrinfo=no])
5049])
5050
5051AS_VAR_IF([ac_cv_func_getaddrinfo], [yes], [
76d14fac 5052 AC_CACHE_CHECK([getaddrinfo bug], [ac_cv_buggy_getaddrinfo],
b159a556 5053 AC_RUN_IFELSE([AC_LANG_SOURCE([[[
19c2139d 5054#include <stdio.h>
01dfdb3d
ML
5055#include <sys/types.h>
5056#include <netdb.h>
5057#include <string.h>
5058#include <sys/socket.h>
5059#include <netinet/in.h>
5060
e35ca417 5061int main(void)
01dfdb3d
ML
5062{
5063 int passive, gaierr, inet4 = 0, inet6 = 0;
5064 struct addrinfo hints, *ai, *aitop;
5065 char straddr[INET6_ADDRSTRLEN], strport[16];
5066
5067 for (passive = 0; passive <= 1; passive++) {
5068 memset(&hints, 0, sizeof(hints));
5069 hints.ai_family = AF_UNSPEC;
5070 hints.ai_flags = passive ? AI_PASSIVE : 0;
5071 hints.ai_socktype = SOCK_STREAM;
54f9439b 5072 hints.ai_protocol = IPPROTO_TCP;
01dfdb3d
ML
5073 if ((gaierr = getaddrinfo(NULL, "54321", &hints, &aitop)) != 0) {
5074 (void)gai_strerror(gaierr);
5075 goto bad;
5076 }
5077 for (ai = aitop; ai; ai = ai->ai_next) {
5078 if (ai->ai_addr == NULL ||
5079 ai->ai_addrlen == 0 ||
5080 getnameinfo(ai->ai_addr, ai->ai_addrlen,
5081 straddr, sizeof(straddr), strport, sizeof(strport),
5082 NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
5083 goto bad;
5084 }
5085 switch (ai->ai_family) {
5086 case AF_INET:
5087 if (strcmp(strport, "54321") != 0) {
5088 goto bad;
5089 }
5090 if (passive) {
5091 if (strcmp(straddr, "0.0.0.0") != 0) {
5092 goto bad;
5093 }
5094 } else {
5095 if (strcmp(straddr, "127.0.0.1") != 0) {
5096 goto bad;
5097 }
5098 }
5099 inet4++;
5100 break;
5101 case AF_INET6:
5102 if (strcmp(strport, "54321") != 0) {
5103 goto bad;
5104 }
5105 if (passive) {
5106 if (strcmp(straddr, "::") != 0) {
5107 goto bad;
5108 }
5109 } else {
5110 if (strcmp(straddr, "::1") != 0) {
5111 goto bad;
5112 }
5113 }
5114 inet6++;
5115 break;
5116 case AF_UNSPEC:
5117 goto bad;
5118 break;
5119 default:
5120 /* another family support? */
5121 break;
5122 }
5123 }
01c340da
BP
5124 freeaddrinfo(aitop);
5125 aitop = NULL;
01dfdb3d
ML
5126 }
5127
5128 if (!(inet4 == 0 || inet4 == 2))
5129 goto bad;
5130 if (!(inet6 == 0 || inet6 == 2))
5131 goto bad;
5132
5133 if (aitop)
5134 freeaddrinfo(aitop);
7b0c1c76 5135 return 0;
01dfdb3d
ML
5136
5137 bad:
5138 if (aitop)
5139 freeaddrinfo(aitop);
7b0c1c76 5140 return 1;
01dfdb3d 5141}
b159a556
MK
5142]]])],
5143[ac_cv_buggy_getaddrinfo=no],
5144[ac_cv_buggy_getaddrinfo=yes],
9635013a
MK
5145[
5146if test "${enable_ipv6+set}" = set; then
5147 ac_cv_buggy_getaddrinfo="no -- configured with --(en|dis)able-ipv6"
5148else
5149 ac_cv_buggy_getaddrinfo=yes
5150fi]))
57c50c9c
CH
5151
5152dnl if ac_cv_func_getaddrinfo
5153])
01dfdb3d 5154
57c50c9c 5155if test "$ac_cv_func_getaddrinfo" = no -o "$ac_cv_buggy_getaddrinfo" = yes
7b0c1c76 5156then
74b23c97
EEA
5157 AS_VAR_IF([ipv6], [yes], [
5158 AC_MSG_ERROR([m4_normalize([
5159 You must get working getaddrinfo() function
5160 or pass the "--disable-ipv6" option to configure.
5161 ])])
5162 ])
861a65bc 5163else
2ea34cfb
EA
5164 AC_DEFINE([HAVE_GETADDRINFO], [1],
5165 [Define if you have the getaddrinfo function.])
01dfdb3d 5166fi
d4694ed1 5167
2ea34cfb 5168AC_CHECK_FUNCS([getnameinfo])
01dfdb3d 5169
627b2d7c 5170# checks for structures
627b2d7c 5171AC_STRUCT_TM
76be6eda 5172AC_STRUCT_TIMEZONE
60a5d729
ML
5173AC_CHECK_MEMBERS([struct stat.st_rdev])
5174AC_CHECK_MEMBERS([struct stat.st_blksize])
5f937a7b 5175AC_CHECK_MEMBERS([struct stat.st_flags])
ebd9d5ba
ML
5176AC_CHECK_MEMBERS([struct stat.st_gen])
5177AC_CHECK_MEMBERS([struct stat.st_birthtime])
d887d1f3 5178AC_CHECK_MEMBERS([struct stat.st_blocks])
267b639a
SK
5179AC_CHECK_MEMBERS([struct passwd.pw_gecos, struct passwd.pw_passwd], [], [], [[
5180 #include <sys/types.h>
5181 #include <pwd.h>
5182]])
e999e961 5183# Issue #21085: In Cygwin, siginfo_t does not have si_band field.
27c68a6d 5184AC_CHECK_MEMBERS([siginfo_t.si_band], [], [], [[@%:@include <signal.h>]])
76be6eda 5185
76d14fac 5186AC_CACHE_CHECK([for time.h that defines altzone], [ac_cv_header_time_altzone], [
27c68a6d 5187 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <time.h>]], [[return altzone;]])],
b159a556
MK
5188 [ac_cv_header_time_altzone=yes],
5189 [ac_cv_header_time_altzone=no])
5190 ])
76be6eda 5191if test $ac_cv_header_time_altzone = yes; then
2ea34cfb
EA
5192 AC_DEFINE([HAVE_ALTZONE], [1],
5193 [Define this if your time.h defines altzone.])
76be6eda
GR
5194fi
5195
76d14fac 5196AC_CACHE_CHECK([for addrinfo], [ac_cv_struct_addrinfo],
27c68a6d 5197AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <netdb.h>]], [[struct addrinfo a]])],
b159a556
MK
5198 [ac_cv_struct_addrinfo=yes],
5199 [ac_cv_struct_addrinfo=no]))
01dfdb3d 5200if test $ac_cv_struct_addrinfo = yes; then
2ea34cfb 5201 AC_DEFINE([HAVE_ADDRINFO], [1], [struct addrinfo (netdb.h)])
01dfdb3d
ML
5202fi
5203
76d14fac 5204AC_CACHE_CHECK([for sockaddr_storage], [ac_cv_struct_sockaddr_storage],
b159a556 5205AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
01dfdb3d 5206# include <sys/types.h>
27c68a6d 5207@%:@ include <sys/socket.h>]], [[struct sockaddr_storage s]])],
b159a556
MK
5208 [ac_cv_struct_sockaddr_storage=yes],
5209 [ac_cv_struct_sockaddr_storage=no]))
01dfdb3d 5210if test $ac_cv_struct_sockaddr_storage = yes; then
2ea34cfb
EA
5211 AC_DEFINE([HAVE_SOCKADDR_STORAGE], [1],
5212 [struct sockaddr_storage (sys/socket.h)])
01dfdb3d
ML
5213fi
5214
76d14fac 5215AC_CACHE_CHECK([for sockaddr_alg], [ac_cv_struct_sockaddr_alg],
dffa3949
CH
5216AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
5217# include <sys/types.h>
5218# include <sys/socket.h>
27c68a6d 5219@%:@ include <linux/if_alg.h>]], [[struct sockaddr_alg s]])],
dffa3949
CH
5220 [ac_cv_struct_sockaddr_alg=yes],
5221 [ac_cv_struct_sockaddr_alg=no]))
dffa3949 5222if test $ac_cv_struct_sockaddr_alg = yes; then
2ea34cfb
EA
5223 AC_DEFINE([HAVE_SOCKADDR_ALG], [1],
5224 [struct sockaddr_alg (linux/if_alg.h)])
dffa3949
CH
5225fi
5226
627b2d7c 5227# checks for compiler characteristics
433c8ade 5228
76be6eda 5229AC_C_CONST
433c8ade 5230
57c50c9c 5231AC_CACHE_CHECK([for working signed char], [ac_cv_working_signed_char_c], [
b159a556 5232AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[signed char c;]])],
57c50c9c
CH
5233 [ac_cv_working_signed_char_c=yes], [ac_cv_working_signed_char_c=no])
5234])
5235AS_VAR_IF([ac_cv_working_signed_char_c], [no], [
2ea34cfb 5236 AC_DEFINE([signed], [], [Define to empty if the keyword does not work.])
57c50c9c 5237])
433c8ade 5238
57c50c9c 5239AC_CACHE_CHECK([for prototypes], [ac_cv_function_prototypes], [
b159a556 5240AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int foo(int x) { return 0; }]], [[return foo(10);]])],
57c50c9c
CH
5241 [ac_cv_function_prototypes=yes], [ac_cv_function_prototypes=no])
5242])
5243AS_VAR_IF([ac_cv_function_prototypes], [yes], [
2ea34cfb 5244 AC_DEFINE([HAVE_PROTOTYPES], [1],
1b80b240 5245 [Define if your compiler supports function prototype])
57c50c9c 5246])
433c8ade 5247
76be6eda 5248
331708b2 5249# check for socketpair
57c50c9c 5250PY_CHECK_FUNC([socketpair], [
331708b2
DC
5251#include <sys/types.h>
5252#include <sys/socket.h>
57c50c9c 5253])
331708b2 5254
01dfdb3d 5255# check if sockaddr has sa_len member
57c50c9c 5256AC_CACHE_CHECK([if sockaddr has sa_len member], [ac_cv_struct_sockaddr_sa_len], [
b159a556 5257AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
27c68a6d 5258@%:@include <sys/socket.h>]], [[struct sockaddr x;
b159a556 5259x.sa_len = 0;]])],
57c50c9c
CH
5260 [ac_cv_struct_sockaddr_sa_len=yes], [ac_cv_struct_sockaddr_sa_len=no])
5261])
5262AS_VAR_IF([ac_cv_struct_sockaddr_sa_len], [yes], [
2ea34cfb
EA
5263 AC_DEFINE([HAVE_SOCKADDR_SA_LEN], [1],
5264 [Define if sockaddr has sa_len member])
57c50c9c 5265])
01dfdb3d 5266
a96f0ba7 5267# sigh -- gethostbyname_r is a mess; it can have 3, 5 or 6 arguments :-(
2ea34cfb 5268AH_TEMPLATE([HAVE_GETHOSTBYNAME_R],
1143799d
ML
5269 [Define this if you have some version of gethostbyname_r()])
5270
2ea34cfb
EA
5271AC_CHECK_FUNC([gethostbyname_r],
5272 [AC_DEFINE([HAVE_GETHOSTBYNAME_R])
a96f0ba7
GR
5273 AC_MSG_CHECKING([gethostbyname_r with 6 args])
5274 OLD_CFLAGS=$CFLAGS
5275 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
b159a556 5276 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
a96f0ba7 5277# include <netdb.h>
b159a556 5278 ]], [[
a96f0ba7
GR
5279 char *name;
5280 struct hostent *he, *res;
5281 char buffer[2048];
5282 int buflen = 2048;
5283 int h_errnop;
5284
5285 (void) gethostbyname_r(name, he, buffer, buflen, &res, &h_errnop)
b159a556 5286 ]])],[
2ea34cfb
EA
5287 AC_DEFINE([HAVE_GETHOSTBYNAME_R])
5288 AC_DEFINE([HAVE_GETHOSTBYNAME_R_6_ARG], [1],
c45929ec 5289 [Define this if you have the 6-arg version of gethostbyname_r().])
2ea34cfb 5290 AC_MSG_RESULT([yes])
b159a556 5291 ],[
2ea34cfb 5292 AC_MSG_RESULT([no])
a96f0ba7 5293 AC_MSG_CHECKING([gethostbyname_r with 5 args])
b159a556 5294 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
a96f0ba7 5295# include <netdb.h>
b159a556 5296 ]], [[
a96f0ba7
GR
5297 char *name;
5298 struct hostent *he;
b159a556
MK
5299 char buffer[2048];
5300 int buflen = 2048;
5301 int h_errnop;
a96f0ba7 5302
b159a556
MK
5303 (void) gethostbyname_r(name, he, buffer, buflen, &h_errnop)
5304 ]])],
5305 [
2ea34cfb
EA
5306 AC_DEFINE([HAVE_GETHOSTBYNAME_R])
5307 AC_DEFINE([HAVE_GETHOSTBYNAME_R_5_ARG], [1],
b159a556 5308 [Define this if you have the 5-arg version of gethostbyname_r().])
2ea34cfb 5309 AC_MSG_RESULT([yes])
a96f0ba7 5310 ], [
2ea34cfb 5311 AC_MSG_RESULT([no])
b159a556
MK
5312 AC_MSG_CHECKING([gethostbyname_r with 3 args])
5313 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
5314# include <netdb.h>
5315 ]], [[
5316 char *name;
5317 struct hostent *he;
5318 struct hostent_data data;
5319
5320 (void) gethostbyname_r(name, he, &data);
5321 ]])],
5322 [
2ea34cfb
EA
5323 AC_DEFINE([HAVE_GETHOSTBYNAME_R])
5324 AC_DEFINE([HAVE_GETHOSTBYNAME_R_3_ARG], [1],
b159a556 5325 [Define this if you have the 3-arg version of gethostbyname_r().])
2ea34cfb 5326 AC_MSG_RESULT([yes])
b159a556 5327 ], [
2ea34cfb 5328 AC_MSG_RESULT([no])
b159a556 5329 ])
a96f0ba7
GR
5330 ])
5331 ])
5332 CFLAGS=$OLD_CFLAGS
5333], [
2ea34cfb 5334 AC_CHECK_FUNCS([gethostbyname])
a96f0ba7 5335])
2ea34cfb
EA
5336AC_SUBST([HAVE_GETHOSTBYNAME_R_6_ARG])
5337AC_SUBST([HAVE_GETHOSTBYNAME_R_5_ARG])
5338AC_SUBST([HAVE_GETHOSTBYNAME_R_3_ARG])
5339AC_SUBST([HAVE_GETHOSTBYNAME_R])
5340AC_SUBST([HAVE_GETHOSTBYNAME])
a96f0ba7 5341
627b2d7c
GR
5342# checks for system services
5343# (none yet)
5344
76be6eda 5345# Linux requires this for correct f.p. operations
2ea34cfb 5346AC_CHECK_FUNC([__fpu_control],
be28f5b2 5347 [],
2ea34cfb 5348 [AC_CHECK_LIB([ieee], [__fpu_control])
be28f5b2 5349])
627b2d7c 5350
433c8ade 5351# check for --with-libm=...
2ea34cfb 5352AC_SUBST([LIBM])
4b6b5798 5353case $ac_sys_system in
3dc0a514 5354Darwin) ;;
4b6b5798
GR
5355*) LIBM=-lm
5356esac
2ea34cfb
EA
5357AC_MSG_CHECKING([for --with-libm=STRING])
5358AC_ARG_WITH([libm],
5359 [AS_HELP_STRING([--with-libm=STRING], [override libm math library to STRING (default is system-dependent)])],
3e2c6326 5360[
93274220
GR
5361if test "$withval" = no
5362then LIBM=
2ea34cfb 5363 AC_MSG_RESULT([force LIBM empty])
93274220 5364elif test "$withval" != yes
433c8ade 5365then LIBM=$withval
2ea34cfb 5366 AC_MSG_RESULT([set LIBM="$withval"])
3e2c6326 5367else AC_MSG_ERROR([proper usage is --with-libm=STRING])
93274220 5368fi],
2ea34cfb 5369[AC_MSG_RESULT([default LIBM="$LIBM"])])
433c8ade
GR
5370
5371# check for --with-libc=...
2ea34cfb
EA
5372AC_SUBST([LIBC])
5373AC_MSG_CHECKING([for --with-libc=STRING])
5374AC_ARG_WITH([libc],
5375 [AS_HELP_STRING([--with-libc=STRING], [override libc C library to STRING (default is system-dependent)])],
3e2c6326 5376[
93274220
GR
5377if test "$withval" = no
5378then LIBC=
2ea34cfb 5379 AC_MSG_RESULT([force LIBC empty])
93274220 5380elif test "$withval" != yes
433c8ade 5381then LIBC=$withval
2ea34cfb 5382 AC_MSG_RESULT([set LIBC="$withval"])
3e2c6326 5383else AC_MSG_ERROR([proper usage is --with-libc=STRING])
93274220 5384fi],
2ea34cfb 5385[AC_MSG_RESULT([default LIBC="$LIBC"])])
433c8ade 5386
1919b7e7
SK
5387# **************************************
5388# * Check for gcc x64 inline assembler *
5389# **************************************
5390
57c50c9c
CH
5391
5392AC_CACHE_CHECK([for x64 gcc inline assembler], [ac_cv_gcc_asm_for_x64], [
5393AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
1919b7e7 5394 __asm__ __volatile__ ("movq %rcx, %rax");
57c50c9c
CH
5395]])],[ac_cv_gcc_asm_for_x64=yes],[ac_cv_gcc_asm_for_x64=no])
5396])
5397
5398AS_VAR_IF([ac_cv_gcc_asm_for_x64], [yes], [
2ea34cfb 5399 AC_DEFINE([HAVE_GCC_ASM_FOR_X64], [1],
1919b7e7 5400 [Define if we can use x64 gcc inline assembler])
57c50c9c 5401])
1919b7e7 5402
b08a53a9
MD
5403# **************************************************
5404# * Check for various properties of floating point *
5405# **************************************************
81ee3efe 5406
2a9c3805
RB
5407AX_C_FLOAT_WORDS_BIGENDIAN
5408if test "$ax_cv_c_float_words_bigendian" = "yes"
b08a53a9 5409then
2ea34cfb 5410 AC_DEFINE([DOUBLE_IS_BIG_ENDIAN_IEEE754], [1],
b08a53a9
MD
5411 [Define if C doubles are 64-bit IEEE 754 binary format, stored
5412 with the most significant byte first])
2a9c3805 5413elif test "$ax_cv_c_float_words_bigendian" = "no"
b08a53a9 5414then
2ea34cfb 5415 AC_DEFINE([DOUBLE_IS_LITTLE_ENDIAN_IEEE754], [1],
2a9c3805
RB
5416 [Define if C doubles are 64-bit IEEE 754 binary format, stored
5417 with the least significant byte first])
5418else
5419 # Some ARM platforms use a mixed-endian representation for doubles.
5420 # While Python doesn't currently have full support for these platforms
5421 # (see e.g., issue 1762561), we can at least make sure that float <-> string
5422 # conversions work.
5423 # FLOAT_WORDS_BIGENDIAN doesnt actually detect this case, but if it's not big
5424 # or little, then it must be this?
2ea34cfb 5425 AC_DEFINE([DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754], [1],
b08a53a9
MD
5426 [Define if C doubles are 64-bit IEEE 754 binary format, stored
5427 in ARM mixed-endian order (byte order 45670123)])
5428fi
5429
7abf8d40
MD
5430# The short float repr introduced in Python 3.1 requires the
5431# correctly-rounded string <-> double conversion functions from
5432# Python/dtoa.c, which in turn require that the FPU uses 53-bit
5433# rounding; this is a problem on x86, where the x87 FPU has a default
f4243f6d 5434# rounding precision of 64 bits. For gcc/x86, we can fix this by
7abf8d40 5435# using inline assembler to get and set the x87 FPU control word.
f4243f6d
MD
5436
5437# This inline assembler syntax may also work for suncc and icc,
5438# so we try it on all platforms.
5439
57c50c9c 5440AC_CACHE_CHECK([whether we can use gcc inline assembler to get and set x87 control word], [ac_cv_gcc_asm_for_x87], [
e31db2a8 5441AC_LINK_IFELSE( [AC_LANG_PROGRAM([[]], [[
f4243f6d
MD
5442 unsigned short cw;
5443 __asm__ __volatile__ ("fnstcw %0" : "=m" (cw));
5444 __asm__ __volatile__ ("fldcw %0" : : "m" (cw));
57c50c9c
CH
5445]])],[ac_cv_gcc_asm_for_x87=yes],[ac_cv_gcc_asm_for_x87=no])
5446])
5447AS_VAR_IF([ac_cv_gcc_asm_for_x87], [yes], [
2ea34cfb 5448 AC_DEFINE([HAVE_GCC_ASM_FOR_X87], [1],
f4243f6d 5449 [Define if we can use gcc inline assembler to get and set x87 control word])
57c50c9c 5450])
81ee3efe 5451
57c50c9c 5452AC_CACHE_CHECK([whether we can use gcc inline assembler to get and set mc68881 fpcr], [ac_cv_gcc_asm_for_mc68881], [
e31db2a8 5453AC_LINK_IFELSE( [AC_LANG_PROGRAM([[]], [[
8bdeb167
BP
5454 unsigned int fpcr;
5455 __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=g" (fpcr));
5456 __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "g" (fpcr));
57c50c9c
CH
5457]])],[ac_cv_gcc_asm_for_mc68881=yes],[ac_cv_gcc_asm_for_mc68881=no])
5458])
5459AS_VAR_IF([ac_cv_gcc_asm_for_mc68881], [yes], [
2ea34cfb 5460 AC_DEFINE([HAVE_GCC_ASM_FOR_MC68881], [1],
8bdeb167 5461 [Define if we can use gcc inline assembler to get and set mc68881 fpcr])
57c50c9c 5462])
8bdeb167 5463
3dc7c6a3
MD
5464# Detect whether system arithmetic is subject to x87-style double
5465# rounding issues. The result of this test has little meaning on non
5466# IEEE 754 platforms. On IEEE 754, test should return 1 if rounding
5467# mode is round-to-nearest and double rounding issues are present, and
af368a7d 5468# 0 otherwise. See https://github.com/python/cpython/issues/47186 for more info.
57c50c9c 5469AC_CACHE_CHECK([for x87-style double rounding], [ac_cv_x87_double_rounding], [
b08a53a9
MD
5470# $BASECFLAGS may affect the result
5471ac_save_cc="$CC"
5472CC="$CC $BASECFLAGS"
b159a556 5473AC_RUN_IFELSE([AC_LANG_SOURCE([[
3dc7c6a3
MD
5474#include <stdlib.h>
5475#include <math.h>
e35ca417 5476int main(void) {
3dc7c6a3
MD
5477 volatile double x, y, z;
5478 /* 1./(1-2**-53) -> 1+2**-52 (correct), 1.0 (double rounding) */
5479 x = 0.99999999999999989; /* 1-2**-53 */
5480 y = 1./x;
5481 if (y != 1.)
5482 exit(0);
5483 /* 1e16+2.99999 -> 1e16+2. (correct), 1e16+4. (double rounding) */
5484 x = 1e16;
5485 y = 2.99999;
5486 z = x + y;
5487 if (z != 1e16+4.)
5488 exit(0);
5489 /* both tests show evidence of double rounding */
5490 exit(1);
5491}
b159a556
MK
5492]])],
5493[ac_cv_x87_double_rounding=no],
5494[ac_cv_x87_double_rounding=yes],
5495[ac_cv_x87_double_rounding=no])
b08a53a9 5496CC="$ac_save_cc"
57c50c9c
CH
5497])
5498
5499AS_VAR_IF([ac_cv_x87_double_rounding], [yes], [
2ea34cfb 5500 AC_DEFINE([X87_DOUBLE_ROUNDING], [1],
3dc7c6a3 5501 [Define if arithmetic is subject to x87-style double rounding issue])
57c50c9c 5502])
3dc7c6a3 5503
b08a53a9
MD
5504# ************************************
5505# * Check for mathematical functions *
5506# ************************************
5507
5508LIBS_SAVE=$LIBS
5509LIBS="$LIBS $LIBM"
5510
fa26245a 5511AC_CHECK_FUNCS(
77e3f224 5512 [acosh asinh atanh erf erfc expm1 log1p log2],
fa26245a
CH
5513 [],
5514 [AC_MSG_ERROR([Python requires C99 compatible libm])]
5515)
5516LIBS=$LIBS_SAVE
7edecdd2 5517
aaf42222
EEA
5518dnl For multiprocessing module, check that sem_open
5519dnl actually works. For FreeBSD versions <= 7.2,
5520dnl the kernel module that provides POSIX semaphores
5521dnl isn't loaded by default, so an attempt to call
5522dnl sem_open results in a 'Signal 12' error.
76d14fac 5523AC_CACHE_CHECK([whether POSIX semaphores are enabled], [ac_cv_posix_semaphores_enabled],
aaf42222
EEA
5524 AC_RUN_IFELSE([
5525 AC_LANG_SOURCE([
5526 #include <unistd.h>
5527 #include <fcntl.h>
5528 #include <stdio.h>
5529 #include <semaphore.h>
5530 #include <sys/stat.h>
5531
5532 int main(void) {
5533 sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0);
5534 if (a == SEM_FAILED) {
5535 perror("sem_open");
5536 return 1;
5537 }
5538 sem_close(a);
5539 sem_unlink("/autoconf");
5540 return 0;
5541 }
5542 ])
5543 ],
5544 [ac_cv_posix_semaphores_enabled=yes],
5545 [ac_cv_posix_semaphores_enabled=no],
5546 [ac_cv_posix_semaphores_enabled=yes])
a614f042 5547)
aaf42222
EEA
5548AS_VAR_IF([ac_cv_posix_semaphores_enabled], [no], [
5549 AC_DEFINE(
5550 [POSIX_SEMAPHORES_NOT_ENABLED], [1],
5551 [Define if POSIX semaphores aren't enabled on your system]
5552 )
5553])
a614f042 5554
aaf42222 5555dnl Multiprocessing check for broken sem_getvalue
76d14fac 5556AC_CACHE_CHECK([for broken sem_getvalue], [ac_cv_broken_sem_getvalue],
aaf42222
EEA
5557 AC_RUN_IFELSE([
5558 AC_LANG_SOURCE([
5559 #include <unistd.h>
5560 #include <fcntl.h>
5561 #include <stdio.h>
5562 #include <semaphore.h>
5563 #include <sys/stat.h>
1068307f 5564
aaf42222
EEA
5565 int main(void){
5566 sem_t *a = sem_open("/autocftw", O_CREAT, S_IRUSR|S_IWUSR, 0);
5567 int count;
5568 int res;
5569 if(a==SEM_FAILED){
5570 perror("sem_open");
5571 return 1;
1068307f 5572
aaf42222
EEA
5573 }
5574 res = sem_getvalue(a, &count);
5575 sem_close(a);
5576 sem_unlink("/autocftw");
5577 return res==-1 ? 1 : 0;
5578 }
5579 ])
5580 ],
5581 [ac_cv_broken_sem_getvalue=no],
5582 [ac_cv_broken_sem_getvalue=yes],
5583 [ac_cv_broken_sem_getvalue=yes])
1068307f 5584)
aaf42222
EEA
5585AS_VAR_IF([ac_cv_broken_sem_getvalue], [yes], [
5586 AC_DEFINE(
5587 [HAVE_BROKEN_SEM_GETVALUE], [1],
5588 [define to 1 if your sem_getvalue is broken.]
5589 )
5590])
1068307f 5591
27c68a6d 5592AC_CHECK_DECLS([RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL, RTLD_LOCAL, RTLD_NODELETE, RTLD_NOLOAD, RTLD_DEEPBIND, RTLD_MEMBER], [], [], [[@%:@include <dlfcn.h>]])
c2f7d878 5593
bd792647
MD
5594# determine what size digit to use for Python's longs
5595AC_MSG_CHECKING([digit size for Python's longs])
2ea34cfb 5596AC_ARG_ENABLE([big-digits],
025cbe7a 5597AS_HELP_STRING([--enable-big-digits@<:@=15|30@:>@],[use big digits (30 or 15 bits) for Python longs (default is 30)]]),
bd792647
MD
5598[case $enable_big_digits in
5599yes)
5600 enable_big_digits=30 ;;
5601no)
5602 enable_big_digits=15 ;;
5603[15|30])
5604 ;;
5605*)
5606 AC_MSG_ERROR([bad value $enable_big_digits for --enable-big-digits; value should be 15 or 30]) ;;
5607esac
2ea34cfb
EA
5608AC_MSG_RESULT([$enable_big_digits])
5609AC_DEFINE_UNQUOTED([PYLONG_BITS_IN_DIGIT], [$enable_big_digits],
5610 [Define as the preferred size in bits of long digits])
bd792647 5611],
2ea34cfb 5612[AC_MSG_RESULT([no value specified])])
bd792647 5613
ef2255b1 5614# check for wchar.h
2ea34cfb
EA
5615AC_CHECK_HEADER([wchar.h], [
5616 AC_DEFINE([HAVE_WCHAR_H], [1],
1b80b240 5617 [Define if the compiler provides a wchar.h header file.])
c45929ec
ML
5618 wchar_h="yes"
5619],
ef2255b1
GR
5620wchar_h="no"
5621)
5622
0ba70cc3
ML
5623# determine wchar_t size
5624if test "$wchar_h" = yes
5625then
2ea34cfb
EA
5626 AC_CHECK_SIZEOF([wchar_t], [4], [m4_normalize([
5627 #include <wchar.h>
5628 ])])
0ba70cc3
ML
5629fi
5630
d7160f88
MAL
5631# check whether wchar_t is signed or not
5632if test "$wchar_h" = yes
5633then
5634 # check whether wchar_t is signed or not
76d14fac 5635 AC_CACHE_CHECK([whether wchar_t is signed], [ac_cv_wchar_t_signed], [
b159a556 5636 AC_RUN_IFELSE([AC_LANG_SOURCE([[
d7160f88
MAL
5637 #include <wchar.h>
5638 int main()
5639 {
49fd7fa4 5640 /* Success: exit code 0 */
674fa0a7 5641 return ((((wchar_t) -1) < ((wchar_t) 0)) ? 0 : 1);
d7160f88 5642 }
b159a556
MK
5643 ]])],
5644 [ac_cv_wchar_t_signed=yes],
5645 [ac_cv_wchar_t_signed=no],
5646 [ac_cv_wchar_t_signed=yes])])
d7160f88 5647fi
0ba70cc3 5648
2ea34cfb 5649AC_MSG_CHECKING([whether wchar_t is usable])
52d168a9 5650# wchar_t is only usable if it maps to an unsigned type
d63a3b8b 5651if test "$ac_cv_sizeof_wchar_t" -ge 2 \
52d168a9 5652 -a "$ac_cv_wchar_t_signed" = "no"
0ba70cc3 5653then
2ea34cfb 5654 AC_DEFINE([HAVE_USABLE_WCHAR_T], [1],
52d168a9
GB
5655 [Define if you have a useable wchar_t type defined in wchar.h; useable
5656 means wchar_t must be an unsigned type with at least 16 bits. (see
5657 Include/unicodeobject.h).])
2ea34cfb 5658 AC_MSG_RESULT([yes])
0ba70cc3 5659else
2ea34cfb 5660 AC_MSG_RESULT([no])
0ba70cc3 5661fi
ef2255b1 5662
9032cf5c
JK
5663case $ac_sys_system/$ac_sys_release in
5664SunOS/*)
5665 if test -f /etc/os-release; then
5666 OS_NAME=$(awk -F= '/^NAME=/ {print substr($2,2,length($2)-2)}' /etc/os-release)
5667 if test "x$OS_NAME" = "xOracle Solaris"; then
5668 # bpo-43667: In Oracle Solaris, the internal form of wchar_t in
5669 # non-Unicode locales is not Unicode and hence cannot be used directly.
5670 # https://docs.oracle.com/cd/E37838_01/html/E61053/gmwke.html
2ea34cfb 5671 AC_DEFINE([HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION], [1],
9032cf5c
JK
5672 [Define if the internal form of wchar_t in non-Unicode locales
5673 is not Unicode.])
5674 fi
5675 fi
5676 ;;
5677esac
5678
ef2255b1
GR
5679# check for endianness
5680AC_C_BIGENDIAN
5681
35f3a2cb
BW
5682# ABI version string for Python extension modules. This appears between the
5683# periods in shared library file names, e.g. foo.<SOABI>.so. It is calculated
5684# from the following attributes which affect the ABI of this Python build (in
5685# this order):
5686#
5687# * The Python implementation (always 'cpython-' for us)
5688# * The major and minor version numbers
773614e0 5689# * --disable-gil (adds a 't')
35f3a2cb 5690# * --with-pydebug (adds a 'd')
35f3a2cb
BW
5691#
5692# Thus for example, Python 3.2 built with wide unicode, pydebug, and pymalloc,
de7d8343
GB
5693# would get a shared library ABI version tag of 'cpython-32dmu' and shared
5694# libraries would be named 'foo.cpython-32dmu.so'.
6c44fde3
VS
5695#
5696# In Python 3.2 and older, --with-wide-unicode added a 'u' flag.
5697# In Python 3.7 and older, --with-pymalloc added a 'm' flag.
2ea34cfb
EA
5698AC_SUBST([SOABI])
5699AC_MSG_CHECKING([ABIFLAGS])
5700AC_MSG_RESULT([$ABIFLAGS])
5701AC_MSG_CHECKING([SOABI])
d3899c1a 5702SOABI='cpython-'`echo $VERSION | tr -d .`${ABIFLAGS}${PLATFORM_TRIPLET:+-$PLATFORM_TRIPLET}
2ea34cfb 5703AC_MSG_RESULT([$SOABI])
35f3a2cb 5704
13a00078
VS
5705# Release build, debug build (Py_DEBUG), and trace refs build (Py_TRACE_REFS)
5706# are ABI compatible
5707if test "$Py_DEBUG" = 'true'; then
5422e3cf 5708 # Similar to SOABI but remove "d" flag from ABIFLAGS
2ea34cfb 5709 AC_SUBST([ALT_SOABI])
5422e3cf 5710 ALT_SOABI='cpython-'`echo $VERSION | tr -d .``echo $ABIFLAGS | tr -d d`${PLATFORM_TRIPLET:+-$PLATFORM_TRIPLET}
2ea34cfb 5711 AC_DEFINE_UNQUOTED([ALT_SOABI], ["${ALT_SOABI}"],
5422e3cf
VS
5712 [Alternative SOABI used in debug build to load C extensions built in release mode])
5713fi
5714
2ea34cfb 5715AC_SUBST([EXT_SUFFIX])
a44ce6c9 5716EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX}
d5537d07 5717
2ea34cfb 5718AC_MSG_CHECKING([LDVERSION])
8cf4eae5 5719LDVERSION='$(VERSION)$(ABIFLAGS)'
2ea34cfb 5720AC_MSG_RESULT([$LDVERSION])
8cf4eae5 5721
c994c8fc 5722# On Android and Cygwin the shared libraries must be linked with libpython.
2ea34cfb 5723AC_SUBST([LIBPYTHON])
226484e4 5724if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then
254b309c 5725 LIBPYTHON="-lpython${VERSION}${ABIFLAGS}"
b1fc4178
B
5726else
5727 LIBPYTHON=''
254b309c 5728fi
5729
8510f430 5730
2ea34cfb 5731AC_SUBST([BINLIBDEST])
51ae31e5
VS
5732BINLIBDEST='$(LIBDIR)/python$(VERSION)'
5733
5734
5735# Check for --with-platlibdir
8510f430 5736# /usr/$LIDIRNAME/python$VERSION
2ea34cfb 5737AC_SUBST([PLATLIBDIR])
8510f430 5738PLATLIBDIR="lib"
2ea34cfb
EA
5739AC_MSG_CHECKING([for --with-platlibdir])
5740AC_ARG_WITH(
5741 [platlibdir],
5742 [AS_HELP_STRING(
5743 [--with-platlibdir=DIRNAME],
5744 [Python library directory name (default is "lib")]
5745 )],
8510f430
VS
5746[
5747# ignore 3 options:
5748# --with-platlibdir
5749# --with-platlibdir=
5750# --without-platlibdir
5751if test -n "$withval" -a "$withval" != yes -a "$withval" != no
5752then
2ea34cfb 5753 AC_MSG_RESULT([yes])
8510f430 5754 PLATLIBDIR="$withval"
51ae31e5 5755 BINLIBDEST='${exec_prefix}/${PLATLIBDIR}/python$(VERSION)'
8510f430 5756else
2ea34cfb 5757 AC_MSG_RESULT([no])
8510f430 5758fi],
2ea34cfb 5759[AC_MSG_RESULT([no])])
8510f430
VS
5760
5761
87421197 5762dnl define LIBPL after ABIFLAGS and LDVERSION is defined.
2ea34cfb 5763AC_SUBST([PY_ENABLE_SHARED])
5553231b 5764if test x$PLATFORM_TRIPLET = x; then
8510f430 5765 LIBPL='$(prefix)'"/${PLATLIBDIR}/python${VERSION}/config-${LDVERSION}"
5553231b 5766else
8510f430 5767 LIBPL='$(prefix)'"/${PLATLIBDIR}/python${VERSION}/config-${LDVERSION}-${PLATFORM_TRIPLET}"
5553231b 5768fi
2ea34cfb 5769AC_SUBST([LIBPL])
87421197 5770
75e59a97 5771# Check for --with-wheel-pkg-dir=PATH
2ea34cfb 5772AC_SUBST([WHEEL_PKG_DIR])
75e59a97 5773WHEEL_PKG_DIR=""
2ea34cfb
EA
5774AC_MSG_CHECKING([for --with-wheel-pkg-dir])
5775AC_ARG_WITH(
5776 [wheel-pkg-dir],
5777 [AS_HELP_STRING(
5778 [--with-wheel-pkg-dir=PATH],
5779 [Directory of wheel packages used by ensurepip (default: none)]
5780 )],
75e59a97
VS
5781[
5782if test -n "$withval"; then
2ea34cfb 5783 AC_MSG_RESULT([yes])
75e59a97
VS
5784 WHEEL_PKG_DIR="$withval"
5785else
2ea34cfb 5786 AC_MSG_RESULT([no])
75e59a97 5787fi],
2ea34cfb 5788[AC_MSG_RESULT([no])])
75e59a97 5789
9a5a5d1c
VM
5790# Check whether right shifting a negative integer extends the sign bit
5791# or fills with zeros (like the Cray J90, according to Tim Peters).
76d14fac 5792AC_CACHE_CHECK([whether right shift extends the sign bit], [ac_cv_rshift_extends_sign], [
b159a556 5793AC_RUN_IFELSE([AC_LANG_SOURCE([[
e35ca417 5794int main(void)
9a5a5d1c 5795{
674fa0a7 5796 return (((-1)>>3 == -1) ? 0 : 1);
9a5a5d1c 5797}
b159a556
MK
5798]])],
5799[ac_cv_rshift_extends_sign=yes],
5800[ac_cv_rshift_extends_sign=no],
5801[ac_cv_rshift_extends_sign=yes])])
a618028e
VM
5802if test "$ac_cv_rshift_extends_sign" = no
5803then
2ea34cfb 5804 AC_DEFINE([SIGNED_RIGHT_SHIFT_ZERO_FILLS], [1],
c45929ec
ML
5805 [Define if i>>j for signed int i does not extend the sign bit
5806 when i < 0])
a618028e
VM
5807fi
5808
cadfaeca 5809# check for getc_unlocked and related locking functions
76d14fac 5810AC_CACHE_CHECK([for getc_unlocked() and friends], [ac_cv_have_getc_unlocked], [
27c68a6d 5811AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <stdio.h>]], [[
cadfaeca
GR
5812 FILE *f = fopen("/dev/null", "r");
5813 flockfile(f);
5814 getc_unlocked(f);
5815 funlockfile(f);
b159a556 5816]])],[ac_cv_have_getc_unlocked=yes],[ac_cv_have_getc_unlocked=no])])
cadfaeca
GR
5817if test "$ac_cv_have_getc_unlocked" = yes
5818then
2ea34cfb 5819 AC_DEFINE([HAVE_GETC_UNLOCKED], [1],
c45929ec 5820 [Define this if you have flockfile(), getc_unlocked(), and funlockfile()])
cadfaeca 5821fi
9a5a5d1c 5822
e925241d
CH
5823dnl Check for libreadline and libedit
5824dnl - libreadline provides "readline/readline.h" header and "libreadline"
5825dnl shared library. pkg-config file is readline.pc
5826dnl - libedit provides "editline/readline.h" header and "libedit" shared
5827dnl library. pkg-config file ins libedit.pc
5828dnl - editline is not supported ("readline.h" and "libeditline" shared library)
5829dnl
5830dnl NOTE: In the past we checked if readline needs an additional termcap
5831dnl library (tinfo ncursesw ncurses termcap). We now assume that libreadline
5832dnl or readline.pc provide correct linker information.
e1f77695 5833
e925241d 5834AH_TEMPLATE([WITH_EDITLINE], [Define to build the readline module against libedit.])
501939c9 5835AH_TEMPLATE([WITH_APPLE_EDITLINE], [Define to build the readline module against Apple BSD editline.])
18820946 5836
e925241d
CH
5837AC_ARG_WITH(
5838 [readline],
5839 [AS_HELP_STRING([--with(out)-readline@<:@=editline|readline|no@:>@],
5840 [use libedit for backend or disable readline module])],
5841 [
5842 AS_CASE([$with_readline],
5843 [editline|edit], [with_readline=edit],
5844 [yes|readline], [with_readline=readline],
5845 [no], [],
5846 [AC_MSG_ERROR([proper usage is --with(out)-readline@<:@=editline|readline|no@:>@])]
5847 )
5848 ],
5849 [with_readline=readline]
5850)
5851
501939c9
DN
5852# gh-105323: Need to handle the macOS editline as an alias of readline.
5853AS_CASE([$ac_sys_system/$ac_sys_release],
5854 [Darwin/*], [AC_CHECK_TYPE([Function],
5855 [AC_DEFINE([WITH_APPLE_EDITLINE])],
5856 [],
5857 [@%:@include <readline/readline.h>])],
5858 []
5859)
5860
e925241d
CH
5861AS_VAR_IF([with_readline], [readline], [
5862 PKG_CHECK_MODULES([LIBREADLINE], [readline], [
e1f77695 5863 LIBREADLINE=readline
e925241d
CH
5864 READLINE_CFLAGS=$LIBREADLINE_CFLAGS
5865 READLINE_LIBS=$LIBREADLINE_LIBS
5866 ], [
944ff8c5 5867 WITH_SAVE_ENV([
9af7f87d 5868 CPPFLAGS="$CPPFLAGS $LIBREADLINE_CFLAGS"
944ff8c5
CH
5869 LDFLAGS="$LDFLAGS $LIBREADLINE_LIBS"
5870 AC_CHECK_HEADERS([readline/readline.h], [
e925241d
CH
5871 AC_CHECK_LIB([readline], [readline], [
5872 LIBREADLINE=readline
5873 READLINE_CFLAGS=${LIBREADLINE_CFLAGS-""}
5874 READLINE_LIBS=${LIBREADLINE_LIBS-"-lreadline"}
944ff8c5
CH
5875 ], [with_readline=no])
5876 ], [with_readline=no])
5877 ])
e925241d
CH
5878 ])
5879])
e1f77695 5880
e925241d
CH
5881AS_VAR_IF([with_readline], [edit], [
5882 PKG_CHECK_MODULES([LIBEDIT], [libedit], [
5883 AC_DEFINE([WITH_EDITLINE], [1])
5884 LIBREADLINE=edit
5885 READLINE_CFLAGS=$LIBEDIT_CFLAGS
5886 READLINE_LIBS=$LIBEDIT_LIBS
5887 ], [
944ff8c5 5888 WITH_SAVE_ENV([
9af7f87d 5889 CPPFLAGS="$CPPFLAGS $LIBEDIT_CFLAGS"
944ff8c5
CH
5890 LDFLAGS="$LDFLAGS $LIBEDIT_LIBS"
5891 AC_CHECK_HEADERS([editline/readline.h], [
e925241d
CH
5892 AC_CHECK_LIB([edit], [readline], [
5893 LIBREADLINE=edit
5894 AC_DEFINE([WITH_EDITLINE], [1])
5895 READLINE_CFLAGS=${LIBEDIT_CFLAGS-""}
5896 READLINE_LIBS=${LIBEDIT_LIBS-"-ledit"}
944ff8c5
CH
5897 ], [with_readline=no])
5898 ], [with_readline=no])
5899 ])
e925241d
CH
5900 ])
5901])
e1f77695 5902
29f86d6c
CH
5903dnl pyconfig.h defines _XOPEN_SOURCE=700
5904READLINE_CFLAGS=$(echo $READLINE_CFLAGS | sed 's/-D_XOPEN_SOURCE=600//g')
fe8e3d91 5905
e925241d
CH
5906AC_MSG_CHECKING([how to link readline])
5907AS_VAR_IF([with_readline], [no], [
5908 AC_MSG_RESULT([no])
5909], [
5910 AC_MSG_RESULT([$with_readline (CFLAGS: $READLINE_CFLAGS, LIBS: $READLINE_LIBS)])
5911
5912 WITH_SAVE_ENV([
9af7f87d 5913 CPPFLAGS="$CPPFLAGS $READLINE_CFLAGS"
e925241d
CH
5914 LIBS="$READLINE_LIBS $LIBS"
5915 LIBS_SAVE=$LIBS
5916
5917 m4_define([readline_includes], [
5918 #include <stdio.h> /* Must be first for Gnu Readline */
5919 #ifdef WITH_EDITLINE
5920 # include <editline/readline.h>
5921 #else
5922 # include <readline/readline.h>
5923 # include <readline/history.h>
5924 #endif
e1f77695 5925 ])
e925241d
CH
5926
5927 # check for readline 2.2
5928 AC_CHECK_DECL([rl_completion_append_character], [
5929 AC_DEFINE([HAVE_RL_COMPLETION_APPEND_CHARACTER], [1], [Define if you have readline 2.2])
5930 ], [], [readline_includes])
5931
5932 AC_CHECK_DECL([rl_completion_suppress_append], [
5933 AC_DEFINE([HAVE_RL_COMPLETION_SUPPRESS_APPEND], [1], [Define if you have rl_completion_suppress_append])
5934 ], [], [readline_includes])
5935
5936 # check for readline 4.0
5937 AC_CACHE_CHECK([for rl_pre_input_hook in -l$LIBREADLINE], [ac_cv_readline_rl_pre_input_hook], [
5938 AC_LINK_IFELSE(
5939 [AC_LANG_PROGRAM([readline_includes], [void *x = rl_pre_input_hook])],
5940 [ac_cv_readline_rl_pre_input_hook=yes], [ac_cv_readline_rl_pre_input_hook=no]
5941 )
5942 ])
5943 AS_VAR_IF([ac_cv_readline_rl_pre_input_hook], [yes], [
5944 AC_DEFINE([HAVE_RL_PRE_INPUT_HOOK], [1], [Define if you have readline 4.0])
e1f77695 5945 ])
faf5e4d4 5946
e925241d
CH
5947 # also in 4.0
5948 AC_CACHE_CHECK([for rl_completion_display_matches_hook in -l$LIBREADLINE], [ac_cv_readline_rl_completion_display_matches_hook], [
5949 AC_LINK_IFELSE(
5950 [AC_LANG_PROGRAM([readline_includes], [void *x = rl_completion_display_matches_hook])],
5951 [ac_cv_readline_rl_completion_display_matches_hook=yes], [ac_cv_readline_rl_completion_display_matches_hook=no]
5952 )
5953 ])
5954 AS_VAR_IF([ac_cv_readline_rl_completion_display_matches_hook], [yes], [
5955 AC_DEFINE([HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK], [1], [Define if you have readline 4.0])
e1f77695 5956 ])
30ea2f22 5957
e925241d
CH
5958 # also in 4.0, but not in editline
5959 AC_CACHE_CHECK([for rl_resize_terminal in -l$LIBREADLINE], [ac_cv_readline_rl_resize_terminal], [
5960 AC_LINK_IFELSE(
5961 [AC_LANG_PROGRAM([readline_includes], [void *x = rl_resize_terminal])],
5962 [ac_cv_readline_rl_resize_terminal=yes], [ac_cv_readline_rl_resize_terminal=no]
5963 )
5964 ])
5965 AS_VAR_IF([ac_cv_readline_rl_resize_terminal], [yes], [
5966 AC_DEFINE([HAVE_RL_RESIZE_TERMINAL], [1], [Define if you have readline 4.0])
5967 ])
d1e22ba7 5968
e925241d
CH
5969 # check for readline 4.2
5970 AC_CACHE_CHECK([for rl_completion_matches in -l$LIBREADLINE], [ac_cv_readline_rl_completion_matches], [
5971 AC_LINK_IFELSE(
5972 [AC_LANG_PROGRAM([readline_includes], [void *x = rl_completion_matches])],
5973 [ac_cv_readline_rl_completion_matches=yes], [ac_cv_readline_rl_completion_matches=no]
5974 )
5975 ])
5976 AS_VAR_IF([ac_cv_readline_rl_completion_matches], [yes], [
5977 AC_DEFINE([HAVE_RL_COMPLETION_MATCHES], [1], [Define if you have readline 4.2])
5978 ])
5979
5980 # also in readline 4.2
5981 AC_CHECK_DECL([rl_catch_signals], [
5982 AC_DEFINE([HAVE_RL_CATCH_SIGNAL], [1], [Define if you can turn off readline's signal handling.])
5983 ], [], [readline_includes])
5984
5985 AC_CACHE_CHECK([for append_history in -l$LIBREADLINE], [ac_cv_readline_append_history], [
5986 AC_LINK_IFELSE(
5987 [AC_LANG_PROGRAM([readline_includes], [void *x = append_history])],
5988 [ac_cv_readline_append_history=yes], [ac_cv_readline_append_history=no]
5989 )
5990 ])
5991 AS_VAR_IF([ac_cv_readline_append_history], [yes], [
5992 AC_DEFINE([HAVE_RL_APPEND_HISTORY], [1], [Define if readline supports append_history])
5993 ])
5994
5995 m4_undefine([readline_includes])
5996 ])dnl WITH_SAVE_ENV()
5997])
82bca63c 5998
76d14fac 5999AC_CACHE_CHECK([for broken nice()], [ac_cv_broken_nice], [
b159a556 6000AC_RUN_IFELSE([AC_LANG_SOURCE([[
90c6face 6001#include <stdlib.h>
6002#include <unistd.h>
e35ca417 6003int main(void)
e38b2f1f
TW
6004{
6005 int val1 = nice(1);
6006 if (val1 != -1 && val1 == nice(2))
6007 exit(0);
6008 exit(1);
6009}
b159a556
MK
6010]])],
6011[ac_cv_broken_nice=yes],
6012[ac_cv_broken_nice=no],
6013[ac_cv_broken_nice=no])])
e38b2f1f
TW
6014if test "$ac_cv_broken_nice" = yes
6015then
2ea34cfb 6016 AC_DEFINE([HAVE_BROKEN_NICE], [1],
c45929ec 6017 [Define if nice() returns success/failure instead of the new priority.])
e38b2f1f
TW
6018fi
6019
76d14fac 6020AC_CACHE_CHECK([for broken poll()], [ac_cv_broken_poll],
b159a556 6021AC_RUN_IFELSE([AC_LANG_SOURCE([[
e62c5c88 6022#include <poll.h>
674fa0a7 6023#include <unistd.h>
e62c5c88 6024
e35ca417 6025int main(void)
aee170aa 6026{
e62c5c88 6027 struct pollfd poll_struct = { 42, POLLIN|POLLPRI|POLLOUT, 0 };
aee170aa 6028 int poll_test;
e62c5c88 6029
aee170aa 6030 close (42);
e62c5c88 6031
aee170aa 6032 poll_test = poll(&poll_struct, 1, 0);
e62c5c88 6033 if (poll_test < 0)
aee170aa 6034 return 0;
e62c5c88 6035 else if (poll_test == 0 && poll_struct.revents != POLLNVAL)
aee170aa 6036 return 0;
e62c5c88 6037 else
aee170aa
AV
6038 return 1;
6039}
b159a556
MK
6040]])],
6041[ac_cv_broken_poll=yes],
6042[ac_cv_broken_poll=no],
6043[ac_cv_broken_poll=no]))
e62c5c88
NB
6044if test "$ac_cv_broken_poll" = yes
6045then
2ea34cfb 6046 AC_DEFINE([HAVE_BROKEN_POLL], [1],
e62c5c88
NB
6047 [Define if poll() sets errno on invalid file descriptors.])
6048fi
6049
43802425 6050# check tzset(3) exists and works like we expect it to
76d14fac 6051AC_CACHE_CHECK([for working tzset()], [ac_cv_working_tzset], [
b159a556 6052AC_RUN_IFELSE([AC_LANG_SOURCE([[
d11b62ed
GR
6053#include <stdlib.h>
6054#include <time.h>
1836781f 6055#include <string.h>
43802425
BC
6056
6057#if HAVE_TZNAME
6058extern char *tzname[];
6059#endif
6060
e35ca417 6061int main(void)
d11b62ed 6062{
1836781f
BC
6063 /* Note that we need to ensure that not only does tzset(3)
6064 do 'something' with localtime, but it works as documented
6065 in the library reference and as expected by the test suite.
43802425
BC
6066 This includes making sure that tzname is set properly if
6067 tm->tm_zone does not exist since it is the alternative way
6068 of getting timezone info.
1836781f 6069
1b80b240 6070 Red Hat 6.2 doesn't understand the southern hemisphere
43802425 6071 after New Year's Day.
1836781f
BC
6072 */
6073
43802425 6074 time_t groundhogday = 1044144000; /* GMT-based */
1836781f
BC
6075 time_t midyear = groundhogday + (365 * 24 * 3600 / 2);
6076
7f2588c0 6077 putenv("TZ=UTC+0");
d11b62ed 6078 tzset();
1836781f
BC
6079 if (localtime(&groundhogday)->tm_hour != 0)
6080 exit(1);
43802425
BC
6081#if HAVE_TZNAME
6082 /* For UTC, tzname[1] is sometimes "", sometimes " " */
1b80b240 6083 if (strcmp(tzname[0], "UTC") ||
43802425
BC
6084 (tzname[1][0] != 0 && tzname[1][0] != ' '))
6085 exit(1);
6086#endif
1836781f 6087
7f2588c0 6088 putenv("TZ=EST+5EDT,M4.1.0,M10.5.0");
d11b62ed 6089 tzset();
1836781f 6090 if (localtime(&groundhogday)->tm_hour != 19)
d11b62ed 6091 exit(1);
43802425
BC
6092#if HAVE_TZNAME
6093 if (strcmp(tzname[0], "EST") || strcmp(tzname[1], "EDT"))
6094 exit(1);
6095#endif
1836781f
BC
6096
6097 putenv("TZ=AEST-10AEDT-11,M10.5.0,M3.5.0");
6098 tzset();
6099 if (localtime(&groundhogday)->tm_hour != 11)
6100 exit(1);
43802425
BC
6101#if HAVE_TZNAME
6102 if (strcmp(tzname[0], "AEST") || strcmp(tzname[1], "AEDT"))
6103 exit(1);
6104#endif
6105
6106#if HAVE_STRUCT_TM_TM_ZONE
1836781f
BC
6107 if (strcmp(localtime(&groundhogday)->tm_zone, "AEDT"))
6108 exit(1);
6109 if (strcmp(localtime(&midyear)->tm_zone, "AEST"))
6110 exit(1);
43802425 6111#endif
1836781f 6112
d11b62ed
GR
6113 exit(0);
6114}
b159a556
MK
6115]])],
6116[ac_cv_working_tzset=yes],
6117[ac_cv_working_tzset=no],
6118[ac_cv_working_tzset=no])])
d11b62ed
GR
6119if test "$ac_cv_working_tzset" = yes
6120then
2ea34cfb 6121 AC_DEFINE([HAVE_WORKING_TZSET], [1],
d11b62ed
GR
6122 [Define if tzset() actually switches the local timezone in a meaningful way.])
6123fi
6124
94717ed1 6125# Look for subsecond timestamps in struct stat
76d14fac 6126AC_CACHE_CHECK([for tv_nsec in struct stat], [ac_cv_stat_tv_nsec],
27c68a6d 6127AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <sys/stat.h>]], [[
94717ed1
ML
6128struct stat st;
6129st.st_mtim.tv_nsec = 1;
b159a556
MK
6130]])],
6131[ac_cv_stat_tv_nsec=yes],
6132[ac_cv_stat_tv_nsec=no]))
94717ed1
ML
6133if test "$ac_cv_stat_tv_nsec" = yes
6134then
2ea34cfb 6135 AC_DEFINE([HAVE_STAT_TV_NSEC], [1],
94717ed1
ML
6136 [Define if you have struct stat.st_mtim.tv_nsec])
6137fi
6138
ebd9d5ba 6139# Look for BSD style subsecond timestamps in struct stat
76d14fac 6140AC_CACHE_CHECK([for tv_nsec2 in struct stat], [ac_cv_stat_tv_nsec2],
27c68a6d 6141AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <sys/stat.h>]], [[
ebd9d5ba
ML
6142struct stat st;
6143st.st_mtimespec.tv_nsec = 1;
b159a556
MK
6144]])],
6145[ac_cv_stat_tv_nsec2=yes],
6146[ac_cv_stat_tv_nsec2=no]))
ebd9d5ba
ML
6147if test "$ac_cv_stat_tv_nsec2" = yes
6148then
2ea34cfb 6149 AC_DEFINE([HAVE_STAT_TV_NSEC2], [1],
ebd9d5ba
ML
6150 [Define if you have struct stat.st_mtimensec])
6151fi
6152
e925241d
CH
6153dnl check for ncurses/ncursesw and panel/panelw
6154dnl NOTE: old curses is not detected.
6155dnl have_curses=[no, ncursesw, ncurses]
6156dnl have_panel=[no, panelw, panel]
6157have_curses=no
6158have_panel=no
6159
6160AH_TEMPLATE([HAVE_NCURSESW], [Define to 1 if you have the `ncursesw' library.])
6161AC_CHECK_HEADERS([curses.h ncurses.h])
6162
6163AS_VAR_IF([ac_cv_header_ncurses_h], [yes], [
6164 if test "$ac_sys_system" != "Darwin"; then
6165 dnl On macOS, there is no separate /usr/lib/libncursesw nor libpanelw.
6166 PKG_CHECK_MODULES([CURSES], [ncursesw], [
9c60b25a 6167 AC_DEFINE([HAVE_NCURSESW], [1])
e925241d
CH
6168 have_curses=ncursesw
6169 ], [
6170 WITH_SAVE_ENV([
6171 AC_CHECK_LIB([ncursesw], [initscr], [
6172 AC_DEFINE([HAVE_NCURSESW], [1])
6173 have_curses=ncursesw
6174 CURSES_CFLAGS=${CURSES_CFLAGS-""}
6175 CURSES_LIBS=${CURSES_LIBS-"-lncursesw"}
6176 ])
6177 ])
6178 ])
6179 fi
6180
6181 AS_VAR_IF([have_curses], [no], [
6182 PKG_CHECK_MODULES([CURSES], [ncurses], [
6183 have_curses=ncurses
6184 ], [
6185 WITH_SAVE_ENV([
6186 AC_CHECK_LIB([ncurses], [initscr], [
6187 have_curses=ncurses
6188 CURSES_CFLAGS=${CURSES_CFLAGS-""}
6189 CURSES_LIBS=${CURSES_LIBS-"-lncurses"}
6190 ])
6191 ])
6192 ])
6193 ])
6194
6195])dnl ac_cv_header_ncurses_h = yes
6196
6197dnl remove _XOPEN_SOURCE macro from curses cflags. pyconfig.h sets
6198dnl the macro to 700.
29f86d6c 6199CURSES_CFLAGS=$(echo $CURSES_CFLAGS | sed 's/-D_XOPEN_SOURCE=600//g')
e925241d
CH
6200
6201if test "$have_curses" = no -a "$ac_sys_system" = "Darwin"; then
6202 dnl On macOS, there is no separate /usr/lib/libncursesw nor libpanelw.
6203 dnl If we are here, we found a locally-supplied version of libncursesw.
6204 dnl There should also be a libpanelw.
6205 dnl _XOPEN_SOURCE defines are usually excluded for macOS, but we need
6206 dnl _XOPEN_SOURCE_EXTENDED here for ncurses wide char support.
6207
6208 AS_VAR_APPEND([CURSES_CFLAGS], [" -D_XOPEN_SOURCE_EXTENDED=1"])
6209 AC_DEFINE([HAVE_NCURSESW], [1])
6210fi
6211
6212dnl TODO: detect "curses" and special cases tinfo, terminfo, or termcap
6213
6214AC_MSG_CHECKING([curses module flags])
6215AS_VAR_IF([have_curses], [no], [
af368a7d 6216 AC_MSG_RESULT([no])
e925241d
CH
6217], [
6218 AC_MSG_RESULT([$have_curses (CFLAGS: $CURSES_CFLAGS, LIBS: $CURSES_LIBS)])
6219])
6220
6221dnl check for ncurses' panel/panelw library
6222AC_CHECK_HEADERS([panel.h])
6223
6224AS_VAR_IF([ac_cv_header_panel_h], [yes], [
6225
6226 if test "$ac_sys_system" != "Darwin"; then
6227 dnl On macOS, there is no separate /usr/lib/libncursesw nor libpanelw.
6228 AS_VAR_IF([have_curses], [ncursesw], [
6229 PKG_CHECK_MODULES([PANEL], [panelw], [
6230 have_panel=panelw
6231 ], [
6232 WITH_SAVE_ENV([
6233 AC_CHECK_LIB([panelw], [update_panels], [
6234 have_panel=panelw
6235 PANEL_CFLAGS=${PANEL_CFLAGS-""}
6236 PANEL_LIBS=${PANEL_LIBS-"-lpanelw"}
6237 ])
6238 ])
6239 ])
6240 ])
6241 fi
6242
6243 AS_VAR_IF([have_curses], [ncurses], [
6244 PKG_CHECK_MODULES([PANEL], [panel], [
6245 have_panel=panel
6246 ], [
6247 WITH_SAVE_ENV([
6248 AC_CHECK_LIB([panel], [update_panels], [
6249 have_panel=panel
6250 PANEL_CFLAGS=${PANEL_CFLAGS-""}
6251 PANEL_LIBS=${PANEL_LIBS-"-lpanel"}
6252 ])
6253 ])
6254 ])
6255 ])
6256
6257])dnl ac_cv_header_panel_h = yes
6258
29f86d6c
CH
6259dnl pyconfig.h defines _XOPEN_SOURCE=700
6260PANEL_CFLAGS=$(echo $PANEL_CFLAGS | sed 's/-D_XOPEN_SOURCE=600//g')
6261
e925241d
CH
6262AC_MSG_CHECKING([panel flags])
6263AS_VAR_IF([have_panel], [no], [
af368a7d 6264 AC_MSG_RESULT([no])
e925241d
CH
6265], [
6266 AC_MSG_RESULT([$have_panel (CFLAGS: $PANEL_CFLAGS, LIBS: $PANEL_LIBS)])
6267])
6268
1a4f561d 6269# first curses header check
9dc823d2 6270ac_save_cppflags="$CPPFLAGS"
e13c3201
XG
6271if test "$cross_compiling" = no; then
6272 CPPFLAGS="$CPPFLAGS -I/usr/include/ncursesw"
6273fi
1a4f561d 6274
1a4f561d 6275# On Solaris, term.h requires curses.h
2ea34cfb 6276AC_CHECK_HEADERS([term.h], [], [], [
1a4f561d 6277#ifdef HAVE_CURSES_H
6278#include <curses.h>
6279#endif
6280])
6281
eb9b1032 6282# On HP/UX 11.0, mvwdelch is a block with a return statement
76d14fac 6283AC_CACHE_CHECK([whether mvwdelch is an expression], [ac_cv_mvwdelch_is_expression],
27c68a6d 6284AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <curses.h>]], [[
eb9b1032
ML
6285 int rtn;
6286 rtn = mvwdelch(0,0,0);
b159a556
MK
6287]])],
6288[ac_cv_mvwdelch_is_expression=yes],
6289[ac_cv_mvwdelch_is_expression=no]))
eb9b1032
ML
6290
6291if test "$ac_cv_mvwdelch_is_expression" = yes
6292then
2ea34cfb 6293 AC_DEFINE([MVWDELCH_IS_EXPRESSION], [1],
c45929ec 6294 [Define if mvwdelch in curses.h is an expression.])
eb9b1032
ML
6295fi
6296
8bc7d635
MY
6297# Issue #25720: ncurses has introduced the NCURSES_OPAQUE symbol making opaque
6298# structs since version 5.7. If the macro is defined as zero before including
6299# [n]curses.h, ncurses will expose fields of the structs regardless of the
6300# configuration.
76d14fac 6301AC_CACHE_CHECK([whether WINDOW has _flags], [ac_cv_window_has_flags],
8bc7d635
MY
6302AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
6303 #define NCURSES_OPAQUE 0
6304 #include <curses.h>
6305]], [[
eb9b1032
ML
6306 WINDOW *w;
6307 w->_flags = 0;
b159a556
MK
6308]])],
6309[ac_cv_window_has_flags=yes],
6310[ac_cv_window_has_flags=no]))
eb9b1032
ML
6311
6312
6313if test "$ac_cv_window_has_flags" = yes
6314then
2ea34cfb 6315 AC_DEFINE([WINDOW_HAS_FLAGS], [1],
c45929ec 6316 [Define if WINDOW in curses.h offers a field _flags.])
eb9b1032
ML
6317fi
6318
57c50c9c
CH
6319dnl PY_CHECK_CURSES_FUNC(FUNCTION)
6320AC_DEFUN([PY_CHECK_CURSES_FUNC],
6321[ AS_VAR_PUSHDEF([py_var], [ac_cv_lib_curses_$1])
6322 AS_VAR_PUSHDEF([py_define], [HAVE_CURSES_]m4_toupper($1))
6323 AC_CACHE_CHECK(
6324 [for curses function $1],
6325 [py_var],
6326 [AC_COMPILE_IFELSE(
6327 [AC_LANG_PROGRAM(
27c68a6d 6328 [@%:@include <curses.h>], [
57c50c9c
CH
6329 #ifndef $1
6330 void *x=$1
6331 #endif
6332 ])],
6333 [AS_VAR_SET([py_var], [yes])],
6334 [AS_VAR_SET([py_var], [no])])]
6335 )
6336 AS_VAR_IF(
6337 [py_var],
6338 [yes],
6339 [AC_DEFINE([py_define], [1], [Define if you have the '$1' function.])])
6340 AS_VAR_POPDEF([py_var])
6341 AS_VAR_POPDEF([py_define])
6342])
baac01e6 6343
57c50c9c
CH
6344PY_CHECK_CURSES_FUNC([is_pad])
6345PY_CHECK_CURSES_FUNC([is_term_resized])
6346PY_CHECK_CURSES_FUNC([resize_term])
6347PY_CHECK_CURSES_FUNC([resizeterm])
6348PY_CHECK_CURSES_FUNC([immedok])
6349PY_CHECK_CURSES_FUNC([syncok])
6350PY_CHECK_CURSES_FUNC([wchgat])
6351PY_CHECK_CURSES_FUNC([filter])
6352PY_CHECK_CURSES_FUNC([has_key])
6353PY_CHECK_CURSES_FUNC([typeahead])
6354PY_CHECK_CURSES_FUNC([use_env])
9dc823d2 6355CPPFLAGS=$ac_save_cppflags
0e3f591a 6356
b457b9be 6357AC_MSG_NOTICE([checking for device files])
6358
6359dnl NOTE: Inform user how to proceed with files when cross compiling.
6360if test "x$cross_compiling" = xyes; then
6361 if test "${ac_cv_file__dev_ptmx+set}" != set; then
6362 AC_MSG_CHECKING([for /dev/ptmx])
6363 AC_MSG_RESULT([not set])
6364 AC_MSG_ERROR([set ac_cv_file__dev_ptmx to yes/no in your CONFIG_SITE file when cross compiling])
6365 fi
6366 if test "${ac_cv_file__dev_ptc+set}" != set; then
6367 AC_MSG_CHECKING([for /dev/ptc])
6368 AC_MSG_RESULT([not set])
6369 AC_MSG_ERROR([set ac_cv_file__dev_ptc to yes/no in your CONFIG_SITE file when cross compiling])
6370 fi
6371fi
89f507fe 6372
2ea34cfb 6373AC_CHECK_FILE([/dev/ptmx], [], [])
b457b9be 6374if test "x$ac_cv_file__dev_ptmx" = xyes; then
2ea34cfb 6375 AC_DEFINE([HAVE_DEV_PTMX], [1],
b457b9be 6376 [Define to 1 if you have the /dev/ptmx device file.])
89f507fe 6377fi
2ea34cfb 6378AC_CHECK_FILE([/dev/ptc], [], [])
b457b9be 6379if test "x$ac_cv_file__dev_ptc" = xyes; then
2ea34cfb 6380 AC_DEFINE([HAVE_DEV_PTC], [1],
b457b9be 6381 [Define to 1 if you have the /dev/ptc device file.])
89f507fe 6382fi
865400fd 6383
3c1928a5
RO
6384if test $ac_sys_system = Darwin
6385then
6386 LIBS="$LIBS -framework CoreFoundation"
6387fi
6ce4a9a9 6388
2ea34cfb
EA
6389AC_CHECK_TYPE(
6390 [socklen_t], [],
6391 [AC_DEFINE(
6392 [socklen_t], [int],
6393 [Define to `int' if <sys/socket.h> does not define.]
6394 )], [
01c04013
ML
6395#ifdef HAVE_SYS_TYPES_H
6396#include <sys/types.h>
6397#endif
95713eb9
GR
6398#ifdef HAVE_SYS_SOCKET_H
6399#include <sys/socket.h>
6400#endif
01c04013 6401])
55f0cf33 6402
76d14fac 6403AC_CACHE_CHECK([for broken mbstowcs], [ac_cv_broken_mbstowcs],
b159a556 6404AC_RUN_IFELSE([AC_LANG_SOURCE([[
e35ca417 6405#include <stddef.h>
19c2139d 6406#include <stdio.h>
e35ca417
SJ
6407#include <stdlib.h>
6408int main(void) {
fff95304
AP
6409 size_t len = -1;
6410 const char *str = "text";
6411 len = mbstowcs(NULL, str, 0);
6412 return (len != 4);
6413}
b159a556
MK
6414]])],
6415[ac_cv_broken_mbstowcs=no],
6416[ac_cv_broken_mbstowcs=yes],
6417[ac_cv_broken_mbstowcs=no]))
fff95304
AP
6418if test "$ac_cv_broken_mbstowcs" = yes
6419then
2ea34cfb 6420 AC_DEFINE([HAVE_BROKEN_MBSTOWCS], [1],
1b80b240 6421 [Define if mbstowcs(NULL, "text", 0) does not return the number of
fff95304
AP
6422 wide chars that would be converted.])
6423fi
6424
b52ec78b 6425# Check for --with-computed-gotos
2ea34cfb
EA
6426AC_MSG_CHECKING([for --with-computed-gotos])
6427AC_ARG_WITH(
6428 [computed-gotos],
6429 [AS_HELP_STRING(
6430 [--with-computed-gotos],
6431 [enable computed gotos in evaluation loop (enabled by default on supported compilers)]
6432 )],
b52ec78b 6433[
042b128f 6434if test "$withval" = yes
1b80b240 6435then
2ea34cfb 6436 AC_DEFINE([USE_COMPUTED_GOTOS], [1],
1b80b240 6437 [Define if you want to use computed gotos in ceval.c.])
2ea34cfb 6438 AC_MSG_RESULT([yes])
042b128f
AP
6439fi
6440if test "$withval" = no
1b80b240 6441then
2ea34cfb 6442 AC_DEFINE([USE_COMPUTED_GOTOS], [0],
1b80b240 6443 [Define if you want to use computed gotos in ceval.c.])
2ea34cfb 6444 AC_MSG_RESULT([no])
042b128f
AP
6445fi
6446],
2ea34cfb 6447[AC_MSG_RESULT([no value specified])])
b52ec78b 6448
76d14fac 6449AC_CACHE_CHECK([whether $CC supports computed gotos], [ac_cv_computed_gotos],
b17289e1
MK
6450AC_RUN_IFELSE([AC_LANG_SOURCE([[[
6451int main(int argc, char **argv)
6452{
6453 static void *targets[1] = { &&LABEL1 };
6454 goto LABEL2;
6455LABEL1:
6456 return 0;
6457LABEL2:
6458 goto *targets[0];
6459 return 1;
6460}
6461]]])],
6462[ac_cv_computed_gotos=yes],
6463[ac_cv_computed_gotos=no],
6464[if test "${with_computed_gotos+set}" = set; then
6465 ac_cv_computed_gotos="$with_computed_gotos -- configured --with(out)-computed-gotos"
6466 else
6467 ac_cv_computed_gotos=no
6468 fi]))
b17289e1 6469case "$ac_cv_computed_gotos" in yes*)
2ea34cfb 6470 AC_DEFINE([HAVE_COMPUTED_GOTOS], [1],
b17289e1
MK
6471 [Define if the C compiler supports computed gotos.])
6472esac
6473
e16cda9a 6474case $ac_sys_system in
1b80b240 6475AIX*)
2ea34cfb
EA
6476 AC_DEFINE([HAVE_BROKEN_PIPE_BUF], [1],
6477 [Define if the system reports an invalid PIPE_BUF value.]) ;;
e16cda9a 6478esac
b52ec78b 6479
6a792298 6480
2ea34cfb 6481AC_SUBST([THREADHEADERS])
06f15bbc
ML
6482
6483for h in `(cd $srcdir;echo Python/thread_*.h)`
6484do
6485 THREADHEADERS="$THREADHEADERS \$(srcdir)/$h"
6486done
6487
2ea34cfb 6488AC_SUBST([SRCDIRS])
4c95fb46
CH
6489SRCDIRS="\
6490 Modules \
6491 Modules/_blake2 \
6492 Modules/_ctypes \
6493 Modules/_decimal \
6494 Modules/_decimal/libmpdec \
1fcc0efd 6495 Modules/_hacl \
4c95fb46
CH
6496 Modules/_io \
6497 Modules/_multiprocessing \
4c95fb46 6498 Modules/_sqlite \
1578f06c 6499 Modules/_sre \
18ef240a 6500 Modules/_testcapi \
aa52888e 6501 Modules/_testinternalcapi \
4c95fb46
CH
6502 Modules/_xxtestfuzz \
6503 Modules/cjkcodecs \
6504 Modules/expat \
6505 Objects \
6506 Parser \
6507 Programs \
1cbaa505 6508 Python \
5be98e57 6509 Python/frozen_modules \
1cbaa505 6510 Python/deepfreeze"
2ea34cfb 6511AC_MSG_CHECKING([for build directories])
55f0cf33
NS
6512for dir in $SRCDIRS; do
6513 if test ! -d $dir; then
6514 mkdir $dir
884d3ba9 6515 fi
55f0cf33 6516done
2ea34cfb 6517AC_MSG_RESULT([done])
036144d2 6518
1919b7e7 6519# Availability of -O2:
57c50c9c 6520AC_CACHE_CHECK([for -O2], [ac_cv_compile_o2], [
1919b7e7
SK
6521saved_cflags="$CFLAGS"
6522CFLAGS="-O2"
57c50c9c 6523AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [ac_cv_compile_o2=yes], [ac_cv_compile_o2=no])
1919b7e7 6524CFLAGS="$saved_cflags"
57c50c9c 6525])
1919b7e7
SK
6526
6527# _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
6528# http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
2ea34cfb 6529AC_MSG_CHECKING([for glibc _FORTIFY_SOURCE/memmove bug])
1919b7e7
SK
6530saved_cflags="$CFLAGS"
6531CFLAGS="-O2 -D_FORTIFY_SOURCE=2"
57c50c9c 6532if test "$ac_cv_compile_o2" = no; then
1919b7e7
SK
6533 CFLAGS=""
6534fi
6535AC_RUN_IFELSE([AC_LANG_SOURCE([[
6536#include <stdio.h>
6537#include <stdlib.h>
6538#include <string.h>
6539void foo(void *p, void *q) { memmove(p, q, 19); }
e35ca417 6540int main(void) {
1919b7e7
SK
6541 char a[32] = "123456789000000000";
6542 foo(&a[9], a);
6543 if (strcmp(a, "123456789123456789000000000") != 0)
6544 return 1;
6545 foo(a, &a[9]);
6546 if (strcmp(a, "123456789000000000") != 0)
6547 return 1;
6548 return 0;
6549}
6550]])],
6551[have_glibc_memmove_bug=no],
6552[have_glibc_memmove_bug=yes],
6553[have_glibc_memmove_bug=undefined])
6554CFLAGS="$saved_cflags"
2ea34cfb 6555AC_MSG_RESULT([$have_glibc_memmove_bug])
1919b7e7 6556if test "$have_glibc_memmove_bug" = yes; then
2ea34cfb 6557 AC_DEFINE([HAVE_GLIBC_MEMMOVE_BUG], [1],
1919b7e7
SK
6558 [Define if glibc has incorrect _FORTIFY_SOURCE wrappers
6559 for memmove and bcopy.])
6560fi
6561
57c50c9c 6562if test "$ac_cv_gcc_asm_for_x87" = yes; then
1919b7e7
SK
6563 # Some versions of gcc miscompile inline asm:
6564 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
6565 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
6566 case $CC in
6567 *gcc*)
2ea34cfb 6568 AC_MSG_CHECKING([for gcc ipa-pure-const bug])
1919b7e7
SK
6569 saved_cflags="$CFLAGS"
6570 CFLAGS="-O2"
6571 AC_RUN_IFELSE([AC_LANG_SOURCE([[
6572 __attribute__((noinline)) int
6573 foo(int *p) {
6574 int r;
6575 asm ( "movl \$6, (%1)\n\t"
6576 "xorl %0, %0\n\t"
6577 : "=r" (r) : "r" (p) : "memory"
6578 );
6579 return r;
6580 }
e35ca417 6581 int main(void) {
1919b7e7
SK
6582 int p = 8;
6583 if ((foo(&p) ? : p) != 6)
6584 return 1;
6585 return 0;
6586 }
6587 ]])],
6588 [have_ipa_pure_const_bug=no],
6589 [have_ipa_pure_const_bug=yes],
6590 [have_ipa_pure_const_bug=undefined])
6591 CFLAGS="$saved_cflags"
2ea34cfb 6592 AC_MSG_RESULT([$have_ipa_pure_const_bug])
1919b7e7 6593 if test "$have_ipa_pure_const_bug" = yes; then
2ea34cfb 6594 AC_DEFINE([HAVE_IPA_PURE_CONST_BUG], [1],
1919b7e7
SK
6595 [Define if gcc has the ipa-pure-const bug.])
6596 fi
6597 ;;
6598 esac
6599fi
6600
4f5366e6 6601# Check for stdatomic.h
57c50c9c 6602AC_CACHE_CHECK([for stdatomic.h], [ac_cv_header_stdatomic_h], [
4f5366e6
VS
6603AC_LINK_IFELSE(
6604[
6605 AC_LANG_SOURCE([[
6606 #include <stdatomic.h>
028f7349
VS
6607 atomic_int int_var;
6608 atomic_uintptr_t uintptr_var;
e35ca417 6609 int main(void) {
028f7349
VS
6610 atomic_store_explicit(&int_var, 5, memory_order_relaxed);
6611 atomic_store_explicit(&uintptr_var, 0, memory_order_relaxed);
6612 int loaded_value = atomic_load_explicit(&int_var, memory_order_seq_cst);
4f5366e6
VS
6613 return 0;
6614 }
6615 ]])
57c50c9c
CH
6616],[ac_cv_header_stdatomic_h=yes],[ac_cv_header_stdatomic_h=no])
6617])
4f5366e6 6618
57c50c9c 6619AS_VAR_IF([ac_cv_header_stdatomic_h], [yes], [
2ea34cfb 6620 AC_DEFINE([HAVE_STD_ATOMIC], [1],
028f7349 6621 [Has stdatomic.h with atomic_int and atomic_uintptr_t])
57c50c9c 6622])
4f5366e6 6623
52a327c1 6624# Check for GCC >= 4.7 and clang __atomic builtin functions
57c50c9c 6625AC_CACHE_CHECK([for builtin __atomic_load_n and __atomic_store_n functions], [ac_cv_builtin_atomic], [
4f5366e6
VS
6626AC_LINK_IFELSE(
6627[
6628 AC_LANG_SOURCE([[
52a327c1 6629 int val;
e35ca417 6630 int main(void) {
52a327c1
VS
6631 __atomic_store_n(&val, 1, __ATOMIC_SEQ_CST);
6632 (void)__atomic_load_n(&val, __ATOMIC_SEQ_CST);
4f5366e6
VS
6633 return 0;
6634 }
6635 ]])
57c50c9c
CH
6636],[ac_cv_builtin_atomic=yes],[ac_cv_builtin_atomic=no])
6637])
4f5366e6 6638
57c50c9c 6639AS_VAR_IF([ac_cv_builtin_atomic], [yes], [
2ea34cfb
EA
6640 AC_DEFINE([HAVE_BUILTIN_ATOMIC], [1],
6641 [Has builtin __atomic_load_n() and __atomic_store_n() functions])
57c50c9c 6642])
4f5366e6 6643
322f5ba0 6644# ensurepip option
2ea34cfb
EA
6645AC_MSG_CHECKING([for ensurepip])
6646AC_ARG_WITH([ensurepip],
2de064e6
AS
6647 [AS_HELP_STRING([--with-ensurepip@<:@=install|upgrade|no@:>@],
6648 ["install" or "upgrade" using bundled pip (default is upgrade)])],
322f5ba0 6649 [],
9deb8346
CH
6650 [
6651 AS_CASE([$ac_sys_system],
309110f3 6652 [Emscripten], [with_ensurepip=no],
4aea656d 6653 [WASI], [with_ensurepip=no],
9deb8346
CH
6654 [with_ensurepip=upgrade]
6655 )
6656 ])
2ea34cfb 6657AS_CASE([$with_ensurepip],
322f5ba0
ND
6658 [yes|upgrade],[ENSUREPIP=upgrade],
6659 [install],[ENSUREPIP=install],
6660 [no],[ENSUREPIP=no],
6661 [AC_MSG_ERROR([--with-ensurepip=upgrade|install|no])])
2ea34cfb
EA
6662AC_MSG_RESULT([$ENSUREPIP])
6663AC_SUBST([ENSUREPIP])
322f5ba0 6664
35a97c0b 6665# check if the dirent structure of a d_type field and DT_UNKNOWN is defined
57c50c9c 6666AC_CACHE_CHECK([if the dirent structure of a d_type field], [ac_cv_dirent_d_type], [
35a97c0b
VS
6667AC_LINK_IFELSE(
6668[
6669 AC_LANG_SOURCE([[
6670 #include <dirent.h>
6671
e35ca417 6672 int main(void) {
35a97c0b
VS
6673 struct dirent entry;
6674 return entry.d_type == DT_UNKNOWN;
6675 }
6676 ]])
57c50c9c
CH
6677],[ac_cv_dirent_d_type=yes],[ac_cv_dirent_d_type=no])
6678])
35a97c0b 6679
57c50c9c 6680AS_VAR_IF([ac_cv_dirent_d_type], [yes], [
2ea34cfb 6681 AC_DEFINE([HAVE_DIRENT_D_TYPE], [1],
35a97c0b 6682 [Define to 1 if the dirent structure has a d_type field])
57c50c9c 6683])
35a97c0b 6684
9eb57c5f 6685# check if the Linux getrandom() syscall is available
57c50c9c 6686AC_CACHE_CHECK([for the Linux getrandom() syscall], [ac_cv_getrandom_syscall], [
9eb57c5f
VS
6687AC_LINK_IFELSE(
6688[
6689 AC_LANG_SOURCE([[
e35ca417 6690 #include <stddef.h>
1b80b240 6691 #include <unistd.h>
9eb57c5f 6692 #include <sys/syscall.h>
dddf4849 6693 #include <linux/random.h>
9eb57c5f 6694
e35ca417 6695 int main(void) {
9eb57c5f 6696 char buffer[1];
3abf44e4 6697 const size_t buflen = sizeof(buffer);
dddf4849
VS
6698 const int flags = GRND_NONBLOCK;
6699 /* ignore the result, Python checks for ENOSYS and EAGAIN at runtime */
3abf44e4 6700 (void)syscall(SYS_getrandom, buffer, buflen, flags);
9eb57c5f
VS
6701 return 0;
6702 }
6703 ]])
57c50c9c
CH
6704],[ac_cv_getrandom_syscall=yes],[ac_cv_getrandom_syscall=no])
6705])
9eb57c5f 6706
57c50c9c 6707AS_VAR_IF([ac_cv_getrandom_syscall], [yes], [
2ea34cfb 6708 AC_DEFINE([HAVE_GETRANDOM_SYSCALL], [1],
9eb57c5f 6709 [Define to 1 if the Linux getrandom() syscall is available])
57c50c9c 6710])
9eb57c5f 6711
3abf44e4
VS
6712# check if the getrandom() function is available
6713# the test was written for the Solaris function of <sys/random.h>
57c50c9c 6714AC_CACHE_CHECK([for the getrandom() function], [ac_cv_func_getrandom], [
3abf44e4
VS
6715AC_LINK_IFELSE(
6716[
6717 AC_LANG_SOURCE([[
e35ca417 6718 #include <stddef.h>
3abf44e4
VS
6719 #include <sys/random.h>
6720
e35ca417 6721 int main(void) {
3abf44e4
VS
6722 char buffer[1];
6723 const size_t buflen = sizeof(buffer);
6724 const int flags = 0;
6725 /* ignore the result, Python checks for ENOSYS at runtime */
6726 (void)getrandom(buffer, buflen, flags);
6727 return 0;
6728 }
6729 ]])
57c50c9c
CH
6730],[ac_cv_func_getrandom=yes],[ac_cv_func_getrandom=no])
6731])
3abf44e4 6732
57c50c9c 6733AS_VAR_IF([ac_cv_func_getrandom], [yes], [
2ea34cfb 6734 AC_DEFINE([HAVE_GETRANDOM], [1],
3abf44e4 6735 [Define to 1 if the getrandom() function is available])
57c50c9c 6736])
3abf44e4 6737
5741c45a
NS
6738# checks for POSIX shared memory, used by Modules/_multiprocessing/posixshmem.c
6739# shm_* may only be available if linking against librt
32452701
EEA
6740POSIXSHMEM_CFLAGS='-I$(srcdir)/Modules/_multiprocessing'
6741WITH_SAVE_ENV([
6742 AC_SEARCH_LIBS([shm_open], [rt])
6743 AS_VAR_IF([ac_cv_search_shm_open], [-lrt], [POSIXSHMEM_LIBS="-lrt"])
6744
6745 dnl Temporarily override ac_includes_default for AC_CHECK_FUNCS below.
6746 _SAVE_VAR([ac_includes_default])
6747 ac_includes_default="\
6748 ${ac_includes_default}
6749 #ifndef __cplusplus
6750 # ifdef HAVE_SYS_MMAN_H
6751 # include <sys/mman.h>
6752 # endif
6753 #endif
6754 "
6755 AC_CHECK_FUNCS([shm_open shm_unlink], [have_posix_shmem=yes], [have_posix_shmem=no])
6756 _RESTORE_VAR([ac_includes_default])
6757])
5741c45a 6758
ff5be6e8
CH
6759# Check for usable OpenSSL
6760AX_CHECK_OPENSSL([have_openssl=yes],[have_openssl=no])
6761
32eba61e 6762# rpath to libssl and libcrypto
b9e9292d
CH
6763AS_VAR_IF([GNULD], [yes], [
6764 rpath_arg="-Wl,--enable-new-dtags,-rpath="
6765], [
6766 rpath_arg="-Wl,-rpath="
6767])
6768
2ea34cfb
EA
6769AC_MSG_CHECKING([for --with-openssl-rpath])
6770AC_ARG_WITH([openssl-rpath],
32eba61e
CH
6771 AS_HELP_STRING([--with-openssl-rpath=@<:@DIR|auto|no@:>@],
6772 [Set runtime library directory (rpath) for OpenSSL libraries,
6773 no (default): don't set rpath,
6774 auto: auto-detect rpath from --with-openssl and pkg-config,
6775 DIR: set an explicit rpath
6776 ]),
6777 [],
6778 [with_openssl_rpath=no]
6779)
2ea34cfb 6780AS_CASE([$with_openssl_rpath],
b9e9292d
CH
6781 [auto|yes], [
6782 OPENSSL_RPATH=auto
6783 dnl look for linker directories
6784 for arg in "$OPENSSL_LDFLAGS"; do
6785 AS_CASE([$arg],
6786 [-L*], [OPENSSL_LDFLAGS_RPATH="$OPENSSL_LDFLAGS_RPATH ${rpath_arg}$(echo $arg | cut -c3-)"]
6787 )
6788 done
6789 ],
6790 [no], [OPENSSL_RPATH=],
32eba61e
CH
6791 [AS_IF(
6792 [test -d "$with_openssl_rpath"],
b9e9292d
CH
6793 [
6794 OPENSSL_RPATH="$with_openssl_rpath"
6795 OPENSSL_LDFLAGS_RPATH="${rpath_arg}$with_openssl_rpath"
6796 ],
32eba61e
CH
6797 AC_MSG_ERROR([--with-openssl-rpath "$with_openssl_rpath" is not a directory]))
6798 ]
6799)
2ea34cfb 6800AC_MSG_RESULT([$OPENSSL_RPATH])
32eba61e 6801
b9e9292d
CH
6802# This static linking is NOT OFFICIALLY SUPPORTED and not advertised.
6803# Requires static OpenSSL build with position-independent code. Some features
6804# like DSO engines or external OSSL providers don't work. Only tested with GCC
6805# and clang on X86_64.
6806AS_VAR_IF([PY_UNSUPPORTED_OPENSSL_BUILD], [static], [
6807 AC_MSG_CHECKING([for unsupported static openssl build])
6808 new_OPENSSL_LIBS=
6809 for arg in $OPENSSL_LIBS; do
6810 AS_CASE([$arg],
6811 [-l*], [
6812 libname=$(echo $arg | cut -c3-)
6813 new_OPENSSL_LIBS="$new_OPENSSL_LIBS -l:lib${libname}.a -Wl,--exclude-libs,lib${libname}.a"
6814 ],
6815 [new_OPENSSL_LIBS="$new_OPENSSL_LIBS $arg"]
6816 )
6817 done
6818 dnl include libz for OpenSSL build flavors with compression support
6819 OPENSSL_LIBS="$new_OPENSSL_LIBS $ZLIB_LIBS"
6820 AC_MSG_RESULT([$OPENSSL_LIBS])
6821])
6822
6823dnl AX_CHECK_OPENSSL does not export libcrypto-only libs
6824LIBCRYPTO_LIBS=
6825for arg in $OPENSSL_LIBS; do
6826 AS_CASE([$arg],
6827 [-l*ssl*|-Wl*ssl*], [],
6828 [LIBCRYPTO_LIBS="$LIBCRYPTO_LIBS $arg"]
6829 )
6830done
6831
81520fe6 6832# check if OpenSSL libraries work as expected
b9e9292d
CH
6833WITH_SAVE_ENV([
6834 LIBS="$LIBS $OPENSSL_LIBS"
6835 CFLAGS="$CFLAGS $OPENSSL_INCLUDES"
6836 LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH"
81520fe6 6837
b9e9292d
CH
6838 AC_CACHE_CHECK([whether OpenSSL provides required ssl module APIs], [ac_cv_working_openssl_ssl], [
6839 AC_LINK_IFELSE([AC_LANG_PROGRAM([
6840 #include <openssl/opensslv.h>
6841 #include <openssl/ssl.h>
6842 #if OPENSSL_VERSION_NUMBER < 0x10101000L
6843 #error "OpenSSL >= 1.1.1 is required"
6844 #endif
6845 static void keylog_cb(const SSL *ssl, const char *line) {}
6846 ], [
6847 SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
6848 SSL_CTX_set_keylog_callback(ctx, keylog_cb);
6849 SSL *ssl = SSL_new(ctx);
6850 X509_VERIFY_PARAM *param = SSL_get0_param(ssl);
6851 X509_VERIFY_PARAM_set1_host(param, "python.org", 0);
6852 SSL_free(ssl);
6853 SSL_CTX_free(ctx);
6854 ])], [ac_cv_working_openssl_ssl=yes], [ac_cv_working_openssl_ssl=no])
6855 ])
6856])
81520fe6 6857
b9e9292d
CH
6858WITH_SAVE_ENV([
6859 LIBS="$LIBS $LIBCRYPTO_LIBS"
6860 CFLAGS="$CFLAGS $OPENSSL_INCLUDES"
6861 LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH"
81520fe6 6862
b9e9292d
CH
6863 AC_CACHE_CHECK([whether OpenSSL provides required hashlib module APIs], [ac_cv_working_openssl_hashlib], [
6864 AC_LINK_IFELSE([AC_LANG_PROGRAM([
6865 #include <openssl/opensslv.h>
6866 #include <openssl/evp.h>
6867 #if OPENSSL_VERSION_NUMBER < 0x10101000L
6868 #error "OpenSSL >= 1.1.1 is required"
6869 #endif
6870 ], [
6871 OBJ_nid2sn(NID_md5);
6872 OBJ_nid2sn(NID_sha1);
6873 OBJ_nid2sn(NID_sha3_512);
6874 OBJ_nid2sn(NID_blake2b512);
6875 EVP_PBE_scrypt(NULL, 0, NULL, 0, 2, 8, 1, 0, NULL, 0);
6876 ])], [ac_cv_working_openssl_hashlib=yes], [ac_cv_working_openssl_hashlib=no])
6877 ])
57c50c9c 6878])
81520fe6 6879
892d66e4 6880# ssl module default cipher suite string
2ea34cfb 6881AH_TEMPLATE([PY_SSL_DEFAULT_CIPHERS],
892d66e4
CH
6882 [Default cipher suites list for ssl module.
6883 1: Python's preferred selection, 2: leave OpenSSL defaults untouched, 0: custom string])
2ea34cfb 6884AH_TEMPLATE([PY_SSL_DEFAULT_CIPHER_STRING],
892d66e4
CH
6885 [Cipher suite string for PY_SSL_DEFAULT_CIPHERS=0]
6886)
6887
2ea34cfb
EA
6888AC_MSG_CHECKING([for --with-ssl-default-suites])
6889AC_ARG_WITH(
6890 [ssl-default-suites],
6891 [AS_HELP_STRING(
6892 [--with-ssl-default-suites=@<:@python|openssl|STRING@:>@],
6893 [override default cipher suites string,
6894 python: use Python's preferred selection (default),
6895 openssl: leave OpenSSL's defaults untouched,
6896 STRING: use a custom string,
6897 python and STRING also set TLS 1.2 as minimum TLS version]
6898 )],
892d66e4 6899[
2ea34cfb 6900AC_MSG_RESULT([$withval])
892d66e4
CH
6901case "$withval" in
6902 python)
2ea34cfb 6903 AC_DEFINE([PY_SSL_DEFAULT_CIPHERS], [1])
892d66e4
CH
6904 ;;
6905 openssl)
2ea34cfb 6906 AC_DEFINE([PY_SSL_DEFAULT_CIPHERS], [2])
892d66e4
CH
6907 ;;
6908 *)
2ea34cfb
EA
6909 AC_DEFINE([PY_SSL_DEFAULT_CIPHERS], [0])
6910 AC_DEFINE_UNQUOTED([PY_SSL_DEFAULT_CIPHER_STRING], ["$withval"])
892d66e4
CH
6911 ;;
6912esac
6913],
6914[
2ea34cfb
EA
6915AC_MSG_RESULT([python])
6916AC_DEFINE([PY_SSL_DEFAULT_CIPHERS], [1])
892d66e4
CH
6917])
6918
9b60e55d 6919# builtin hash modules
0b13575e 6920default_hashlib_hashes="md5,sha1,sha2,sha3,blake2"
9b60e55d
CH
6921AC_DEFINE([PY_BUILTIN_HASHLIB_HASHES], [], [enabled builtin hash modules]
6922)
2ea34cfb
EA
6923AC_MSG_CHECKING([for --with-builtin-hashlib-hashes])
6924AC_ARG_WITH(
6925 [builtin-hashlib-hashes],
6926 [AS_HELP_STRING(
6927 [--with-builtin-hashlib-hashes=md5,sha1,sha2,sha3,blake2],
6928 [builtin hash modules, md5, sha1, sha2, sha3 (with shake), blake2]
6929 )],
9b60e55d 6930[
c8c21bdd
CH
6931 AS_CASE([$with_builtin_hashlib_hashes],
6932 [yes], [with_builtin_hashlib_hashes=$default_hashlib_hashes],
6933 [no], [with_builtin_hashlib_hashes=""]
6934 )
6935], [with_builtin_hashlib_hashes=$default_hashlib_hashes])
6936
2ea34cfb
EA
6937AC_MSG_RESULT([$with_builtin_hashlib_hashes])
6938AC_DEFINE_UNQUOTED([PY_BUILTIN_HASHLIB_HASHES],
6939 ["$with_builtin_hashlib_hashes"])
c8c21bdd
CH
6940
6941as_save_IFS=$IFS
6942IFS=,
6943for builtin_hash in $with_builtin_hashlib_hashes; do
2ea34cfb 6944 AS_CASE([$builtin_hash],
c8c21bdd
CH
6945 [md5], [with_builtin_md5=yes],
6946 [sha1], [with_builtin_sha1=yes],
0b13575e 6947 [sha2], [with_builtin_sha2=yes],
c8c21bdd
CH
6948 [sha3], [with_builtin_sha3=yes],
6949 [blake2], [with_builtin_blake2=yes]
6950 )
6951done
6952IFS=$as_save_IFS
9b60e55d 6953
b16b6bb8
CH
6954dnl libb2 for blake2. _blake2 module falls back to vendored copy.
6955AS_VAR_IF([with_builtin_blake2], [yes], [
6956 PKG_CHECK_MODULES([LIBB2], [libb2], [
6957 have_libb2=yes
6958 AC_DEFINE([HAVE_LIBB2], [1],
6959 [Define to 1 if you want to build _blake2 module with libb2])
6960 ], [have_libb2=no])
6961])
6962
277ce306 6963# Check whether to disable test modules. Once set, setup.py will not build
6964# test extension modules and "make install" will not install test suites.
7acedd71
CH
6965AC_MSG_CHECKING([for --disable-test-modules])
6966AC_ARG_ENABLE([test-modules],
6967 [AS_HELP_STRING([--disable-test-modules], [don't build nor install test modules])], [
6968 AS_VAR_IF([enable_test_modules], [yes], [TEST_MODULES=yes], [TEST_MODULES=no])
6969], [
6970 AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
6971 [Emscripten/browser*], [TEST_MODULES=no],
6972 [TEST_MODULES=yes]
6973 )
6974])
6975AC_MSG_RESULT([$TEST_MODULES])
6976AC_SUBST([TEST_MODULES])
277ce306 6977
1f7e4213
VS
6978# gh-109054: Check if -latomic is needed to get <pyatomic.h> atomic functions.
6979# On Linux aarch64, GCC may require programs and libraries to be linked
6980# explicitly to libatomic. Call _Py_atomic_or_uint64() which may require
6981# libatomic __atomic_fetch_or_8(), or not, depending on the C compiler and the
6982# compiler flags.
6983#
6984# Avoid #include <Python.h> or #include <pyport.h>. The <Python.h> header
6985# requires <pyconfig.h> header which is only written below by AC_OUTPUT below.
0c89056f 6986# If the check is done after AC_OUTPUT, modifying LIBS has no effect
1f7e4213
VS
6987# anymore. <pyport.h> cannot be included alone, it's designed to be included
6988# by <Python.h>: it expects other includes and macros to be defined.
6989_SAVE_VAR([CPPFLAGS])
6990CPPFLAGS="${BASECPPFLAGS} -I. -I${srcdir}/Include ${CPPFLAGS}"
6991
6992AC_CACHE_CHECK([whether libatomic is needed by <pyatomic.h>],
6993 [ac_cv_libatomic_needed],
6994[AC_RUN_IFELSE([AC_LANG_SOURCE([[
6995// pyatomic.h needs uint64_t and Py_ssize_t types
6996#include <stdint.h> // int64_t, intptr_t
6997#ifdef HAVE_SYS_TYPES_H
6998# include <sys/types.h> // ssize_t
6999#endif
7000// Code adapted from Include/pyport.h
7001#if HAVE_SSIZE_T
7002typedef ssize_t Py_ssize_t;
7003#elif SIZEOF_VOID_P == SIZEOF_SIZE_T
7004typedef intptr_t Py_ssize_t;
7005#else
7006# error "unable to define Py_ssize_t"
7007#endif
7008
0c89056f 7009#include "pyatomic.h"
1f7e4213
VS
7010
7011int main()
7012{
7013 uint64_t byte;
7014 _Py_atomic_store_uint64(&byte, 2);
7015 if (_Py_atomic_or_uint64(&byte, 8) != 2) {
7016 return 1; // error
7017 }
7018 if (_Py_atomic_load_uint64(&byte) != 10) {
7019 return 1; // error
7020 }
7021 return 0; // all good
7022}
71b6e260
VS
7023]])],
7024 [ac_cv_libatomic_needed=no], dnl build succeeded
7025 [ac_cv_libatomic_needed=yes], dnl build failed
7026 [ac_cv_libatomic_needed=no]) dnl cross compilation
1f7e4213
VS
7027])
7028
7029AS_VAR_IF([ac_cv_libatomic_needed], [yes],
0c89056f 7030 [LIBS="${LIBS} -latomic"])
1f7e4213
VS
7031_RESTORE_VAR([CPPFLAGS])
7032
7033
7034# stdlib
ca9689f8
CH
7035AC_DEFUN([PY_STDLIB_MOD_SET_NA], [
7036 m4_foreach([mod], [$@], [
7037 AS_VAR_SET([py_cv_module_]mod, [n/a])])
7038])
7039
7040# stdlib not available
25ecc040 7041dnl Modules that are not available on some platforms
9b5ca540 7042AS_CASE([$ac_sys_system],
684e99d0 7043 [AIX], [PY_STDLIB_MOD_SET_NA([_scproxy])],
e4127eaa 7044 [VxWorks*], [PY_STDLIB_MOD_SET_NA([_scproxy], [termios], [grp])],
dbcdbf18
VS
7045 dnl The _scproxy module is available on macOS
7046 [Darwin], [],
17e1fe0f
VS
7047 [CYGWIN*], [PY_STDLIB_MOD_SET_NA([_scproxy])],
7048 [QNX*], [PY_STDLIB_MOD_SET_NA([_scproxy])],
684e99d0 7049 [FreeBSD*], [PY_STDLIB_MOD_SET_NA([_scproxy])],
9b5ca540
CH
7050 [Emscripten|WASI], [
7051 dnl subprocess and multiprocessing are not supported (no fork syscall).
7052 dnl curses and tkinter user interface are not available.
7053 dnl dbm and gdbm aren't available, too.
7054 dnl Emscripten and WASI provide only stubs for pwd, grp APIs.
a36235d5 7055 dnl resource functions (get/setrusage) are stubs, too.
ca9689f8 7056 PY_STDLIB_MOD_SET_NA(
ca9689f8
CH
7057 [_curses],
7058 [_curses_panel],
7059 [_dbm],
7060 [_gdbm],
082d3495
CH
7061 [_multiprocessing],
7062 [_posixshmem],
7063 [_posixsubprocess],
ca9689f8
CH
7064 [_scproxy],
7065 [_tkinter],
7066 [_xxsubinterpreters],
c67b0053 7067 [_xxinterpchannels],
ca9689f8 7068 [grp],
ca9689f8 7069 [pwd],
a36235d5 7070 [resource],
ca9689f8
CH
7071 [syslog],
7072 )
9b5ca540
CH
7073 AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
7074 [Emscripten/browser*], [
7075 dnl These modules are not particularly useful in browsers.
7076 PY_STDLIB_MOD_SET_NA(
7077 [fcntl],
9b5ca540
CH
7078 [readline],
7079 [termios],
7080 )
7081 ],
7082 [Emscripten/node*], [],
d81d57e9 7083 [WASI/*], [
069c96f8 7084 dnl WASI SDK 15.0 does not support file locking, mmap, and more.
d81d57e9
CH
7085 PY_STDLIB_MOD_SET_NA(
7086 [_ctypes_test],
069c96f8
CH
7087 [fcntl],
7088 [mmap],
069c96f8 7089 [termios],
d81d57e9
CH
7090 )
7091 ]
4aea656d
CH
7092 )
7093 ],
ca9689f8 7094 [PY_STDLIB_MOD_SET_NA([_scproxy])]
25ecc040
CH
7095)
7096
ca9689f8
CH
7097dnl AC_MSG_NOTICE([m4_set_list([_PY_STDLIB_MOD_SET_NA])])
7098
ee1e2c60
CH
7099dnl Default value for Modules/Setup.stdlib build type
7100AS_CASE([$host_cpu],
7101 [wasm32|wasm64], [MODULE_BUILDTYPE=static],
7102 [MODULE_BUILDTYPE=${MODULE_BUILDTYPE:-shared}]
7103)
7104AC_SUBST([MODULE_BUILDTYPE])
7105
25ecc040
CH
7106dnl _MODULE_BLOCK_ADD([VAR], [VALUE])
7107dnl internal: adds $1=quote($2) to MODULE_BLOCK
7108AC_DEFUN([_MODULE_BLOCK_ADD], [AS_VAR_APPEND([MODULE_BLOCK], ["$1=_AS_QUOTE([$2])$as_nl"])])
7109MODULE_BLOCK=
7110
7111dnl Check for stdlib extension modules
7112dnl PY_STDLIB_MOD([NAME], [ENABLED-TEST], [SUPPORTED-TEST], [CFLAGS], [LDFLAGS])
71868a00 7113dnl sets MODULE_$NAME_STATE based on PY_STDLIB_MOD_SET_NA(), ENABLED-TEST,
25ecc040
CH
7114dnl and SUPPORTED_TEST. ENABLED-TEST and SUPPORTED-TEST default to true if
7115dnl empty.
ca9689f8 7116dnl n/a: marked unavailable on platform by PY_STDLIB_MOD_SET_NA()
25ecc040
CH
7117dnl yes: enabled and supported
7118dnl missing: enabled and not supported
7119dnl disabled: not enabled
7120dnl sets MODULE_$NAME_CFLAGS and MODULE_$NAME_LDFLAGS
7121AC_DEFUN([PY_STDLIB_MOD], [
7122 AC_MSG_CHECKING([for stdlib extension module $1])
7123 m4_pushdef([modcond], [MODULE_]m4_toupper([$1]))dnl
7124 m4_pushdef([modstate], [py_cv_module_$1])dnl
ca9689f8
CH
7125 dnl Check if module has been disabled by PY_STDLIB_MOD_SET_NA()
7126 AS_IF([test "$modstate" != "n/a"], [
2ea34cfb 7127 AS_IF([m4_ifblank([$2], [true], [$2])],
ca9689f8
CH
7128 [AS_IF([m4_ifblank([$3], [true], [$3])], [modstate=yes], [modstate=missing])],
7129 [modstate=disabled])
7130 ])
71868a00 7131 _MODULE_BLOCK_ADD(modcond[_STATE], [$modstate])
25ecc040 7132 AS_VAR_IF([modstate], [yes], [
f36c69a2
CH
7133 m4_ifblank([$4], [], [_MODULE_BLOCK_ADD([MODULE_]m4_toupper([$1])[_CFLAGS], [$4])])
7134 m4_ifblank([$5], [], [_MODULE_BLOCK_ADD([MODULE_]m4_toupper([$1])[_LDFLAGS], [$5])])
25ecc040 7135 ])
f36c69a2 7136 AM_CONDITIONAL(modcond, [test "$modstate" = yes])
25ecc040
CH
7137 AC_MSG_RESULT([$modstate])
7138 m4_popdef([modcond])dnl
7139 m4_popdef([modstate])dnl
7140])
7141
b394af13 7142dnl Define simple stdlib extension module
ca9689f8 7143dnl Always enable unless the module is disabled by PY_STDLIB_MOD_SET_NA
7e44dc0b
CH
7144dnl PY_STDLIB_MOD_SIMPLE([NAME], [CFLAGS], [LDFLAGS])
7145dnl cflags and ldflags are optional
7146AC_DEFUN([PY_STDLIB_MOD_SIMPLE], [
7147 m4_pushdef([modcond], [MODULE_]m4_toupper([$1]))dnl
b394af13 7148 m4_pushdef([modstate], [py_cv_module_$1])dnl
ca9689f8
CH
7149 dnl Check if module has been disabled by PY_STDLIB_MOD_SET_NA()
7150 AS_IF([test "$modstate" != "n/a"], [modstate=yes])
b394af13 7151 AM_CONDITIONAL(modcond, [test "$modstate" = yes])
71868a00 7152 _MODULE_BLOCK_ADD(modcond[_STATE], [$modstate])
b394af13
CH
7153 AS_VAR_IF([modstate], [yes], [
7154 m4_ifblank([$2], [], [_MODULE_BLOCK_ADD([MODULE_]m4_toupper([$1])[_CFLAGS], [$2])])
7155 m4_ifblank([$3], [], [_MODULE_BLOCK_ADD([MODULE_]m4_toupper([$1])[_LDFLAGS], [$3])])
7156 ])
7e44dc0b 7157 m4_popdef([modcond])dnl
b394af13 7158 m4_popdef([modstate])dnl
7e44dc0b
CH
7159])
7160
7161dnl static modules in Modules/Setup.bootstrap
7162PY_STDLIB_MOD_SIMPLE([_io], [-I\$(srcdir)/Modules/_io], [])
7163PY_STDLIB_MOD_SIMPLE([time], [], [$TIMEMODULE_LIB])
7164
7165dnl always enabled extension modules
133c65a8 7166PY_STDLIB_MOD_SIMPLE([array])
39f7d2ff 7167PY_STDLIB_MOD_SIMPLE([_asyncio])
718cee08 7168PY_STDLIB_MOD_SIMPLE([_bisect])
133c65a8 7169PY_STDLIB_MOD_SIMPLE([_contextvars])
eee683cb 7170PY_STDLIB_MOD_SIMPLE([_csv])
718cee08
EEA
7171PY_STDLIB_MOD_SIMPLE([_heapq])
7172PY_STDLIB_MOD_SIMPLE([_json])
39f7d2ff
EEA
7173PY_STDLIB_MOD_SIMPLE([_lsprof])
7174PY_STDLIB_MOD_SIMPLE([_opcode])
718cee08 7175PY_STDLIB_MOD_SIMPLE([_pickle])
eee683cb 7176PY_STDLIB_MOD_SIMPLE([_posixsubprocess])
39f7d2ff 7177PY_STDLIB_MOD_SIMPLE([_queue])
718cee08 7178PY_STDLIB_MOD_SIMPLE([_random])
b451673f 7179PY_STDLIB_MOD_SIMPLE([select])
0e1c2f3e 7180PY_STDLIB_MOD_SIMPLE([_struct])
39f7d2ff 7181PY_STDLIB_MOD_SIMPLE([_typing])
b451673f 7182PY_STDLIB_MOD_SIMPLE([_xxsubinterpreters])
c67b0053 7183PY_STDLIB_MOD_SIMPLE([_xxinterpchannels])
718cee08 7184PY_STDLIB_MOD_SIMPLE([_zoneinfo])
7e44dc0b 7185
aaf42222 7186dnl multiprocessing modules
b394af13
CH
7187PY_STDLIB_MOD([_multiprocessing],
7188 [], [test "$ac_cv_func_sem_unlink" = "yes"],
7189 [-I\$(srcdir)/Modules/_multiprocessing])
aaf42222
EEA
7190PY_STDLIB_MOD([_posixshmem],
7191 [], [test "$have_posix_shmem" = "yes"],
7192 [$POSIXSHMEM_CFLAGS], [$POSIXSHMEM_LIBS])
7193
39f7d2ff
EEA
7194dnl needs libm
7195PY_STDLIB_MOD_SIMPLE([_statistics], [], [$LIBM])
7196PY_STDLIB_MOD_SIMPLE([cmath], [], [$LIBM])
7197PY_STDLIB_MOD_SIMPLE([math], [], [$LIBM])
7198
7199dnl needs libm and on some platforms librt
7200PY_STDLIB_MOD_SIMPLE([_datetime], [], [$TIMEMODULE_LIB $LIBM])
7201
b451673f 7202dnl modules with some unix dependencies
5b946cad
EEA
7203PY_STDLIB_MOD([fcntl],
7204 [], [test "$ac_cv_header_sys_ioctl_h" = "yes" -a "$ac_cv_header_fcntl_h" = "yes"],
7205 [], [$FCNTL_LIBS])
b451673f
EEA
7206PY_STDLIB_MOD([mmap],
7207 [], [test "$ac_cv_header_sys_mman_h" = "yes" -a "$ac_cv_header_sys_stat_h" = "yes"])
f7a62f24
EEA
7208PY_STDLIB_MOD([_socket],
7209 [], m4_flatten([test "$ac_cv_header_sys_socket_h" = "yes"
7210 -a "$ac_cv_header_sys_types_h" = "yes"
7211 -a "$ac_cv_header_netinet_in_h" = "yes"]))
5b946cad 7212
5275e59c 7213dnl platform specific extensions
f201d261 7214PY_STDLIB_MOD([grp], [], [test "$ac_cv_func_getgrgid" = yes -o "$ac_cv_func_getgrgid_r" = yes])
ca9689f8 7215PY_STDLIB_MOD([pwd], [], [test "$ac_cv_func_getpwuid" = yes -o "$ac_cv_func_getpwuid_r" = yes])
f201d261 7216PY_STDLIB_MOD([resource], [], [test "$ac_cv_header_sys_resource_h" = yes])
5596909e
CH
7217PY_STDLIB_MOD([_scproxy],
7218 [test "$ac_sys_system" = "Darwin"], [],
7219 [], [-framework SystemConfiguration -framework CoreFoundation])
f201d261
CH
7220PY_STDLIB_MOD([syslog], [], [test "$ac_cv_header_syslog_h" = yes])
7221PY_STDLIB_MOD([termios], [], [test "$ac_cv_header_termios_h" = yes])
5275e59c 7222
25ecc040 7223dnl _elementtree loads libexpat via CAPI hook in pyexpat
9ab587b7
EA
7224PY_STDLIB_MOD([pyexpat],
7225 [], [test "$ac_cv_header_sys_time_h" = "yes"],
7226 [$LIBEXPAT_CFLAGS], [$LIBEXPAT_LDFLAGS])
25ecc040 7227PY_STDLIB_MOD([_elementtree], [], [], [$LIBEXPAT_CFLAGS], [])
2afa1a12
CH
7228PY_STDLIB_MOD_SIMPLE([_codecs_cn])
7229PY_STDLIB_MOD_SIMPLE([_codecs_hk])
7230PY_STDLIB_MOD_SIMPLE([_codecs_iso2022])
7231PY_STDLIB_MOD_SIMPLE([_codecs_jp])
7232PY_STDLIB_MOD_SIMPLE([_codecs_kr])
7233PY_STDLIB_MOD_SIMPLE([_codecs_tw])
7234PY_STDLIB_MOD_SIMPLE([_multibytecodec])
7235PY_STDLIB_MOD_SIMPLE([unicodedata])
25ecc040 7236
c8c21bdd
CH
7237dnl By default we always compile these even when OpenSSL is available
7238dnl (issue #14693). The modules are small.
fcadc7e4
JP
7239PY_STDLIB_MOD([_md5],
7240 [test "$with_builtin_md5" = yes], [],
7241 [-I\$(srcdir)/Modules/_hacl/include -I\$(srcdir)/Modules/_hacl/internal -D_BSD_SOURCE -D_DEFAULT_SOURCE])
7242PY_STDLIB_MOD([_sha1],
7243 [test "$with_builtin_sha1" = yes], [],
7244 [-I\$(srcdir)/Modules/_hacl/include -I\$(srcdir)/Modules/_hacl/internal -D_BSD_SOURCE -D_DEFAULT_SOURCE])
0b13575e
GS
7245PY_STDLIB_MOD([_sha2],
7246 [test "$with_builtin_sha2" = yes], [],
e5da9ab2 7247 [-I\$(srcdir)/Modules/_hacl/include -I\$(srcdir)/Modules/_hacl/internal -D_BSD_SOURCE -D_DEFAULT_SOURCE])
c8c21bdd 7248PY_STDLIB_MOD([_sha3], [test "$with_builtin_sha3" = yes])
b16b6bb8
CH
7249PY_STDLIB_MOD([_blake2],
7250 [test "$with_builtin_blake2" = yes], [],
7251 [$LIBB2_CFLAGS], [$LIBB2_LIBS])
c8c21bdd 7252
bb8b9313
CH
7253PY_STDLIB_MOD([_ctypes],
7254 [], [test "$have_libffi" = yes],
eff9f439 7255 [$NO_STRICT_OVERFLOW_CFLAGS $LIBFFI_CFLAGS], [$LIBFFI_LIBS])
e925241d
CH
7256PY_STDLIB_MOD([_curses],
7257 [], [test "$have_curses" != "no"],
7258 [$CURSES_CFLAGS], [$CURSES_LIBS]
7259)
7260PY_STDLIB_MOD([_curses_panel],
7261 [], [test "$have_panel" != "no"],
7262 [$PANEL_CFLAGS $CURSES_CFLAGS], [$PANEL_LIBS $CURSES_LIBS]
7263)
25ecc040 7264PY_STDLIB_MOD([_decimal], [], [], [$LIBMPDEC_CFLAGS], [$LIBMPDEC_LDFLAGS])
ec5e2535
CH
7265PY_STDLIB_MOD([_dbm],
7266 [test -n "$with_dbmliborder"], [test "$have_dbm" != "no"],
7267 [$DBM_CFLAGS], [$DBM_LIBS])
9cf5646b
CH
7268PY_STDLIB_MOD([_gdbm],
7269 [test "$have_gdbm_dbmliborder" = yes], [test "$have_gdbm" = yes],
7270 [$GDBM_CFLAGS], [$GDBM_LIBS])
e925241d
CH
7271 PY_STDLIB_MOD([readline],
7272 [], [test "$with_readline" != "no"],
7273 [$READLINE_CFLAGS], [$READLINE_LIBS])
29e5874d
EEA
7274PY_STDLIB_MOD([_sqlite3],
7275 [test "$have_sqlite3" = "yes"],
7276 [test "$have_supported_sqlite3" = "yes"],
7277 [$LIBSQLITE3_CFLAGS], [$LIBSQLITE3_LIBS])
269e7267
EEA
7278PY_STDLIB_MOD([_tkinter],
7279 [], [test "$have_tcltk" = "yes"],
7280 [$TCLTK_CFLAGS], [$TCLTK_LIBS])
8af6481f
CH
7281PY_STDLIB_MOD([_uuid],
7282 [], [test "$have_uuid" = "yes"],
7283 [$LIBUUID_CFLAGS], [$LIBUUID_LIBS])
25ecc040 7284
d9cedabe
CH
7285dnl compression libs
7286PY_STDLIB_MOD([zlib], [], [test "$have_zlib" = yes],
7287 [$ZLIB_CFLAGS], [$ZLIB_LIBS])
7288dnl binascii can use zlib for optimized crc32.
7289PY_STDLIB_MOD_SIMPLE([binascii], [$BINASCII_CFLAGS], [$BINASCII_LIBS])
7290PY_STDLIB_MOD([_bz2], [], [test "$have_bzip2" = yes],
7291 [$BZIP2_CFLAGS], [$BZIP2_LIBS])
7292PY_STDLIB_MOD([_lzma], [], [test "$have_liblzma" = yes],
7293 [$LIBLZMA_CFLAGS], [$LIBLZMA_LIBS])
7294
b9e9292d
CH
7295dnl OpenSSL bindings
7296PY_STDLIB_MOD([_ssl], [], [test "$ac_cv_working_openssl_ssl" = yes],
7297 [$OPENSSL_INCLUDES], [$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $OPENSSL_LIBS])
7298PY_STDLIB_MOD([_hashlib], [], [test "$ac_cv_working_openssl_hashlib" = yes],
7299 [$OPENSSL_INCLUDES], [$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $LIBCRYPTO_LIBS])
7300
f36c69a2 7301dnl test modules
0c89056f 7302PY_STDLIB_MOD([_testcapi], [test "$TEST_MODULES" = yes])
c450c8c9 7303PY_STDLIB_MOD([_testclinic], [test "$TEST_MODULES" = yes])
13a00078 7304PY_STDLIB_MOD([_testclinic_limited], [test "$TEST_MODULES" = yes])
f36c69a2
CH
7305PY_STDLIB_MOD([_testinternalcapi], [test "$TEST_MODULES" = yes])
7306PY_STDLIB_MOD([_testbuffer], [test "$TEST_MODULES" = yes])
d5fd438b
CH
7307PY_STDLIB_MOD([_testimportmultiple], [test "$TEST_MODULES" = yes], [test "$ac_cv_func_dlopen" = yes])
7308PY_STDLIB_MOD([_testmultiphase], [test "$TEST_MODULES" = yes], [test "$ac_cv_func_dlopen" = yes])
81dca70d 7309PY_STDLIB_MOD([xxsubtype], [test "$TEST_MODULES" = yes])
f36c69a2 7310PY_STDLIB_MOD([_xxtestfuzz], [test "$TEST_MODULES" = yes])
bb8b9313
CH
7311PY_STDLIB_MOD([_ctypes_test],
7312 [test "$TEST_MODULES" = yes], [test "$have_libffi" = yes -a "$ac_cv_func_dlopen" = yes],
7313 [], [$LIBM])
f36c69a2 7314
2dc7d3dd 7315dnl Limited API template modules.
43839ba4 7316dnl Emscripten does not support shared libraries yet.
13a00078
VS
7317PY_STDLIB_MOD([xxlimited], [], [test "$ac_cv_func_dlopen" = yes])
7318PY_STDLIB_MOD([xxlimited_35], [], [test "$ac_cv_func_dlopen" = yes])
2dc7d3dd 7319
25ecc040
CH
7320# substitute multiline block, must come after last PY_STDLIB_MOD()
7321AC_SUBST([MODULE_BLOCK])
892d66e4 7322
627b2d7c 7323# generate output files
2ea34cfb
EA
7324AC_CONFIG_FILES(m4_normalize([
7325 Makefile.pre
7326 Misc/python.pc
7327 Misc/python-embed.pc
7328 Misc/python-config.sh
7329]))
7330AC_CONFIG_FILES(m4_normalize([
7331 Modules/Setup.bootstrap
7332 Modules/Setup.stdlib
7333]))
8e6b407d 7334AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])
1f7e4213 7335# Generate files like pyconfig.h
88afe666 7336AC_OUTPUT
55f0cf33 7337
74b23c97 7338AC_MSG_NOTICE([creating Modules/Setup.local])
61c51156
NS
7339if test ! -f Modules/Setup.local
7340then
7341 echo "# Edit this file for local setup changes" >Modules/Setup.local
7342fi
7343
74b23c97 7344AC_MSG_NOTICE([creating Makefile])
61c51156 7345$SHELL $srcdir/Modules/makesetup -c $srcdir/Modules/config.c.in \
a6a4dc81 7346 -s Modules \
81dca70d
CH
7347 Modules/Setup.local Modules/Setup.stdlib Modules/Setup.bootstrap $srcdir/Modules/Setup
7348if test $? -ne 0; then
7349 AC_MSG_ERROR([makesetup failed])
7350fi
7351
66252167 7352mv config.c Modules
63d98bcd 7353
be3cd5c0 7354if test -z "$PKG_CONFIG"; then
74b23c97 7355 AC_MSG_WARN([pkg-config is missing. Some dependencies may not be detected correctly.])
be3cd5c0
CH
7356fi
7357
63d98bcd 7358if test "$Py_OPT" = 'false' -a "$Py_DEBUG" != 'true'; then
74b23c97
EEA
7359 AC_MSG_NOTICE([
7360
7361If you want a release build with all stable optimizations active (PGO, etc),
7362please run ./configure --enable-optimizations
7363])
63d98bcd 7364fi
3124d9a5
CH
7365
7366AS_VAR_IF([PY_SUPPORT_TIER], [0], [AC_MSG_WARN([
7367
7368Platform "$host" with compiler "$ac_cv_cc_name" is not supported by the
7369CPython core team, see https://peps.python.org/pep-0011/ for more information.
7370])])