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