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