1#! /bin/bash -norc
2dnl	This file is an input file used by the GNU "autoconf" program to
3dnl	generate the file "configure", which is run during Tcl installation
4dnl	to configure the system for the local environment.
5#
6# RCS: @(#) $Id: configure.in,v 1.180.2.18 2010/09/06 12:57:34 stwo Exp $
7
8AC_INIT([tcl],[8.5])
9AC_PREREQ(2.59)
10
11dnl This is only used when included from macosx/configure.ac
12m4_ifdef([SC_USE_CONFIG_HEADERS], [
13    AC_CONFIG_HEADERS([tclConfig.h:../unix/tclConfig.h.in])
14    AC_CONFIG_COMMANDS_PRE([DEFS="-DHAVE_TCL_CONFIG_H  -imacros tclConfig.h"])
15    AH_TOP([
16    #ifndef _TCLCONFIG
17    #define _TCLCONFIG])
18    AH_BOTTOM([
19    /* Undef unused package specific autoheader defines so that we can
20     * include both tclConfig.h and tkConfig.h at the same time: */
21    /* override */ #undef PACKAGE_NAME
22    /* override */ #undef PACKAGE_STRING
23    /* override */ #undef PACKAGE_TARNAME
24    #endif /* _TCLCONFIG */])
25])
26
27TCL_VERSION=8.5
28TCL_MAJOR_VERSION=8
29TCL_MINOR_VERSION=5
30TCL_PATCH_LEVEL=".9"
31VERSION=${TCL_VERSION}
32
33#------------------------------------------------------------------------
34# Handle the --prefix=... option
35#------------------------------------------------------------------------
36
37if test "${prefix}" = "NONE"; then
38    prefix=/usr/local
39fi
40if test "${exec_prefix}" = "NONE"; then
41    exec_prefix=$prefix
42fi
43# Make sure srcdir is fully qualified!
44srcdir="`cd "$srcdir" ; pwd`"
45TCL_SRC_DIR="`cd "$srcdir"/..; pwd`"
46
47#------------------------------------------------------------------------
48# Compress and/or soft link the manpages?
49#------------------------------------------------------------------------
50
51SC_CONFIG_MANPAGES
52
53#------------------------------------------------------------------------
54# Standard compiler checks
55#------------------------------------------------------------------------
56
57# If the user did not set CFLAGS, set it now to keep
58# the AC_PROG_CC macro from adding "-g -O2".
59if test "${CFLAGS+set}" != "set" ; then
60    CFLAGS=""
61fi
62
63AC_PROG_CC
64AC_C_INLINE
65
66#--------------------------------------------------------------------
67# Supply substitutes for missing POSIX header files.  Special notes:
68#	- stdlib.h doesn't define strtol, strtoul, or
69#	  strtod insome versions of SunOS
70#	- some versions of string.h don't declare procedures such
71#	  as strstr
72# Do this early, otherwise an autoconf bug throws errors on configure
73#--------------------------------------------------------------------
74
75SC_MISSING_POSIX_HEADERS
76
77#------------------------------------------------------------------------
78# If we're using GCC, see if the compiler understands -pipe.  If so, use it.
79# It makes compiling go faster.  (This is only a performance feature.)
80#------------------------------------------------------------------------
81
82if test -z "$no_pipe" && test -n "$GCC"; then
83    AC_CACHE_CHECK([if the compiler understands -pipe],
84	tcl_cv_cc_pipe, [
85	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -pipe"
86	AC_TRY_COMPILE(,, tcl_cv_cc_pipe=yes, tcl_cv_cc_pipe=no)
87	CFLAGS=$hold_cflags])
88    if test $tcl_cv_cc_pipe = yes; then
89	CFLAGS="$CFLAGS -pipe"
90    fi
91fi
92
93#------------------------------------------------------------------------
94# Threads support
95#------------------------------------------------------------------------
96
97SC_ENABLE_THREADS
98
99#------------------------------------------------------------------------
100# Embedded configuration information, encoding to use for the values, TIP #59
101#------------------------------------------------------------------------
102
103SC_TCL_CFG_ENCODING
104
105#--------------------------------------------------------------------
106# Look for libraries that we will need when compiling the Tcl shell
107#--------------------------------------------------------------------
108
109SC_TCL_LINK_LIBS
110
111# Add the threads support libraries
112LIBS="$LIBS$THREADS_LIBS"
113
114SC_ENABLE_SHARED
115
116#--------------------------------------------------------------------
117# The statements below define a collection of compile flags.  This
118# macro depends on the value of SHARED_BUILD, and should be called
119# after SC_ENABLE_SHARED checks the configure switches.
120#--------------------------------------------------------------------
121
122SC_CONFIG_CFLAGS
123
124SC_ENABLE_SYMBOLS(bccdebug)
125
126AC_DEFINE(TCL_TOMMATH, 1, [Build libtommath?])
127AC_DEFINE(MP_PREC, 4, [Default libtommath precision.])
128
129#--------------------------------------------------------------------
130#	Detect what compiler flags to set for 64-bit support.
131#--------------------------------------------------------------------
132
133SC_TCL_EARLY_FLAGS
134
135SC_TCL_64BIT_FLAGS
136
137#--------------------------------------------------------------------
138#	Check endianness because we can optimize comparisons of
139#	Tcl_UniChar strings to memcmp on big-endian systems.
140#--------------------------------------------------------------------
141
142AC_C_BIGENDIAN
143
144#--------------------------------------------------------------------
145#	Supply substitutes for missing POSIX library procedures, or
146#	set flags so Tcl uses alternate procedures.
147#--------------------------------------------------------------------
148
149# Check if Posix compliant getcwd exists, if not we'll use getwd.
150AC_CHECK_FUNCS(getcwd, , [AC_DEFINE(USEGETWD, 1, [Is getcwd Posix-compliant?])])
151# Nb: if getcwd uses popen and pwd(1) (like SunOS 4) we should really
152# define USEGETWD even if the posix getcwd exists. Add a test ?
153
154AC_REPLACE_FUNCS(opendir strtol waitpid)
155AC_CHECK_FUNC(strerror, , [AC_DEFINE(NO_STRERROR, 1, [Do we have strerror()])])
156AC_CHECK_FUNC(getwd, , [AC_DEFINE(NO_GETWD, 1, [Do we have getwd()])])
157AC_CHECK_FUNC(wait3, , [AC_DEFINE(NO_WAIT3, 1, [Do we have wait3()])])
158AC_CHECK_FUNC(uname, , [AC_DEFINE(NO_UNAME, 1, [Do we have uname()])])
159
160if test "`uname -s`" = "Darwin" && test "${TCL_THREADS}" = 1 && \
161	test "`uname -r | awk -F. '{print [$]1}'`" -lt 7; then
162    # prior to Darwin 7, realpath is not threadsafe, so don't
163    # use it when threads are enabled, c.f. bug # 711232
164    ac_cv_func_realpath=no
165fi
166AC_CHECK_FUNC(realpath, , [AC_DEFINE(NO_REALPATH, 1, [Do we have realpath()])])
167
168SC_TCL_GETADDRINFO
169
170#-------------------------------------------------------------------- 
171#	Look for thread-safe variants of some library functions.
172#--------------------------------------------------------------------
173
174if test "${TCL_THREADS}" = 1; then
175    SC_TCL_GETPWUID_R
176    SC_TCL_GETPWNAM_R
177    SC_TCL_GETGRGID_R
178    SC_TCL_GETGRNAM_R
179    if test "`uname -s`" = "Darwin" && \
180	    test "`uname -r | awk -F. '{print [$]1}'`" -gt 5; then
181	# Starting with Darwin 6 (Mac OSX 10.2), gethostbyX
182	# are actually MT-safe as they always return pointers
183	# from TSD instead of static storage.
184	AC_DEFINE(HAVE_MTSAFE_GETHOSTBYNAME, 1,
185		[Do we have MT-safe gethostbyname() ?])
186	AC_DEFINE(HAVE_MTSAFE_GETHOSTBYADDR, 1,
187		[Do we have MT-safe gethostbyaddr() ?])
188
189    elif test "`uname -s`" = "HP-UX" && \
190	      test "`uname -r|sed -e 's|B\.||' -e 's|\..*$||'`" -gt 10; then
191        # Starting with HPUX 11.00 (we believe), gethostbyX
192        # are actually MT-safe as they always return pointers
193	# from TSD instead of static storage.
194	AC_DEFINE(HAVE_MTSAFE_GETHOSTBYNAME, 1,
195		[Do we have MT-safe gethostbyname() ?])
196	AC_DEFINE(HAVE_MTSAFE_GETHOSTBYADDR, 1,
197		[Do we have MT-safe gethostbyaddr() ?])
198
199    else
200	SC_TCL_GETHOSTBYNAME_R
201	SC_TCL_GETHOSTBYADDR_R
202    fi
203fi
204
205#---------------------------------------------------------------------------
206#	Determine which interface to use to talk to the serial port.
207#	Note that #include lines must begin in leftmost column for
208#	some compilers to recognize them as preprocessor directives.
209#---------------------------------------------------------------------------
210
211SC_SERIAL_PORT
212
213#--------------------------------------------------------------------
214#	Include sys/select.h if it exists and if it supplies things
215#	that appear to be useful and aren't already in sys/types.h.
216#	This appears to be true only on the RS/6000 under AIX.  Some
217#	systems like OSF/1 have a sys/select.h that's of no use, and
218#	other systems like SCO UNIX have a sys/select.h that's
219#	pernicious.  If "fd_set" isn't defined anywhere then set a
220#	special flag.
221#--------------------------------------------------------------------
222
223AC_CACHE_CHECK([for fd_set in sys/types], tcl_cv_type_fd_set, [
224    AC_TRY_COMPILE([#include <sys/types.h>],[fd_set readMask, writeMask;],
225	tcl_cv_type_fd_set=yes, tcl_cv_type_fd_set=no)])
226tcl_ok=$tcl_cv_type_fd_set
227if test $tcl_ok = no; then
228    AC_CACHE_CHECK([for fd_mask in sys/select], tcl_cv_grep_fd_mask, [
229	AC_EGREP_HEADER(fd_mask, sys/select.h,
230	     tcl_cv_grep_fd_mask=present, tcl_cv_grep_fd_mask=missing)])
231    if test $tcl_cv_grep_fd_mask = present; then
232	AC_DEFINE(HAVE_SYS_SELECT_H, 1, [Should we include <sys/select.h>?])
233	tcl_ok=yes
234    fi
235fi
236if test $tcl_ok = no; then
237    AC_DEFINE(NO_FD_SET, 1, [Do we have fd_set?])
238fi
239
240#------------------------------------------------------------------------------
241#       Find out all about time handling differences.
242#------------------------------------------------------------------------------
243
244SC_TIME_HANDLER
245
246#--------------------------------------------------------------------
247#	Some systems (e.g., IRIX 4.0.5) lack some fields in struct stat. But
248#	we might be able to use fstatfs instead. Some systems (OpenBSD?) also
249#	lack blkcnt_t.
250#--------------------------------------------------------------------
251
252AC_CHECK_MEMBERS([struct stat.st_blocks, struct stat.st_blksize])
253AC_CHECK_TYPES([blkcnt_t])
254AC_CHECK_FUNC(fstatfs, , [AC_DEFINE(NO_FSTATFS, 1, [Do we have fstatfs()?])])
255
256#--------------------------------------------------------------------
257#       Some system have no memcmp or it does not work with 8 bit
258#       data, this checks it and add memcmp.o to LIBOBJS if needed
259#--------------------------------------------------------------------
260
261AC_FUNC_MEMCMP
262
263#--------------------------------------------------------------------
264#       Some system like SunOS 4 and other BSD like systems
265#       have no memmove (we assume they have bcopy instead).
266#       {The replacement define is in compat/string.h}
267#--------------------------------------------------------------------
268
269AC_CHECK_FUNC(memmove, , [
270    AC_DEFINE(NO_MEMMOVE, 1, [Do we have memmove()?])
271    AC_DEFINE(NO_STRING_H, 1, [Do we have <string.h>?]) ])
272
273#--------------------------------------------------------------------
274#	On some systems strstr is broken: it returns a pointer even
275#	even if the original string is empty.
276#--------------------------------------------------------------------
277
278SC_TCL_CHECK_BROKEN_FUNC(strstr, [
279    extern int strstr();
280    exit(strstr("\0test", "test") ? 1 : 0);
281])
282
283#--------------------------------------------------------------------
284#	Check for strtoul function.  This is tricky because under some
285#	versions of AIX strtoul returns an incorrect terminator
286#	pointer for the string "0".
287#--------------------------------------------------------------------
288
289SC_TCL_CHECK_BROKEN_FUNC(strtoul, [
290    extern int strtoul();
291    char *term, *string = "0";
292    exit(strtoul(string,&term,0) != 0 || term != string+1);
293])
294
295#--------------------------------------------------------------------
296#	Check for the strtod function.  This is tricky because in some
297#	versions of Linux strtod mis-parses strings starting with "+".
298#--------------------------------------------------------------------
299
300SC_TCL_CHECK_BROKEN_FUNC(strtod, [
301    extern double strtod();
302    char *term, *string = " +69";
303    exit(strtod(string,&term) != 69 || term != string+4);
304])
305
306#--------------------------------------------------------------------
307#	Under Solaris 2.4, strtod returns the wrong value for the
308#	terminating character under some conditions.  Check for this
309#	and if the problem exists use a substitute procedure
310#	"fixstrtod" that corrects the error.
311#--------------------------------------------------------------------
312
313SC_BUGGY_STRTOD
314
315#--------------------------------------------------------------------
316#	Check for various typedefs and provide substitutes if
317#	they don't exist.
318#--------------------------------------------------------------------
319
320AC_TYPE_MODE_T
321AC_TYPE_PID_T
322AC_TYPE_SIZE_T
323AC_TYPE_UID_T
324
325AC_CACHE_CHECK([for socklen_t], tcl_cv_type_socklen_t, [
326    AC_TRY_COMPILE([
327	#include <sys/types.h>
328	#include <sys/socket.h>
329    ],[
330    	socklen_t foo;
331    ],[tcl_cv_type_socklen_t=yes],[tcl_cv_type_socklen_t=no])])
332if test $tcl_cv_type_socklen_t = no; then
333    AC_DEFINE(socklen_t, int, [Define as int if socklen_t is not available])
334fi
335
336AC_CHECK_TYPE([intptr_t], [
337    AC_DEFINE([HAVE_INTPTR_T], 1, [Do we have the intptr_t type?])], [
338    AC_CACHE_CHECK([for pointer-size signed integer type], tcl_cv_intptr_t, [
339    for tcl_cv_intptr_t in "int" "long" "long long" none; do
340	if test "$tcl_cv_intptr_t" != none; then
341	    AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT],
342		    [[sizeof (void *) <= sizeof ($tcl_cv_intptr_t)]])], 
343		[tcl_ok=yes], [tcl_ok=no])
344	    test "$tcl_ok" = yes && break; fi
345    done])
346    if test "$tcl_cv_intptr_t" != none; then
347	AC_DEFINE_UNQUOTED([intptr_t], [$tcl_cv_intptr_t], [Signed integer
348	   type wide enough to hold a pointer.])
349    fi
350])
351AC_CHECK_TYPE([uintptr_t], [
352    AC_DEFINE([HAVE_UINTPTR_T], 1, [Do we have the uintptr_t type?])], [
353    AC_CACHE_CHECK([for pointer-size unsigned integer type], tcl_cv_uintptr_t, [
354    for tcl_cv_uintptr_t in "unsigned int" "unsigned long" "unsigned long long" \
355	    none; do
356	if test "$tcl_cv_uintptr_t" != none; then
357	    AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT],
358		    [[sizeof (void *) <= sizeof ($tcl_cv_uintptr_t)]])], 
359		[tcl_ok=yes], [tcl_ok=no])
360	    test "$tcl_ok" = yes && break; fi
361    done])
362    if test "$tcl_cv_uintptr_t" != none; then
363	AC_DEFINE_UNQUOTED([uintptr_t], [$tcl_cv_uintptr_t], [Unsigned integer
364	   type wide enough to hold a pointer.])
365    fi
366])
367
368#--------------------------------------------------------------------
369#	If a system doesn't have an opendir function (man, that's old!)
370#	then we have to supply a different version of dirent.h which
371#	is compatible with the substitute version of opendir that's
372#	provided.  This version only works with V7-style directories.
373#--------------------------------------------------------------------
374
375AC_CHECK_FUNC(opendir, , [AC_DEFINE(USE_DIRENT2_H, 1, [May we include <dirent2.h>?])])
376
377#--------------------------------------------------------------------
378#	The check below checks whether <sys/wait.h> defines the type
379#	"union wait" correctly.  It's needed because of weirdness in
380#	HP-UX where "union wait" is defined in both the BSD and SYS-V
381#	environments.  Checking the usability of WIFEXITED seems to do
382#	the trick.
383#--------------------------------------------------------------------
384
385AC_CACHE_CHECK([union wait], tcl_cv_union_wait, [
386    AC_TRY_LINK([#include <sys/types.h> 
387#include <sys/wait.h>], [
388union wait x;
389WIFEXITED(x);		/* Generates compiler error if WIFEXITED
390			 * uses an int. */
391    ], tcl_cv_union_wait=yes, tcl_cv_union_wait=no)])
392if test $tcl_cv_union_wait = no; then
393    AC_DEFINE(NO_UNION_WAIT, 1, [Do we have a usable 'union wait'?])
394fi
395
396#--------------------------------------------------------------------
397#	Check whether there is an strncasecmp function on this system.
398#	This is a bit tricky because under SCO it's in -lsocket and
399#	under Sequent Dynix it's in -linet.
400#--------------------------------------------------------------------
401
402AC_CHECK_FUNC(strncasecmp, tcl_ok=1, tcl_ok=0)
403if test "$tcl_ok" = 0; then
404    AC_CHECK_LIB(socket, strncasecmp, tcl_ok=1, tcl_ok=0)
405fi
406if test "$tcl_ok" = 0; then
407    AC_CHECK_LIB(inet, strncasecmp, tcl_ok=1, tcl_ok=0)
408fi
409if test "$tcl_ok" = 0; then
410    AC_LIBOBJ([strncasecmp])
411    USE_COMPAT=1
412fi
413
414#--------------------------------------------------------------------
415#	The code below deals with several issues related to gettimeofday:
416#	1. Some systems don't provide a gettimeofday function at all
417#	   (set NO_GETTOD if this is the case).
418#	2. SGI systems don't use the BSD form of the gettimeofday function,
419#	   but they have a BSDgettimeofday function that can be used instead.
420#	3. See if gettimeofday is declared in the <sys/time.h> header file.
421#	   if not, set the GETTOD_NOT_DECLARED flag so that tclPort.h can
422#	   declare it.
423#--------------------------------------------------------------------
424
425AC_CHECK_FUNC(BSDgettimeofday,
426    [AC_DEFINE(HAVE_BSDGETTIMEOFDAY, 1, [Do we have BSDgettimeofday()?])], [
427    AC_CHECK_FUNC(gettimeofday, , [AC_DEFINE(NO_GETTOD, 1, [Do we have gettimeofday()?])])
428])
429AC_CACHE_CHECK([for gettimeofday declaration], tcl_cv_grep_gettimeofday, [
430    AC_EGREP_HEADER(gettimeofday, sys/time.h,
431	tcl_cv_grep_gettimeofday=present, tcl_cv_grep_gettimeofday=missing)])
432if test $tcl_cv_grep_gettimeofday = missing ; then
433    AC_DEFINE(GETTOD_NOT_DECLARED, 1, [Is gettimeofday() actually declared in <sys/time.h>?])
434fi
435
436#--------------------------------------------------------------------
437#	The following code checks to see whether it is possible to get
438#	signed chars on this platform.  This is needed in order to
439#	properly generate sign-extended ints from character values.
440#--------------------------------------------------------------------
441
442AC_C_CHAR_UNSIGNED
443AC_CACHE_CHECK([signed char declarations], tcl_cv_char_signed, [
444    AC_TRY_COMPILE(, [
445	signed char *p;
446	p = 0;
447	], tcl_cv_char_signed=yes, tcl_cv_char_signed=no)])
448if test $tcl_cv_char_signed = yes; then
449    AC_DEFINE(HAVE_SIGNED_CHAR, 1, [Are characters signed?])
450fi
451
452#--------------------------------------------------------------------
453#  Does putenv() copy or not?  We need to know to avoid memory leaks.
454#--------------------------------------------------------------------
455
456AC_CACHE_CHECK([for a putenv() that copies the buffer], tcl_cv_putenv_copy, [
457    AC_TRY_RUN([
458	#include <stdlib.h>
459	#define OURVAR "havecopy=yes"
460	int main (int argc, char *argv[])
461	{
462	    char *foo, *bar;
463	    foo = (char *)strdup(OURVAR);
464	    putenv(foo);
465	    strcpy((char *)(strchr(foo, '=') + 1), "no");
466	    bar = getenv("havecopy");
467	    if (!strcmp(bar, "no")) {
468		/* doesnt copy */
469		return 0;
470	    } else {
471		/* does copy */
472		return 1;
473	    }
474	}
475    ],
476    tcl_cv_putenv_copy=no,
477    tcl_cv_putenv_copy=yes,
478    tcl_cv_putenv_copy=no)])
479if test $tcl_cv_putenv_copy = yes; then
480    AC_DEFINE(HAVE_PUTENV_THAT_COPIES, 1,
481	[Does putenv() copy strings or incorporate them by reference?])
482fi
483
484#--------------------------------------------------------------------
485# Check for support of nl_langinfo function
486#--------------------------------------------------------------------
487
488SC_ENABLE_LANGINFO
489
490#--------------------------------------------------------------------
491# Check for support of chflags function
492#--------------------------------------------------------------------
493
494AC_CHECK_FUNCS(chflags)
495
496#--------------------------------------------------------------------
497# Check for support of isnan() function or macro
498#--------------------------------------------------------------------
499
500AC_CACHE_CHECK([isnan], tcl_cv_isnan, [
501    AC_TRY_LINK([#include <math.h>], [
502isnan(0.0);			/* Generates an error if isnan is missing */
503], tcl_cv_isnan=yes, tcl_cv_isnan=no)])
504if test $tcl_cv_isnan = no; then
505    AC_DEFINE(NO_ISNAN, 1, [Do we have a usable 'isnan'?])
506fi
507
508#--------------------------------------------------------------------
509# Darwin specific API checks and defines
510#--------------------------------------------------------------------
511
512if test "`uname -s`" = "Darwin" ; then
513    AC_CHECK_FUNCS(getattrlist)
514    AC_CHECK_HEADERS(copyfile.h)
515    AC_CHECK_FUNCS(copyfile)
516    if test $tcl_corefoundation = yes; then
517	AC_CHECK_HEADERS(libkern/OSAtomic.h)
518	AC_CHECK_FUNCS(OSSpinLockLock)
519	AC_CHECK_FUNCS(pthread_atfork)
520    fi
521    AC_DEFINE(USE_VFORK, 1, [Should we use vfork() instead of fork()?])
522    AC_DEFINE(TCL_DEFAULT_ENCODING, "utf-8",
523	[Are we to override what our default encoding is?])
524    AC_DEFINE(TCL_LOAD_FROM_MEMORY, 1,
525	[Can this platform load code from memory?])
526    AC_DEFINE(TCL_WIDE_CLICKS, 1,
527	[Does this platform have wide high-resolution clicks?])
528    AC_CHECK_HEADERS(AvailabilityMacros.h)
529    if test "$ac_cv_header_AvailabilityMacros_h" = yes; then
530	AC_CACHE_CHECK([if weak import is available], tcl_cv_cc_weak_import, [
531	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
532	    AC_TRY_LINK([
533		    #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
534		    #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1020
535		    #error __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1020
536		    #endif
537		    #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1020
538		    #error MAC_OS_X_VERSION_MIN_REQUIRED < 1020
539		    #endif
540		    int rand(void) __attribute__((weak_import));
541		], [rand();],
542		tcl_cv_cc_weak_import=yes, tcl_cv_cc_weak_import=no)
543	    CFLAGS=$hold_cflags])
544	if test $tcl_cv_cc_weak_import = yes; then
545	    AC_DEFINE(HAVE_WEAK_IMPORT, 1, [Is weak import available?])
546	fi
547	AC_CACHE_CHECK([if Darwin SUSv3 extensions are available],
548	    tcl_cv_cc_darwin_c_source, [
549	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
550	    AC_TRY_COMPILE([
551		    #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
552		    #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
553		    #error __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
554		    #endif
555		    #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1050
556		    #error MAC_OS_X_VERSION_MIN_REQUIRED < 1050
557		    #endif
558		    #define _DARWIN_C_SOURCE 1
559		    #include <sys/cdefs.h>
560		],,tcl_cv_cc_darwin_c_source=yes, tcl_cv_cc_darwin_c_source=no)
561	    CFLAGS=$hold_cflags])
562	if test $tcl_cv_cc_darwin_c_source = yes; then
563	    AC_DEFINE(_DARWIN_C_SOURCE, 1,
564		    [Are Darwin SUSv3 extensions available?])
565	fi
566    fi
567    # Build .bundle dltest binaries in addition to .dylib
568    DLTEST_LD='${CC} -bundle -Wl,-w ${CFLAGS} ${LDFLAGS}'
569    DLTEST_SUFFIX=".bundle"
570else
571    DLTEST_LD='${SHLIB_LD}'
572    DLTEST_SUFFIX=""
573fi
574
575#--------------------------------------------------------------------
576# Check for support of fts functions (readdir replacement)
577#--------------------------------------------------------------------
578
579AC_CACHE_CHECK([for fts], tcl_cv_api_fts, [
580    AC_TRY_LINK([
581	    #include <sys/param.h>
582	    #include <sys/stat.h>
583	    #include <fts.h>
584	], [
585	    char*const p[2] = {"/", NULL};
586	    FTS *f = fts_open(p, FTS_PHYSICAL|FTS_NOCHDIR|FTS_NOSTAT, NULL);
587	    FTSENT *e = fts_read(f); fts_close(f);
588	], tcl_cv_api_fts=yes, tcl_cv_api_fts=no)])
589if test $tcl_cv_api_fts = yes; then
590    AC_DEFINE(HAVE_FTS, 1, [Do we have fts functions?])
591fi
592
593#--------------------------------------------------------------------
594#	The statements below check for systems where POSIX-style
595#	non-blocking I/O (O_NONBLOCK) doesn't work or is unimplemented. 
596#	On these systems (mostly older ones), use the old BSD-style
597#	FIONBIO approach instead.
598#--------------------------------------------------------------------
599
600SC_BLOCKING_STYLE
601
602#------------------------------------------------------------------------
603
604AC_MSG_CHECKING([whether to use dll unloading])
605AC_ARG_ENABLE(dll-unloading,
606    AC_HELP_STRING([--enable-dll-unloading],
607	[enable the 'unload' command (default: on)]),
608    [tcl_ok=$enableval], [tcl_ok=yes])
609if test $tcl_ok = yes; then
610    AC_DEFINE(TCL_UNLOAD_DLLS, 1, [Do we allow unloading of shared libraries?])
611fi
612AC_MSG_RESULT([$tcl_ok])
613
614#------------------------------------------------------------------------
615#	Check whether the timezone data is supplied by the OS or has
616#	to be installed by Tcl. The default is autodetection, but can
617#	be overriden on the configure command line either way.
618#------------------------------------------------------------------------
619
620AC_MSG_CHECKING([for timezone data])
621AC_ARG_WITH(tzdata,
622    AC_HELP_STRING([--with-tzdata],
623	[install timezone data (default: autodetect)]),
624    [tcl_ok=$withval], [tcl_ok=auto])
625#
626# Any directories that get added here must also be added to the
627# search path in ::tcl::clock::Initialize (library/clock.tcl).
628#
629case $tcl_ok in 
630    no)
631	AC_MSG_RESULT([supplied by OS vendor])
632    ;;
633    yes)
634	# nothing to do here
635    ;;
636    auto*)
637	AC_CACHE_VAL([tcl_cv_dir_zoneinfo], [
638	for dir in /usr/share/zoneinfo \
639		/usr/share/lib/zoneinfo \
640		/usr/lib/zoneinfo
641	do
642		if test -f $dir/UTC -o -f $dir/GMT
643		then
644			tcl_cv_dir_zoneinfo="$dir"
645			break
646		fi
647	done])
648	if test -n "$tcl_cv_dir_zoneinfo"; then
649	    tcl_ok=no
650	    AC_MSG_RESULT([$dir])
651	else
652	    tcl_ok=yes
653	fi
654    ;;
655    *)
656	AC_MSG_ERROR([invalid argument: $tcl_ok])	
657    ;;
658esac
659if test $tcl_ok = yes
660then
661    AC_MSG_RESULT([supplied by Tcl])
662    INSTALL_TZDATA=install-tzdata
663fi
664
665#--------------------------------------------------------------------
666#	DTrace support
667#--------------------------------------------------------------------
668
669AC_ARG_ENABLE(dtrace,
670    AC_HELP_STRING([--enable-dtrace],
671	[build with DTrace support (default: off)]),
672    [tcl_ok=$enableval], [tcl_ok=no])
673if test $tcl_ok = yes; then
674    AC_CHECK_HEADER(sys/sdt.h, [tcl_ok=yes], [tcl_ok=no])
675fi
676if test $tcl_ok = yes; then
677    AC_PATH_PROG(DTRACE, dtrace,, [$PATH:/usr/sbin])
678    test -z "$ac_cv_path_DTRACE" && tcl_ok=no
679fi
680AC_MSG_CHECKING([whether to enable DTrace support])
681MAKEFILE_SHELL='/bin/sh'
682if test $tcl_ok = yes; then
683    AC_DEFINE(USE_DTRACE, 1, [Are we building with DTrace support?])
684    DTRACE_SRC="\${DTRACE_SRC}"
685    DTRACE_HDR="\${DTRACE_HDR}"
686    if test "`uname -s`" != "Darwin" ; then
687	DTRACE_OBJ="\${DTRACE_OBJ}"
688	if test "`uname -s`" = "SunOS" -a "$SHARED_BUILD" = "0" ; then
689	    # Need to create an intermediate object file to ensure tclDTrace.o
690	    # gets included when linking against the static tcl library.
691	    STLIB_LD='stlib_ld () { /usr/ccs/bin/ld -r -o $${1%.a}.o "$${@:2}" && '"${STLIB_LD}"' $${1} $${1%.a}.o ; } && stlib_ld'
692	    MAKEFILE_SHELL='/bin/bash'
693	    # Force use of Sun ar and ranlib, the GNU versions choke on
694	    # tclDTrace.o and the combined object file above.
695	    AR='/usr/ccs/bin/ar'
696	    RANLIB='/usr/ccs/bin/ranlib'
697	fi
698    fi
699fi
700AC_MSG_RESULT([$tcl_ok])
701
702#--------------------------------------------------------------------
703#  Does the C stack grow upwards or downwards? Or cross-compiling?
704#--------------------------------------------------------------------
705
706AC_CACHE_CHECK([if the C stack grows upwards in memory], tcl_cv_stack_grows_up, [
707    AC_TRY_RUN([
708	int StackGrowsUp(int *parent) {
709	    int here;
710	    return (&here < parent);
711	}
712	int main (int argc, char *argv[]) {
713	    int foo;
714	    return StackGrowsUp(&foo);
715	}
716    ], tcl_cv_stack_grows_up=yes, tcl_cv_stack_grows_up=no,
717    tcl_cv_stack_grows_up=unknown)])
718if test $tcl_cv_stack_grows_up = unknown; then
719    AC_DEFINE(TCL_CROSS_COMPILE, 1, [Are we cross-compiling?])
720elif test $tcl_cv_stack_grows_up = yes; then
721    AC_DEFINE(TCL_STACK_GROWS_UP, 1, [The C stack grows upwards in memory.])
722fi
723
724#--------------------------------------------------------------------
725#	The statements below define a collection of symbols related to
726#	building libtcl as a shared library instead of a static library.
727#--------------------------------------------------------------------
728
729TCL_UNSHARED_LIB_SUFFIX=${UNSHARED_LIB_SUFFIX}
730TCL_SHARED_LIB_SUFFIX=${SHARED_LIB_SUFFIX}
731eval "TCL_LIB_FILE=libtcl${LIB_SUFFIX}"
732
733# tclConfig.sh needs a version of the _LIB_SUFFIX that has been eval'ed
734# since on some platforms TCL_LIB_FILE contains shell escapes. 
735# (See also: TCL_TRIM_DOTS).
736
737eval "TCL_LIB_FILE=${TCL_LIB_FILE}"
738
739TCL_LIBRARY='$(prefix)/lib/tcl$(VERSION)'
740PRIVATE_INCLUDE_DIR='$(includedir)'
741HTML_DIR='$(DISTDIR)/html'
742
743# Note:  in the following variable, it's important to use the absolute
744# path name of the Tcl directory rather than "..":  this is because
745# AIX remembers this path and will attempt to use it at run-time to look
746# up the Tcl library.
747
748if test "`uname -s`" = "Darwin" ; then
749    SC_ENABLE_FRAMEWORK
750    TCL_SHLIB_LD_EXTRAS="-compatibility_version ${TCL_VERSION} -current_version ${TCL_VERSION}`echo ${TCL_PATCH_LEVEL} | awk ['{match($0, "\\\.[0-9]+"); print substr($0,RSTART,RLENGTH)}']`"
751    TCL_SHLIB_LD_EXTRAS="${TCL_SHLIB_LD_EXTRAS}"' -install_name "${DYLIB_INSTALL_DIR}"/${TCL_LIB_FILE}'
752    echo "$LDFLAGS " | grep -q -- '-prebind ' && TCL_SHLIB_LD_EXTRAS="${TCL_SHLIB_LD_EXTRAS}"' -seg1addr 0xa000000'
753    TCL_SHLIB_LD_EXTRAS="${TCL_SHLIB_LD_EXTRAS}"' -sectcreate __TEXT __info_plist Tcl-Info.plist'
754    EXTRA_TCLSH_LIBS='-sectcreate __TEXT __info_plist Tclsh-Info.plist'
755    EXTRA_APP_CC_SWITCHES='-mdynamic-no-pic'
756    AC_CONFIG_FILES([Tcl-Info.plist:../macosx/Tcl-Info.plist.in Tclsh-Info.plist:../macosx/Tclsh-Info.plist.in])
757    TCL_YEAR="`date +%Y`"
758fi
759
760if test "$FRAMEWORK_BUILD" = "1" ; then
761    AC_DEFINE(TCL_FRAMEWORK, 1, [Is Tcl built as a framework?])
762    # Construct a fake local framework structure to make linking with
763    # '-framework Tcl' and running of tcltest work
764    AC_CONFIG_COMMANDS([Tcl.framework], [n=Tcl &&
765        f=$n.framework && v=Versions/$VERSION &&
766        rm -rf $f && mkdir -p $f/$v/Resources &&
767        ln -s $v/$n $v/Resources $f && ln -s ../../../$n $f/$v &&
768        ln -s ../../../../$n-Info.plist $f/$v/Resources/Info.plist &&
769        unset n f v
770    ], VERSION=${TCL_VERSION})
771    LD_LIBRARY_PATH_VAR="DYLD_FRAMEWORK_PATH"
772    if test "${libdir}" = '${exec_prefix}/lib'; then
773        # override libdir default
774        libdir="/Library/Frameworks"
775    fi
776    TCL_LIB_FILE="Tcl"
777    TCL_LIB_FLAG="-framework Tcl"
778    TCL_BUILD_LIB_SPEC="-F`pwd | sed -e 's/ /\\\\ /g'` -framework Tcl"
779    TCL_LIB_SPEC="-F${libdir} -framework Tcl"
780    libdir="${libdir}/Tcl.framework/Versions/\${VERSION}"
781    TCL_LIBRARY="${libdir}/Resources/Scripts"
782    includedir="${libdir}/Headers"
783    PRIVATE_INCLUDE_DIR="${libdir}/PrivateHeaders"
784    HTML_DIR="${libdir}/Resources/Documentation/Reference/Tcl"
785    EXTRA_INSTALL="install-private-headers html-tcl"
786    EXTRA_BUILD_HTML='@ln -fs contents.htm "$(HTML_INSTALL_DIR)"/TclTOC.html' 
787    EXTRA_INSTALL_BINARIES='@echo "Installing Info.plist to $(LIB_INSTALL_DIR)/Resources" && mkdir -p "$(LIB_INSTALL_DIR)/Resources" && $(INSTALL_DATA) Tcl-Info.plist "$(LIB_INSTALL_DIR)/Resources/Info.plist"'
788    EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing license.terms to $(LIB_INSTALL_DIR)/Resources" && $(INSTALL_DATA) "$(TOP_DIR)/license.terms" "$(LIB_INSTALL_DIR)/Resources"'
789    EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Finalizing Tcl.framework" && rm -f "$(LIB_INSTALL_DIR)/../Current" && ln -s "$(VERSION)" "$(LIB_INSTALL_DIR)/../Current" && for f in "$(LIB_FILE)" tclConfig.sh Resources Headers PrivateHeaders; do rm -f "$(LIB_INSTALL_DIR)/../../$$f" && ln -s "Versions/Current/$$f" "$(LIB_INSTALL_DIR)/../.."; done && f="$(STUB_LIB_FILE)" && rm -f "$(LIB_INSTALL_DIR)/../../$$f" && ln -s "Versions/$(VERSION)/$$f" "$(LIB_INSTALL_DIR)/../.."'
790    # Don't use AC_DEFINE for the following as the framework version define 
791    # needs to go into the Makefile even when using autoheader, so that we  
792    # can pick up a potential make override of VERSION. Also, don't put this
793    # into CFLAGS as it should not go into tclConfig.sh
794    EXTRA_CC_SWITCHES='-DTCL_FRAMEWORK_VERSION=\"$(VERSION)\"'
795else
796    # libdir must be a fully qualified path and not ${exec_prefix}/lib
797    eval libdir="$libdir"
798    if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
799        TCL_LIB_FLAG="-ltcl${TCL_VERSION}"
800    else
801        TCL_LIB_FLAG="-ltcl`echo ${TCL_VERSION} | tr -d .`"
802    fi
803    TCL_BUILD_LIB_SPEC="-L`pwd | sed -e 's/ /\\\\ /g'` ${TCL_LIB_FLAG}"
804    TCL_LIB_SPEC="-L${libdir} ${TCL_LIB_FLAG}"
805fi
806VERSION='${VERSION}'
807eval "CFG_TCL_SHARED_LIB_SUFFIX=${TCL_SHARED_LIB_SUFFIX}"
808eval "CFG_TCL_UNSHARED_LIB_SUFFIX=${TCL_UNSHARED_LIB_SUFFIX}"
809VERSION=${TCL_VERSION}
810
811#--------------------------------------------------------------------
812#	The statements below define the symbol TCL_PACKAGE_PATH, which
813#	gives a list of directories that may contain packages.  The list
814#	consists of one directory for machine-dependent binaries and
815#	another for platform-independent scripts.
816#--------------------------------------------------------------------
817
818if test "$FRAMEWORK_BUILD" = "1" ; then
819    test -z "$TCL_PACKAGE_PATH" && \
820	TCL_PACKAGE_PATH="~/Library/Tcl /Library/Tcl /System/Library/Tcl ~/Library/Frameworks /Library/Frameworks /System/Library/Frameworks"
821    test -z "$TCL_MODULE_PATH"  && \
822	TCL_MODULE_PATH="~/Library/Tcl /Library/Tcl /System/Library/Tcl"
823elif test "$prefix/lib" != "$libdir"; then
824    TCL_PACKAGE_PATH="${libdir} ${prefix}/lib ${TCL_PACKAGE_PATH}"
825else
826    TCL_PACKAGE_PATH="${prefix}/lib ${TCL_PACKAGE_PATH}"
827fi
828
829#--------------------------------------------------------------------
830#       The statements below define various symbols relating to Tcl
831#       stub support.
832#--------------------------------------------------------------------
833
834# Replace ${VERSION} with contents of ${TCL_VERSION}
835# double-eval to account for TCL_TRIM_DOTS.
836#
837eval "TCL_STUB_LIB_FILE=libtclstub${TCL_UNSHARED_LIB_SUFFIX}"
838eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""
839eval "TCL_STUB_LIB_DIR=${libdir}"
840
841if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
842    TCL_STUB_LIB_FLAG="-ltclstub${TCL_VERSION}"
843else
844    TCL_STUB_LIB_FLAG="-ltclstub`echo ${TCL_VERSION} | tr -d .`"
845fi
846
847TCL_BUILD_STUB_LIB_SPEC="-L`pwd | sed -e 's/ /\\\\ /g'` ${TCL_STUB_LIB_FLAG}"
848TCL_STUB_LIB_SPEC="-L${TCL_STUB_LIB_DIR} ${TCL_STUB_LIB_FLAG}"
849TCL_BUILD_STUB_LIB_PATH="`pwd`/${TCL_STUB_LIB_FILE}"
850TCL_STUB_LIB_PATH="${TCL_STUB_LIB_DIR}/${TCL_STUB_LIB_FILE}"
851
852# Install time header dir can be set via --includedir
853eval "TCL_INCLUDE_SPEC=\"-I${includedir}\""
854
855#------------------------------------------------------------------------
856# tclConfig.sh refers to this by a different name
857#------------------------------------------------------------------------
858
859TCL_SHARED_BUILD=${SHARED_BUILD}
860
861AC_SUBST(TCL_VERSION)
862AC_SUBST(TCL_MAJOR_VERSION)
863AC_SUBST(TCL_MINOR_VERSION)
864AC_SUBST(TCL_PATCH_LEVEL)
865AC_SUBST(TCL_YEAR)
866
867AC_SUBST(TCL_LIB_FILE)
868AC_SUBST(TCL_LIB_FLAG)
869AC_SUBST(TCL_LIB_SPEC)
870AC_SUBST(TCL_STUB_LIB_FILE)
871AC_SUBST(TCL_STUB_LIB_FLAG)
872AC_SUBST(TCL_STUB_LIB_SPEC)
873AC_SUBST(TCL_STUB_LIB_PATH)
874AC_SUBST(TCL_INCLUDE_SPEC)
875AC_SUBST(TCL_BUILD_STUB_LIB_SPEC)
876AC_SUBST(TCL_BUILD_STUB_LIB_PATH)
877
878AC_SUBST(TCL_SRC_DIR)
879AC_SUBST(CFG_TCL_SHARED_LIB_SUFFIX)
880AC_SUBST(CFG_TCL_UNSHARED_LIB_SUFFIX)
881
882AC_SUBST(TCL_SHARED_BUILD)
883AC_SUBST(LD_LIBRARY_PATH_VAR)
884
885AC_SUBST(TCL_BUILD_LIB_SPEC)
886
887AC_SUBST(TCL_LIB_VERSIONS_OK)
888AC_SUBST(TCL_SHARED_LIB_SUFFIX)
889AC_SUBST(TCL_UNSHARED_LIB_SUFFIX)
890
891AC_SUBST(TCL_HAS_LONGLONG)
892
893AC_SUBST(INSTALL_TZDATA)
894
895AC_SUBST(DTRACE_SRC)
896AC_SUBST(DTRACE_HDR)
897AC_SUBST(DTRACE_OBJ)
898AC_SUBST(MAKEFILE_SHELL)
899
900AC_SUBST(BUILD_DLTEST)
901AC_SUBST(TCL_PACKAGE_PATH)
902AC_SUBST(TCL_MODULE_PATH)
903
904AC_SUBST(TCL_LIBRARY)
905AC_SUBST(PRIVATE_INCLUDE_DIR)
906AC_SUBST(HTML_DIR)
907
908AC_SUBST(EXTRA_CC_SWITCHES)
909AC_SUBST(EXTRA_APP_CC_SWITCHES)
910AC_SUBST(EXTRA_INSTALL)
911AC_SUBST(EXTRA_INSTALL_BINARIES)
912AC_SUBST(EXTRA_BUILD_HTML)
913AC_SUBST(EXTRA_TCLSH_LIBS)
914
915AC_SUBST(DLTEST_LD)
916AC_SUBST(DLTEST_SUFFIX)
917
918dnl	Disable the automake-friendly normalization of LIBOBJS
919dnl	performed by autoconf 2.53 and later.  It's not correct for us.
920define([_AC_LIBOBJS_NORMALIZE],[])
921AC_CONFIG_FILES([
922    Makefile:../unix/Makefile.in
923    dltest/Makefile:../unix/dltest/Makefile.in
924    tclConfig.sh:../unix/tclConfig.sh.in
925])
926AC_OUTPUT
927