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