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