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