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