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