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