1# tcl.m4 --
2#
3#	This file provides a set of autoconf macros to help TEA-enable
4#	a Tcl extension.
5#
6# Copyright (c) 1999-2000 Ajuba Solutions.
7# Copyright (c) 2002-2005 ActiveState Corporation.
8#
9# See the file "license.terms" for information on usage and redistribution
10# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11#
12# RCS: @(#) $Id: tcl.m4,v 1.12 2009/05/07 05:30:35 andreas_kupries Exp $
13
14AC_PREREQ(2.57)
15
16dnl TEA extensions pass us the version of TEA they think they
17dnl are compatible with (must be set in TEA_INIT below)
18dnl TEA_VERSION="3.7"
19
20# Possible values for key variables defined:
21#
22# TEA_WINDOWINGSYSTEM - win32 aqua x11 (mirrors 'tk windowingsystem')
23# TEA_PLATFORM        - windows unix
24#
25
26#------------------------------------------------------------------------
27# TEA_PATH_TCLCONFIG --
28#
29#	Locate the tclConfig.sh file and perform a sanity check on
30#	the Tcl compile flags
31#
32# Arguments:
33#	none
34#
35# Results:
36#
37#	Adds the following arguments to configure:
38#		--with-tcl=...
39#
40#	Defines the following vars:
41#		TCL_BIN_DIR	Full path to the directory containing
42#				the tclConfig.sh file
43#------------------------------------------------------------------------
44
45AC_DEFUN([TEA_PATH_TCLCONFIG], [
46    dnl TEA specific: Make sure we are initialized
47    AC_REQUIRE([TEA_INIT])
48    #
49    # Ok, lets find the tcl configuration
50    # First, look for one uninstalled.
51    # the alternative search directory is invoked by --with-tcl
52    #
53
54    if test x"${no_tcl}" = x ; then
55	# we reset no_tcl in case something fails here
56	no_tcl=true
57	AC_ARG_WITH(tcl,
58	    AC_HELP_STRING([--with-tcl],
59		[directory containing tcl configuration (tclConfig.sh)]),
60	    with_tclconfig=${withval})
61	AC_MSG_CHECKING([for Tcl configuration])
62	AC_CACHE_VAL(ac_cv_c_tclconfig,[
63
64	    # First check to see if --with-tcl was specified.
65	    if test x"${with_tclconfig}" != x ; then
66		case ${with_tclconfig} in
67		    */tclConfig.sh )
68			if test -f ${with_tclconfig}; then
69			    AC_MSG_WARN([--with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself])
70			    with_tclconfig=`echo ${with_tclconfig} | sed 's!/tclConfig\.sh$!!'`
71			fi ;;
72		esac
73		if test -f "${with_tclconfig}/tclConfig.sh" ; then
74		    ac_cv_c_tclconfig=`(cd ${with_tclconfig}; pwd)`
75		else
76		    AC_MSG_ERROR([${with_tclconfig} directory doesn't contain tclConfig.sh])
77		fi
78	    fi
79
80	    # then check for a private Tcl installation
81	    if test x"${ac_cv_c_tclconfig}" = x ; then
82		for i in \
83			../tcl \
84			`ls -dr ../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
85			`ls -dr ../tcl[[8-9]].[[0-9]] 2>/dev/null` \
86			`ls -dr ../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
87			../../tcl \
88			`ls -dr ../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
89			`ls -dr ../../tcl[[8-9]].[[0-9]] 2>/dev/null` \
90			`ls -dr ../../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
91			../../../tcl \
92			`ls -dr ../../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
93			`ls -dr ../../../tcl[[8-9]].[[0-9]] 2>/dev/null` \
94			`ls -dr ../../../tcl[[8-9]].[[0-9]]* 2>/dev/null` ; do
95		    if test -f "$i/unix/tclConfig.sh" ; then
96			ac_cv_c_tclconfig=`(cd $i/unix; pwd)`
97			break
98		    fi
99		done
100	    fi
101
102	    # on Darwin, check in Framework installation locations
103	    if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tclconfig}" = x ; then
104		for i in `ls -d ~/Library/Frameworks 2>/dev/null` \
105			`ls -d /Library/Frameworks 2>/dev/null` \
106			`ls -d /Network/Library/Frameworks 2>/dev/null` \
107			`ls -d /System/Library/Frameworks 2>/dev/null` \
108			; do
109		    if test -f "$i/Tcl.framework/tclConfig.sh" ; then
110			ac_cv_c_tclconfig=`(cd $i/Tcl.framework; pwd)`
111			break
112		    fi
113		done
114	    fi
115
116	    # TEA specific: on Windows, check in common installation locations
117	    if test "${TEA_PLATFORM}" = "windows" \
118		-a x"${ac_cv_c_tclconfig}" = x ; then
119		for i in `ls -d C:/Tcl/lib 2>/dev/null` \
120			`ls -d C:/Progra~1/Tcl/lib 2>/dev/null` \
121			; do
122		    if test -f "$i/tclConfig.sh" ; then
123			ac_cv_c_tclconfig=`(cd $i; pwd)`
124			break
125		    fi
126		done
127	    fi
128
129	    # check in a few common install locations
130	    if test x"${ac_cv_c_tclconfig}" = x ; then
131		for i in `ls -d ${libdir} 2>/dev/null` \
132			`ls -d ${exec_prefix}/lib 2>/dev/null` \
133			`ls -d ${prefix}/lib 2>/dev/null` \
134			`ls -d /usr/local/lib 2>/dev/null` \
135			`ls -d /usr/contrib/lib 2>/dev/null` \
136			`ls -d /usr/lib 2>/dev/null` \
137			; do
138		    if test -f "$i/tclConfig.sh" ; then
139			ac_cv_c_tclconfig=`(cd $i; pwd)`
140			break
141		    fi
142		done
143	    fi
144
145	    # check in a few other private locations
146	    if test x"${ac_cv_c_tclconfig}" = x ; then
147		for i in \
148			${srcdir}/../tcl \
149			`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
150			`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]] 2>/dev/null` \
151			`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]]* 2>/dev/null` ; do
152		    if test -f "$i/unix/tclConfig.sh" ; then
153		    ac_cv_c_tclconfig=`(cd $i/unix; pwd)`
154		    break
155		fi
156		done
157	    fi
158	])
159
160	if test x"${ac_cv_c_tclconfig}" = x ; then
161	    TCL_BIN_DIR="# no Tcl configs found"
162	    AC_MSG_ERROR([Can't find Tcl configuration definitions])
163	else
164	    no_tcl=
165	    TCL_BIN_DIR=${ac_cv_c_tclconfig}
166	    AC_MSG_RESULT([found ${TCL_BIN_DIR}/tclConfig.sh])
167	fi
168    fi
169])
170
171#------------------------------------------------------------------------
172# TEA_PATH_TKCONFIG --
173#
174#	Locate the tkConfig.sh file
175#
176# Arguments:
177#	none
178#
179# Results:
180#
181#	Adds the following arguments to configure:
182#		--with-tk=...
183#
184#	Defines the following vars:
185#		TK_BIN_DIR	Full path to the directory containing
186#				the tkConfig.sh file
187#------------------------------------------------------------------------
188
189AC_DEFUN([TEA_PATH_TKCONFIG], [
190    #
191    # Ok, lets find the tk configuration
192    # First, look for one uninstalled.
193    # the alternative search directory is invoked by --with-tk
194    #
195
196    if test x"${no_tk}" = x ; then
197	# we reset no_tk in case something fails here
198	no_tk=true
199	AC_ARG_WITH(tk,
200	    AC_HELP_STRING([--with-tk],
201		[directory containing tk configuration (tkConfig.sh)]),
202	    with_tkconfig=${withval})
203	AC_MSG_CHECKING([for Tk configuration])
204	AC_CACHE_VAL(ac_cv_c_tkconfig,[
205
206	    # First check to see if --with-tkconfig was specified.
207	    if test x"${with_tkconfig}" != x ; then
208		case ${with_tkconfig} in
209		    */tkConfig.sh )
210			if test -f ${with_tkconfig}; then
211			    AC_MSG_WARN([--with-tk argument should refer to directory containing tkConfig.sh, not to tkConfig.sh itself])
212			    with_tkconfig=`echo ${with_tkconfig} | sed 's!/tkConfig\.sh$!!'`
213			fi ;;
214		esac
215		if test -f "${with_tkconfig}/tkConfig.sh" ; then
216		    ac_cv_c_tkconfig=`(cd ${with_tkconfig}; pwd)`
217		else
218		    AC_MSG_ERROR([${with_tkconfig} directory doesn't contain tkConfig.sh])
219		fi
220	    fi
221
222	    # then check for a private Tk library
223	    if test x"${ac_cv_c_tkconfig}" = x ; then
224		for i in \
225			../tk \
226			`ls -dr ../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
227			`ls -dr ../tk[[8-9]].[[0-9]] 2>/dev/null` \
228			`ls -dr ../tk[[8-9]].[[0-9]]* 2>/dev/null` \
229			../../tk \
230			`ls -dr ../../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
231			`ls -dr ../../tk[[8-9]].[[0-9]] 2>/dev/null` \
232			`ls -dr ../../tk[[8-9]].[[0-9]]* 2>/dev/null` \
233			../../../tk \
234			`ls -dr ../../../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
235			`ls -dr ../../../tk[[8-9]].[[0-9]] 2>/dev/null` \
236			`ls -dr ../../../tk[[8-9]].[[0-9]]* 2>/dev/null` ; do
237		    if test -f "$i/unix/tkConfig.sh" ; then
238			ac_cv_c_tkconfig=`(cd $i/unix; pwd)`
239			break
240		    fi
241		done
242	    fi
243
244	    # on Darwin, check in Framework installation locations
245	    if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tkconfig}" = x ; then
246		for i in `ls -d ~/Library/Frameworks 2>/dev/null` \
247			`ls -d /Library/Frameworks 2>/dev/null` \
248			`ls -d /Network/Library/Frameworks 2>/dev/null` \
249			`ls -d /System/Library/Frameworks 2>/dev/null` \
250			; do
251		    if test -f "$i/Tk.framework/tkConfig.sh" ; then
252			ac_cv_c_tkconfig=`(cd $i/Tk.framework; pwd)`
253			break
254		    fi
255		done
256	    fi
257
258	    # check in a few common install locations
259	    if test x"${ac_cv_c_tkconfig}" = x ; then
260		for i in `ls -d ${libdir} 2>/dev/null` \
261			`ls -d ${exec_prefix}/lib 2>/dev/null` \
262			`ls -d ${prefix}/lib 2>/dev/null` \
263			`ls -d /usr/local/lib 2>/dev/null` \
264			`ls -d /usr/contrib/lib 2>/dev/null` \
265			`ls -d /usr/lib 2>/dev/null` \
266			; do
267		    if test -f "$i/tkConfig.sh" ; then
268			ac_cv_c_tkconfig=`(cd $i; pwd)`
269			break
270		    fi
271		done
272	    fi
273
274	    # TEA specific: on Windows, check in common installation locations
275	    if test "${TEA_PLATFORM}" = "windows" \
276		-a x"${ac_cv_c_tkconfig}" = x ; then
277		for i in `ls -d C:/Tcl/lib 2>/dev/null` \
278			`ls -d C:/Progra~1/Tcl/lib 2>/dev/null` \
279			; do
280		    if test -f "$i/tkConfig.sh" ; then
281			ac_cv_c_tkconfig=`(cd $i; pwd)`
282			break
283		    fi
284		done
285	    fi
286
287	    # check in a few other private locations
288	    if test x"${ac_cv_c_tkconfig}" = x ; then
289		for i in \
290			${srcdir}/../tk \
291			`ls -dr ${srcdir}/../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
292			`ls -dr ${srcdir}/../tk[[8-9]].[[0-9]] 2>/dev/null` \
293			`ls -dr ${srcdir}/../tk[[8-9]].[[0-9]]* 2>/dev/null` ; do
294		    if test -f "$i/unix/tkConfig.sh" ; then
295			ac_cv_c_tkconfig=`(cd $i/unix; pwd)`
296			break
297		    fi
298		done
299	    fi
300	])
301
302	if test x"${ac_cv_c_tkconfig}" = x ; then
303	    TK_BIN_DIR="# no Tk configs found"
304	    AC_MSG_ERROR([Can't find Tk configuration definitions])
305	else
306	    no_tk=
307	    TK_BIN_DIR=${ac_cv_c_tkconfig}
308	    AC_MSG_RESULT([found ${TK_BIN_DIR}/tkConfig.sh])
309	fi
310    fi
311])
312
313#------------------------------------------------------------------------
314# TEA_LOAD_TCLCONFIG --
315#
316#	Load the tclConfig.sh file
317#
318# Arguments:
319#
320#	Requires the following vars to be set:
321#		TCL_BIN_DIR
322#
323# Results:
324#
325#	Subst the following vars:
326#		TCL_BIN_DIR
327#		TCL_SRC_DIR
328#		TCL_LIB_FILE
329#
330#------------------------------------------------------------------------
331
332AC_DEFUN([TEA_LOAD_TCLCONFIG], [
333    AC_MSG_CHECKING([for existence of ${TCL_BIN_DIR}/tclConfig.sh])
334
335    if test -f "${TCL_BIN_DIR}/tclConfig.sh" ; then
336        AC_MSG_RESULT([loading])
337	. "${TCL_BIN_DIR}/tclConfig.sh"
338    else
339        AC_MSG_RESULT([could not find ${TCL_BIN_DIR}/tclConfig.sh])
340    fi
341
342    # eval is required to do the TCL_DBGX substitution
343    eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
344    eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""
345
346    # If the TCL_BIN_DIR is the build directory (not the install directory),
347    # then set the common variable name to the value of the build variables.
348    # For example, the variable TCL_LIB_SPEC will be set to the value
349    # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC
350    # instead of TCL_BUILD_LIB_SPEC since it will work with both an
351    # installed and uninstalled version of Tcl.
352    if test -f "${TCL_BIN_DIR}/Makefile" ; then
353        TCL_LIB_SPEC=${TCL_BUILD_LIB_SPEC}
354        TCL_STUB_LIB_SPEC=${TCL_BUILD_STUB_LIB_SPEC}
355        TCL_STUB_LIB_PATH=${TCL_BUILD_STUB_LIB_PATH}
356    elif test "`uname -s`" = "Darwin"; then
357	# If Tcl was built as a framework, attempt to use the libraries
358	# from the framework at the given location so that linking works
359	# against Tcl.framework installed in an arbitary location.
360	case ${TCL_DEFS} in
361	    *TCL_FRAMEWORK*)
362		if test -f "${TCL_BIN_DIR}/${TCL_LIB_FILE}"; then
363		    for i in "`cd ${TCL_BIN_DIR}; pwd`" \
364			     "`cd ${TCL_BIN_DIR}/../..; pwd`"; do
365			if test "`basename "$i"`" = "${TCL_LIB_FILE}.framework"; then
366			    TCL_LIB_SPEC="-F`dirname "$i"` -framework ${TCL_LIB_FILE}"
367			    break
368			fi
369		    done
370		fi
371		if test -f "${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}"; then
372		    TCL_STUB_LIB_SPEC="-L${TCL_BIN_DIR} ${TCL_STUB_LIB_FLAG}"
373		    TCL_STUB_LIB_PATH="${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}"
374		fi
375		;;
376	esac
377    fi
378
379    # eval is required to do the TCL_DBGX substitution
380    eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
381    eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""
382    eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
383    eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""
384
385    AC_SUBST(TCL_VERSION)
386    AC_SUBST(TCL_BIN_DIR)
387    AC_SUBST(TCL_SRC_DIR)
388
389    AC_SUBST(TCL_LIB_FILE)
390    AC_SUBST(TCL_LIB_FLAG)
391    AC_SUBST(TCL_LIB_SPEC)
392
393    AC_SUBST(TCL_STUB_LIB_FILE)
394    AC_SUBST(TCL_STUB_LIB_FLAG)
395    AC_SUBST(TCL_STUB_LIB_SPEC)
396
397    # TEA specific:
398    AC_SUBST(TCL_LIBS)
399    AC_SUBST(TCL_DEFS)
400    AC_SUBST(TCL_EXTRA_CFLAGS)
401    AC_SUBST(TCL_LD_FLAGS)
402    AC_SUBST(TCL_SHLIB_LD_LIBS)
403])
404
405#------------------------------------------------------------------------
406# TEA_LOAD_TKCONFIG --
407#
408#	Load the tkConfig.sh file
409#
410# Arguments:
411#
412#	Requires the following vars to be set:
413#		TK_BIN_DIR
414#
415# Results:
416#
417#	Sets the following vars that should be in tkConfig.sh:
418#		TK_BIN_DIR
419#------------------------------------------------------------------------
420
421AC_DEFUN([TEA_LOAD_TKCONFIG], [
422    AC_MSG_CHECKING([for existence of ${TK_BIN_DIR}/tkConfig.sh])
423
424    if test -f "${TK_BIN_DIR}/tkConfig.sh" ; then
425        AC_MSG_RESULT([loading])
426	. "${TK_BIN_DIR}/tkConfig.sh"
427    else
428        AC_MSG_RESULT([could not find ${TK_BIN_DIR}/tkConfig.sh])
429    fi
430
431    # eval is required to do the TK_DBGX substitution
432    eval "TK_LIB_FILE=\"${TK_LIB_FILE}\""
433    eval "TK_STUB_LIB_FILE=\"${TK_STUB_LIB_FILE}\""
434
435    # If the TK_BIN_DIR is the build directory (not the install directory),
436    # then set the common variable name to the value of the build variables.
437    # For example, the variable TK_LIB_SPEC will be set to the value
438    # of TK_BUILD_LIB_SPEC. An extension should make use of TK_LIB_SPEC
439    # instead of TK_BUILD_LIB_SPEC since it will work with both an
440    # installed and uninstalled version of Tcl.
441    if test -f "${TK_BIN_DIR}/Makefile" ; then
442        TK_LIB_SPEC=${TK_BUILD_LIB_SPEC}
443        TK_STUB_LIB_SPEC=${TK_BUILD_STUB_LIB_SPEC}
444        TK_STUB_LIB_PATH=${TK_BUILD_STUB_LIB_PATH}
445    elif test "`uname -s`" = "Darwin"; then
446	# If Tk was built as a framework, attempt to use the libraries
447	# from the framework at the given location so that linking works
448	# against Tk.framework installed in an arbitary location.
449	case ${TK_DEFS} in
450	    *TK_FRAMEWORK*)
451		if test -f "${TK_BIN_DIR}/${TK_LIB_FILE}"; then
452		    for i in "`cd ${TK_BIN_DIR}; pwd`" \
453			     "`cd ${TK_BIN_DIR}/../..; pwd`"; do
454			if test "`basename "$i"`" = "${TK_LIB_FILE}.framework"; then
455			    TK_LIB_SPEC="-F`dirname "$i"` -framework ${TK_LIB_FILE}"
456			    break
457			fi
458		    done
459		fi
460		if test -f "${TK_BIN_DIR}/${TK_STUB_LIB_FILE}"; then
461		    TK_STUB_LIB_SPEC="-L${TK_BIN_DIR} ${TK_STUB_LIB_FLAG}"
462		    TK_STUB_LIB_PATH="${TK_BIN_DIR}/${TK_STUB_LIB_FILE}"
463		fi
464		;;
465	esac
466    fi
467
468    # eval is required to do the TK_DBGX substitution
469    eval "TK_LIB_FLAG=\"${TK_LIB_FLAG}\""
470    eval "TK_LIB_SPEC=\"${TK_LIB_SPEC}\""
471    eval "TK_STUB_LIB_FLAG=\"${TK_STUB_LIB_FLAG}\""
472    eval "TK_STUB_LIB_SPEC=\"${TK_STUB_LIB_SPEC}\""
473
474    # TEA specific: Ensure windowingsystem is defined
475    if test "${TEA_PLATFORM}" = "unix" ; then
476	case ${TK_DEFS} in
477	    *MAC_OSX_TK*)
478		AC_DEFINE(MAC_OSX_TK, 1, [Are we building against Mac OS X TkAqua?])
479		TEA_WINDOWINGSYSTEM="aqua"
480		;;
481	    *)
482		TEA_WINDOWINGSYSTEM="x11"
483		;;
484	esac
485    elif test "${TEA_PLATFORM}" = "windows" ; then
486	TEA_WINDOWINGSYSTEM="win32"
487    fi
488
489    AC_SUBST(TK_VERSION)
490    AC_SUBST(TK_BIN_DIR)
491    AC_SUBST(TK_SRC_DIR)
492
493    AC_SUBST(TK_LIB_FILE)
494    AC_SUBST(TK_LIB_FLAG)
495    AC_SUBST(TK_LIB_SPEC)
496
497    AC_SUBST(TK_STUB_LIB_FILE)
498    AC_SUBST(TK_STUB_LIB_FLAG)
499    AC_SUBST(TK_STUB_LIB_SPEC)
500
501    # TEA specific:
502    AC_SUBST(TK_LIBS)
503    AC_SUBST(TK_XINCLUDES)
504])
505
506#------------------------------------------------------------------------
507# TEA_PROG_TCLSH
508#	Determine the fully qualified path name of the tclsh executable
509#	in the Tcl build directory or the tclsh installed in a bin
510#	directory. This macro will correctly determine the name
511#	of the tclsh executable even if tclsh has not yet been
512#	built in the build directory. The tclsh found is always
513#	associated with a tclConfig.sh file. This tclsh should be used
514#	only for running extension test cases. It should never be
515#	or generation of files (like pkgIndex.tcl) at build time.
516#
517# Arguments
518#	none
519#
520# Results
521#	Subst's the following values:
522#		TCLSH_PROG
523#------------------------------------------------------------------------
524
525AC_DEFUN([TEA_PROG_TCLSH], [
526    AC_MSG_CHECKING([for tclsh])
527    if test -f "${TCL_BIN_DIR}/Makefile" ; then
528        # tclConfig.sh is in Tcl build directory
529        if test "${TEA_PLATFORM}" = "windows"; then
530            TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}"
531        else
532            TCLSH_PROG="${TCL_BIN_DIR}/tclsh"
533        fi
534    else
535        # tclConfig.sh is in install location
536        if test "${TEA_PLATFORM}" = "windows"; then
537            TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}"
538        else
539            TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}${TCL_DBGX}"
540        fi
541        list="`ls -d ${TCL_BIN_DIR}/../bin 2>/dev/null` \
542              `ls -d ${TCL_BIN_DIR}/..     2>/dev/null` \
543              `ls -d ${TCL_PREFIX}/bin     2>/dev/null`"
544        for i in $list ; do
545            if test -f "$i/${TCLSH_PROG}" ; then
546                REAL_TCL_BIN_DIR="`cd "$i"; pwd`/"
547                break
548            fi
549        done
550        TCLSH_PROG="${REAL_TCL_BIN_DIR}${TCLSH_PROG}"
551    fi
552    AC_MSG_RESULT([${TCLSH_PROG}])
553    AC_SUBST(TCLSH_PROG)
554])
555
556#------------------------------------------------------------------------
557# TEA_PROG_WISH
558#	Determine the fully qualified path name of the wish executable
559#	in the Tk build directory or the wish installed in a bin
560#	directory. This macro will correctly determine the name
561#	of the wish executable even if wish has not yet been
562#	built in the build directory. The wish found is always
563#	associated with a tkConfig.sh file. This wish should be used
564#	only for running extension test cases. It should never be
565#	or generation of files (like pkgIndex.tcl) at build time.
566#
567# Arguments
568#	none
569#
570# Results
571#	Subst's the following values:
572#		WISH_PROG
573#------------------------------------------------------------------------
574
575AC_DEFUN([TEA_PROG_WISH], [
576    AC_MSG_CHECKING([for wish])
577    if test -f "${TK_BIN_DIR}/Makefile" ; then
578        # tkConfig.sh is in Tk build directory
579        if test "${TEA_PLATFORM}" = "windows"; then
580            WISH_PROG="${TK_BIN_DIR}/wish${TK_MAJOR_VERSION}${TK_MINOR_VERSION}${TK_DBGX}${EXEEXT}"
581        else
582            WISH_PROG="${TK_BIN_DIR}/wish"
583        fi
584    else
585        # tkConfig.sh is in install location
586        if test "${TEA_PLATFORM}" = "windows"; then
587            WISH_PROG="wish${TK_MAJOR_VERSION}${TK_MINOR_VERSION}${TK_DBGX}${EXEEXT}"
588        else
589            WISH_PROG="wish${TK_MAJOR_VERSION}.${TK_MINOR_VERSION}${TK_DBGX}"
590        fi
591        list="`ls -d ${TK_BIN_DIR}/../bin 2>/dev/null` \
592              `ls -d ${TK_BIN_DIR}/..     2>/dev/null` \
593              `ls -d ${TK_PREFIX}/bin     2>/dev/null`"
594        for i in $list ; do
595            if test -f "$i/${WISH_PROG}" ; then
596                REAL_TK_BIN_DIR="`cd "$i"; pwd`/"
597                break
598            fi
599        done
600        WISH_PROG="${REAL_TK_BIN_DIR}${WISH_PROG}"
601    fi
602    AC_MSG_RESULT([${WISH_PROG}])
603    AC_SUBST(WISH_PROG)
604])
605
606#------------------------------------------------------------------------
607# TEA_ENABLE_SHARED --
608#
609#	Allows the building of shared libraries
610#
611# Arguments:
612#	none
613#
614# Results:
615#
616#	Adds the following arguments to configure:
617#		--enable-shared=yes|no
618#
619#	Defines the following vars:
620#		STATIC_BUILD	Used for building import/export libraries
621#				on Windows.
622#
623#	Sets the following vars:
624#		SHARED_BUILD	Value of 1 or 0
625#------------------------------------------------------------------------
626
627AC_DEFUN([TEA_ENABLE_SHARED], [
628    AC_MSG_CHECKING([how to build libraries])
629    AC_ARG_ENABLE(shared,
630	AC_HELP_STRING([--enable-shared],
631	    [build and link with shared libraries (default: on)]),
632	[tcl_ok=$enableval], [tcl_ok=yes])
633
634    if test "${enable_shared+set}" = set; then
635	enableval="$enable_shared"
636	tcl_ok=$enableval
637    else
638	tcl_ok=yes
639    fi
640
641    if test "$tcl_ok" = "yes" ; then
642	AC_MSG_RESULT([shared])
643	SHARED_BUILD=1
644    else
645	AC_MSG_RESULT([static])
646	SHARED_BUILD=0
647	AC_DEFINE(STATIC_BUILD, 1, [Is this a static build?])
648    fi
649    AC_SUBST(SHARED_BUILD)
650])
651
652#------------------------------------------------------------------------
653# TEA_ENABLE_THREADS --
654#
655#	Specify if thread support should be enabled.  If "yes" is specified
656#	as an arg (optional), threads are enabled by default, "no" means
657#	threads are disabled.  "yes" is the default.
658#
659#	TCL_THREADS is checked so that if you are compiling an extension
660#	against a threaded core, your extension must be compiled threaded
661#	as well.
662#
663#	Note that it is legal to have a thread enabled extension run in a
664#	threaded or non-threaded Tcl core, but a non-threaded extension may
665#	only run in a non-threaded Tcl core.
666#
667# Arguments:
668#	none
669#
670# Results:
671#
672#	Adds the following arguments to configure:
673#		--enable-threads
674#
675#	Sets the following vars:
676#		THREADS_LIBS	Thread library(s)
677#
678#	Defines the following vars:
679#		TCL_THREADS
680#		_REENTRANT
681#		_THREAD_SAFE
682#
683#------------------------------------------------------------------------
684
685AC_DEFUN([TEA_ENABLE_THREADS], [
686    AC_ARG_ENABLE(threads,
687	AC_HELP_STRING([--enable-threads],
688	    [build with threads]),
689	[tcl_ok=$enableval], [tcl_ok=yes])
690
691    if test "${enable_threads+set}" = set; then
692	enableval="$enable_threads"
693	tcl_ok=$enableval
694    else
695	tcl_ok=yes
696    fi
697
698    if test "$tcl_ok" = "yes" -o "${TCL_THREADS}" = 1; then
699	TCL_THREADS=1
700
701	if test "${TEA_PLATFORM}" != "windows" ; then
702	    # We are always OK on Windows, so check what this platform wants:
703
704	    # USE_THREAD_ALLOC tells us to try the special thread-based
705	    # allocator that significantly reduces lock contention
706	    AC_DEFINE(USE_THREAD_ALLOC, 1,
707		[Do we want to use the threaded memory allocator?])
708	    AC_DEFINE(_REENTRANT, 1, [Do we want the reentrant OS API?])
709	    if test "`uname -s`" = "SunOS" ; then
710		AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1,
711			[Do we really want to follow the standard? Yes we do!])
712	    fi
713	    AC_DEFINE(_THREAD_SAFE, 1, [Do we want the thread-safe OS API?])
714	    AC_CHECK_LIB(pthread,pthread_mutex_init,tcl_ok=yes,tcl_ok=no)
715	    if test "$tcl_ok" = "no"; then
716		# Check a little harder for __pthread_mutex_init in the same
717		# library, as some systems hide it there until pthread.h is
718		# defined.  We could alternatively do an AC_TRY_COMPILE with
719		# pthread.h, but that will work with libpthread really doesn't
720		# exist, like AIX 4.2.  [Bug: 4359]
721		AC_CHECK_LIB(pthread, __pthread_mutex_init,
722		    tcl_ok=yes, tcl_ok=no)
723	    fi
724
725	    if test "$tcl_ok" = "yes"; then
726		# The space is needed
727		THREADS_LIBS=" -lpthread"
728	    else
729		AC_CHECK_LIB(pthreads, pthread_mutex_init,
730		    tcl_ok=yes, tcl_ok=no)
731		if test "$tcl_ok" = "yes"; then
732		    # The space is needed
733		    THREADS_LIBS=" -lpthreads"
734		else
735		    AC_CHECK_LIB(c, pthread_mutex_init,
736			tcl_ok=yes, tcl_ok=no)
737		    if test "$tcl_ok" = "no"; then
738			AC_CHECK_LIB(c_r, pthread_mutex_init,
739			    tcl_ok=yes, tcl_ok=no)
740			if test "$tcl_ok" = "yes"; then
741			    # The space is needed
742			    THREADS_LIBS=" -pthread"
743			else
744			    TCL_THREADS=0
745			    AC_MSG_WARN([Do not know how to find pthread lib on your system - thread support disabled])
746			fi
747		    fi
748		fi
749	    fi
750	fi
751    else
752	TCL_THREADS=0
753    fi
754    # Do checking message here to not mess up interleaved configure output
755    AC_MSG_CHECKING([for building with threads])
756    if test "${TCL_THREADS}" = 1; then
757	AC_DEFINE(TCL_THREADS, 1, [Are we building with threads enabled?])
758	AC_MSG_RESULT([yes (default)])
759    else
760	AC_MSG_RESULT([no])
761    fi
762    # TCL_THREADS sanity checking.  See if our request for building with
763    # threads is the same as the way Tcl was built.  If not, warn the user.
764    case ${TCL_DEFS} in
765	*THREADS=1*)
766	    if test "${TCL_THREADS}" = "0"; then
767		AC_MSG_WARN([
768    Building ${PACKAGE_NAME} without threads enabled, but building against Tcl
769    that IS thread-enabled.  It is recommended to use --enable-threads.])
770	    fi
771	    ;;
772	*)
773	    if test "${TCL_THREADS}" = "1"; then
774		AC_MSG_WARN([
775    --enable-threads requested, but building against a Tcl that is NOT
776    thread-enabled.  This is an OK configuration that will also run in
777    a thread-enabled core.])
778	    fi
779	    ;;
780    esac
781    AC_SUBST(TCL_THREADS)
782])
783
784#------------------------------------------------------------------------
785# TEA_ENABLE_SYMBOLS --
786#
787#	Specify if debugging symbols should be used.
788#	Memory (TCL_MEM_DEBUG) debugging can also be enabled.
789#
790# Arguments:
791#	none
792#
793#	TEA varies from core Tcl in that C|LDFLAGS_DEFAULT receives
794#	the value of C|LDFLAGS_OPTIMIZE|DEBUG already substituted.
795#	Requires the following vars to be set in the Makefile:
796#		CFLAGS_DEFAULT
797#		LDFLAGS_DEFAULT
798#
799# Results:
800#
801#	Adds the following arguments to configure:
802#		--enable-symbols
803#
804#	Defines the following vars:
805#		CFLAGS_DEFAULT	Sets to $(CFLAGS_DEBUG) if true
806#				Sets to $(CFLAGS_OPTIMIZE) if false
807#		LDFLAGS_DEFAULT	Sets to $(LDFLAGS_DEBUG) if true
808#				Sets to $(LDFLAGS_OPTIMIZE) if false
809#		DBGX		Formerly used as debug library extension;
810#				always blank now.
811#
812#------------------------------------------------------------------------
813
814AC_DEFUN([TEA_ENABLE_SYMBOLS], [
815    dnl TEA specific: Make sure we are initialized
816    AC_REQUIRE([TEA_CONFIG_CFLAGS])
817    AC_MSG_CHECKING([for build with symbols])
818    AC_ARG_ENABLE(symbols,
819	AC_HELP_STRING([--enable-symbols],
820	    [build with debugging symbols (default: off)]),
821	[tcl_ok=$enableval], [tcl_ok=no])
822    DBGX=""
823    if test "$tcl_ok" = "no"; then
824	CFLAGS_DEFAULT="${CFLAGS_OPTIMIZE}"
825	LDFLAGS_DEFAULT="${LDFLAGS_OPTIMIZE}"
826	AC_MSG_RESULT([no])
827    else
828	CFLAGS_DEFAULT="${CFLAGS_DEBUG}"
829	LDFLAGS_DEFAULT="${LDFLAGS_DEBUG}"
830	if test "$tcl_ok" = "yes"; then
831	    AC_MSG_RESULT([yes (standard debugging)])
832	fi
833    fi
834    # TEA specific:
835    if test "${TEA_PLATFORM}" != "windows" ; then
836	LDFLAGS_DEFAULT="${LDFLAGS}"
837    fi
838    AC_SUBST(CFLAGS_DEFAULT)
839    AC_SUBST(LDFLAGS_DEFAULT)
840    AC_SUBST(TCL_DBGX)
841
842    if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then
843	AC_DEFINE(TCL_MEM_DEBUG, 1, [Is memory debugging enabled?])
844    fi
845
846    if test "$tcl_ok" != "yes" -a "$tcl_ok" != "no"; then
847	if test "$tcl_ok" = "all"; then
848	    AC_MSG_RESULT([enabled symbols mem debugging])
849	else
850	    AC_MSG_RESULT([enabled $tcl_ok debugging])
851	fi
852    fi
853])
854
855#------------------------------------------------------------------------
856# TEA_ENABLE_LANGINFO --
857#
858#	Allows use of modern nl_langinfo check for better l10n.
859#	This is only relevant for Unix.
860#
861# Arguments:
862#	none
863#
864# Results:
865#
866#	Adds the following arguments to configure:
867#		--enable-langinfo=yes|no (default is yes)
868#
869#	Defines the following vars:
870#		HAVE_LANGINFO	Triggers use of nl_langinfo if defined.
871#
872#------------------------------------------------------------------------
873
874AC_DEFUN([TEA_ENABLE_LANGINFO], [
875    AC_ARG_ENABLE(langinfo,
876	AC_HELP_STRING([--enable-langinfo],
877	    [use nl_langinfo if possible to determine encoding at startup, otherwise use old heuristic (default: on)]),
878	[langinfo_ok=$enableval], [langinfo_ok=yes])
879
880    HAVE_LANGINFO=0
881    if test "$langinfo_ok" = "yes"; then
882	AC_CHECK_HEADER(langinfo.h,[langinfo_ok=yes],[langinfo_ok=no])
883    fi
884    AC_MSG_CHECKING([whether to use nl_langinfo])
885    if test "$langinfo_ok" = "yes"; then
886	AC_CACHE_VAL(tcl_cv_langinfo_h, [
887	    AC_TRY_COMPILE([#include <langinfo.h>], [nl_langinfo(CODESET);],
888		    [tcl_cv_langinfo_h=yes],[tcl_cv_langinfo_h=no])])
889	AC_MSG_RESULT([$tcl_cv_langinfo_h])
890	if test $tcl_cv_langinfo_h = yes; then
891	    AC_DEFINE(HAVE_LANGINFO, 1, [Do we have nl_langinfo()?])
892	fi
893    else
894	AC_MSG_RESULT([$langinfo_ok])
895    fi
896])
897
898#--------------------------------------------------------------------
899# TEA_CONFIG_SYSTEM
900#
901#	Determine what the system is (some things cannot be easily checked
902#	on a feature-driven basis, alas). This can usually be done via the
903#	"uname" command, but there are a few systems, like Next, where
904#	this doesn't work.
905#
906# Arguments:
907#	none
908#
909# Results:
910#	Defines the following var:
911#
912#	system -	System/platform/version identification code.
913#
914#--------------------------------------------------------------------
915
916AC_DEFUN([TEA_CONFIG_SYSTEM], [
917    AC_CACHE_CHECK([system version], tcl_cv_sys_version, [
918	# TEA specific:
919	if test "${TEA_PLATFORM}" = "windows" ; then
920	    tcl_cv_sys_version=windows
921	elif test -f /usr/lib/NextStep/software_version; then
922	    tcl_cv_sys_version=NEXTSTEP-`awk '/3/,/3/' /usr/lib/NextStep/software_version`
923	else
924	    tcl_cv_sys_version=`uname -s`-`uname -r`
925	    if test "$?" -ne 0 ; then
926		AC_MSG_WARN([can't find uname command])
927		tcl_cv_sys_version=unknown
928	    else
929		# Special check for weird MP-RAS system (uname returns weird
930		# results, and the version is kept in special file).
931
932		if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
933		    tcl_cv_sys_version=MP-RAS-`awk '{print $[3]}' /etc/.relid`
934		fi
935		if test "`uname -s`" = "AIX" ; then
936		    tcl_cv_sys_version=AIX-`uname -v`.`uname -r`
937		fi
938	    fi
939	fi
940    ])
941    system=$tcl_cv_sys_version
942])
943
944#--------------------------------------------------------------------
945# TEA_CONFIG_CFLAGS
946#
947#	Try to determine the proper flags to pass to the compiler
948#	for building shared libraries and other such nonsense.
949#
950# Arguments:
951#	none
952#
953# Results:
954#
955#	Defines and substitutes the following vars:
956#
957#       DL_OBJS -       Name of the object file that implements dynamic
958#                       loading for Tcl on this system.
959#       DL_LIBS -       Library file(s) to include in tclsh and other base
960#                       applications in order for the "load" command to work.
961#       LDFLAGS -      Flags to pass to the compiler when linking object
962#                       files into an executable application binary such
963#                       as tclsh.
964#       LD_SEARCH_FLAGS-Flags to pass to ld, such as "-R /usr/local/tcl/lib",
965#                       that tell the run-time dynamic linker where to look
966#                       for shared libraries such as libtcl.so.  Depends on
967#                       the variable LIB_RUNTIME_DIR in the Makefile. Could
968#                       be the same as CC_SEARCH_FLAGS if ${CC} is used to link.
969#       CC_SEARCH_FLAGS-Flags to pass to ${CC}, such as "-Wl,-rpath,/usr/local/tcl/lib",
970#                       that tell the run-time dynamic linker where to look
971#                       for shared libraries such as libtcl.so.  Depends on
972#                       the variable LIB_RUNTIME_DIR in the Makefile.
973#       SHLIB_CFLAGS -  Flags to pass to cc when compiling the components
974#                       of a shared library (may request position-independent
975#                       code, among other things).
976#       SHLIB_LD -      Base command to use for combining object files
977#                       into a shared library.
978#       SHLIB_LD_LIBS - Dependent libraries for the linker to scan when
979#                       creating shared libraries.  This symbol typically
980#                       goes at the end of the "ld" commands that build
981#                       shared libraries. The value of the symbol is
982#                       "${LIBS}" if all of the dependent libraries should
983#                       be specified when creating a shared library.  If
984#                       dependent libraries should not be specified (as on
985#                       SunOS 4.x, where they cause the link to fail, or in
986#                       general if Tcl and Tk aren't themselves shared
987#                       libraries), then this symbol has an empty string
988#                       as its value.
989#       SHLIB_SUFFIX -  Suffix to use for the names of dynamically loadable
990#                       extensions.  An empty string means we don't know how
991#                       to use shared libraries on this platform.
992#       LIB_SUFFIX -    Specifies everything that comes after the "libfoo"
993#                       in a static or shared library name, using the $VERSION variable
994#                       to put the version in the right place.  This is used
995#                       by platforms that need non-standard library names.
996#                       Examples:  ${VERSION}.so.1.1 on NetBSD, since it needs
997#                       to have a version after the .so, and ${VERSION}.a
998#                       on AIX, since a shared library needs to have
999#                       a .a extension whereas shared objects for loadable
1000#                       extensions have a .so extension.  Defaults to
1001#                       ${VERSION}${SHLIB_SUFFIX}.
1002#       TCL_NEEDS_EXP_FILE -
1003#                       1 means that an export file is needed to link to a
1004#                       shared library.
1005#       TCL_EXP_FILE -  The name of the installed export / import file which
1006#                       should be used to link to the Tcl shared library.
1007#                       Empty if Tcl is unshared.
1008#       TCL_BUILD_EXP_FILE -
1009#                       The name of the built export / import file which
1010#                       should be used to link to the Tcl shared library.
1011#                       Empty if Tcl is unshared.
1012#	CFLAGS_DEBUG -
1013#			Flags used when running the compiler in debug mode
1014#	CFLAGS_OPTIMIZE -
1015#			Flags used when running the compiler in optimize mode
1016#	CFLAGS -	Additional CFLAGS added as necessary (usually 64-bit)
1017#
1018#--------------------------------------------------------------------
1019
1020AC_DEFUN([TEA_CONFIG_CFLAGS], [
1021    dnl TEA specific: Make sure we are initialized
1022    AC_REQUIRE([TEA_INIT])
1023
1024    # Step 0.a: Enable 64 bit support?
1025
1026    AC_MSG_CHECKING([if 64bit support is requested])
1027    AC_ARG_ENABLE(64bit,
1028	AC_HELP_STRING([--enable-64bit],
1029	    [enable 64bit support (default: off)]),
1030	[do64bit=$enableval], [do64bit=no])
1031    AC_MSG_RESULT([$do64bit])
1032
1033    # Step 0.b: Enable Solaris 64 bit VIS support?
1034
1035    AC_MSG_CHECKING([if 64bit Sparc VIS support is requested])
1036    AC_ARG_ENABLE(64bit-vis,
1037	AC_HELP_STRING([--enable-64bit-vis],
1038	    [enable 64bit Sparc VIS support (default: off)]),
1039	[do64bitVIS=$enableval], [do64bitVIS=no])
1040    AC_MSG_RESULT([$do64bitVIS])
1041    # Force 64bit on with VIS
1042    AS_IF([test "$do64bitVIS" = "yes"], [do64bit=yes])
1043
1044    # Step 0.c: Check if visibility support is available. Do this here so
1045    # that platform specific alternatives can be used below if this fails.
1046
1047    AC_CACHE_CHECK([if compiler supports visibility "hidden"],
1048	tcl_cv_cc_visibility_hidden, [
1049	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
1050	AC_TRY_LINK([
1051	    extern __attribute__((__visibility__("hidden"))) void f(void);
1052	    void f(void) {}], [f();], tcl_cv_cc_visibility_hidden=yes,
1053	    tcl_cv_cc_visibility_hidden=no)
1054	CFLAGS=$hold_cflags])
1055    AS_IF([test $tcl_cv_cc_visibility_hidden = yes], [
1056	AC_DEFINE(MODULE_SCOPE,
1057	    [extern __attribute__((__visibility__("hidden")))],
1058	    [Compiler support for module scope symbols])
1059    ])
1060
1061    # Step 0.d: Disable -rpath support?
1062
1063    AC_MSG_CHECKING([if rpath support is requested])
1064    AC_ARG_ENABLE(rpath,
1065	AC_HELP_STRING([--disable-rpath],
1066	    [disable rpath support (default: on)]),
1067	[doRpath=$enableval], [doRpath=yes])
1068    AC_MSG_RESULT([$doRpath])
1069
1070    # TEA specific: Cross-compiling options for Windows/CE builds?
1071
1072    AS_IF([test "${TEA_PLATFORM}" = windows], [
1073	AC_MSG_CHECKING([if Windows/CE build is requested])
1074	AC_ARG_ENABLE(wince,
1075	    AC_HELP_STRING([--enable-wince],
1076		[enable Win/CE support (where applicable)]),
1077	    [doWince=$enableval], [doWince=no])
1078	AC_MSG_RESULT([$doWince])
1079    ])
1080
1081    # Step 1: set the variable "system" to hold the name and version number
1082    # for the system.
1083
1084    TEA_CONFIG_SYSTEM
1085
1086    # Step 2: check for existence of -ldl library.  This is needed because
1087    # Linux can use either -ldl or -ldld for dynamic loading.
1088
1089    AC_CHECK_LIB(dl, dlopen, have_dl=yes, have_dl=no)
1090
1091    # Require ranlib early so we can override it in special cases below.
1092
1093    AC_REQUIRE([AC_PROG_RANLIB])
1094
1095    # Step 3: set configuration options based on system name and version.
1096    # This is similar to Tcl's unix/tcl.m4 except that we've added a
1097    # "windows" case.
1098
1099    do64bit_ok=no
1100    LDFLAGS_ORIG="$LDFLAGS"
1101    # When ld needs options to work in 64-bit mode, put them in
1102    # LDFLAGS_ARCH so they eventually end up in LDFLAGS even if [load]
1103    # is disabled by the user. [Bug 1016796]
1104    LDFLAGS_ARCH=""
1105    TCL_EXPORT_FILE_SUFFIX=""
1106    UNSHARED_LIB_SUFFIX=""
1107    # TEA specific: use PACKAGE_VERSION instead of VERSION
1108    TCL_TRIM_DOTS='`echo ${PACKAGE_VERSION} | tr -d .`'
1109    ECHO_VERSION='`echo ${PACKAGE_VERSION}`'
1110    TCL_LIB_VERSIONS_OK=ok
1111    CFLAGS_DEBUG=-g
1112    CFLAGS_OPTIMIZE=-O
1113    AS_IF([test "$GCC" = yes], [
1114	# TEA specific:
1115	CFLAGS_OPTIMIZE=-O2
1116	CFLAGS_WARNING="-Wall -Wno-implicit-int"
1117    ], [CFLAGS_WARNING=""])
1118    TCL_NEEDS_EXP_FILE=0
1119    TCL_BUILD_EXP_FILE=""
1120    TCL_EXP_FILE=""
1121dnl FIXME: Replace AC_CHECK_PROG with AC_CHECK_TOOL once cross compiling is fixed.
1122dnl AC_CHECK_TOOL(AR, ar)
1123    AC_CHECK_PROG(AR, ar, ar)
1124    STLIB_LD='${AR} cr'
1125    LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH"
1126    case $system in
1127	# TEA specific:
1128	windows)
1129	    # This is a 2-stage check to make sure we have the 64-bit SDK
1130	    # We have to know where the SDK is installed.
1131	    # This magic is based on MS Platform SDK for Win2003 SP1 - hobbs
1132	    # MACHINE is IX86 for LINK, but this is used by the manifest,
1133	    # which requires x86|amd64|ia64.
1134	    MACHINE="X86"
1135	    if test "$do64bit" != "no" ; then
1136		if test "x${MSSDK}x" = "xx" ; then
1137		    MSSDK="C:/Progra~1/Microsoft Platform SDK"
1138		fi
1139		MSSDK=`echo "$MSSDK" | sed -e  's!\\\!/!g'`
1140		PATH64=""
1141		case "$do64bit" in
1142		    amd64|x64|yes)
1143			MACHINE="AMD64" ; # default to AMD64 64-bit build
1144			PATH64="${MSSDK}/Bin/Win64/x86/AMD64"
1145			;;
1146		    ia64)
1147			MACHINE="IA64"
1148			PATH64="${MSSDK}/Bin/Win64"
1149			;;
1150		esac
1151		if test ! -d "${PATH64}" ; then
1152		    AC_MSG_WARN([Could not find 64-bit $MACHINE SDK to enable 64bit mode])
1153		    AC_MSG_WARN([Ensure latest Platform SDK is installed])
1154		    do64bit="no"
1155		else
1156		    AC_MSG_RESULT([   Using 64-bit $MACHINE mode])
1157		    do64bit_ok="yes"
1158		fi
1159	    fi
1160
1161	    if test "$doWince" != "no" ; then
1162		if test "$do64bit" != "no" ; then
1163		    AC_MSG_ERROR([Windows/CE and 64-bit builds incompatible])
1164		fi
1165		if test "$GCC" = "yes" ; then
1166		    AC_MSG_ERROR([Windows/CE and GCC builds incompatible])
1167		fi
1168		TEA_PATH_CELIB
1169		# Set defaults for common evc4/PPC2003 setup
1170		# Currently Tcl requires 300+, possibly 420+ for sockets
1171		CEVERSION=420; 		# could be 211 300 301 400 420 ...
1172		TARGETCPU=ARMV4;	# could be ARMV4 ARM MIPS SH3 X86 ...
1173		ARCH=ARM;		# could be ARM MIPS X86EM ...
1174		PLATFORM="Pocket PC 2003"; # or "Pocket PC 2002"
1175		if test "$doWince" != "yes"; then
1176		    # If !yes then the user specified something
1177		    # Reset ARCH to allow user to skip specifying it
1178		    ARCH=
1179		    eval `echo $doWince | awk -F, '{ \
1180	    if (length([$]1)) { printf "CEVERSION=\"%s\"\n", [$]1; \
1181	    if ([$]1 < 400)   { printf "PLATFORM=\"Pocket PC 2002\"\n" } }; \
1182	    if (length([$]2)) { printf "TARGETCPU=\"%s\"\n", toupper([$]2) }; \
1183	    if (length([$]3)) { printf "ARCH=\"%s\"\n", toupper([$]3) }; \
1184	    if (length([$]4)) { printf "PLATFORM=\"%s\"\n", [$]4 }; \
1185		    }'`
1186		    if test "x${ARCH}" = "x" ; then
1187			ARCH=$TARGETCPU;
1188		    fi
1189		fi
1190		OSVERSION=WCE$CEVERSION;
1191	    	if test "x${WCEROOT}" = "x" ; then
1192			WCEROOT="C:/Program Files/Microsoft eMbedded C++ 4.0"
1193		    if test ! -d "${WCEROOT}" ; then
1194			WCEROOT="C:/Program Files/Microsoft eMbedded Tools"
1195		    fi
1196		fi
1197		if test "x${SDKROOT}" = "x" ; then
1198		    SDKROOT="C:/Program Files/Windows CE Tools"
1199		    if test ! -d "${SDKROOT}" ; then
1200			SDKROOT="C:/Windows CE Tools"
1201		    fi
1202		fi
1203		WCEROOT=`echo "$WCEROOT" | sed -e 's!\\\!/!g'`
1204		SDKROOT=`echo "$SDKROOT" | sed -e 's!\\\!/!g'`
1205		if test ! -d "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}" \
1206		    -o ! -d "${WCEROOT}/EVC/${OSVERSION}/bin"; then
1207		    AC_MSG_ERROR([could not find PocketPC SDK or target compiler to enable WinCE mode [$CEVERSION,$TARGETCPU,$ARCH,$PLATFORM]])
1208		    doWince="no"
1209		else
1210		    # We could PATH_NOSPACE these, but that's not important,
1211		    # as long as we quote them when used.
1212		    CEINCLUDE="${SDKROOT}/${OSVERSION}/${PLATFORM}/include"
1213		    if test -d "${CEINCLUDE}/${TARGETCPU}" ; then
1214			CEINCLUDE="${CEINCLUDE}/${TARGETCPU}"
1215		    fi
1216		    CELIBPATH="${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}"
1217    		fi
1218	    fi
1219
1220	    if test "$GCC" != "yes" ; then
1221	        if test "${SHARED_BUILD}" = "0" ; then
1222		    runtime=-MT
1223	        else
1224		    runtime=-MD
1225	        fi
1226
1227                if test "$do64bit" != "no" ; then
1228		    # All this magic is necessary for the Win64 SDK RC1 - hobbs
1229		    CC="\"${PATH64}/cl.exe\""
1230		    CFLAGS="${CFLAGS} -I\"${MSSDK}/Include\" -I\"${MSSDK}/Include/crt\" -I\"${MSSDK}/Include/crt/sys\""
1231		    RC="\"${MSSDK}/bin/rc.exe\""
1232		    lflags="-nologo -MACHINE:${MACHINE} -LIBPATH:\"${MSSDK}/Lib/${MACHINE}\""
1233		    LINKBIN="\"${PATH64}/link.exe\""
1234		    CFLAGS_DEBUG="-nologo -Zi -Od -W3 ${runtime}d"
1235		    CFLAGS_OPTIMIZE="-nologo -O2 -W2 ${runtime}"
1236		    # Avoid 'unresolved external symbol __security_cookie'
1237		    # errors, c.f. http://support.microsoft.com/?id=894573
1238		    TEA_ADD_LIBS([bufferoverflowU.lib])
1239		elif test "$doWince" != "no" ; then
1240		    CEBINROOT="${WCEROOT}/EVC/${OSVERSION}/bin"
1241		    if test "${TARGETCPU}" = "X86"; then
1242			CC="\"${CEBINROOT}/cl.exe\""
1243		    else
1244			CC="\"${CEBINROOT}/cl${ARCH}.exe\""
1245		    fi
1246		    CFLAGS="$CFLAGS -I\"${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\""
1247		    RC="\"${WCEROOT}/Common/EVC/bin/rc.exe\""
1248		    arch=`echo ${ARCH} | awk '{print tolower([$]0)}'`
1249		    defs="${ARCH} _${ARCH}_ ${arch} PALM_SIZE _MT _WINDOWS"
1250		    if test "${SHARED_BUILD}" = "1" ; then
1251			# Static CE builds require static celib as well
1252		    	defs="${defs} _DLL"
1253		    fi
1254		    for i in $defs ; do
1255			AC_DEFINE_UNQUOTED($i, 1, [WinCE def ]$i)
1256		    done
1257		    AC_DEFINE_UNQUOTED(_WIN32_WCE, $CEVERSION, [_WIN32_WCE version])
1258		    AC_DEFINE_UNQUOTED(UNDER_CE, $CEVERSION, [UNDER_CE version])
1259		    CFLAGS_DEBUG="-nologo -Zi -Od"
1260		    CFLAGS_OPTIMIZE="-nologo -Ox"
1261		    lversion=`echo ${CEVERSION} | sed -e 's/\(.\)\(..\)/\1\.\2/'`
1262		    lflags="-MACHINE:${ARCH} -LIBPATH:\"${CELIBPATH}\" -subsystem:windowsce,${lversion} -nologo"
1263		    LINKBIN="\"${CEBINROOT}/link.exe\""
1264		    AC_SUBST(CELIB_DIR)
1265		else
1266		    RC="rc"
1267		    lflags="-nologo"
1268    		    LINKBIN="link"
1269		    CFLAGS_DEBUG="-nologo -Z7 -Od -W3 -WX ${runtime}d"
1270		    CFLAGS_OPTIMIZE="-nologo -O2 -W2 ${runtime}"
1271		fi
1272	    fi
1273
1274	    if test "$GCC" = "yes"; then
1275		# mingw gcc mode
1276		RC="windres"
1277		CFLAGS_DEBUG="-g"
1278		CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer"
1279		SHLIB_LD="$CC -shared"
1280		UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1281		LDFLAGS_CONSOLE="-wl,--subsystem,console ${lflags}"
1282		LDFLAGS_WINDOW="-wl,--subsystem,windows ${lflags}"
1283	    else
1284		SHLIB_LD="${LINKBIN} -dll ${lflags}"
1285		# link -lib only works when -lib is the first arg
1286		STLIB_LD="${LINKBIN} -lib ${lflags}"
1287		UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.lib'
1288		PATHTYPE=-w
1289		# For information on what debugtype is most useful, see:
1290		# http://msdn.microsoft.com/library/en-us/dnvc60/html/gendepdebug.asp
1291		# and also
1292		# http://msdn2.microsoft.com/en-us/library/y0zzbyt4%28VS.80%29.aspx
1293		# This essentially turns it all on.
1294		LDFLAGS_DEBUG="-debug -debugtype:cv"
1295		LDFLAGS_OPTIMIZE="-release"
1296		if test "$doWince" != "no" ; then
1297		    LDFLAGS_CONSOLE="-link ${lflags}"
1298		    LDFLAGS_WINDOW=${LDFLAGS_CONSOLE}
1299		else
1300		    LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}"
1301		    LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}"
1302		fi
1303	    fi
1304
1305	    SHLIB_LD_LIBS='${LIBS}'
1306	    SHLIB_SUFFIX=".dll"
1307	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.dll'
1308
1309	    TCL_LIB_VERSIONS_OK=nodots
1310	    # Bogus to avoid getting this turned off
1311	    DL_OBJS="tclLoadNone.obj"
1312    	    ;;
1313	AIX-*)
1314	    AS_IF([test "${TCL_THREADS}" = "1" -a "$GCC" != "yes"], [
1315		# AIX requires the _r compiler when gcc isn't being used
1316		case "${CC}" in
1317		    *_r)
1318			# ok ...
1319			;;
1320		    *)
1321			CC=${CC}_r
1322			;;
1323		esac
1324		AC_MSG_RESULT([Using $CC for compiling with threads])
1325	    ])
1326	    LIBS="$LIBS -lc"
1327	    SHLIB_CFLAGS=""
1328	    SHLIB_LD_LIBS='${LIBS}'
1329	    SHLIB_SUFFIX=".so"
1330
1331	    DL_OBJS="tclLoadDl.o"
1332	    LD_LIBRARY_PATH_VAR="LIBPATH"
1333
1334	    # Check to enable 64-bit flags for compiler/linker on AIX 4+
1335	    AS_IF([test "$do64bit" = yes -a "`uname -v`" -gt 3], [
1336		AS_IF([test "$GCC" = yes], [
1337		    AC_MSG_WARN([64bit mode not supported with GCC on $system])
1338		], [
1339		    do64bit_ok=yes
1340		    CFLAGS="$CFLAGS -q64"
1341		    LDFLAGS_ARCH="-q64"
1342		    RANLIB="${RANLIB} -X64"
1343		    AR="${AR} -X64"
1344		    SHLIB_LD_FLAGS="-b64"
1345		])
1346	    ])
1347
1348	    AS_IF([test "`uname -m`" = ia64], [
1349		# AIX-5 uses ELF style dynamic libraries on IA-64, but not PPC
1350		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
1351		# AIX-5 has dl* in libc.so
1352		DL_LIBS=""
1353		AS_IF([test "$GCC" = yes], [
1354		    CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
1355		], [
1356		    CC_SEARCH_FLAGS='-R${LIB_RUNTIME_DIR}'
1357		])
1358		LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}'
1359	    ], [
1360		AS_IF([test "$GCC" = yes], [SHLIB_LD='${CC} -shared'], [
1361		    SHLIB_LD="/bin/ld -bhalt:4 -bM:SRE -bE:lib.exp -H512 -T512 -bnoentry"
1362		])
1363		SHLIB_LD="${TCL_SRC_DIR}/unix/ldAix ${SHLIB_LD} ${SHLIB_LD_FLAGS}"
1364		DL_LIBS="-ldl"
1365		CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
1366		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1367		TCL_NEEDS_EXP_FILE=1
1368		# TEA specific: use PACKAGE_VERSION instead of VERSION
1369		TCL_EXPORT_FILE_SUFFIX='${PACKAGE_VERSION}.exp'
1370	    ])
1371
1372	    # AIX v<=4.1 has some different flags than 4.2+
1373	    AS_IF([test "$system" = "AIX-4.1" -o "`uname -v`" -lt 4], [
1374		AC_LIBOBJ([tclLoadAix])
1375		DL_LIBS="-lld"
1376	    ])
1377
1378	    # On AIX <=v4 systems, libbsd.a has to be linked in to support
1379	    # non-blocking file IO.  This library has to be linked in after
1380	    # the MATH_LIBS or it breaks the pow() function.  The way to
1381	    # insure proper sequencing, is to add it to the tail of MATH_LIBS.
1382	    # This library also supplies gettimeofday.
1383	    #
1384	    # AIX does not have a timezone field in struct tm. When the AIX
1385	    # bsd library is used, the timezone global and the gettimeofday
1386	    # methods are to be avoided for timezone deduction instead, we
1387	    # deduce the timezone by comparing the localtime result on a
1388	    # known GMT value.
1389
1390	    AC_CHECK_LIB(bsd, gettimeofday, libbsd=yes, libbsd=no)
1391	    AS_IF([test $libbsd = yes], [
1392	    	MATH_LIBS="$MATH_LIBS -lbsd"
1393	    	AC_DEFINE(USE_DELTA_FOR_TZ, 1, [Do we need a special AIX hack for timezones?])
1394	    ])
1395	    ;;
1396	BeOS*)
1397	    SHLIB_CFLAGS="-fPIC"
1398	    SHLIB_LD='${CC} -nostart'
1399	    SHLIB_LD_LIBS='${LIBS}'
1400	    SHLIB_SUFFIX=".so"
1401	    DL_OBJS="tclLoadDl.o"
1402	    DL_LIBS="-ldl"
1403
1404	    #-----------------------------------------------------------
1405	    # Check for inet_ntoa in -lbind, for BeOS (which also needs
1406	    # -lsocket, even if the network functions are in -lnet which
1407	    # is always linked to, for compatibility.
1408	    #-----------------------------------------------------------
1409	    AC_CHECK_LIB(bind, inet_ntoa, [LIBS="$LIBS -lbind -lsocket"])
1410	    ;;
1411	BSD/OS-2.1*|BSD/OS-3*)
1412	    SHLIB_CFLAGS=""
1413	    SHLIB_LD="shlicc -r"
1414	    SHLIB_LD_LIBS='${LIBS}'
1415	    SHLIB_SUFFIX=".so"
1416	    DL_OBJS="tclLoadDl.o"
1417	    DL_LIBS="-ldl"
1418	    CC_SEARCH_FLAGS=""
1419	    LD_SEARCH_FLAGS=""
1420	    ;;
1421	BSD/OS-4.*)
1422	    SHLIB_CFLAGS="-export-dynamic -fPIC"
1423	    SHLIB_LD='${CC} -shared'
1424	    SHLIB_LD_LIBS='${LIBS}'
1425	    SHLIB_SUFFIX=".so"
1426	    DL_OBJS="tclLoadDl.o"
1427	    DL_LIBS="-ldl"
1428	    LDFLAGS="$LDFLAGS -export-dynamic"
1429	    CC_SEARCH_FLAGS=""
1430	    LD_SEARCH_FLAGS=""
1431	    ;;
1432	dgux*)
1433	    SHLIB_CFLAGS="-K PIC"
1434	    SHLIB_LD='${CC} -G'
1435	    SHLIB_LD_LIBS=""
1436	    SHLIB_SUFFIX=".so"
1437	    DL_OBJS="tclLoadDl.o"
1438	    DL_LIBS="-ldl"
1439	    CC_SEARCH_FLAGS=""
1440	    LD_SEARCH_FLAGS=""
1441	    ;;
1442	HP-UX-*.11.*)
1443	    # Use updated header definitions where possible
1444	    AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, [Do we want to use the XOPEN network library?])
1445	    # TEA specific: Needed by Tcl, but not most extensions
1446	    #AC_DEFINE(_XOPEN_SOURCE, 1, [Do we want to use the XOPEN network library?])
1447	    #LIBS="$LIBS -lxnet"               # Use the XOPEN network library
1448
1449	    AS_IF([test "`uname -m`" = ia64], [
1450		SHLIB_SUFFIX=".so"
1451		# Use newer C++ library for C++ extensions
1452		#if test "$GCC" != "yes" ; then
1453		#   CPPFLAGS="-AA"
1454		#fi
1455	    ], [
1456		SHLIB_SUFFIX=".sl"
1457	    ])
1458	    AC_CHECK_LIB(dld, shl_load, tcl_ok=yes, tcl_ok=no)
1459	    AS_IF([test "$tcl_ok" = yes], [
1460		SHLIB_CFLAGS="+z"
1461		SHLIB_LD="ld -b"
1462		SHLIB_LD_LIBS='${LIBS}'
1463		DL_OBJS="tclLoadShl.o"
1464		DL_LIBS="-ldld"
1465		LDFLAGS="$LDFLAGS -Wl,-E"
1466		CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.'
1467		LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:.'
1468		LD_LIBRARY_PATH_VAR="SHLIB_PATH"
1469	    ])
1470	    AS_IF([test "$GCC" = yes], [
1471		SHLIB_LD='${CC} -shared'
1472		SHLIB_LD_LIBS='${LIBS}'
1473		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1474	    ])
1475
1476	    # Users may want PA-RISC 1.1/2.0 portable code - needs HP cc
1477	    #CFLAGS="$CFLAGS +DAportable"
1478
1479	    # Check to enable 64-bit flags for compiler/linker
1480	    AS_IF([test "$do64bit" = "yes"], [
1481		AS_IF([test "$GCC" = yes], [
1482		    case `${CC} -dumpmachine` in
1483			hppa64*)
1484			    # 64-bit gcc in use.  Fix flags for GNU ld.
1485			    do64bit_ok=yes
1486			    SHLIB_LD='${CC} -shared'
1487			    SHLIB_LD_LIBS='${LIBS}'
1488			    AS_IF([test $doRpath = yes], [
1489				CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
1490			    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1491			    ;;
1492			*)
1493			    AC_MSG_WARN([64bit mode not supported with GCC on $system])
1494			    ;;
1495		    esac
1496		], [
1497		    do64bit_ok=yes
1498		    CFLAGS="$CFLAGS +DD64"
1499		    LDFLAGS_ARCH="+DD64"
1500		])
1501	    ]) ;;
1502	HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*)
1503	    SHLIB_SUFFIX=".sl"
1504	    AC_CHECK_LIB(dld, shl_load, tcl_ok=yes, tcl_ok=no)
1505	    AS_IF([test "$tcl_ok" = yes], [
1506		SHLIB_CFLAGS="+z"
1507		SHLIB_LD="ld -b"
1508		SHLIB_LD_LIBS=""
1509		DL_OBJS="tclLoadShl.o"
1510		DL_LIBS="-ldld"
1511		LDFLAGS="$LDFLAGS -Wl,-E"
1512		CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.'
1513		LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:.'
1514		LD_LIBRARY_PATH_VAR="SHLIB_PATH"
1515	    ]) ;;
1516	IRIX-5.*)
1517	    SHLIB_CFLAGS=""
1518	    SHLIB_LD="ld -shared -rdata_shared"
1519	    SHLIB_LD_LIBS='${LIBS}'
1520	    SHLIB_SUFFIX=".so"
1521	    DL_OBJS="tclLoadDl.o"
1522	    DL_LIBS=""
1523	    AS_IF([test $doRpath = yes], [
1524		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1525		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1526	    ;;
1527	IRIX-6.*)
1528	    SHLIB_CFLAGS=""
1529	    SHLIB_LD="ld -n32 -shared -rdata_shared"
1530	    SHLIB_LD_LIBS='${LIBS}'
1531	    SHLIB_SUFFIX=".so"
1532	    DL_OBJS="tclLoadDl.o"
1533	    DL_LIBS=""
1534	    AS_IF([test $doRpath = yes], [
1535		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1536		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1537	    AS_IF([test "$GCC" = yes], [
1538		CFLAGS="$CFLAGS -mabi=n32"
1539		LDFLAGS="$LDFLAGS -mabi=n32"
1540	    ], [
1541		case $system in
1542		    IRIX-6.3)
1543			# Use to build 6.2 compatible binaries on 6.3.
1544			CFLAGS="$CFLAGS -n32 -D_OLD_TERMIOS"
1545			;;
1546		    *)
1547			CFLAGS="$CFLAGS -n32"
1548			;;
1549		esac
1550		LDFLAGS="$LDFLAGS -n32"
1551	    ])
1552	    ;;
1553	IRIX64-6.*)
1554	    SHLIB_CFLAGS=""
1555	    SHLIB_LD="ld -n32 -shared -rdata_shared"
1556	    SHLIB_LD_LIBS='${LIBS}'
1557	    SHLIB_SUFFIX=".so"
1558	    DL_OBJS="tclLoadDl.o"
1559	    DL_LIBS=""
1560	    AS_IF([test $doRpath = yes], [
1561		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1562		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1563
1564	    # Check to enable 64-bit flags for compiler/linker
1565
1566	    AS_IF([test "$do64bit" = yes], [
1567	        AS_IF([test "$GCC" = yes], [
1568	            AC_MSG_WARN([64bit mode not supported by gcc])
1569	        ], [
1570	            do64bit_ok=yes
1571	            SHLIB_LD="ld -64 -shared -rdata_shared"
1572	            CFLAGS="$CFLAGS -64"
1573	            LDFLAGS_ARCH="-64"
1574	        ])
1575	    ])
1576	    ;;
1577	Linux*)
1578	    SHLIB_CFLAGS="-fPIC"
1579	    SHLIB_LD_LIBS='${LIBS}'
1580	    SHLIB_SUFFIX=".so"
1581
1582	    # TEA specific:
1583	    CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer"
1584	    # egcs-2.91.66 on Redhat Linux 6.0 generates lots of warnings
1585	    # when you inline the string and math operations.  Turn this off to
1586	    # get rid of the warnings.
1587	    #CFLAGS_OPTIMIZE="${CFLAGS_OPTIMIZE} -D__NO_STRING_INLINES -D__NO_MATH_INLINES"
1588
1589	    # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS
1590	    SHLIB_LD='${CC} -shared ${CFLAGS} ${LDFLAGS_DEFAULT}'
1591	    DL_OBJS="tclLoadDl.o"
1592	    DL_LIBS="-ldl"
1593	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
1594	    AS_IF([test $doRpath = yes], [
1595		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
1596	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1597	    AS_IF([test "`uname -m`" = "alpha"], [CFLAGS="$CFLAGS -mieee"])
1598	    AS_IF([test $do64bit = yes], [
1599		AC_CACHE_CHECK([if compiler accepts -m64 flag], tcl_cv_cc_m64, [
1600		    hold_cflags=$CFLAGS
1601		    CFLAGS="$CFLAGS -m64"
1602		    AC_TRY_LINK(,, tcl_cv_cc_m64=yes, tcl_cv_cc_m64=no)
1603		    CFLAGS=$hold_cflags])
1604		AS_IF([test $tcl_cv_cc_m64 = yes], [
1605		    CFLAGS="$CFLAGS -m64"
1606		    do64bit_ok=yes
1607		])
1608	   ])
1609
1610	    # The combo of gcc + glibc has a bug related to inlining of
1611	    # functions like strtod(). The -fno-builtin flag should address
1612	    # this problem but it does not work. The -fno-inline flag is kind
1613	    # of overkill but it works. Disable inlining only when one of the
1614	    # files in compat/*.c is being linked in.
1615
1616	    AS_IF([test x"${USE_COMPAT}" != x],[CFLAGS="$CFLAGS -fno-inline"])
1617
1618	    ;;
1619	GNU*)
1620	    SHLIB_CFLAGS="-fPIC"
1621	    SHLIB_LD_LIBS='${LIBS}'
1622	    SHLIB_SUFFIX=".so"
1623
1624	    SHLIB_LD='${CC} -shared'
1625	    DL_OBJS=""
1626	    DL_LIBS="-ldl"
1627	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
1628	    CC_SEARCH_FLAGS=""
1629	    LD_SEARCH_FLAGS=""
1630	    AS_IF([test "`uname -m`" = "alpha"], [CFLAGS="$CFLAGS -mieee"])
1631	    ;;
1632	Lynx*)
1633	    SHLIB_CFLAGS="-fPIC"
1634	    SHLIB_LD_LIBS='${LIBS}'
1635	    SHLIB_SUFFIX=".so"
1636	    CFLAGS_OPTIMIZE=-02
1637	    SHLIB_LD='${CC} -shared'
1638	    DL_OBJS="tclLoadDl.o"
1639	    DL_LIBS="-mshared -ldl"
1640	    LD_FLAGS="-Wl,--export-dynamic"
1641	    AS_IF([test $doRpath = yes], [
1642		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1643		LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
1644	    ;;
1645	MP-RAS-02*)
1646	    SHLIB_CFLAGS="-K PIC"
1647	    SHLIB_LD='${CC} -G'
1648	    SHLIB_LD_LIBS=""
1649	    SHLIB_SUFFIX=".so"
1650	    DL_OBJS="tclLoadDl.o"
1651	    DL_LIBS="-ldl"
1652	    CC_SEARCH_FLAGS=""
1653	    LD_SEARCH_FLAGS=""
1654	    ;;
1655	MP-RAS-*)
1656	    SHLIB_CFLAGS="-K PIC"
1657	    SHLIB_LD='${CC} -G'
1658	    SHLIB_LD_LIBS=""
1659	    SHLIB_SUFFIX=".so"
1660	    DL_OBJS="tclLoadDl.o"
1661	    DL_LIBS="-ldl"
1662	    LDFLAGS="$LDFLAGS -Wl,-Bexport"
1663	    CC_SEARCH_FLAGS=""
1664	    LD_SEARCH_FLAGS=""
1665	    ;;
1666	NetBSD-1.*|FreeBSD-[[1-2]].*)
1667	    SHLIB_CFLAGS="-fPIC"
1668	    SHLIB_LD="ld -Bshareable -x"
1669	    SHLIB_LD_LIBS='${LIBS}'
1670	    SHLIB_SUFFIX=".so"
1671	    DL_OBJS="tclLoadDl.o"
1672	    DL_LIBS=""
1673	    AS_IF([test $doRpath = yes], [
1674		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1675		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1676	    AC_CACHE_CHECK([for ELF], tcl_cv_ld_elf, [
1677		AC_EGREP_CPP(yes, [
1678#ifdef __ELF__
1679	yes
1680#endif
1681		], tcl_cv_ld_elf=yes, tcl_cv_ld_elf=no)])
1682	    AS_IF([test $tcl_cv_ld_elf = yes], [
1683		SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so'
1684	    ], [
1685		SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.1.0'
1686	    ])
1687
1688	    # Ancient FreeBSD doesn't handle version numbers with dots.
1689
1690	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1691	    TCL_LIB_VERSIONS_OK=nodots
1692	    ;;
1693	OpenBSD-*)
1694	    SHLIB_CFLAGS="-fPIC"
1695	    SHLIB_LD='${CC} -shared ${SHLIB_CFLAGS}'
1696	    SHLIB_LD_LIBS='${LIBS}'
1697	    SHLIB_SUFFIX=".so"
1698	    DL_OBJS="tclLoadDl.o"
1699	    DL_LIBS=""
1700	    AS_IF([test $doRpath = yes], [
1701		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
1702	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1703	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.1.0'
1704	    AC_CACHE_CHECK([for ELF], tcl_cv_ld_elf, [
1705		AC_EGREP_CPP(yes, [
1706#ifdef __ELF__
1707	yes
1708#endif
1709		], tcl_cv_ld_elf=yes, tcl_cv_ld_elf=no)])
1710	    AS_IF([test $tcl_cv_ld_elf = yes], [
1711		LDFLAGS=-Wl,-export-dynamic
1712	    ], [LDFLAGS=""])
1713
1714	    # OpenBSD doesn't do version numbers with dots.
1715	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1716	    TCL_LIB_VERSIONS_OK=nodots
1717	    ;;
1718	NetBSD-*|DragonFly-*|FreeBSD-*)
1719	    # FreeBSD 3.* and greater have ELF.
1720	    # NetBSD 2.* has ELF and can use 'cc -shared' to build shared libs
1721	    SHLIB_CFLAGS="-fPIC"
1722	    SHLIB_LD='${CC} -shared ${SHLIB_CFLAGS}'
1723	    SHLIB_LD_LIBS='${LIBS}'
1724	    SHLIB_SUFFIX=".so"
1725	    DL_OBJS="tclLoadDl.o"
1726	    DL_LIBS=""
1727	    LDFLAGS="$LDFLAGS -export-dynamic"
1728	    AS_IF([test $doRpath = yes], [
1729		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
1730	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1731	    AS_IF([test "${TCL_THREADS}" = "1"], [
1732		# The -pthread needs to go in the CFLAGS, not LIBS
1733		LIBS=`echo $LIBS | sed s/-pthread//`
1734		CFLAGS="$CFLAGS -pthread"
1735	    	LDFLAGS="$LDFLAGS -pthread"
1736	    ])
1737	    case $system in
1738	    FreeBSD-3.*)
1739	    	# FreeBSD-3 doesn't handle version numbers with dots.
1740	    	UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1741	    	SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so'
1742	    	TCL_LIB_VERSIONS_OK=nodots
1743		;;
1744	    esac
1745	    ;;
1746	Darwin-*)
1747	    CFLAGS_OPTIMIZE="-Os"
1748	    SHLIB_CFLAGS="-fno-common"
1749	    # To avoid discrepancies between what headers configure sees during
1750	    # preprocessing tests and compiling tests, move any -isysroot and
1751	    # -mmacosx-version-min flags from CFLAGS to CPPFLAGS:
1752	    CPPFLAGS="${CPPFLAGS} `echo " ${CFLAGS}" | \
1753		awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \
1754		if ([$]i~/^(isysroot|mmacosx-version-min)/) print "-"[$]i}'`"
1755	    CFLAGS="`echo " ${CFLAGS}" | \
1756		awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \
1757		if (!([$]i~/^(isysroot|mmacosx-version-min)/)) print "-"[$]i}'`"
1758	    AS_IF([test $do64bit = yes], [
1759		case `arch` in
1760		    ppc)
1761			AC_CACHE_CHECK([if compiler accepts -arch ppc64 flag],
1762				tcl_cv_cc_arch_ppc64, [
1763			    hold_cflags=$CFLAGS
1764			    CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
1765			    AC_TRY_LINK(,, tcl_cv_cc_arch_ppc64=yes,
1766				    tcl_cv_cc_arch_ppc64=no)
1767			    CFLAGS=$hold_cflags])
1768			AS_IF([test $tcl_cv_cc_arch_ppc64 = yes], [
1769			    CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
1770			    do64bit_ok=yes
1771			]);;
1772		    i386)
1773			AC_CACHE_CHECK([if compiler accepts -arch x86_64 flag],
1774				tcl_cv_cc_arch_x86_64, [
1775			    hold_cflags=$CFLAGS
1776			    CFLAGS="$CFLAGS -arch x86_64"
1777			    AC_TRY_LINK(,, tcl_cv_cc_arch_x86_64=yes,
1778				    tcl_cv_cc_arch_x86_64=no)
1779			    CFLAGS=$hold_cflags])
1780			AS_IF([test $tcl_cv_cc_arch_x86_64 = yes], [
1781			    CFLAGS="$CFLAGS -arch x86_64"
1782			    do64bit_ok=yes
1783			]);;
1784		    *)
1785			AC_MSG_WARN([Don't know how enable 64-bit on architecture `arch`]);;
1786		esac
1787	    ], [
1788		# Check for combined 32-bit and 64-bit fat build
1789		AS_IF([echo "$CFLAGS " |grep -E -q -- '-arch (ppc64|x86_64) ' \
1790		    && echo "$CFLAGS " |grep -E -q -- '-arch (ppc|i386) '], [
1791		    fat_32_64=yes])
1792	    ])
1793	    # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS
1794	    SHLIB_LD='${CC} -dynamiclib ${CFLAGS} ${LDFLAGS_DEFAULT}'
1795	    AC_CACHE_CHECK([if ld accepts -single_module flag], tcl_cv_ld_single_module, [
1796		hold_ldflags=$LDFLAGS
1797		LDFLAGS="$LDFLAGS -dynamiclib -Wl,-single_module"
1798		AC_TRY_LINK(, [int i;], tcl_cv_ld_single_module=yes, tcl_cv_ld_single_module=no)
1799		LDFLAGS=$hold_ldflags])
1800	    AS_IF([test $tcl_cv_ld_single_module = yes], [
1801		SHLIB_LD="${SHLIB_LD} -Wl,-single_module"
1802	    ])
1803	    # TEA specific: link shlib with current and compatiblity version flags
1804	    vers=`echo ${PACKAGE_VERSION} | sed -e 's/^\([[0-9]]\{1,5\}\)\(\(\.[[0-9]]\{1,3\}\)\{0,2\}\).*$/\1\2/p' -e d`
1805	    SHLIB_LD="${SHLIB_LD} -current_version ${vers:-0} -compatibility_version ${vers:-0}"
1806	    SHLIB_LD_LIBS='${LIBS}'
1807	    SHLIB_SUFFIX=".dylib"
1808	    DL_OBJS="tclLoadDyld.o"
1809	    DL_LIBS=""
1810	    # Don't use -prebind when building for Mac OS X 10.4 or later only:
1811	    AS_IF([test "`echo "${MACOSX_DEPLOYMENT_TARGET}" | awk -F '10\\.' '{print int([$]2)}'`" -lt 4 -a \
1812		"`echo "${CPPFLAGS}" | awk -F '-mmacosx-version-min=10\\.' '{print int([$]2)}'`" -lt 4], [
1813		LDFLAGS="$LDFLAGS -prebind"])
1814	    LDFLAGS="$LDFLAGS -headerpad_max_install_names"
1815	    AC_CACHE_CHECK([if ld accepts -search_paths_first flag],
1816		    tcl_cv_ld_search_paths_first, [
1817		hold_ldflags=$LDFLAGS
1818		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
1819		AC_TRY_LINK(, [int i;], tcl_cv_ld_search_paths_first=yes,
1820			tcl_cv_ld_search_paths_first=no)
1821		LDFLAGS=$hold_ldflags])
1822	    AS_IF([test $tcl_cv_ld_search_paths_first = yes], [
1823		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
1824	    ])
1825	    AS_IF([test "$tcl_cv_cc_visibility_hidden" != yes], [
1826		AC_DEFINE(MODULE_SCOPE, [__private_extern__],
1827		    [Compiler support for module scope symbols])
1828	    ])
1829	    CC_SEARCH_FLAGS=""
1830	    LD_SEARCH_FLAGS=""
1831	    LD_LIBRARY_PATH_VAR="DYLD_LIBRARY_PATH"
1832	    # TEA specific: for combined 32 & 64 bit fat builds of Tk
1833	    # extensions, verify that 64-bit build is possible.
1834	    AS_IF([test "$fat_32_64" = yes && test -n "${TK_BIN_DIR}"], [
1835		AS_IF([test "${TEA_WINDOWINGSYSTEM}" = x11], [
1836		    AC_CACHE_CHECK([for 64-bit X11], tcl_cv_lib_x11_64, [
1837			for v in CFLAGS CPPFLAGS LDFLAGS; do
1838			    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"'
1839			done
1840			CPPFLAGS="$CPPFLAGS -I/usr/X11R6/include"
1841			LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
1842			AC_TRY_LINK([#include <X11/Xlib.h>], [XrmInitialize();],
1843			    tcl_cv_lib_x11_64=yes, tcl_cv_lib_x11_64=no)
1844			for v in CFLAGS CPPFLAGS LDFLAGS; do
1845			    eval $v'="$hold_'$v'"'
1846			done])
1847		])
1848		# remove 64-bit arch flags from CFLAGS et al. if configuration
1849		# does not support 64-bit.
1850		AS_IF([test "${TEA_WINDOWINGSYSTEM}" = aqua -o "$tcl_cv_lib_x11_64" = no], [
1851		    AC_MSG_NOTICE([Removing 64-bit architectures from compiler & linker flags])
1852		    for v in CFLAGS CPPFLAGS LDFLAGS; do
1853			eval $v'="`echo "$'$v' "|sed -e "s/-arch ppc64 / /g" -e "s/-arch x86_64 / /g"`"'
1854		    done])
1855	    ])
1856	    ;;
1857	NEXTSTEP-*)
1858	    SHLIB_CFLAGS=""
1859	    SHLIB_LD='${CC} -nostdlib -r'
1860	    SHLIB_LD_LIBS=""
1861	    SHLIB_SUFFIX=".so"
1862	    DL_OBJS="tclLoadNext.o"
1863	    DL_LIBS=""
1864	    CC_SEARCH_FLAGS=""
1865	    LD_SEARCH_FLAGS=""
1866	    ;;
1867	OS/390-*)
1868	    CFLAGS_OPTIMIZE=""		# Optimizer is buggy
1869	    AC_DEFINE(_OE_SOCKETS, 1,	# needed in sys/socket.h
1870		[Should OS/390 do the right thing with sockets?])
1871	    ;;
1872	OSF1-1.0|OSF1-1.1|OSF1-1.2)
1873	    # OSF/1 1.[012] from OSF, and derivatives, including Paragon OSF/1
1874	    SHLIB_CFLAGS=""
1875	    # Hack: make package name same as library name
1876	    SHLIB_LD='ld -R -export $@:'
1877	    SHLIB_LD_LIBS=""
1878	    SHLIB_SUFFIX=".so"
1879	    DL_OBJS="tclLoadOSF.o"
1880	    DL_LIBS=""
1881	    CC_SEARCH_FLAGS=""
1882	    LD_SEARCH_FLAGS=""
1883	    ;;
1884	OSF1-1.*)
1885	    # OSF/1 1.3 from OSF using ELF, and derivatives, including AD2
1886	    SHLIB_CFLAGS="-fPIC"
1887	    AS_IF([test "$SHARED_BUILD" = 1], [SHLIB_LD="ld -shared"], [
1888	        SHLIB_LD="ld -non_shared"
1889	    ])
1890	    SHLIB_LD_LIBS=""
1891	    SHLIB_SUFFIX=".so"
1892	    DL_OBJS="tclLoadDl.o"
1893	    DL_LIBS=""
1894	    CC_SEARCH_FLAGS=""
1895	    LD_SEARCH_FLAGS=""
1896	    ;;
1897	OSF1-V*)
1898	    # Digital OSF/1
1899	    SHLIB_CFLAGS=""
1900	    AS_IF([test "$SHARED_BUILD" = 1], [
1901	        SHLIB_LD='ld -shared -expect_unresolved "*"'
1902	    ], [
1903	        SHLIB_LD='ld -non_shared -expect_unresolved "*"'
1904	    ])
1905	    SHLIB_LD_LIBS=""
1906	    SHLIB_SUFFIX=".so"
1907	    DL_OBJS="tclLoadDl.o"
1908	    DL_LIBS=""
1909	    AS_IF([test $doRpath = yes], [
1910		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1911		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1912	    AS_IF([test "$GCC" = yes], [CFLAGS="$CFLAGS -mieee"], [
1913		CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee"])
1914	    # see pthread_intro(3) for pthread support on osf1, k.furukawa
1915	    AS_IF([test "${TCL_THREADS}" = 1], [
1916		CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE"
1917		CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64"
1918		LIBS=`echo $LIBS | sed s/-lpthreads//`
1919		AS_IF([test "$GCC" = yes], [
1920		    LIBS="$LIBS -lpthread -lmach -lexc"
1921		], [
1922		    CFLAGS="$CFLAGS -pthread"
1923		    LDFLAGS="$LDFLAGS -pthread"
1924		])
1925	    ])
1926	    ;;
1927	QNX-6*)
1928	    # QNX RTP
1929	    # This may work for all QNX, but it was only reported for v6.
1930	    SHLIB_CFLAGS="-fPIC"
1931	    SHLIB_LD="ld -Bshareable -x"
1932	    SHLIB_LD_LIBS=""
1933	    SHLIB_SUFFIX=".so"
1934	    DL_OBJS="tclLoadDl.o"
1935	    # dlopen is in -lc on QNX
1936	    DL_LIBS=""
1937	    CC_SEARCH_FLAGS=""
1938	    LD_SEARCH_FLAGS=""
1939	    ;;
1940	SCO_SV-3.2*)
1941	    # Note, dlopen is available only on SCO 3.2.5 and greater. However,
1942	    # this test works, since "uname -s" was non-standard in 3.2.4 and
1943	    # below.
1944	    AS_IF([test "$GCC" = yes], [
1945	    	SHLIB_CFLAGS="-fPIC -melf"
1946	    	LDFLAGS="$LDFLAGS -melf -Wl,-Bexport"
1947	    ], [
1948	    	SHLIB_CFLAGS="-Kpic -belf"
1949	    	LDFLAGS="$LDFLAGS -belf -Wl,-Bexport"
1950	    ])
1951	    SHLIB_LD="ld -G"
1952	    SHLIB_LD_LIBS=""
1953	    SHLIB_SUFFIX=".so"
1954	    DL_OBJS="tclLoadDl.o"
1955	    DL_LIBS=""
1956	    CC_SEARCH_FLAGS=""
1957	    LD_SEARCH_FLAGS=""
1958	    ;;
1959	SINIX*5.4*)
1960	    SHLIB_CFLAGS="-K PIC"
1961	    SHLIB_LD='${CC} -G'
1962	    SHLIB_LD_LIBS=""
1963	    SHLIB_SUFFIX=".so"
1964	    DL_OBJS="tclLoadDl.o"
1965	    DL_LIBS="-ldl"
1966	    CC_SEARCH_FLAGS=""
1967	    LD_SEARCH_FLAGS=""
1968	    ;;
1969	SunOS-4*)
1970	    SHLIB_CFLAGS="-PIC"
1971	    SHLIB_LD="ld"
1972	    SHLIB_LD_LIBS=""
1973	    SHLIB_SUFFIX=".so"
1974	    DL_OBJS="tclLoadDl.o"
1975	    DL_LIBS="-ldl"
1976	    CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
1977	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1978
1979	    # SunOS can't handle version numbers with dots in them in library
1980	    # specs, like -ltcl7.5, so use -ltcl75 instead.  Also, it
1981	    # requires an extra version number at the end of .so file names.
1982	    # So, the library has to have a name like libtcl75.so.1.0
1983
1984	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.1.0'
1985	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1986	    TCL_LIB_VERSIONS_OK=nodots
1987	    ;;
1988	SunOS-5.[[0-6]])
1989	    # Careful to not let 5.10+ fall into this case
1990
1991	    # Note: If _REENTRANT isn't defined, then Solaris
1992	    # won't define thread-safe library routines.
1993
1994	    AC_DEFINE(_REENTRANT, 1, [Do we want the reentrant OS API?])
1995	    AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1,
1996		[Do we really want to follow the standard? Yes we do!])
1997
1998	    SHLIB_CFLAGS="-KPIC"
1999
2000	    # Note: need the LIBS below, otherwise Tk won't find Tcl's
2001	    # symbols when dynamically loaded into tclsh.
2002
2003	    SHLIB_LD_LIBS='${LIBS}'
2004	    SHLIB_SUFFIX=".so"
2005	    DL_OBJS="tclLoadDl.o"
2006	    DL_LIBS="-ldl"
2007	    AS_IF([test "$GCC" = yes], [
2008		SHLIB_LD='${CC} -shared'
2009		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
2010		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
2011	    ], [
2012		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
2013		CC_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}'
2014		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
2015	    ])
2016	    ;;
2017	SunOS-5*)
2018	    # Note: If _REENTRANT isn't defined, then Solaris
2019	    # won't define thread-safe library routines.
2020
2021	    AC_DEFINE(_REENTRANT, 1, [Do we want the reentrant OS API?])
2022	    AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1,
2023		[Do we really want to follow the standard? Yes we do!])
2024
2025	    SHLIB_CFLAGS="-KPIC"
2026
2027	    # Check to enable 64-bit flags for compiler/linker
2028	    AS_IF([test "$do64bit" = yes], [
2029		arch=`isainfo`
2030		AS_IF([test "$arch" = "sparcv9 sparc"], [
2031		    AS_IF([test "$GCC" = yes], [
2032			AS_IF([test "`${CC} -dumpversion | awk -F. '{print [$]1}'`" -lt 3], [
2033			    AC_MSG_WARN([64bit mode not supported with GCC < 3.2 on $system])
2034			], [
2035			    do64bit_ok=yes
2036			    CFLAGS="$CFLAGS -m64 -mcpu=v9"
2037			    LDFLAGS="$LDFLAGS -m64 -mcpu=v9"
2038			    SHLIB_CFLAGS="-fPIC"
2039			])
2040		    ], [
2041			do64bit_ok=yes
2042			AS_IF([test "$do64bitVIS" = yes], [
2043			    CFLAGS="$CFLAGS -xarch=v9a"
2044			    LDFLAGS_ARCH="-xarch=v9a"
2045			], [
2046			    CFLAGS="$CFLAGS -xarch=v9"
2047			    LDFLAGS_ARCH="-xarch=v9"
2048			])
2049			# Solaris 64 uses this as well
2050			#LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH_64"
2051		    ])
2052		], [AS_IF([test "$arch" = "amd64 i386"], [
2053		    AS_IF([test "$GCC" = yes], [
2054			case $system in
2055			    SunOS-5.1[[1-9]]*|SunOS-5.[[2-9]][[0-9]]*)
2056				do64bit_ok=yes
2057				CFLAGS="$CFLAGS -m64"
2058				LDFLAGS="$LDFLAGS -m64";;
2059			    *)
2060				AC_MSG_WARN([64bit mode not supported with GCC on $system]);;
2061			esac
2062		    ], [
2063			do64bit_ok=yes
2064			case $system in
2065			    SunOS-5.1[[1-9]]*|SunOS-5.[[2-9]][[0-9]]*)
2066				CFLAGS="$CFLAGS -m64"
2067				LDFLAGS="$LDFLAGS -m64";;
2068			    *)
2069				CFLAGS="$CFLAGS -xarch=amd64"
2070				LDFLAGS="$LDFLAGS -xarch=amd64";;
2071			esac
2072		    ])
2073		], [AC_MSG_WARN([64bit mode not supported for $arch])])])
2074	    ])
2075
2076	    # Note: need the LIBS below, otherwise Tk won't find Tcl's
2077	    # symbols when dynamically loaded into tclsh.
2078
2079	    SHLIB_LD_LIBS='${LIBS}'
2080	    SHLIB_SUFFIX=".so"
2081	    DL_OBJS="tclLoadDl.o"
2082	    DL_LIBS="-ldl"
2083	    AS_IF([test "$GCC" = yes], [
2084		SHLIB_LD='${CC} -shared'
2085		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
2086		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
2087		AS_IF([test "$do64bit_ok" = yes], [
2088		    AS_IF([test "$arch" = "sparcv9 sparc"], [
2089			# We need to specify -static-libgcc or we need to
2090			# add the path to the sparv9 libgcc.
2091			# JH: static-libgcc is necessary for core Tcl, but may
2092			# not be necessary for extensions.
2093			SHLIB_LD="$SHLIB_LD -m64 -mcpu=v9 -static-libgcc"
2094			# for finding sparcv9 libgcc, get the regular libgcc
2095			# path, remove so name and append 'sparcv9'
2096			#v9gcclibdir="`gcc -print-file-name=libgcc_s.so` | ..."
2097			#CC_SEARCH_FLAGS="${CC_SEARCH_FLAGS},-R,$v9gcclibdir"
2098		    ], [AS_IF([test "$arch" = "amd64 i386"], [
2099			# JH: static-libgcc is necessary for core Tcl, but may
2100			# not be necessary for extensions.
2101			SHLIB_LD="$SHLIB_LD -m64 -static-libgcc"
2102		    ])])
2103		])
2104	    ], [
2105		case $system in
2106		    SunOS-5.[[1-9]][[0-9]]*)
2107			SHLIB_LD='${CC} -G -z text ${LDFLAGS}';;
2108		    *)
2109			SHLIB_LD='/usr/ccs/bin/ld -G -z text';;
2110		esac
2111		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
2112		LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}'
2113	    ])
2114	    ;;
2115	UNIX_SV* | UnixWare-5*)
2116	    SHLIB_CFLAGS="-KPIC"
2117	    SHLIB_LD='${CC} -G'
2118	    SHLIB_LD_LIBS=""
2119	    SHLIB_SUFFIX=".so"
2120	    DL_OBJS="tclLoadDl.o"
2121	    DL_LIBS="-ldl"
2122	    # Some UNIX_SV* systems (unixware 1.1.2 for example) have linkers
2123	    # that don't grok the -Bexport option.  Test that it does.
2124	    AC_CACHE_CHECK([for ld accepts -Bexport flag], tcl_cv_ld_Bexport, [
2125		hold_ldflags=$LDFLAGS
2126		LDFLAGS="$LDFLAGS -Wl,-Bexport"
2127		AC_TRY_LINK(, [int i;], tcl_cv_ld_Bexport=yes, tcl_cv_ld_Bexport=no)
2128	        LDFLAGS=$hold_ldflags])
2129	    AS_IF([test $tcl_cv_ld_Bexport = yes], [
2130		LDFLAGS="$LDFLAGS -Wl,-Bexport"
2131	    ])
2132	    CC_SEARCH_FLAGS=""
2133	    LD_SEARCH_FLAGS=""
2134	    ;;
2135    esac
2136
2137    AS_IF([test "$do64bit" = yes -a "$do64bit_ok" = no], [
2138	AC_MSG_WARN([64bit support being disabled -- don't know magic for this platform])
2139    ])
2140
2141dnl # Add any CPPFLAGS set in the environment to our CFLAGS, but delay doing so
2142dnl # until the end of configure, as configure's compile and link tests use
2143dnl # both CPPFLAGS and CFLAGS (unlike our compile and link) but configure's
2144dnl # preprocessing tests use only CPPFLAGS.
2145    AC_CONFIG_COMMANDS_PRE([CFLAGS="${CFLAGS} ${CPPFLAGS}"; CPPFLAGS=""])
2146
2147    # Step 4: disable dynamic loading if requested via a command-line switch.
2148
2149    AC_ARG_ENABLE(load,
2150	AC_HELP_STRING([--enable-load],
2151	    [allow dynamic loading and "load" command (default: on)]),
2152	[tcl_ok=$enableval], [tcl_ok=yes])
2153    AS_IF([test "$tcl_ok" = no], [DL_OBJS=""])
2154
2155    AS_IF([test "x$DL_OBJS" != x], [BUILD_DLTEST="\$(DLTEST_TARGETS)"], [
2156	AC_MSG_WARN([Can't figure out how to do dynamic loading or shared libraries on this system.])
2157	SHLIB_CFLAGS=""
2158	SHLIB_LD=""
2159	SHLIB_SUFFIX=""
2160	DL_OBJS="tclLoadNone.o"
2161	DL_LIBS=""
2162	LDFLAGS="$LDFLAGS_ORIG"
2163	CC_SEARCH_FLAGS=""
2164	LD_SEARCH_FLAGS=""
2165	BUILD_DLTEST=""
2166    ])
2167    LDFLAGS="$LDFLAGS $LDFLAGS_ARCH"
2168
2169    # If we're running gcc, then change the C flags for compiling shared
2170    # libraries to the right flags for gcc, instead of those for the
2171    # standard manufacturer compiler.
2172
2173    AS_IF([test "$DL_OBJS" != "tclLoadNone.o" -a "$GCC" = yes], [
2174	case $system in
2175	    AIX-*) ;;
2176	    BSD/OS*) ;;
2177	    IRIX*) ;;
2178	    NetBSD-*|FreeBSD-*) ;;
2179	    DragonFly-*) ;;
2180	    Darwin-*) ;;
2181	    SCO_SV-3.2*) ;;
2182	    *) SHLIB_CFLAGS="-fPIC" ;;
2183	esac])
2184
2185    AS_IF([test "$SHARED_LIB_SUFFIX" = ""], [
2186	# TEA specific: use PACKAGE_VERSION instead of VERSION
2187	SHARED_LIB_SUFFIX='${PACKAGE_VERSION}${SHLIB_SUFFIX}'])
2188    AS_IF([test "$UNSHARED_LIB_SUFFIX" = ""], [
2189	# TEA specific: use PACKAGE_VERSION instead of VERSION
2190	UNSHARED_LIB_SUFFIX='${PACKAGE_VERSION}.a'])
2191
2192    AC_SUBST(DL_LIBS)
2193
2194    AC_SUBST(CFLAGS_DEBUG)
2195    AC_SUBST(CFLAGS_OPTIMIZE)
2196    AC_SUBST(CFLAGS_WARNING)
2197
2198    AC_SUBST(STLIB_LD)
2199    AC_SUBST(SHLIB_LD)
2200
2201    AC_SUBST(SHLIB_LD_LIBS)
2202    AC_SUBST(SHLIB_CFLAGS)
2203
2204    AC_SUBST(LD_LIBRARY_PATH_VAR)
2205
2206    # These must be called after we do the basic CFLAGS checks and
2207    # verify any possible 64-bit or similar switches are necessary
2208    TEA_TCL_EARLY_FLAGS
2209    TEA_TCL_64BIT_FLAGS
2210])
2211
2212#--------------------------------------------------------------------
2213# TEA_SERIAL_PORT
2214#
2215#	Determine which interface to use to talk to the serial port.
2216#	Note that #include lines must begin in leftmost column for
2217#	some compilers to recognize them as preprocessor directives,
2218#	and some build environments have stdin not pointing at a
2219#	pseudo-terminal (usually /dev/null instead.)
2220#
2221# Arguments:
2222#	none
2223#
2224# Results:
2225#
2226#	Defines only one of the following vars:
2227#		HAVE_SYS_MODEM_H
2228#		USE_TERMIOS
2229#		USE_TERMIO
2230#		USE_SGTTY
2231#
2232#--------------------------------------------------------------------
2233
2234AC_DEFUN([TEA_SERIAL_PORT], [
2235    AC_CHECK_HEADERS(sys/modem.h)
2236    AC_CACHE_CHECK([termios vs. termio vs. sgtty], tcl_cv_api_serial, [
2237    AC_TRY_RUN([
2238#include <termios.h>
2239
2240int main() {
2241    struct termios t;
2242    if (tcgetattr(0, &t) == 0) {
2243	cfsetospeed(&t, 0);
2244	t.c_cflag |= PARENB | PARODD | CSIZE | CSTOPB;
2245	return 0;
2246    }
2247    return 1;
2248}], tcl_cv_api_serial=termios, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2249    if test $tcl_cv_api_serial = no ; then
2250	AC_TRY_RUN([
2251#include <termio.h>
2252
2253int main() {
2254    struct termio t;
2255    if (ioctl(0, TCGETA, &t) == 0) {
2256	t.c_cflag |= CBAUD | PARENB | PARODD | CSIZE | CSTOPB;
2257	return 0;
2258    }
2259    return 1;
2260}], tcl_cv_api_serial=termio, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2261    fi
2262    if test $tcl_cv_api_serial = no ; then
2263	AC_TRY_RUN([
2264#include <sgtty.h>
2265
2266int main() {
2267    struct sgttyb t;
2268    if (ioctl(0, TIOCGETP, &t) == 0) {
2269	t.sg_ospeed = 0;
2270	t.sg_flags |= ODDP | EVENP | RAW;
2271	return 0;
2272    }
2273    return 1;
2274}], tcl_cv_api_serial=sgtty, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2275    fi
2276    if test $tcl_cv_api_serial = no ; then
2277	AC_TRY_RUN([
2278#include <termios.h>
2279#include <errno.h>
2280
2281int main() {
2282    struct termios t;
2283    if (tcgetattr(0, &t) == 0
2284	|| errno == ENOTTY || errno == ENXIO || errno == EINVAL) {
2285	cfsetospeed(&t, 0);
2286	t.c_cflag |= PARENB | PARODD | CSIZE | CSTOPB;
2287	return 0;
2288    }
2289    return 1;
2290}], tcl_cv_api_serial=termios, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2291    fi
2292    if test $tcl_cv_api_serial = no; then
2293	AC_TRY_RUN([
2294#include <termio.h>
2295#include <errno.h>
2296
2297int main() {
2298    struct termio t;
2299    if (ioctl(0, TCGETA, &t) == 0
2300	|| errno == ENOTTY || errno == ENXIO || errno == EINVAL) {
2301	t.c_cflag |= CBAUD | PARENB | PARODD | CSIZE | CSTOPB;
2302	return 0;
2303    }
2304    return 1;
2305    }], tcl_cv_api_serial=termio, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2306    fi
2307    if test $tcl_cv_api_serial = no; then
2308	AC_TRY_RUN([
2309#include <sgtty.h>
2310#include <errno.h>
2311
2312int main() {
2313    struct sgttyb t;
2314    if (ioctl(0, TIOCGETP, &t) == 0
2315	|| errno == ENOTTY || errno == ENXIO || errno == EINVAL) {
2316	t.sg_ospeed = 0;
2317	t.sg_flags |= ODDP | EVENP | RAW;
2318	return 0;
2319    }
2320    return 1;
2321}], tcl_cv_api_serial=sgtty, tcl_cv_api_serial=none, tcl_cv_api_serial=none)
2322    fi])
2323    case $tcl_cv_api_serial in
2324	termios) AC_DEFINE(USE_TERMIOS, 1, [Use the termios API for serial lines]);;
2325	termio)  AC_DEFINE(USE_TERMIO, 1, [Use the termio API for serial lines]);;
2326	sgtty)   AC_DEFINE(USE_SGTTY, 1, [Use the sgtty API for serial lines]);;
2327    esac
2328])
2329
2330#--------------------------------------------------------------------
2331# TEA_MISSING_POSIX_HEADERS
2332#
2333#	Supply substitutes for missing POSIX header files.  Special
2334#	notes:
2335#	    - stdlib.h doesn't define strtol, strtoul, or
2336#	      strtod insome versions of SunOS
2337#	    - some versions of string.h don't declare procedures such
2338#	      as strstr
2339#
2340# Arguments:
2341#	none
2342#
2343# Results:
2344#
2345#	Defines some of the following vars:
2346#		NO_DIRENT_H
2347#		NO_ERRNO_H
2348#		NO_VALUES_H
2349#		HAVE_LIMITS_H or NO_LIMITS_H
2350#		NO_STDLIB_H
2351#		NO_STRING_H
2352#		NO_SYS_WAIT_H
2353#		NO_DLFCN_H
2354#		HAVE_SYS_PARAM_H
2355#
2356#		HAVE_STRING_H ?
2357#
2358# tkUnixPort.h checks for HAVE_LIMITS_H, so do both HAVE and
2359# CHECK on limits.h
2360#--------------------------------------------------------------------
2361
2362AC_DEFUN([TEA_MISSING_POSIX_HEADERS], [
2363    AC_CACHE_CHECK([dirent.h], tcl_cv_dirent_h, [
2364    AC_TRY_LINK([#include <sys/types.h>
2365#include <dirent.h>], [
2366#ifndef _POSIX_SOURCE
2367#   ifdef __Lynx__
2368	/*
2369	 * Generate compilation error to make the test fail:  Lynx headers
2370	 * are only valid if really in the POSIX environment.
2371	 */
2372
2373	missing_procedure();
2374#   endif
2375#endif
2376DIR *d;
2377struct dirent *entryPtr;
2378char *p;
2379d = opendir("foobar");
2380entryPtr = readdir(d);
2381p = entryPtr->d_name;
2382closedir(d);
2383], tcl_cv_dirent_h=yes, tcl_cv_dirent_h=no)])
2384
2385    if test $tcl_cv_dirent_h = no; then
2386	AC_DEFINE(NO_DIRENT_H, 1, [Do we have <dirent.h>?])
2387    fi
2388
2389    # TEA specific:
2390    AC_CHECK_HEADER(errno.h, , [AC_DEFINE(NO_ERRNO_H, 1, [Do we have <errno.h>?])])
2391    AC_CHECK_HEADER(float.h, , [AC_DEFINE(NO_FLOAT_H, 1, [Do we have <float.h>?])])
2392    AC_CHECK_HEADER(values.h, , [AC_DEFINE(NO_VALUES_H, 1, [Do we have <values.h>?])])
2393    AC_CHECK_HEADER(limits.h,
2394	[AC_DEFINE(HAVE_LIMITS_H, 1, [Do we have <limits.h>?])],
2395	[AC_DEFINE(NO_LIMITS_H, 1, [Do we have <limits.h>?])])
2396    AC_CHECK_HEADER(stdlib.h, tcl_ok=1, tcl_ok=0)
2397    AC_EGREP_HEADER(strtol, stdlib.h, , tcl_ok=0)
2398    AC_EGREP_HEADER(strtoul, stdlib.h, , tcl_ok=0)
2399    AC_EGREP_HEADER(strtod, stdlib.h, , tcl_ok=0)
2400    if test $tcl_ok = 0; then
2401	AC_DEFINE(NO_STDLIB_H, 1, [Do we have <stdlib.h>?])
2402    fi
2403    AC_CHECK_HEADER(string.h, tcl_ok=1, tcl_ok=0)
2404    AC_EGREP_HEADER(strstr, string.h, , tcl_ok=0)
2405    AC_EGREP_HEADER(strerror, string.h, , tcl_ok=0)
2406
2407    # See also memmove check below for a place where NO_STRING_H can be
2408    # set and why.
2409
2410    if test $tcl_ok = 0; then
2411	AC_DEFINE(NO_STRING_H, 1, [Do we have <string.h>?])
2412    fi
2413
2414    AC_CHECK_HEADER(sys/wait.h, , [AC_DEFINE(NO_SYS_WAIT_H, 1, [Do we have <sys/wait.h>?])])
2415    AC_CHECK_HEADER(dlfcn.h, , [AC_DEFINE(NO_DLFCN_H, 1, [Do we have <dlfcn.h>?])])
2416
2417    # OS/390 lacks sys/param.h (and doesn't need it, by chance).
2418    AC_HAVE_HEADERS(sys/param.h)
2419])
2420
2421#--------------------------------------------------------------------
2422# TEA_PATH_X
2423#
2424#	Locate the X11 header files and the X11 library archive.  Try
2425#	the ac_path_x macro first, but if it doesn't find the X stuff
2426#	(e.g. because there's no xmkmf program) then check through
2427#	a list of possible directories.  Under some conditions the
2428#	autoconf macro will return an include directory that contains
2429#	no include files, so double-check its result just to be safe.
2430#
2431#	This should be called after TEA_CONFIG_CFLAGS as setting the
2432#	LIBS line can confuse some configure macro magic.
2433#
2434# Arguments:
2435#	none
2436#
2437# Results:
2438#
2439#	Sets the following vars:
2440#		XINCLUDES
2441#		XLIBSW
2442#		PKG_LIBS (appends to)
2443#
2444#--------------------------------------------------------------------
2445
2446AC_DEFUN([TEA_PATH_X], [
2447    if test "${TEA_WINDOWINGSYSTEM}" = "x11" ; then
2448	TEA_PATH_UNIX_X
2449    fi
2450])
2451
2452AC_DEFUN([TEA_PATH_UNIX_X], [
2453    AC_PATH_X
2454    not_really_there=""
2455    if test "$no_x" = ""; then
2456	if test "$x_includes" = ""; then
2457	    AC_TRY_CPP([#include <X11/XIntrinsic.h>], , not_really_there="yes")
2458	else
2459	    if test ! -r $x_includes/X11/Intrinsic.h; then
2460		not_really_there="yes"
2461	    fi
2462	fi
2463    fi
2464    if test "$no_x" = "yes" -o "$not_really_there" = "yes"; then
2465	AC_MSG_CHECKING([for X11 header files])
2466	found_xincludes="no"
2467	AC_TRY_CPP([#include <X11/Intrinsic.h>], found_xincludes="yes", found_xincludes="no")
2468	if test "$found_xincludes" = "no"; then
2469	    dirs="/usr/unsupported/include /usr/local/include /usr/X386/include /usr/X11R6/include /usr/X11R5/include /usr/include/X11R5 /usr/include/X11R4 /usr/openwin/include /usr/X11/include /usr/sww/include"
2470	    for i in $dirs ; do
2471		if test -r $i/X11/Intrinsic.h; then
2472		    AC_MSG_RESULT([$i])
2473		    XINCLUDES=" -I$i"
2474		    found_xincludes="yes"
2475		    break
2476		fi
2477	    done
2478	fi
2479    else
2480	if test "$x_includes" != ""; then
2481	    XINCLUDES="-I$x_includes"
2482	    found_xincludes="yes"
2483	fi
2484    fi
2485    if test found_xincludes = "no"; then
2486	AC_MSG_RESULT([couldn't find any!])
2487    fi
2488
2489    if test "$no_x" = yes; then
2490	AC_MSG_CHECKING([for X11 libraries])
2491	XLIBSW=nope
2492	dirs="/usr/unsupported/lib /usr/local/lib /usr/X386/lib /usr/X11R6/lib /usr/X11R5/lib /usr/lib/X11R5 /usr/lib/X11R4 /usr/openwin/lib /usr/X11/lib /usr/sww/X11/lib"
2493	for i in $dirs ; do
2494	    if test -r $i/libX11.a -o -r $i/libX11.so -o -r $i/libX11.sl -o -r $i/libX11.dylib; then
2495		AC_MSG_RESULT([$i])
2496		XLIBSW="-L$i -lX11"
2497		x_libraries="$i"
2498		break
2499	    fi
2500	done
2501    else
2502	if test "$x_libraries" = ""; then
2503	    XLIBSW=-lX11
2504	else
2505	    XLIBSW="-L$x_libraries -lX11"
2506	fi
2507    fi
2508    if test "$XLIBSW" = nope ; then
2509	AC_CHECK_LIB(Xwindow, XCreateWindow, XLIBSW=-lXwindow)
2510    fi
2511    if test "$XLIBSW" = nope ; then
2512	AC_MSG_RESULT([could not find any!  Using -lX11.])
2513	XLIBSW=-lX11
2514    fi
2515    # TEA specific:
2516    if test x"${XLIBSW}" != x ; then
2517	PKG_LIBS="${PKG_LIBS} ${XLIBSW}"
2518    fi
2519])
2520
2521#--------------------------------------------------------------------
2522# TEA_BLOCKING_STYLE
2523#
2524#	The statements below check for systems where POSIX-style
2525#	non-blocking I/O (O_NONBLOCK) doesn't work or is unimplemented.
2526#	On these systems (mostly older ones), use the old BSD-style
2527#	FIONBIO approach instead.
2528#
2529# Arguments:
2530#	none
2531#
2532# Results:
2533#
2534#	Defines some of the following vars:
2535#		HAVE_SYS_IOCTL_H
2536#		HAVE_SYS_FILIO_H
2537#		USE_FIONBIO
2538#		O_NONBLOCK
2539#
2540#--------------------------------------------------------------------
2541
2542AC_DEFUN([TEA_BLOCKING_STYLE], [
2543    AC_CHECK_HEADERS(sys/ioctl.h)
2544    AC_CHECK_HEADERS(sys/filio.h)
2545    TEA_CONFIG_SYSTEM
2546    AC_MSG_CHECKING([FIONBIO vs. O_NONBLOCK for nonblocking I/O])
2547    case $system in
2548	# There used to be code here to use FIONBIO under AIX.  However, it
2549	# was reported that FIONBIO doesn't work under AIX 3.2.5.  Since
2550	# using O_NONBLOCK seems fine under AIX 4.*, I removed the FIONBIO
2551	# code (JO, 5/31/97).
2552
2553	OSF*)
2554	    AC_DEFINE(USE_FIONBIO, 1, [Should we use FIONBIO?])
2555	    AC_MSG_RESULT([FIONBIO])
2556	    ;;
2557	SunOS-4*)
2558	    AC_DEFINE(USE_FIONBIO, 1, [Should we use FIONBIO?])
2559	    AC_MSG_RESULT([FIONBIO])
2560	    ;;
2561	*)
2562	    AC_MSG_RESULT([O_NONBLOCK])
2563	    ;;
2564    esac
2565])
2566
2567#--------------------------------------------------------------------
2568# TEA_TIME_HANLDER
2569#
2570#	Checks how the system deals with time.h, what time structures
2571#	are used on the system, and what fields the structures have.
2572#
2573# Arguments:
2574#	none
2575#
2576# Results:
2577#
2578#	Defines some of the following vars:
2579#		USE_DELTA_FOR_TZ
2580#		HAVE_TM_GMTOFF
2581#		HAVE_TM_TZADJ
2582#		HAVE_TIMEZONE_VAR
2583#
2584#--------------------------------------------------------------------
2585
2586AC_DEFUN([TEA_TIME_HANDLER], [
2587    AC_CHECK_HEADERS(sys/time.h)
2588    AC_HEADER_TIME
2589    AC_STRUCT_TIMEZONE
2590
2591    AC_CHECK_FUNCS(gmtime_r localtime_r)
2592
2593    AC_CACHE_CHECK([tm_tzadj in struct tm], tcl_cv_member_tm_tzadj, [
2594	AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_tzadj;],
2595	    tcl_cv_member_tm_tzadj=yes, tcl_cv_member_tm_tzadj=no)])
2596    if test $tcl_cv_member_tm_tzadj = yes ; then
2597	AC_DEFINE(HAVE_TM_TZADJ, 1, [Should we use the tm_tzadj field of struct tm?])
2598    fi
2599
2600    AC_CACHE_CHECK([tm_gmtoff in struct tm], tcl_cv_member_tm_gmtoff, [
2601	AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_gmtoff;],
2602	    tcl_cv_member_tm_gmtoff=yes, tcl_cv_member_tm_gmtoff=no)])
2603    if test $tcl_cv_member_tm_gmtoff = yes ; then
2604	AC_DEFINE(HAVE_TM_GMTOFF, 1, [Should we use the tm_gmtoff field of struct tm?])
2605    fi
2606
2607    #
2608    # Its important to include time.h in this check, as some systems
2609    # (like convex) have timezone functions, etc.
2610    #
2611    AC_CACHE_CHECK([long timezone variable], tcl_cv_timezone_long, [
2612	AC_TRY_COMPILE([#include <time.h>],
2613	    [extern long timezone;
2614	    timezone += 1;
2615	    exit (0);],
2616	    tcl_cv_timezone_long=yes, tcl_cv_timezone_long=no)])
2617    if test $tcl_cv_timezone_long = yes ; then
2618	AC_DEFINE(HAVE_TIMEZONE_VAR, 1, [Should we use the global timezone variable?])
2619    else
2620	#
2621	# On some systems (eg IRIX 6.2), timezone is a time_t and not a long.
2622	#
2623	AC_CACHE_CHECK([time_t timezone variable], tcl_cv_timezone_time, [
2624	    AC_TRY_COMPILE([#include <time.h>],
2625		[extern time_t timezone;
2626		timezone += 1;
2627		exit (0);],
2628		tcl_cv_timezone_time=yes, tcl_cv_timezone_time=no)])
2629	if test $tcl_cv_timezone_time = yes ; then
2630	    AC_DEFINE(HAVE_TIMEZONE_VAR, 1, [Should we use the global timezone variable?])
2631	fi
2632    fi
2633])
2634
2635#--------------------------------------------------------------------
2636# TEA_BUGGY_STRTOD
2637#
2638#	Under Solaris 2.4, strtod returns the wrong value for the
2639#	terminating character under some conditions.  Check for this
2640#	and if the problem exists use a substitute procedure
2641#	"fixstrtod" (provided by Tcl) that corrects the error.
2642#	Also, on Compaq's Tru64 Unix 5.0,
2643#	strtod(" ") returns 0.0 instead of a failure to convert.
2644#
2645# Arguments:
2646#	none
2647#
2648# Results:
2649#
2650#	Might defines some of the following vars:
2651#		strtod (=fixstrtod)
2652#
2653#--------------------------------------------------------------------
2654
2655AC_DEFUN([TEA_BUGGY_STRTOD], [
2656    AC_CHECK_FUNC(strtod, tcl_strtod=1, tcl_strtod=0)
2657    if test "$tcl_strtod" = 1; then
2658	AC_CACHE_CHECK([for Solaris2.4/Tru64 strtod bugs], tcl_cv_strtod_buggy,[
2659	    AC_TRY_RUN([
2660		extern double strtod();
2661		int main() {
2662		    char *infString="Inf", *nanString="NaN", *spaceString=" ";
2663		    char *term;
2664		    double value;
2665		    value = strtod(infString, &term);
2666		    if ((term != infString) && (term[-1] == 0)) {
2667			exit(1);
2668		    }
2669		    value = strtod(nanString, &term);
2670		    if ((term != nanString) && (term[-1] == 0)) {
2671			exit(1);
2672		    }
2673		    value = strtod(spaceString, &term);
2674		    if (term == (spaceString+1)) {
2675			exit(1);
2676		    }
2677		    exit(0);
2678		}], tcl_cv_strtod_buggy=ok, tcl_cv_strtod_buggy=buggy,
2679		    tcl_cv_strtod_buggy=buggy)])
2680	if test "$tcl_cv_strtod_buggy" = buggy; then
2681	    AC_LIBOBJ([fixstrtod])
2682	    USE_COMPAT=1
2683	    AC_DEFINE(strtod, fixstrtod, [Do we want to use the strtod() in compat?])
2684	fi
2685    fi
2686])
2687
2688#--------------------------------------------------------------------
2689# TEA_TCL_LINK_LIBS
2690#
2691#	Search for the libraries needed to link the Tcl shell.
2692#	Things like the math library (-lm) and socket stuff (-lsocket vs.
2693#	-lnsl) are dealt with here.
2694#
2695# Arguments:
2696#	Requires the following vars to be set in the Makefile:
2697#		DL_LIBS
2698#		LIBS
2699#		MATH_LIBS
2700#
2701# Results:
2702#
2703#	Subst's the following var:
2704#		TCL_LIBS
2705#		MATH_LIBS
2706#
2707#	Might append to the following vars:
2708#		LIBS
2709#
2710#	Might define the following vars:
2711#		HAVE_NET_ERRNO_H
2712#
2713#--------------------------------------------------------------------
2714
2715AC_DEFUN([TEA_TCL_LINK_LIBS], [
2716    #--------------------------------------------------------------------
2717    # On a few very rare systems, all of the libm.a stuff is
2718    # already in libc.a.  Set compiler flags accordingly.
2719    # Also, Linux requires the "ieee" library for math to work
2720    # right (and it must appear before "-lm").
2721    #--------------------------------------------------------------------
2722
2723    AC_CHECK_FUNC(sin, MATH_LIBS="", MATH_LIBS="-lm")
2724    AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"])
2725
2726    #--------------------------------------------------------------------
2727    # Interactive UNIX requires -linet instead of -lsocket, plus it
2728    # needs net/errno.h to define the socket-related error codes.
2729    #--------------------------------------------------------------------
2730
2731    AC_CHECK_LIB(inet, main, [LIBS="$LIBS -linet"])
2732    AC_CHECK_HEADER(net/errno.h, [
2733	AC_DEFINE(HAVE_NET_ERRNO_H, 1, [Do we have <net/errno.h>?])])
2734
2735    #--------------------------------------------------------------------
2736    #	Check for the existence of the -lsocket and -lnsl libraries.
2737    #	The order here is important, so that they end up in the right
2738    #	order in the command line generated by make.  Here are some
2739    #	special considerations:
2740    #	1. Use "connect" and "accept" to check for -lsocket, and
2741    #	   "gethostbyname" to check for -lnsl.
2742    #	2. Use each function name only once:  can't redo a check because
2743    #	   autoconf caches the results of the last check and won't redo it.
2744    #	3. Use -lnsl and -lsocket only if they supply procedures that
2745    #	   aren't already present in the normal libraries.  This is because
2746    #	   IRIX 5.2 has libraries, but they aren't needed and they're
2747    #	   bogus:  they goof up name resolution if used.
2748    #	4. On some SVR4 systems, can't use -lsocket without -lnsl too.
2749    #	   To get around this problem, check for both libraries together
2750    #	   if -lsocket doesn't work by itself.
2751    #--------------------------------------------------------------------
2752
2753    tcl_checkBoth=0
2754    AC_CHECK_FUNC(connect, tcl_checkSocket=0, tcl_checkSocket=1)
2755    if test "$tcl_checkSocket" = 1; then
2756	AC_CHECK_FUNC(setsockopt, , [AC_CHECK_LIB(socket, setsockopt,
2757	    LIBS="$LIBS -lsocket", tcl_checkBoth=1)])
2758    fi
2759    if test "$tcl_checkBoth" = 1; then
2760	tk_oldLibs=$LIBS
2761	LIBS="$LIBS -lsocket -lnsl"
2762	AC_CHECK_FUNC(accept, tcl_checkNsl=0, [LIBS=$tk_oldLibs])
2763    fi
2764    AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(nsl, gethostbyname,
2765	    [LIBS="$LIBS -lnsl"])])
2766
2767    # TEA specific: Don't perform the eval of the libraries here because
2768    # DL_LIBS won't be set until we call TEA_CONFIG_CFLAGS
2769
2770    TCL_LIBS='${DL_LIBS} ${LIBS} ${MATH_LIBS}'
2771    AC_SUBST(TCL_LIBS)
2772    AC_SUBST(MATH_LIBS)
2773])
2774
2775#--------------------------------------------------------------------
2776# TEA_TCL_EARLY_FLAGS
2777#
2778#	Check for what flags are needed to be passed so the correct OS
2779#	features are available.
2780#
2781# Arguments:
2782#	None
2783#
2784# Results:
2785#
2786#	Might define the following vars:
2787#		_ISOC99_SOURCE
2788#		_LARGEFILE64_SOURCE
2789#		_LARGEFILE_SOURCE64
2790#
2791#--------------------------------------------------------------------
2792
2793AC_DEFUN([TEA_TCL_EARLY_FLAG],[
2794    AC_CACHE_VAL([tcl_cv_flag_]translit($1,[A-Z],[a-z]),
2795	AC_TRY_COMPILE([$2], $3, [tcl_cv_flag_]translit($1,[A-Z],[a-z])=no,
2796	    AC_TRY_COMPILE([[#define ]$1[ 1
2797]$2], $3,
2798		[tcl_cv_flag_]translit($1,[A-Z],[a-z])=yes,
2799		[tcl_cv_flag_]translit($1,[A-Z],[a-z])=no)))
2800    if test ["x${tcl_cv_flag_]translit($1,[A-Z],[a-z])[}" = "xyes"] ; then
2801	AC_DEFINE($1, 1, [Add the ]$1[ flag when building])
2802	tcl_flags="$tcl_flags $1"
2803    fi
2804])
2805
2806AC_DEFUN([TEA_TCL_EARLY_FLAGS],[
2807    AC_MSG_CHECKING([for required early compiler flags])
2808    tcl_flags=""
2809    TEA_TCL_EARLY_FLAG(_ISOC99_SOURCE,[#include <stdlib.h>],
2810	[char *p = (char *)strtoll; char *q = (char *)strtoull;])
2811    TEA_TCL_EARLY_FLAG(_LARGEFILE64_SOURCE,[#include <sys/stat.h>],
2812	[struct stat64 buf; int i = stat64("/", &buf);])
2813    TEA_TCL_EARLY_FLAG(_LARGEFILE_SOURCE64,[#include <sys/stat.h>],
2814	[char *p = (char *)open64;])
2815    if test "x${tcl_flags}" = "x" ; then
2816	AC_MSG_RESULT([none])
2817    else
2818	AC_MSG_RESULT([${tcl_flags}])
2819    fi
2820])
2821
2822#--------------------------------------------------------------------
2823# TEA_TCL_64BIT_FLAGS
2824#
2825#	Check for what is defined in the way of 64-bit features.
2826#
2827# Arguments:
2828#	None
2829#
2830# Results:
2831#
2832#	Might define the following vars:
2833#		TCL_WIDE_INT_IS_LONG
2834#		TCL_WIDE_INT_TYPE
2835#		HAVE_STRUCT_DIRENT64
2836#		HAVE_STRUCT_STAT64
2837#		HAVE_TYPE_OFF64_T
2838#
2839#--------------------------------------------------------------------
2840
2841AC_DEFUN([TEA_TCL_64BIT_FLAGS], [
2842    AC_MSG_CHECKING([for 64-bit integer type])
2843    AC_CACHE_VAL(tcl_cv_type_64bit,[
2844	tcl_cv_type_64bit=none
2845	# See if the compiler knows natively about __int64
2846	AC_TRY_COMPILE(,[__int64 value = (__int64) 0;],
2847	    tcl_type_64bit=__int64, tcl_type_64bit="long long")
2848	# See if we should use long anyway  Note that we substitute in the
2849	# type that is our current guess for a 64-bit type inside this check
2850	# program, so it should be modified only carefully...
2851        AC_TRY_COMPILE(,[switch (0) {
2852            case 1: case (sizeof(]${tcl_type_64bit}[)==sizeof(long)): ;
2853        }],tcl_cv_type_64bit=${tcl_type_64bit})])
2854    if test "${tcl_cv_type_64bit}" = none ; then
2855	AC_DEFINE(TCL_WIDE_INT_IS_LONG, 1, [Are wide integers to be implemented with C 'long's?])
2856	AC_MSG_RESULT([using long])
2857    elif test "${tcl_cv_type_64bit}" = "__int64" \
2858		-a "${TEA_PLATFORM}" = "windows" ; then
2859	# TEA specific: We actually want to use the default tcl.h checks in
2860	# this case to handle both TCL_WIDE_INT_TYPE and TCL_LL_MODIFIER*
2861	AC_MSG_RESULT([using Tcl header defaults])
2862    else
2863	AC_DEFINE_UNQUOTED(TCL_WIDE_INT_TYPE,${tcl_cv_type_64bit},
2864	    [What type should be used to define wide integers?])
2865	AC_MSG_RESULT([${tcl_cv_type_64bit}])
2866
2867	# Now check for auxiliary declarations
2868	AC_CACHE_CHECK([for struct dirent64], tcl_cv_struct_dirent64,[
2869	    AC_TRY_COMPILE([#include <sys/types.h>
2870#include <sys/dirent.h>],[struct dirent64 p;],
2871		tcl_cv_struct_dirent64=yes,tcl_cv_struct_dirent64=no)])
2872	if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then
2873	    AC_DEFINE(HAVE_STRUCT_DIRENT64, 1, [Is 'struct dirent64' in <sys/types.h>?])
2874	fi
2875
2876	AC_CACHE_CHECK([for struct stat64], tcl_cv_struct_stat64,[
2877	    AC_TRY_COMPILE([#include <sys/stat.h>],[struct stat64 p;
2878],
2879		tcl_cv_struct_stat64=yes,tcl_cv_struct_stat64=no)])
2880	if test "x${tcl_cv_struct_stat64}" = "xyes" ; then
2881	    AC_DEFINE(HAVE_STRUCT_STAT64, 1, [Is 'struct stat64' in <sys/stat.h>?])
2882	fi
2883
2884	AC_CHECK_FUNCS(open64 lseek64)
2885	AC_MSG_CHECKING([for off64_t])
2886	AC_CACHE_VAL(tcl_cv_type_off64_t,[
2887	    AC_TRY_COMPILE([#include <sys/types.h>],[off64_t offset;
2888],
2889		tcl_cv_type_off64_t=yes,tcl_cv_type_off64_t=no)])
2890	dnl Define HAVE_TYPE_OFF64_T only when the off64_t type and the
2891	dnl functions lseek64 and open64 are defined.
2892	if test "x${tcl_cv_type_off64_t}" = "xyes" && \
2893	        test "x${ac_cv_func_lseek64}" = "xyes" && \
2894	        test "x${ac_cv_func_open64}" = "xyes" ; then
2895	    AC_DEFINE(HAVE_TYPE_OFF64_T, 1, [Is off64_t in <sys/types.h>?])
2896	    AC_MSG_RESULT([yes])
2897	else
2898	    AC_MSG_RESULT([no])
2899	fi
2900    fi
2901])
2902
2903##
2904## Here ends the standard Tcl configuration bits and starts the
2905## TEA specific functions
2906##
2907
2908#------------------------------------------------------------------------
2909# TEA_INIT --
2910#
2911#	Init various Tcl Extension Architecture (TEA) variables.
2912#	This should be the first called TEA_* macro.
2913#
2914# Arguments:
2915#	none
2916#
2917# Results:
2918#
2919#	Defines and substs the following vars:
2920#		CYGPATH
2921#		EXEEXT
2922#	Defines only:
2923#		TEA_VERSION
2924#		TEA_INITED
2925#		TEA_PLATFORM (windows or unix)
2926#
2927# "cygpath" is used on windows to generate native path names for include
2928# files. These variables should only be used with the compiler and linker
2929# since they generate native path names.
2930#
2931# EXEEXT
2932#	Select the executable extension based on the host type.  This
2933#	is a lightweight replacement for AC_EXEEXT that doesn't require
2934#	a compiler.
2935#------------------------------------------------------------------------
2936
2937AC_DEFUN([TEA_INIT], [
2938    # TEA extensions pass this us the version of TEA they think they
2939    # are compatible with.
2940    TEA_VERSION="3.7"
2941
2942    AC_MSG_CHECKING([for correct TEA configuration])
2943    if test x"${PACKAGE_NAME}" = x ; then
2944	AC_MSG_ERROR([
2945The PACKAGE_NAME variable must be defined by your TEA configure.in])
2946    fi
2947    if test x"$1" = x ; then
2948	AC_MSG_ERROR([
2949TEA version not specified.])
2950    elif test "$1" != "${TEA_VERSION}" ; then
2951	AC_MSG_RESULT([warning: requested TEA version "$1", have "${TEA_VERSION}"])
2952    else
2953	AC_MSG_RESULT([ok (TEA ${TEA_VERSION})])
2954    fi
2955    case "`uname -s`" in
2956	*win32*|*WIN32*|*CYGWIN_NT*|*CYGWIN_9*|*CYGWIN_ME*|*MINGW32_*)
2957	    AC_CHECK_PROG(CYGPATH, cygpath, cygpath -w, echo)
2958	    EXEEXT=".exe"
2959	    TEA_PLATFORM="windows"
2960	    ;;
2961	*)
2962	    CYGPATH=echo
2963	    EXEEXT=""
2964	    TEA_PLATFORM="unix"
2965	    ;;
2966    esac
2967
2968    # Check if exec_prefix is set. If not use fall back to prefix.
2969    # Note when adjusted, so that TEA_PREFIX can correct for this.
2970    # This is needed for recursive configures, since autoconf propagates
2971    # $prefix, but not $exec_prefix (doh!).
2972    if test x$exec_prefix = xNONE ; then
2973	exec_prefix_default=yes
2974	exec_prefix=$prefix
2975    fi
2976
2977    AC_SUBST(EXEEXT)
2978    AC_SUBST(CYGPATH)
2979
2980    # This package name must be replaced statically for AC_SUBST to work
2981    AC_SUBST(PKG_LIB_FILE)
2982    # Substitute STUB_LIB_FILE in case package creates a stub library too.
2983    AC_SUBST(PKG_STUB_LIB_FILE)
2984
2985    # We AC_SUBST these here to ensure they are subst'ed,
2986    # in case the user doesn't call TEA_ADD_...
2987    AC_SUBST(PKG_STUB_SOURCES)
2988    AC_SUBST(PKG_STUB_OBJECTS)
2989    AC_SUBST(PKG_TCL_SOURCES)
2990    AC_SUBST(PKG_HEADERS)
2991    AC_SUBST(PKG_INCLUDES)
2992    AC_SUBST(PKG_LIBS)
2993    AC_SUBST(PKG_CFLAGS)
2994])
2995
2996#------------------------------------------------------------------------
2997# TEA_ADD_SOURCES --
2998#
2999#	Specify one or more source files.  Users should check for
3000#	the right platform before adding to their list.
3001#	It is not important to specify the directory, as long as it is
3002#	in the generic, win or unix subdirectory of $(srcdir).
3003#
3004# Arguments:
3005#	one or more file names
3006#
3007# Results:
3008#
3009#	Defines and substs the following vars:
3010#		PKG_SOURCES
3011#		PKG_OBJECTS
3012#------------------------------------------------------------------------
3013AC_DEFUN([TEA_ADD_SOURCES], [
3014    vars="$@"
3015    for i in $vars; do
3016	case $i in
3017	    [\$]*)
3018		# allow $-var names
3019		PKG_SOURCES="$PKG_SOURCES $i"
3020		PKG_OBJECTS="$PKG_OBJECTS $i"
3021		;;
3022	    *)
3023		# check for existence - allows for generic/win/unix VPATH
3024		# To add more dirs here (like 'src'), you have to update VPATH
3025		# in Makefile.in as well
3026		if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \
3027		    -a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \
3028		    ; then
3029		    AC_MSG_ERROR([could not find source file '$i'])
3030		fi
3031		PKG_SOURCES="$PKG_SOURCES $i"
3032		# this assumes it is in a VPATH dir
3033		i=`basename $i`
3034		# handle user calling this before or after TEA_SETUP_COMPILER
3035		if test x"${OBJEXT}" != x ; then
3036		    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.${OBJEXT}"
3037		else
3038		    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.\${OBJEXT}"
3039		fi
3040		PKG_OBJECTS="$PKG_OBJECTS $j"
3041		;;
3042	esac
3043    done
3044    AC_SUBST(PKG_SOURCES)
3045    AC_SUBST(PKG_OBJECTS)
3046])
3047
3048#------------------------------------------------------------------------
3049# TEA_ADD_STUB_SOURCES --
3050#
3051#	Specify one or more source files.  Users should check for
3052#	the right platform before adding to their list.
3053#	It is not important to specify the directory, as long as it is
3054#	in the generic, win or unix subdirectory of $(srcdir).
3055#
3056# Arguments:
3057#	one or more file names
3058#
3059# Results:
3060#
3061#	Defines and substs the following vars:
3062#		PKG_STUB_SOURCES
3063#		PKG_STUB_OBJECTS
3064#------------------------------------------------------------------------
3065AC_DEFUN([TEA_ADD_STUB_SOURCES], [
3066    vars="$@"
3067    for i in $vars; do
3068	# check for existence - allows for generic/win/unix VPATH
3069	if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \
3070	    -a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \
3071	    ; then
3072	    AC_MSG_ERROR([could not find stub source file '$i'])
3073	fi
3074	PKG_STUB_SOURCES="$PKG_STUB_SOURCES $i"
3075	# this assumes it is in a VPATH dir
3076	i=`basename $i`
3077	# handle user calling this before or after TEA_SETUP_COMPILER
3078	if test x"${OBJEXT}" != x ; then
3079	    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.${OBJEXT}"
3080	else
3081	    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.\${OBJEXT}"
3082	fi
3083	PKG_STUB_OBJECTS="$PKG_STUB_OBJECTS $j"
3084    done
3085    AC_SUBST(PKG_STUB_SOURCES)
3086    AC_SUBST(PKG_STUB_OBJECTS)
3087])
3088
3089#------------------------------------------------------------------------
3090# TEA_ADD_TCL_SOURCES --
3091#
3092#	Specify one or more Tcl source files.  These should be platform
3093#	independent runtime files.
3094#
3095# Arguments:
3096#	one or more file names
3097#
3098# Results:
3099#
3100#	Defines and substs the following vars:
3101#		PKG_TCL_SOURCES
3102#------------------------------------------------------------------------
3103AC_DEFUN([TEA_ADD_TCL_SOURCES], [
3104    vars="$@"
3105    for i in $vars; do
3106	# check for existence, be strict because it is installed
3107	if test ! -f "${srcdir}/$i" ; then
3108	    AC_MSG_ERROR([could not find tcl source file '${srcdir}/$i'])
3109	fi
3110	PKG_TCL_SOURCES="$PKG_TCL_SOURCES $i"
3111    done
3112    AC_SUBST(PKG_TCL_SOURCES)
3113])
3114
3115#------------------------------------------------------------------------
3116# TEA_ADD_HEADERS --
3117#
3118#	Specify one or more source headers.  Users should check for
3119#	the right platform before adding to their list.
3120#
3121# Arguments:
3122#	one or more file names
3123#
3124# Results:
3125#
3126#	Defines and substs the following vars:
3127#		PKG_HEADERS
3128#------------------------------------------------------------------------
3129AC_DEFUN([TEA_ADD_HEADERS], [
3130    vars="$@"
3131    for i in $vars; do
3132	# check for existence, be strict because it is installed
3133	if test ! -f "${srcdir}/$i" ; then
3134	    AC_MSG_ERROR([could not find header file '${srcdir}/$i'])
3135	fi
3136	PKG_HEADERS="$PKG_HEADERS $i"
3137    done
3138    AC_SUBST(PKG_HEADERS)
3139])
3140
3141#------------------------------------------------------------------------
3142# TEA_ADD_INCLUDES --
3143#
3144#	Specify one or more include dirs.  Users should check for
3145#	the right platform before adding to their list.
3146#
3147# Arguments:
3148#	one or more file names
3149#
3150# Results:
3151#
3152#	Defines and substs the following vars:
3153#		PKG_INCLUDES
3154#------------------------------------------------------------------------
3155AC_DEFUN([TEA_ADD_INCLUDES], [
3156    vars="$@"
3157    for i in $vars; do
3158	PKG_INCLUDES="$PKG_INCLUDES $i"
3159    done
3160    AC_SUBST(PKG_INCLUDES)
3161])
3162
3163#------------------------------------------------------------------------
3164# TEA_ADD_LIBS --
3165#
3166#	Specify one or more libraries.  Users should check for
3167#	the right platform before adding to their list.  For Windows,
3168#	libraries provided in "foo.lib" format will be converted to
3169#	"-lfoo" when using GCC (mingw).
3170#
3171# Arguments:
3172#	one or more file names
3173#
3174# Results:
3175#
3176#	Defines and substs the following vars:
3177#		PKG_LIBS
3178#------------------------------------------------------------------------
3179AC_DEFUN([TEA_ADD_LIBS], [
3180    vars="$@"
3181    for i in $vars; do
3182	if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then
3183	    # Convert foo.lib to -lfoo for GCC.  No-op if not *.lib
3184	    i=`echo "$i" | sed -e 's/^\([[^-]].*\)\.lib[$]/-l\1/i'`
3185	fi
3186	PKG_LIBS="$PKG_LIBS $i"
3187    done
3188    AC_SUBST(PKG_LIBS)
3189])
3190
3191#------------------------------------------------------------------------
3192# TEA_ADD_CFLAGS --
3193#
3194#	Specify one or more CFLAGS.  Users should check for
3195#	the right platform before adding to their list.
3196#
3197# Arguments:
3198#	one or more file names
3199#
3200# Results:
3201#
3202#	Defines and substs the following vars:
3203#		PKG_CFLAGS
3204#------------------------------------------------------------------------
3205AC_DEFUN([TEA_ADD_CFLAGS], [
3206    PKG_CFLAGS="$PKG_CFLAGS $@"
3207    AC_SUBST(PKG_CFLAGS)
3208])
3209
3210#------------------------------------------------------------------------
3211# TEA_PREFIX --
3212#
3213#	Handle the --prefix=... option by defaulting to what Tcl gave
3214#
3215# Arguments:
3216#	none
3217#
3218# Results:
3219#
3220#	If --prefix or --exec-prefix was not specified, $prefix and
3221#	$exec_prefix will be set to the values given to Tcl when it was
3222#	configured.
3223#------------------------------------------------------------------------
3224AC_DEFUN([TEA_PREFIX], [
3225    if test "${prefix}" = "NONE"; then
3226	prefix_default=yes
3227	if test x"${TCL_PREFIX}" != x; then
3228	    AC_MSG_NOTICE([--prefix defaulting to TCL_PREFIX ${TCL_PREFIX}])
3229	    prefix=${TCL_PREFIX}
3230	else
3231	    AC_MSG_NOTICE([--prefix defaulting to /usr/local])
3232	    prefix=/usr/local
3233	fi
3234    fi
3235    if test "${exec_prefix}" = "NONE" -a x"${prefix_default}" = x"yes" \
3236	-o x"${exec_prefix_default}" = x"yes" ; then
3237	if test x"${TCL_EXEC_PREFIX}" != x; then
3238	    AC_MSG_NOTICE([--exec-prefix defaulting to TCL_EXEC_PREFIX ${TCL_EXEC_PREFIX}])
3239	    exec_prefix=${TCL_EXEC_PREFIX}
3240	else
3241	    AC_MSG_NOTICE([--exec-prefix defaulting to ${prefix}])
3242	    exec_prefix=$prefix
3243	fi
3244    fi
3245])
3246
3247#------------------------------------------------------------------------
3248# TEA_SETUP_COMPILER_CC --
3249#
3250#	Do compiler checks the way we want.  This is just a replacement
3251#	for AC_PROG_CC in TEA configure.in files to make them cleaner.
3252#
3253# Arguments:
3254#	none
3255#
3256# Results:
3257#
3258#	Sets up CC var and other standard bits we need to make executables.
3259#------------------------------------------------------------------------
3260AC_DEFUN([TEA_SETUP_COMPILER_CC], [
3261    # Don't put any macros that use the compiler (e.g. AC_TRY_COMPILE)
3262    # in this macro, they need to go into TEA_SETUP_COMPILER instead.
3263
3264    # If the user did not set CFLAGS, set it now to keep
3265    # the AC_PROG_CC macro from adding "-g -O2".
3266    if test "${CFLAGS+set}" != "set" ; then
3267	CFLAGS=""
3268    fi
3269
3270    AC_PROG_CC
3271    AC_PROG_CPP
3272
3273    AC_PROG_INSTALL
3274
3275    #--------------------------------------------------------------------
3276    # Checks to see if the make program sets the $MAKE variable.
3277    #--------------------------------------------------------------------
3278
3279    AC_PROG_MAKE_SET
3280
3281    #--------------------------------------------------------------------
3282    # Find ranlib
3283    #--------------------------------------------------------------------
3284
3285    AC_PROG_RANLIB
3286
3287    #--------------------------------------------------------------------
3288    # Determines the correct binary file extension (.o, .obj, .exe etc.)
3289    #--------------------------------------------------------------------
3290
3291    AC_OBJEXT
3292    AC_EXEEXT
3293])
3294
3295#------------------------------------------------------------------------
3296# TEA_SETUP_COMPILER --
3297#
3298#	Do compiler checks that use the compiler.  This must go after
3299#	TEA_SETUP_COMPILER_CC, which does the actual compiler check.
3300#
3301# Arguments:
3302#	none
3303#
3304# Results:
3305#
3306#	Sets up CC var and other standard bits we need to make executables.
3307#------------------------------------------------------------------------
3308AC_DEFUN([TEA_SETUP_COMPILER], [
3309    # Any macros that use the compiler (e.g. AC_TRY_COMPILE) have to go here.
3310    AC_REQUIRE([TEA_SETUP_COMPILER_CC])
3311
3312    #------------------------------------------------------------------------
3313    # If we're using GCC, see if the compiler understands -pipe. If so, use it.
3314    # It makes compiling go faster.  (This is only a performance feature.)
3315    #------------------------------------------------------------------------
3316
3317    if test -z "$no_pipe" -a -n "$GCC"; then
3318	AC_CACHE_CHECK([if the compiler understands -pipe],
3319	    tcl_cv_cc_pipe, [
3320	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -pipe"
3321	    AC_TRY_COMPILE(,, tcl_cv_cc_pipe=yes, tcl_cv_cc_pipe=no)
3322	    CFLAGS=$hold_cflags])
3323	if test $tcl_cv_cc_pipe = yes; then
3324	    CFLAGS="$CFLAGS -pipe"
3325	fi
3326    fi
3327
3328    #--------------------------------------------------------------------
3329    # Common compiler flag setup
3330    #--------------------------------------------------------------------
3331
3332    AC_C_BIGENDIAN
3333    if test "${TEA_PLATFORM}" = "unix" ; then
3334	TEA_TCL_LINK_LIBS
3335	TEA_MISSING_POSIX_HEADERS
3336	# Let the user call this, because if it triggers, they will
3337	# need a compat/strtod.c that is correct.  Users can also
3338	# use Tcl_GetDouble(FromObj) instead.
3339	#TEA_BUGGY_STRTOD
3340    fi
3341])
3342
3343#------------------------------------------------------------------------
3344# TEA_MAKE_LIB --
3345#
3346#	Generate a line that can be used to build a shared/unshared library
3347#	in a platform independent manner.
3348#
3349# Arguments:
3350#	none
3351#
3352#	Requires:
3353#
3354# Results:
3355#
3356#	Defines the following vars:
3357#	CFLAGS -	Done late here to note disturb other AC macros
3358#       MAKE_LIB -      Command to execute to build the Tcl library;
3359#                       differs depending on whether or not Tcl is being
3360#                       compiled as a shared library.
3361#	MAKE_SHARED_LIB	Makefile rule for building a shared library
3362#	MAKE_STATIC_LIB	Makefile rule for building a static library
3363#	MAKE_STUB_LIB	Makefile rule for building a stub library
3364#------------------------------------------------------------------------
3365
3366AC_DEFUN([TEA_MAKE_LIB], [
3367    if test "${TEA_PLATFORM}" = "windows" -a "$GCC" != "yes"; then
3368	MAKE_STATIC_LIB="\${STLIB_LD} -out:\[$]@ \$(PKG_OBJECTS)"
3369	MAKE_SHARED_LIB="\${SHLIB_LD} \${SHLIB_LD_LIBS} \${LDFLAGS_DEFAULT} -out:\[$]@ \$(PKG_OBJECTS)"
3370	MAKE_STUB_LIB="\${STLIB_LD} -out:\[$]@ \$(PKG_STUB_OBJECTS)"
3371    else
3372	MAKE_STATIC_LIB="\${STLIB_LD} \[$]@ \$(PKG_OBJECTS)"
3373	MAKE_SHARED_LIB="\${SHLIB_LD} -o \[$]@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}"
3374	MAKE_STUB_LIB="\${STLIB_LD} \[$]@ \$(PKG_STUB_OBJECTS)"
3375    fi
3376
3377    if test "${SHARED_BUILD}" = "1" ; then
3378	MAKE_LIB="${MAKE_SHARED_LIB} "
3379    else
3380	MAKE_LIB="${MAKE_STATIC_LIB} "
3381    fi
3382
3383    #--------------------------------------------------------------------
3384    # Shared libraries and static libraries have different names.
3385    # Use the double eval to make sure any variables in the suffix is
3386    # substituted. (@@@ Might not be necessary anymore)
3387    #--------------------------------------------------------------------
3388
3389    if test "${TEA_PLATFORM}" = "windows" ; then
3390	if test "${SHARED_BUILD}" = "1" ; then
3391	    # We force the unresolved linking of symbols that are really in
3392	    # the private libraries of Tcl and Tk.
3393	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \"`${CYGPATH} ${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}`\""
3394	    if test x"${TK_BIN_DIR}" != x ; then
3395		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \"`${CYGPATH} ${TK_BIN_DIR}/${TK_STUB_LIB_FILE}`\""
3396	    fi
3397	    eval eval "PKG_LIB_FILE=${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
3398	else
3399	    eval eval "PKG_LIB_FILE=${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
3400	fi
3401	# Some packages build their own stubs libraries
3402	eval eval "PKG_STUB_LIB_FILE=${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}"
3403	if test "$GCC" = "yes"; then
3404	    PKG_STUB_LIB_FILE=lib${PKG_STUB_LIB_FILE}
3405	fi
3406	# These aren't needed on Windows (either MSVC or gcc)
3407	RANLIB=:
3408	RANLIB_STUB=:
3409    else
3410	RANLIB_STUB="${RANLIB}"
3411	if test "${SHARED_BUILD}" = "1" ; then
3412	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} ${TCL_STUB_LIB_SPEC}"
3413	    if test x"${TK_BIN_DIR}" != x ; then
3414		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} ${TK_STUB_LIB_SPEC}"
3415	    fi
3416	    eval eval "PKG_LIB_FILE=lib${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
3417	    RANLIB=:
3418	else
3419	    eval eval "PKG_LIB_FILE=lib${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
3420	fi
3421	# Some packages build their own stubs libraries
3422	eval eval "PKG_STUB_LIB_FILE=lib${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}"
3423    fi
3424
3425    # These are escaped so that only CFLAGS is picked up at configure time.
3426    # The other values will be substituted at make time.
3427    CFLAGS="${CFLAGS} \${CFLAGS_DEFAULT} \${CFLAGS_WARNING}"
3428    if test "${SHARED_BUILD}" = "1" ; then
3429	CFLAGS="${CFLAGS} \${SHLIB_CFLAGS}"
3430    fi
3431
3432    AC_SUBST(MAKE_LIB)
3433    AC_SUBST(MAKE_SHARED_LIB)
3434    AC_SUBST(MAKE_STATIC_LIB)
3435    AC_SUBST(MAKE_STUB_LIB)
3436    AC_SUBST(RANLIB_STUB)
3437])
3438
3439#------------------------------------------------------------------------
3440# TEA_LIB_SPEC --
3441#
3442#	Compute the name of an existing object library located in libdir
3443#	from the given base name and produce the appropriate linker flags.
3444#
3445# Arguments:
3446#	basename	The base name of the library without version
3447#			numbers, extensions, or "lib" prefixes.
3448#	extra_dir	Extra directory in which to search for the
3449#			library.  This location is used first, then
3450#			$prefix/$exec-prefix, then some defaults.
3451#
3452# Requires:
3453#	TEA_INIT and TEA_PREFIX must be called first.
3454#
3455# Results:
3456#
3457#	Defines the following vars:
3458#		${basename}_LIB_NAME	The computed library name.
3459#		${basename}_LIB_SPEC	The computed linker flags.
3460#------------------------------------------------------------------------
3461
3462AC_DEFUN([TEA_LIB_SPEC], [
3463    AC_MSG_CHECKING([for $1 library])
3464
3465    # Look in exec-prefix for the library (defined by TEA_PREFIX).
3466
3467    tea_lib_name_dir="${exec_prefix}/lib"
3468
3469    # Or in a user-specified location.
3470
3471    if test x"$2" != x ; then
3472	tea_extra_lib_dir=$2
3473    else
3474	tea_extra_lib_dir=NONE
3475    fi
3476
3477    for i in \
3478	    `ls -dr ${tea_extra_lib_dir}/$1[[0-9]]*.lib 2>/dev/null ` \
3479	    `ls -dr ${tea_extra_lib_dir}/lib$1[[0-9]]* 2>/dev/null ` \
3480	    `ls -dr ${tea_lib_name_dir}/$1[[0-9]]*.lib 2>/dev/null ` \
3481	    `ls -dr ${tea_lib_name_dir}/lib$1[[0-9]]* 2>/dev/null ` \
3482	    `ls -dr /usr/lib/$1[[0-9]]*.lib 2>/dev/null ` \
3483	    `ls -dr /usr/lib/lib$1[[0-9]]* 2>/dev/null ` \
3484	    `ls -dr /usr/local/lib/$1[[0-9]]*.lib 2>/dev/null ` \
3485	    `ls -dr /usr/local/lib/lib$1[[0-9]]* 2>/dev/null ` ; do
3486	if test -f "$i" ; then
3487	    tea_lib_name_dir=`dirname $i`
3488	    $1_LIB_NAME=`basename $i`
3489	    $1_LIB_PATH_NAME=$i
3490	    break
3491	fi
3492    done
3493
3494    if test "${TEA_PLATFORM}" = "windows"; then
3495	$1_LIB_SPEC=\"`${CYGPATH} ${$1_LIB_PATH_NAME} 2>/dev/null`\"
3496    else
3497	# Strip off the leading "lib" and trailing ".a" or ".so"
3498
3499	tea_lib_name_lib=`echo ${$1_LIB_NAME}|sed -e 's/^lib//' -e 's/\.[[^.]]*$//' -e 's/\.so.*//'`
3500	$1_LIB_SPEC="-L${tea_lib_name_dir} -l${tea_lib_name_lib}"
3501    fi
3502
3503    if test "x${$1_LIB_NAME}" = x ; then
3504	AC_MSG_ERROR([not found])
3505    else
3506	AC_MSG_RESULT([${$1_LIB_SPEC}])
3507    fi
3508])
3509
3510#------------------------------------------------------------------------
3511# TEA_PRIVATE_TCL_HEADERS --
3512#
3513#	Locate the private Tcl include files
3514#
3515# Arguments:
3516#
3517#	Requires:
3518#		TCL_SRC_DIR	Assumes that TEA_LOAD_TCLCONFIG has
3519#				already been called.
3520#
3521# Results:
3522#
3523#	Substs the following vars:
3524#		TCL_TOP_DIR_NATIVE
3525#		TCL_INCLUDES
3526#------------------------------------------------------------------------
3527
3528AC_DEFUN([TEA_PRIVATE_TCL_HEADERS], [
3529    # Allow for --with-tclinclude to take effect and define ${ac_cv_c_tclh}
3530    AC_REQUIRE([TEA_PUBLIC_TCL_HEADERS])
3531    AC_MSG_CHECKING([for Tcl private include files])
3532
3533    TCL_SRC_DIR_NATIVE=`${CYGPATH} ${TCL_SRC_DIR}`
3534    TCL_TOP_DIR_NATIVE=\"${TCL_SRC_DIR_NATIVE}\"
3535
3536    # Check to see if tcl<Plat>Port.h isn't already with the public headers
3537    # Don't look for tclInt.h because that resides with tcl.h in the core
3538    # sources, but the <plat>Port headers are in a different directory
3539    if test "${TEA_PLATFORM}" = "windows" -a \
3540	-f "${ac_cv_c_tclh}/tclWinPort.h"; then
3541	result="private headers found with public headers"
3542    elif test "${TEA_PLATFORM}" = "unix" -a \
3543	-f "${ac_cv_c_tclh}/tclUnixPort.h"; then
3544	result="private headers found with public headers"
3545    else
3546	TCL_GENERIC_DIR_NATIVE=\"${TCL_SRC_DIR_NATIVE}/generic\"
3547	if test "${TEA_PLATFORM}" = "windows"; then
3548	    TCL_PLATFORM_DIR_NATIVE=\"${TCL_SRC_DIR_NATIVE}/win\"
3549	else
3550	    TCL_PLATFORM_DIR_NATIVE=\"${TCL_SRC_DIR_NATIVE}/unix\"
3551	fi
3552	# Overwrite the previous TCL_INCLUDES as this should capture both
3553	# public and private headers in the same set.
3554	# We want to ensure these are substituted so as not to require
3555	# any *_NATIVE vars be defined in the Makefile
3556	TCL_INCLUDES="-I${TCL_GENERIC_DIR_NATIVE} -I${TCL_PLATFORM_DIR_NATIVE}"
3557	if test "`uname -s`" = "Darwin"; then
3558            # If Tcl was built as a framework, attempt to use
3559            # the framework's Headers and PrivateHeaders directories
3560            case ${TCL_DEFS} in
3561	    	*TCL_FRAMEWORK*)
3562		    if test -d "${TCL_BIN_DIR}/Headers" -a \
3563			    -d "${TCL_BIN_DIR}/PrivateHeaders"; then
3564			TCL_INCLUDES="-I\"${TCL_BIN_DIR}/Headers\" -I\"${TCL_BIN_DIR}/PrivateHeaders\" ${TCL_INCLUDES}"
3565		    else
3566			TCL_INCLUDES="${TCL_INCLUDES} ${TCL_INCLUDE_SPEC} `echo "${TCL_INCLUDE_SPEC}" | sed -e 's/Headers/PrivateHeaders/'`"
3567		    fi
3568	            ;;
3569	    esac
3570	    result="Using ${TCL_INCLUDES}"
3571	else
3572	    if test ! -f "${TCL_SRC_DIR}/generic/tclInt.h" ; then
3573		AC_MSG_ERROR([Cannot find private header tclInt.h in ${TCL_SRC_DIR}])
3574	    fi
3575	    result="Using srcdir found in tclConfig.sh: ${TCL_SRC_DIR}"
3576	fi
3577    fi
3578
3579    AC_SUBST(TCL_TOP_DIR_NATIVE)
3580
3581    AC_SUBST(TCL_INCLUDES)
3582    AC_MSG_RESULT([${result}])
3583])
3584
3585#------------------------------------------------------------------------
3586# TEA_PUBLIC_TCL_HEADERS --
3587#
3588#	Locate the installed public Tcl header files
3589#
3590# Arguments:
3591#	None.
3592#
3593# Requires:
3594#	CYGPATH must be set
3595#
3596# Results:
3597#
3598#	Adds a --with-tclinclude switch to configure.
3599#	Result is cached.
3600#
3601#	Substs the following vars:
3602#		TCL_INCLUDES
3603#------------------------------------------------------------------------
3604
3605AC_DEFUN([TEA_PUBLIC_TCL_HEADERS], [
3606    AC_MSG_CHECKING([for Tcl public headers])
3607
3608    AC_ARG_WITH(tclinclude, [  --with-tclinclude       directory containing the public Tcl header files], with_tclinclude=${withval})
3609
3610    AC_CACHE_VAL(ac_cv_c_tclh, [
3611	# Use the value from --with-tclinclude, if it was given
3612
3613	if test x"${with_tclinclude}" != x ; then
3614	    if test -f "${with_tclinclude}/tcl.h" ; then
3615		ac_cv_c_tclh=${with_tclinclude}
3616	    else
3617		AC_MSG_ERROR([${with_tclinclude} directory does not contain tcl.h])
3618	    fi
3619	else
3620	    if test "`uname -s`" = "Darwin"; then
3621		# If Tcl was built as a framework, attempt to use
3622		# the framework's Headers directory
3623		case ${TCL_DEFS} in
3624		    *TCL_FRAMEWORK*)
3625			list="`ls -d ${TCL_BIN_DIR}/Headers 2>/dev/null`"
3626			;;
3627		esac
3628	    fi
3629
3630	    # Look in the source dir only if Tcl is not installed,
3631	    # and in that situation, look there before installed locations.
3632	    if test -f "${TCL_BIN_DIR}/Makefile" ; then
3633		list="$list `ls -d ${TCL_SRC_DIR}/generic 2>/dev/null`"
3634	    fi
3635
3636	    # Check order: pkg --prefix location, Tcl's --prefix location,
3637	    # relative to directory of tclConfig.sh.
3638
3639	    eval "temp_includedir=${includedir}"
3640	    list="$list \
3641		`ls -d ${temp_includedir}        2>/dev/null` \
3642		`ls -d ${TCL_PREFIX}/include     2>/dev/null` \
3643		`ls -d ${TCL_BIN_DIR}/../include 2>/dev/null`"
3644	    if test "${TEA_PLATFORM}" != "windows" -o "$GCC" = "yes"; then
3645		list="$list /usr/local/include /usr/include"
3646		if test x"${TCL_INCLUDE_SPEC}" != x ; then
3647		    d=`echo "${TCL_INCLUDE_SPEC}" | sed -e 's/^-I//'`
3648		    list="$list `ls -d ${d} 2>/dev/null`"
3649		fi
3650	    fi
3651	    for i in $list ; do
3652		if test -f "$i/tcl.h" ; then
3653		    ac_cv_c_tclh=$i
3654		    break
3655		fi
3656	    done
3657	fi
3658    ])
3659
3660    # Print a message based on how we determined the include path
3661
3662    if test x"${ac_cv_c_tclh}" = x ; then
3663	AC_MSG_ERROR([tcl.h not found.  Please specify its location with --with-tclinclude])
3664    else
3665	AC_MSG_RESULT([${ac_cv_c_tclh}])
3666    fi
3667
3668    # Convert to a native path and substitute into the output files.
3669
3670    INCLUDE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tclh}`
3671
3672    TCL_INCLUDES=-I\"${INCLUDE_DIR_NATIVE}\"
3673
3674    AC_SUBST(TCL_INCLUDES)
3675])
3676
3677#------------------------------------------------------------------------
3678# TEA_PRIVATE_TK_HEADERS --
3679#
3680#	Locate the private Tk include files
3681#
3682# Arguments:
3683#
3684#	Requires:
3685#		TK_SRC_DIR	Assumes that TEA_LOAD_TKCONFIG has
3686#				 already been called.
3687#
3688# Results:
3689#
3690#	Substs the following vars:
3691#		TK_INCLUDES
3692#------------------------------------------------------------------------
3693
3694AC_DEFUN([TEA_PRIVATE_TK_HEADERS], [
3695    # Allow for --with-tkinclude to take effect and define ${ac_cv_c_tkh}
3696    AC_REQUIRE([TEA_PUBLIC_TK_HEADERS])
3697    AC_MSG_CHECKING([for Tk private include files])
3698
3699    TK_SRC_DIR_NATIVE=`${CYGPATH} ${TK_SRC_DIR}`
3700    TK_TOP_DIR_NATIVE=\"${TK_SRC_DIR_NATIVE}\"
3701
3702    # Check to see if tk<Plat>Port.h isn't already with the public headers
3703    # Don't look for tkInt.h because that resides with tk.h in the core
3704    # sources, but the <plat>Port headers are in a different directory
3705    if test "${TEA_PLATFORM}" = "windows" -a \
3706	-f "${ac_cv_c_tkh}/tkWinPort.h"; then
3707	result="private headers found with public headers"
3708    elif test "${TEA_PLATFORM}" = "unix" -a \
3709	-f "${ac_cv_c_tkh}/tkUnixPort.h"; then
3710	result="private headers found with public headers"
3711    else
3712	TK_GENERIC_DIR_NATIVE=\"${TK_SRC_DIR_NATIVE}/generic\"
3713	TK_XLIB_DIR_NATIVE=\"${TK_SRC_DIR_NATIVE}/xlib\"
3714	if test "${TEA_PLATFORM}" = "windows"; then
3715	    TK_PLATFORM_DIR_NATIVE=\"${TK_SRC_DIR_NATIVE}/win\"
3716	else
3717	    TK_PLATFORM_DIR_NATIVE=\"${TK_SRC_DIR_NATIVE}/unix\"
3718	fi
3719	# Overwrite the previous TK_INCLUDES as this should capture both
3720	# public and private headers in the same set.
3721	# We want to ensure these are substituted so as not to require
3722	# any *_NATIVE vars be defined in the Makefile
3723	TK_INCLUDES="-I${TK_GENERIC_DIR_NATIVE} -I${TK_PLATFORM_DIR_NATIVE}"
3724	# Detect and add ttk subdir
3725	if test -d "${TK_SRC_DIR}/generic/ttk"; then
3726	   TK_INCLUDES="${TK_INCLUDES} -I\"${TK_SRC_DIR_NATIVE}/generic/ttk\""
3727	fi
3728	if test "${TEA_WINDOWINGSYSTEM}" != "x11"; then
3729	   TK_INCLUDES="${TK_INCLUDES} -I\"${TK_XLIB_DIR_NATIVE}\""
3730	fi
3731	if test "${TEA_WINDOWINGSYSTEM}" = "aqua"; then
3732	   TK_INCLUDES="${TK_INCLUDES} -I\"${TK_SRC_DIR_NATIVE}/macosx\""
3733	fi
3734	if test "`uname -s`" = "Darwin"; then
3735	    # If Tk was built as a framework, attempt to use
3736	    # the framework's Headers and PrivateHeaders directories
3737	    case ${TK_DEFS} in
3738		*TK_FRAMEWORK*)
3739			if test -d "${TK_BIN_DIR}/Headers" -a \
3740				-d "${TK_BIN_DIR}/PrivateHeaders"; then
3741			    TK_INCLUDES="-I\"${TK_BIN_DIR}/Headers\" -I\"${TK_BIN_DIR}/PrivateHeaders\" ${TK_INCLUDES}"
3742			else
3743			    TK_INCLUDES="${TK_INCLUDES} ${TK_INCLUDE_SPEC} `echo "${TK_INCLUDE_SPEC}" | sed -e 's/Headers/PrivateHeaders/'`"
3744			fi
3745			;;
3746	    esac
3747	    result="Using ${TK_INCLUDES}"
3748	else
3749	    if test ! -f "${TK_SRC_DIR}/generic/tkInt.h" ; then
3750	       AC_MSG_ERROR([Cannot find private header tkInt.h in ${TK_SRC_DIR}])
3751	    fi
3752	    result="Using srcdir found in tkConfig.sh: ${TK_SRC_DIR}"
3753	fi
3754    fi
3755
3756    AC_SUBST(TK_TOP_DIR_NATIVE)
3757    AC_SUBST(TK_XLIB_DIR_NATIVE)
3758
3759    AC_SUBST(TK_INCLUDES)
3760    AC_MSG_RESULT([${result}])
3761])
3762
3763#------------------------------------------------------------------------
3764# TEA_PUBLIC_TK_HEADERS --
3765#
3766#	Locate the installed public Tk header files
3767#
3768# Arguments:
3769#	None.
3770#
3771# Requires:
3772#	CYGPATH must be set
3773#
3774# Results:
3775#
3776#	Adds a --with-tkinclude switch to configure.
3777#	Result is cached.
3778#
3779#	Substs the following vars:
3780#		TK_INCLUDES
3781#------------------------------------------------------------------------
3782
3783AC_DEFUN([TEA_PUBLIC_TK_HEADERS], [
3784    AC_MSG_CHECKING([for Tk public headers])
3785
3786    AC_ARG_WITH(tkinclude, [  --with-tkinclude        directory containing the public Tk header files], with_tkinclude=${withval})
3787
3788    AC_CACHE_VAL(ac_cv_c_tkh, [
3789	# Use the value from --with-tkinclude, if it was given
3790
3791	if test x"${with_tkinclude}" != x ; then
3792	    if test -f "${with_tkinclude}/tk.h" ; then
3793		ac_cv_c_tkh=${with_tkinclude}
3794	    else
3795		AC_MSG_ERROR([${with_tkinclude} directory does not contain tk.h])
3796	    fi
3797	else
3798	    if test "`uname -s`" = "Darwin"; then
3799		# If Tk was built as a framework, attempt to use
3800		# the framework's Headers directory.
3801		case ${TK_DEFS} in
3802		    *TK_FRAMEWORK*)
3803			list="`ls -d ${TK_BIN_DIR}/Headers 2>/dev/null`"
3804			;;
3805		esac
3806	    fi
3807
3808	    # Look in the source dir only if Tk is not installed,
3809	    # and in that situation, look there before installed locations.
3810	    if test -f "${TK_BIN_DIR}/Makefile" ; then
3811		list="$list `ls -d ${TK_SRC_DIR}/generic 2>/dev/null`"
3812	    fi
3813
3814	    # Check order: pkg --prefix location, Tk's --prefix location,
3815	    # relative to directory of tkConfig.sh, Tcl's --prefix location,
3816	    # relative to directory of tclConfig.sh.
3817
3818	    eval "temp_includedir=${includedir}"
3819	    list="$list \
3820		`ls -d ${temp_includedir}        2>/dev/null` \
3821		`ls -d ${TK_PREFIX}/include      2>/dev/null` \
3822		`ls -d ${TK_BIN_DIR}/../include  2>/dev/null` \
3823		`ls -d ${TCL_PREFIX}/include     2>/dev/null` \
3824		`ls -d ${TCL_BIN_DIR}/../include 2>/dev/null`"
3825	    if test "${TEA_PLATFORM}" != "windows" -o "$GCC" = "yes"; then
3826		list="$list /usr/local/include /usr/include"
3827	    fi
3828	    for i in $list ; do
3829		if test -f "$i/tk.h" ; then
3830		    ac_cv_c_tkh=$i
3831		    break
3832		fi
3833	    done
3834	fi
3835    ])
3836
3837    # Print a message based on how we determined the include path
3838
3839    if test x"${ac_cv_c_tkh}" = x ; then
3840	AC_MSG_ERROR([tk.h not found.  Please specify its location with --with-tkinclude])
3841    else
3842	AC_MSG_RESULT([${ac_cv_c_tkh}])
3843    fi
3844
3845    # Convert to a native path and substitute into the output files.
3846
3847    INCLUDE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tkh}`
3848
3849    TK_INCLUDES=-I\"${INCLUDE_DIR_NATIVE}\"
3850
3851    AC_SUBST(TK_INCLUDES)
3852
3853    if test "${TEA_WINDOWINGSYSTEM}" != "x11"; then
3854	# On Windows and Aqua, we need the X compat headers
3855	AC_MSG_CHECKING([for X11 header files])
3856	if test ! -r "${INCLUDE_DIR_NATIVE}/X11/Xlib.h"; then
3857	    INCLUDE_DIR_NATIVE="`${CYGPATH} ${TK_SRC_DIR}/xlib`"
3858	    TK_XINCLUDES=-I\"${INCLUDE_DIR_NATIVE}\"
3859	    AC_SUBST(TK_XINCLUDES)
3860	fi
3861	AC_MSG_RESULT([${INCLUDE_DIR_NATIVE}])
3862    fi
3863])
3864
3865#------------------------------------------------------------------------
3866# TEA_PATH_CONFIG --
3867#
3868#	Locate the ${1}Config.sh file and perform a sanity check on
3869#	the ${1} compile flags.  These are used by packages like
3870#	[incr Tk] that load *Config.sh files from more than Tcl and Tk.
3871#
3872# Arguments:
3873#	none
3874#
3875# Results:
3876#
3877#	Adds the following arguments to configure:
3878#		--with-$1=...
3879#
3880#	Defines the following vars:
3881#		$1_BIN_DIR	Full path to the directory containing
3882#				the $1Config.sh file
3883#------------------------------------------------------------------------
3884
3885AC_DEFUN([TEA_PATH_CONFIG], [
3886    #
3887    # Ok, lets find the $1 configuration
3888    # First, look for one uninstalled.
3889    # the alternative search directory is invoked by --with-$1
3890    #
3891
3892    if test x"${no_$1}" = x ; then
3893	# we reset no_$1 in case something fails here
3894	no_$1=true
3895	AC_ARG_WITH($1, [  --with-$1              directory containing $1 configuration ($1Config.sh)], with_$1config=${withval})
3896	AC_MSG_CHECKING([for $1 configuration])
3897	AC_CACHE_VAL(ac_cv_c_$1config,[
3898
3899	    # First check to see if --with-$1 was specified.
3900	    if test x"${with_$1config}" != x ; then
3901		case ${with_$1config} in
3902		    */$1Config.sh )
3903			if test -f ${with_$1config}; then
3904			    AC_MSG_WARN([--with-$1 argument should refer to directory containing $1Config.sh, not to $1Config.sh itself])
3905			    with_$1config=`echo ${with_$1config} | sed 's!/$1Config\.sh$!!'`
3906			fi;;
3907		esac
3908		if test -f "${with_$1config}/$1Config.sh" ; then
3909		    ac_cv_c_$1config=`(cd ${with_$1config}; pwd)`
3910		else
3911		    AC_MSG_ERROR([${with_$1config} directory doesn't contain $1Config.sh])
3912		fi
3913	    fi
3914
3915	    # then check for a private $1 installation
3916	    if test x"${ac_cv_c_$1config}" = x ; then
3917		for i in \
3918			../$1 \
3919			`ls -dr ../$1*[[0-9]].[[0-9]]*.[[0-9]]* 2>/dev/null` \
3920			`ls -dr ../$1*[[0-9]].[[0-9]][[0-9]] 2>/dev/null` \
3921			`ls -dr ../$1*[[0-9]].[[0-9]] 2>/dev/null` \
3922			`ls -dr ../$1*[[0-9]].[[0-9]]* 2>/dev/null` \
3923			../../$1 \
3924			`ls -dr ../../$1*[[0-9]].[[0-9]]*.[[0-9]]* 2>/dev/null` \
3925			`ls -dr ../../$1*[[0-9]].[[0-9]][[0-9]] 2>/dev/null` \
3926			`ls -dr ../../$1*[[0-9]].[[0-9]] 2>/dev/null` \
3927			`ls -dr ../../$1*[[0-9]].[[0-9]]* 2>/dev/null` \
3928			../../../$1 \
3929			`ls -dr ../../../$1*[[0-9]].[[0-9]]*.[[0-9]]* 2>/dev/null` \
3930			`ls -dr ../../../$1*[[0-9]].[[0-9]][[0-9]] 2>/dev/null` \
3931			`ls -dr ../../../$1*[[0-9]].[[0-9]] 2>/dev/null` \
3932			`ls -dr ../../../$1*[[0-9]].[[0-9]]* 2>/dev/null` \
3933			${srcdir}/../$1 \
3934			`ls -dr ${srcdir}/../$1*[[0-9]].[[0-9]]*.[[0-9]]* 2>/dev/null` \
3935			`ls -dr ${srcdir}/../$1*[[0-9]].[[0-9]][[0-9]] 2>/dev/null` \
3936			`ls -dr ${srcdir}/../$1*[[0-9]].[[0-9]] 2>/dev/null` \
3937			`ls -dr ${srcdir}/../$1*[[0-9]].[[0-9]]* 2>/dev/null` \
3938			; do
3939		    if test -f "$i/$1Config.sh" ; then
3940			ac_cv_c_$1config=`(cd $i; pwd)`
3941			break
3942		    fi
3943		    if test -f "$i/unix/$1Config.sh" ; then
3944			ac_cv_c_$1config=`(cd $i/unix; pwd)`
3945			break
3946		    fi
3947		done
3948	    fi
3949
3950	    # check in a few common install locations
3951	    if test x"${ac_cv_c_$1config}" = x ; then
3952		for i in `ls -d ${libdir} 2>/dev/null` \
3953			`ls -d ${exec_prefix}/lib 2>/dev/null` \
3954			`ls -d ${prefix}/lib 2>/dev/null` \
3955			`ls -d /usr/local/lib 2>/dev/null` \
3956			`ls -d /usr/contrib/lib 2>/dev/null` \
3957			`ls -d /usr/lib 2>/dev/null` \
3958			; do
3959		    if test -f "$i/$1Config.sh" ; then
3960			ac_cv_c_$1config=`(cd $i; pwd)`
3961			break
3962		    fi
3963		done
3964	    fi
3965	])
3966
3967	if test x"${ac_cv_c_$1config}" = x ; then
3968	    $1_BIN_DIR="# no $1 configs found"
3969	    AC_MSG_WARN([Cannot find $1 configuration definitions])
3970	    exit 0
3971	else
3972	    no_$1=
3973	    $1_BIN_DIR=${ac_cv_c_$1config}
3974	    AC_MSG_RESULT([found $$1_BIN_DIR/$1Config.sh])
3975	fi
3976    fi
3977])
3978
3979#------------------------------------------------------------------------
3980# TEA_LOAD_CONFIG --
3981#
3982#	Load the $1Config.sh file
3983#
3984# Arguments:
3985#
3986#	Requires the following vars to be set:
3987#		$1_BIN_DIR
3988#
3989# Results:
3990#
3991#	Subst the following vars:
3992#		$1_SRC_DIR
3993#		$1_LIB_FILE
3994#		$1_LIB_SPEC
3995#
3996#------------------------------------------------------------------------
3997
3998AC_DEFUN([TEA_LOAD_CONFIG], [
3999    AC_MSG_CHECKING([for existence of ${$1_BIN_DIR}/$1Config.sh])
4000
4001    if test -f "${$1_BIN_DIR}/$1Config.sh" ; then
4002        AC_MSG_RESULT([loading])
4003	. "${$1_BIN_DIR}/$1Config.sh"
4004    else
4005        AC_MSG_RESULT([file not found])
4006    fi
4007
4008    #
4009    # If the $1_BIN_DIR is the build directory (not the install directory),
4010    # then set the common variable name to the value of the build variables.
4011    # For example, the variable $1_LIB_SPEC will be set to the value
4012    # of $1_BUILD_LIB_SPEC. An extension should make use of $1_LIB_SPEC
4013    # instead of $1_BUILD_LIB_SPEC since it will work with both an
4014    # installed and uninstalled version of Tcl.
4015    #
4016
4017    if test -f "${$1_BIN_DIR}/Makefile" ; then
4018	AC_MSG_WARN([Found Makefile - using build library specs for $1])
4019        $1_LIB_SPEC=${$1_BUILD_LIB_SPEC}
4020        $1_STUB_LIB_SPEC=${$1_BUILD_STUB_LIB_SPEC}
4021        $1_STUB_LIB_PATH=${$1_BUILD_STUB_LIB_PATH}
4022    fi
4023
4024    AC_SUBST($1_VERSION)
4025    AC_SUBST($1_BIN_DIR)
4026    AC_SUBST($1_SRC_DIR)
4027
4028    AC_SUBST($1_LIB_FILE)
4029    AC_SUBST($1_LIB_SPEC)
4030
4031    AC_SUBST($1_STUB_LIB_FILE)
4032    AC_SUBST($1_STUB_LIB_SPEC)
4033    AC_SUBST($1_STUB_LIB_PATH)
4034])
4035
4036#------------------------------------------------------------------------
4037# TEA_PATH_CELIB --
4038#
4039#	Locate Keuchel's celib emulation layer for targeting Win/CE
4040#
4041# Arguments:
4042#	none
4043#
4044# Results:
4045#
4046#	Adds the following arguments to configure:
4047#		--with-celib=...
4048#
4049#	Defines the following vars:
4050#		CELIB_DIR	Full path to the directory containing
4051#				the include and platform lib files
4052#------------------------------------------------------------------------
4053
4054AC_DEFUN([TEA_PATH_CELIB], [
4055    # First, look for one uninstalled.
4056    # the alternative search directory is invoked by --with-celib
4057
4058    if test x"${no_celib}" = x ; then
4059	# we reset no_celib in case something fails here
4060	no_celib=true
4061	AC_ARG_WITH(celib,[  --with-celib=DIR        use Windows/CE support library from DIR], with_celibconfig=${withval})
4062	AC_MSG_CHECKING([for Windows/CE celib directory])
4063	AC_CACHE_VAL(ac_cv_c_celibconfig,[
4064	    # First check to see if --with-celibconfig was specified.
4065	    if test x"${with_celibconfig}" != x ; then
4066		if test -d "${with_celibconfig}/inc" ; then
4067		    ac_cv_c_celibconfig=`(cd ${with_celibconfig}; pwd)`
4068		else
4069		    AC_MSG_ERROR([${with_celibconfig} directory doesn't contain inc directory])
4070		fi
4071	    fi
4072
4073	    # then check for a celib library
4074	    if test x"${ac_cv_c_celibconfig}" = x ; then
4075		for i in \
4076			../celib-palm-3.0 \
4077			../celib \
4078			../../celib-palm-3.0 \
4079			../../celib \
4080			`ls -dr ../celib-*3.[[0-9]]* 2>/dev/null` \
4081			${srcdir}/../celib-palm-3.0 \
4082			${srcdir}/../celib \
4083			`ls -dr ${srcdir}/../celib-*3.[[0-9]]* 2>/dev/null` \
4084			; do
4085		    if test -d "$i/inc" ; then
4086			ac_cv_c_celibconfig=`(cd $i; pwd)`
4087			break
4088		    fi
4089		done
4090	    fi
4091	])
4092	if test x"${ac_cv_c_celibconfig}" = x ; then
4093	    AC_MSG_ERROR([Cannot find celib support library directory])
4094	else
4095	    no_celib=
4096	    CELIB_DIR=${ac_cv_c_celibconfig}
4097	    CELIB_DIR=`echo "$CELIB_DIR" | sed -e 's!\\\!/!g'`
4098	    AC_MSG_RESULT([found $CELIB_DIR])
4099	fi
4100    fi
4101])
4102
4103
4104# Local Variables:
4105# mode: autoconf
4106# End:
4107