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/01/08 04:40:39 gregcouch 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 arbitrary 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 arbitrary 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-*|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 compatibility 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='${CC} -shared'
1902	    ], [
1903	        SHLIB_LD='${CC} -non_shared'
1904	    ])
1905	    SHLIB_LD_LIBS="${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	    Darwin-*) ;;
2180	    SCO_SV-3.2*) ;;
2181	    *) SHLIB_CFLAGS="-fPIC" ;;
2182	esac])
2183
2184    AS_IF([test "$SHARED_LIB_SUFFIX" = ""], [
2185	# TEA specific: use PACKAGE_VERSION instead of VERSION
2186	SHARED_LIB_SUFFIX='${PACKAGE_VERSION}${SHLIB_SUFFIX}'])
2187    AS_IF([test "$UNSHARED_LIB_SUFFIX" = ""], [
2188	# TEA specific: use PACKAGE_VERSION instead of VERSION
2189	UNSHARED_LIB_SUFFIX='${PACKAGE_VERSION}.a'])
2190
2191    AC_SUBST(DL_LIBS)
2192
2193    AC_SUBST(CFLAGS_DEBUG)
2194    AC_SUBST(CFLAGS_OPTIMIZE)
2195    AC_SUBST(CFLAGS_WARNING)
2196
2197    AC_SUBST(STLIB_LD)
2198    AC_SUBST(SHLIB_LD)
2199
2200    AC_SUBST(SHLIB_LD_LIBS)
2201    AC_SUBST(SHLIB_CFLAGS)
2202
2203    AC_SUBST(LD_LIBRARY_PATH_VAR)
2204
2205    # These must be called after we do the basic CFLAGS checks and
2206    # verify any possible 64-bit or similar switches are necessary
2207    TEA_TCL_EARLY_FLAGS
2208    TEA_TCL_64BIT_FLAGS
2209])
2210
2211#--------------------------------------------------------------------
2212# TEA_SERIAL_PORT
2213#
2214#	Determine which interface to use to talk to the serial port.
2215#	Note that #include lines must begin in leftmost column for
2216#	some compilers to recognize them as preprocessor directives,
2217#	and some build environments have stdin not pointing at a
2218#	pseudo-terminal (usually /dev/null instead.)
2219#
2220# Arguments:
2221#	none
2222#
2223# Results:
2224#
2225#	Defines only one of the following vars:
2226#		HAVE_SYS_MODEM_H
2227#		USE_TERMIOS
2228#		USE_TERMIO
2229#		USE_SGTTY
2230#
2231#--------------------------------------------------------------------
2232
2233AC_DEFUN([TEA_SERIAL_PORT], [
2234    AC_CHECK_HEADERS(sys/modem.h)
2235    AC_CACHE_CHECK([termios vs. termio vs. sgtty], tcl_cv_api_serial, [
2236    AC_TRY_RUN([
2237#include <termios.h>
2238
2239int main() {
2240    struct termios t;
2241    if (tcgetattr(0, &t) == 0) {
2242	cfsetospeed(&t, 0);
2243	t.c_cflag |= PARENB | PARODD | CSIZE | CSTOPB;
2244	return 0;
2245    }
2246    return 1;
2247}], tcl_cv_api_serial=termios, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2248    if test $tcl_cv_api_serial = no ; then
2249	AC_TRY_RUN([
2250#include <termio.h>
2251
2252int main() {
2253    struct termio t;
2254    if (ioctl(0, TCGETA, &t) == 0) {
2255	t.c_cflag |= CBAUD | PARENB | PARODD | CSIZE | CSTOPB;
2256	return 0;
2257    }
2258    return 1;
2259}], tcl_cv_api_serial=termio, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2260    fi
2261    if test $tcl_cv_api_serial = no ; then
2262	AC_TRY_RUN([
2263#include <sgtty.h>
2264
2265int main() {
2266    struct sgttyb t;
2267    if (ioctl(0, TIOCGETP, &t) == 0) {
2268	t.sg_ospeed = 0;
2269	t.sg_flags |= ODDP | EVENP | RAW;
2270	return 0;
2271    }
2272    return 1;
2273}], tcl_cv_api_serial=sgtty, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2274    fi
2275    if test $tcl_cv_api_serial = no ; then
2276	AC_TRY_RUN([
2277#include <termios.h>
2278#include <errno.h>
2279
2280int main() {
2281    struct termios t;
2282    if (tcgetattr(0, &t) == 0
2283	|| errno == ENOTTY || errno == ENXIO || errno == EINVAL) {
2284	cfsetospeed(&t, 0);
2285	t.c_cflag |= PARENB | PARODD | CSIZE | CSTOPB;
2286	return 0;
2287    }
2288    return 1;
2289}], tcl_cv_api_serial=termios, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2290    fi
2291    if test $tcl_cv_api_serial = no; then
2292	AC_TRY_RUN([
2293#include <termio.h>
2294#include <errno.h>
2295
2296int main() {
2297    struct termio t;
2298    if (ioctl(0, TCGETA, &t) == 0
2299	|| errno == ENOTTY || errno == ENXIO || errno == EINVAL) {
2300	t.c_cflag |= CBAUD | PARENB | PARODD | CSIZE | CSTOPB;
2301	return 0;
2302    }
2303    return 1;
2304    }], tcl_cv_api_serial=termio, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2305    fi
2306    if test $tcl_cv_api_serial = no; then
2307	AC_TRY_RUN([
2308#include <sgtty.h>
2309#include <errno.h>
2310
2311int main() {
2312    struct sgttyb t;
2313    if (ioctl(0, TIOCGETP, &t) == 0
2314	|| errno == ENOTTY || errno == ENXIO || errno == EINVAL) {
2315	t.sg_ospeed = 0;
2316	t.sg_flags |= ODDP | EVENP | RAW;
2317	return 0;
2318    }
2319    return 1;
2320}], tcl_cv_api_serial=sgtty, tcl_cv_api_serial=none, tcl_cv_api_serial=none)
2321    fi])
2322    case $tcl_cv_api_serial in
2323	termios) AC_DEFINE(USE_TERMIOS, 1, [Use the termios API for serial lines]);;
2324	termio)  AC_DEFINE(USE_TERMIO, 1, [Use the termio API for serial lines]);;
2325	sgtty)   AC_DEFINE(USE_SGTTY, 1, [Use the sgtty API for serial lines]);;
2326    esac
2327])
2328
2329#--------------------------------------------------------------------
2330# TEA_MISSING_POSIX_HEADERS
2331#
2332#	Supply substitutes for missing POSIX header files.  Special
2333#	notes:
2334#	    - stdlib.h doesn't define strtol, strtoul, or
2335#	      strtod insome versions of SunOS
2336#	    - some versions of string.h don't declare procedures such
2337#	      as strstr
2338#
2339# Arguments:
2340#	none
2341#
2342# Results:
2343#
2344#	Defines some of the following vars:
2345#		NO_DIRENT_H
2346#		NO_ERRNO_H
2347#		NO_VALUES_H
2348#		HAVE_LIMITS_H or NO_LIMITS_H
2349#		NO_STDLIB_H
2350#		NO_STRING_H
2351#		NO_SYS_WAIT_H
2352#		NO_DLFCN_H
2353#		HAVE_SYS_PARAM_H
2354#
2355#		HAVE_STRING_H ?
2356#
2357# tkUnixPort.h checks for HAVE_LIMITS_H, so do both HAVE and
2358# CHECK on limits.h
2359#--------------------------------------------------------------------
2360
2361AC_DEFUN([TEA_MISSING_POSIX_HEADERS], [
2362    AC_CACHE_CHECK([dirent.h], tcl_cv_dirent_h, [
2363    AC_TRY_LINK([#include <sys/types.h>
2364#include <dirent.h>], [
2365#ifndef _POSIX_SOURCE
2366#   ifdef __Lynx__
2367	/*
2368	 * Generate compilation error to make the test fail:  Lynx headers
2369	 * are only valid if really in the POSIX environment.
2370	 */
2371
2372	missing_procedure();
2373#   endif
2374#endif
2375DIR *d;
2376struct dirent *entryPtr;
2377char *p;
2378d = opendir("foobar");
2379entryPtr = readdir(d);
2380p = entryPtr->d_name;
2381closedir(d);
2382], tcl_cv_dirent_h=yes, tcl_cv_dirent_h=no)])
2383
2384    if test $tcl_cv_dirent_h = no; then
2385	AC_DEFINE(NO_DIRENT_H, 1, [Do we have <dirent.h>?])
2386    fi
2387
2388    # TEA specific:
2389    AC_CHECK_HEADER(errno.h, , [AC_DEFINE(NO_ERRNO_H, 1, [Do we have <errno.h>?])])
2390    AC_CHECK_HEADER(float.h, , [AC_DEFINE(NO_FLOAT_H, 1, [Do we have <float.h>?])])
2391    AC_CHECK_HEADER(values.h, , [AC_DEFINE(NO_VALUES_H, 1, [Do we have <values.h>?])])
2392    AC_CHECK_HEADER(limits.h,
2393	[AC_DEFINE(HAVE_LIMITS_H, 1, [Do we have <limits.h>?])],
2394	[AC_DEFINE(NO_LIMITS_H, 1, [Do we have <limits.h>?])])
2395    AC_CHECK_HEADER(stdlib.h, tcl_ok=1, tcl_ok=0)
2396    AC_EGREP_HEADER(strtol, stdlib.h, , tcl_ok=0)
2397    AC_EGREP_HEADER(strtoul, stdlib.h, , tcl_ok=0)
2398    AC_EGREP_HEADER(strtod, stdlib.h, , tcl_ok=0)
2399    if test $tcl_ok = 0; then
2400	AC_DEFINE(NO_STDLIB_H, 1, [Do we have <stdlib.h>?])
2401    fi
2402    AC_CHECK_HEADER(string.h, tcl_ok=1, tcl_ok=0)
2403    AC_EGREP_HEADER(strstr, string.h, , tcl_ok=0)
2404    AC_EGREP_HEADER(strerror, string.h, , tcl_ok=0)
2405
2406    # See also memmove check below for a place where NO_STRING_H can be
2407    # set and why.
2408
2409    if test $tcl_ok = 0; then
2410	AC_DEFINE(NO_STRING_H, 1, [Do we have <string.h>?])
2411    fi
2412
2413    AC_CHECK_HEADER(sys/wait.h, , [AC_DEFINE(NO_SYS_WAIT_H, 1, [Do we have <sys/wait.h>?])])
2414    AC_CHECK_HEADER(dlfcn.h, , [AC_DEFINE(NO_DLFCN_H, 1, [Do we have <dlfcn.h>?])])
2415
2416    # OS/390 lacks sys/param.h (and doesn't need it, by chance).
2417    AC_HAVE_HEADERS(sys/param.h)
2418])
2419
2420#--------------------------------------------------------------------
2421# TEA_PATH_X
2422#
2423#	Locate the X11 header files and the X11 library archive.  Try
2424#	the ac_path_x macro first, but if it doesn't find the X stuff
2425#	(e.g. because there's no xmkmf program) then check through
2426#	a list of possible directories.  Under some conditions the
2427#	autoconf macro will return an include directory that contains
2428#	no include files, so double-check its result just to be safe.
2429#
2430#	This should be called after TEA_CONFIG_CFLAGS as setting the
2431#	LIBS line can confuse some configure macro magic.
2432#
2433# Arguments:
2434#	none
2435#
2436# Results:
2437#
2438#	Sets the following vars:
2439#		XINCLUDES
2440#		XLIBSW
2441#		PKG_LIBS (appends to)
2442#
2443#--------------------------------------------------------------------
2444
2445AC_DEFUN([TEA_PATH_X], [
2446    if test "${TEA_WINDOWINGSYSTEM}" = "x11" ; then
2447	TEA_PATH_UNIX_X
2448    fi
2449])
2450
2451AC_DEFUN([TEA_PATH_UNIX_X], [
2452    AC_PATH_X
2453    not_really_there=""
2454    if test "$no_x" = ""; then
2455	if test "$x_includes" = ""; then
2456	    AC_TRY_CPP([#include <X11/XIntrinsic.h>], , not_really_there="yes")
2457	else
2458	    if test ! -r $x_includes/X11/Intrinsic.h; then
2459		not_really_there="yes"
2460	    fi
2461	fi
2462    fi
2463    if test "$no_x" = "yes" -o "$not_really_there" = "yes"; then
2464	AC_MSG_CHECKING([for X11 header files])
2465	found_xincludes="no"
2466	AC_TRY_CPP([#include <X11/Intrinsic.h>], found_xincludes="yes", found_xincludes="no")
2467	if test "$found_xincludes" = "no"; then
2468	    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"
2469	    for i in $dirs ; do
2470		if test -r $i/X11/Intrinsic.h; then
2471		    AC_MSG_RESULT([$i])
2472		    XINCLUDES=" -I$i"
2473		    found_xincludes="yes"
2474		    break
2475		fi
2476	    done
2477	fi
2478    else
2479	if test "$x_includes" != ""; then
2480	    XINCLUDES="-I$x_includes"
2481	    found_xincludes="yes"
2482	fi
2483    fi
2484    if test found_xincludes = "no"; then
2485	AC_MSG_RESULT([couldn't find any!])
2486    fi
2487
2488    if test "$no_x" = yes; then
2489	AC_MSG_CHECKING([for X11 libraries])
2490	XLIBSW=nope
2491	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"
2492	for i in $dirs ; do
2493	    if test -r $i/libX11.a -o -r $i/libX11.so -o -r $i/libX11.sl -o -r $i/libX11.dylib; then
2494		AC_MSG_RESULT([$i])
2495		XLIBSW="-L$i -lX11"
2496		x_libraries="$i"
2497		break
2498	    fi
2499	done
2500    else
2501	if test "$x_libraries" = ""; then
2502	    XLIBSW=-lX11
2503	else
2504	    XLIBSW="-L$x_libraries -lX11"
2505	fi
2506    fi
2507    if test "$XLIBSW" = nope ; then
2508	AC_CHECK_LIB(Xwindow, XCreateWindow, XLIBSW=-lXwindow)
2509    fi
2510    if test "$XLIBSW" = nope ; then
2511	AC_MSG_RESULT([could not find any!  Using -lX11.])
2512	XLIBSW=-lX11
2513    fi
2514    # TEA specific:
2515    if test x"${XLIBSW}" != x ; then
2516	PKG_LIBS="${PKG_LIBS} ${XLIBSW}"
2517    fi
2518])
2519
2520#--------------------------------------------------------------------
2521# TEA_BLOCKING_STYLE
2522#
2523#	The statements below check for systems where POSIX-style
2524#	non-blocking I/O (O_NONBLOCK) doesn't work or is unimplemented.
2525#	On these systems (mostly older ones), use the old BSD-style
2526#	FIONBIO approach instead.
2527#
2528# Arguments:
2529#	none
2530#
2531# Results:
2532#
2533#	Defines some of the following vars:
2534#		HAVE_SYS_IOCTL_H
2535#		HAVE_SYS_FILIO_H
2536#		USE_FIONBIO
2537#		O_NONBLOCK
2538#
2539#--------------------------------------------------------------------
2540
2541AC_DEFUN([TEA_BLOCKING_STYLE], [
2542    AC_CHECK_HEADERS(sys/ioctl.h)
2543    AC_CHECK_HEADERS(sys/filio.h)
2544    TEA_CONFIG_SYSTEM
2545    AC_MSG_CHECKING([FIONBIO vs. O_NONBLOCK for nonblocking I/O])
2546    case $system in
2547	# There used to be code here to use FIONBIO under AIX.  However, it
2548	# was reported that FIONBIO doesn't work under AIX 3.2.5.  Since
2549	# using O_NONBLOCK seems fine under AIX 4.*, I removed the FIONBIO
2550	# code (JO, 5/31/97).
2551
2552	OSF*)
2553	    AC_DEFINE(USE_FIONBIO, 1, [Should we use FIONBIO?])
2554	    AC_MSG_RESULT([FIONBIO])
2555	    ;;
2556	SunOS-4*)
2557	    AC_DEFINE(USE_FIONBIO, 1, [Should we use FIONBIO?])
2558	    AC_MSG_RESULT([FIONBIO])
2559	    ;;
2560	*)
2561	    AC_MSG_RESULT([O_NONBLOCK])
2562	    ;;
2563    esac
2564])
2565
2566#--------------------------------------------------------------------
2567# TEA_TIME_HANLDER
2568#
2569#	Checks how the system deals with time.h, what time structures
2570#	are used on the system, and what fields the structures have.
2571#
2572# Arguments:
2573#	none
2574#
2575# Results:
2576#
2577#	Defines some of the following vars:
2578#		USE_DELTA_FOR_TZ
2579#		HAVE_TM_GMTOFF
2580#		HAVE_TM_TZADJ
2581#		HAVE_TIMEZONE_VAR
2582#
2583#--------------------------------------------------------------------
2584
2585AC_DEFUN([TEA_TIME_HANDLER], [
2586    AC_CHECK_HEADERS(sys/time.h)
2587    AC_HEADER_TIME
2588    AC_STRUCT_TIMEZONE
2589
2590    AC_CHECK_FUNCS(gmtime_r localtime_r)
2591
2592    AC_CACHE_CHECK([tm_tzadj in struct tm], tcl_cv_member_tm_tzadj, [
2593	AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_tzadj;],
2594	    tcl_cv_member_tm_tzadj=yes, tcl_cv_member_tm_tzadj=no)])
2595    if test $tcl_cv_member_tm_tzadj = yes ; then
2596	AC_DEFINE(HAVE_TM_TZADJ, 1, [Should we use the tm_tzadj field of struct tm?])
2597    fi
2598
2599    AC_CACHE_CHECK([tm_gmtoff in struct tm], tcl_cv_member_tm_gmtoff, [
2600	AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_gmtoff;],
2601	    tcl_cv_member_tm_gmtoff=yes, tcl_cv_member_tm_gmtoff=no)])
2602    if test $tcl_cv_member_tm_gmtoff = yes ; then
2603	AC_DEFINE(HAVE_TM_GMTOFF, 1, [Should we use the tm_gmtoff field of struct tm?])
2604    fi
2605
2606    #
2607    # Its important to include time.h in this check, as some systems
2608    # (like convex) have timezone functions, etc.
2609    #
2610    AC_CACHE_CHECK([long timezone variable], tcl_cv_timezone_long, [
2611	AC_TRY_COMPILE([#include <time.h>],
2612	    [extern long timezone;
2613	    timezone += 1;
2614	    exit (0);],
2615	    tcl_cv_timezone_long=yes, tcl_cv_timezone_long=no)])
2616    if test $tcl_cv_timezone_long = yes ; then
2617	AC_DEFINE(HAVE_TIMEZONE_VAR, 1, [Should we use the global timezone variable?])
2618    else
2619	#
2620	# On some systems (eg IRIX 6.2), timezone is a time_t and not a long.
2621	#
2622	AC_CACHE_CHECK([time_t timezone variable], tcl_cv_timezone_time, [
2623	    AC_TRY_COMPILE([#include <time.h>],
2624		[extern time_t timezone;
2625		timezone += 1;
2626		exit (0);],
2627		tcl_cv_timezone_time=yes, tcl_cv_timezone_time=no)])
2628	if test $tcl_cv_timezone_time = yes ; then
2629	    AC_DEFINE(HAVE_TIMEZONE_VAR, 1, [Should we use the global timezone variable?])
2630	fi
2631    fi
2632])
2633
2634#--------------------------------------------------------------------
2635# TEA_BUGGY_STRTOD
2636#
2637#	Under Solaris 2.4, strtod returns the wrong value for the
2638#	terminating character under some conditions.  Check for this
2639#	and if the problem exists use a substitute procedure
2640#	"fixstrtod" (provided by Tcl) that corrects the error.
2641#	Also, on Compaq's Tru64 Unix 5.0,
2642#	strtod(" ") returns 0.0 instead of a failure to convert.
2643#
2644# Arguments:
2645#	none
2646#
2647# Results:
2648#
2649#	Might defines some of the following vars:
2650#		strtod (=fixstrtod)
2651#
2652#--------------------------------------------------------------------
2653
2654AC_DEFUN([TEA_BUGGY_STRTOD], [
2655    AC_CHECK_FUNC(strtod, tcl_strtod=1, tcl_strtod=0)
2656    if test "$tcl_strtod" = 1; then
2657	AC_CACHE_CHECK([for Solaris2.4/Tru64 strtod bugs], tcl_cv_strtod_buggy,[
2658	    AC_TRY_RUN([
2659		extern double strtod();
2660		int main() {
2661		    char *infString="Inf", *nanString="NaN", *spaceString=" ";
2662		    char *term;
2663		    double value;
2664		    value = strtod(infString, &term);
2665		    if ((term != infString) && (term[-1] == 0)) {
2666			exit(1);
2667		    }
2668		    value = strtod(nanString, &term);
2669		    if ((term != nanString) && (term[-1] == 0)) {
2670			exit(1);
2671		    }
2672		    value = strtod(spaceString, &term);
2673		    if (term == (spaceString+1)) {
2674			exit(1);
2675		    }
2676		    exit(0);
2677		}], tcl_cv_strtod_buggy=ok, tcl_cv_strtod_buggy=buggy,
2678		    tcl_cv_strtod_buggy=buggy)])
2679	if test "$tcl_cv_strtod_buggy" = buggy; then
2680	    AC_LIBOBJ([fixstrtod])
2681	    USE_COMPAT=1
2682	    AC_DEFINE(strtod, fixstrtod, [Do we want to use the strtod() in compat?])
2683	fi
2684    fi
2685])
2686
2687#--------------------------------------------------------------------
2688# TEA_TCL_LINK_LIBS
2689#
2690#	Search for the libraries needed to link the Tcl shell.
2691#	Things like the math library (-lm) and socket stuff (-lsocket vs.
2692#	-lnsl) are dealt with here.
2693#
2694# Arguments:
2695#	Requires the following vars to be set in the Makefile:
2696#		DL_LIBS
2697#		LIBS
2698#		MATH_LIBS
2699#
2700# Results:
2701#
2702#	Subst's the following var:
2703#		TCL_LIBS
2704#		MATH_LIBS
2705#
2706#	Might append to the following vars:
2707#		LIBS
2708#
2709#	Might define the following vars:
2710#		HAVE_NET_ERRNO_H
2711#
2712#--------------------------------------------------------------------
2713
2714AC_DEFUN([TEA_TCL_LINK_LIBS], [
2715    #--------------------------------------------------------------------
2716    # On a few very rare systems, all of the libm.a stuff is
2717    # already in libc.a.  Set compiler flags accordingly.
2718    # Also, Linux requires the "ieee" library for math to work
2719    # right (and it must appear before "-lm").
2720    #--------------------------------------------------------------------
2721
2722    AC_CHECK_FUNC(sin, MATH_LIBS="", MATH_LIBS="-lm")
2723    AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"])
2724
2725    #--------------------------------------------------------------------
2726    # Interactive UNIX requires -linet instead of -lsocket, plus it
2727    # needs net/errno.h to define the socket-related error codes.
2728    #--------------------------------------------------------------------
2729
2730    AC_CHECK_LIB(inet, main, [LIBS="$LIBS -linet"])
2731    AC_CHECK_HEADER(net/errno.h, [
2732	AC_DEFINE(HAVE_NET_ERRNO_H, 1, [Do we have <net/errno.h>?])])
2733
2734    #--------------------------------------------------------------------
2735    #	Check for the existence of the -lsocket and -lnsl libraries.
2736    #	The order here is important, so that they end up in the right
2737    #	order in the command line generated by make.  Here are some
2738    #	special considerations:
2739    #	1. Use "connect" and "accept" to check for -lsocket, and
2740    #	   "gethostbyname" to check for -lnsl.
2741    #	2. Use each function name only once:  can't redo a check because
2742    #	   autoconf caches the results of the last check and won't redo it.
2743    #	3. Use -lnsl and -lsocket only if they supply procedures that
2744    #	   aren't already present in the normal libraries.  This is because
2745    #	   IRIX 5.2 has libraries, but they aren't needed and they're
2746    #	   bogus:  they goof up name resolution if used.
2747    #	4. On some SVR4 systems, can't use -lsocket without -lnsl too.
2748    #	   To get around this problem, check for both libraries together
2749    #	   if -lsocket doesn't work by itself.
2750    #--------------------------------------------------------------------
2751
2752    tcl_checkBoth=0
2753    AC_CHECK_FUNC(connect, tcl_checkSocket=0, tcl_checkSocket=1)
2754    if test "$tcl_checkSocket" = 1; then
2755	AC_CHECK_FUNC(setsockopt, , [AC_CHECK_LIB(socket, setsockopt,
2756	    LIBS="$LIBS -lsocket", tcl_checkBoth=1)])
2757    fi
2758    if test "$tcl_checkBoth" = 1; then
2759	tk_oldLibs=$LIBS
2760	LIBS="$LIBS -lsocket -lnsl"
2761	AC_CHECK_FUNC(accept, tcl_checkNsl=0, [LIBS=$tk_oldLibs])
2762    fi
2763    AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(nsl, gethostbyname,
2764	    [LIBS="$LIBS -lnsl"])])
2765
2766    # TEA specific: Don't perform the eval of the libraries here because
2767    # DL_LIBS won't be set until we call TEA_CONFIG_CFLAGS
2768
2769    TCL_LIBS='${DL_LIBS} ${LIBS} ${MATH_LIBS}'
2770    AC_SUBST(TCL_LIBS)
2771    AC_SUBST(MATH_LIBS)
2772])
2773
2774#--------------------------------------------------------------------
2775# TEA_TCL_EARLY_FLAGS
2776#
2777#	Check for what flags are needed to be passed so the correct OS
2778#	features are available.
2779#
2780# Arguments:
2781#	None
2782#
2783# Results:
2784#
2785#	Might define the following vars:
2786#		_ISOC99_SOURCE
2787#		_LARGEFILE64_SOURCE
2788#		_LARGEFILE_SOURCE64
2789#
2790#--------------------------------------------------------------------
2791
2792AC_DEFUN([TEA_TCL_EARLY_FLAG],[
2793    AC_CACHE_VAL([tcl_cv_flag_]translit($1,[A-Z],[a-z]),
2794	AC_TRY_COMPILE([$2], $3, [tcl_cv_flag_]translit($1,[A-Z],[a-z])=no,
2795	    AC_TRY_COMPILE([[#define ]$1[ 1
2796]$2], $3,
2797		[tcl_cv_flag_]translit($1,[A-Z],[a-z])=yes,
2798		[tcl_cv_flag_]translit($1,[A-Z],[a-z])=no)))
2799    if test ["x${tcl_cv_flag_]translit($1,[A-Z],[a-z])[}" = "xyes"] ; then
2800	AC_DEFINE($1, 1, [Add the ]$1[ flag when building])
2801	tcl_flags="$tcl_flags $1"
2802    fi
2803])
2804
2805AC_DEFUN([TEA_TCL_EARLY_FLAGS],[
2806    AC_MSG_CHECKING([for required early compiler flags])
2807    tcl_flags=""
2808    TEA_TCL_EARLY_FLAG(_ISOC99_SOURCE,[#include <stdlib.h>],
2809	[char *p = (char *)strtoll; char *q = (char *)strtoull;])
2810    TEA_TCL_EARLY_FLAG(_LARGEFILE64_SOURCE,[#include <sys/stat.h>],
2811	[struct stat64 buf; int i = stat64("/", &buf);])
2812    TEA_TCL_EARLY_FLAG(_LARGEFILE_SOURCE64,[#include <sys/stat.h>],
2813	[char *p = (char *)open64;])
2814    if test "x${tcl_flags}" = "x" ; then
2815	AC_MSG_RESULT([none])
2816    else
2817	AC_MSG_RESULT([${tcl_flags}])
2818    fi
2819])
2820
2821#--------------------------------------------------------------------
2822# TEA_TCL_64BIT_FLAGS
2823#
2824#	Check for what is defined in the way of 64-bit features.
2825#
2826# Arguments:
2827#	None
2828#
2829# Results:
2830#
2831#	Might define the following vars:
2832#		TCL_WIDE_INT_IS_LONG
2833#		TCL_WIDE_INT_TYPE
2834#		HAVE_STRUCT_DIRENT64
2835#		HAVE_STRUCT_STAT64
2836#		HAVE_TYPE_OFF64_T
2837#
2838#--------------------------------------------------------------------
2839
2840AC_DEFUN([TEA_TCL_64BIT_FLAGS], [
2841    AC_MSG_CHECKING([for 64-bit integer type])
2842    AC_CACHE_VAL(tcl_cv_type_64bit,[
2843	tcl_cv_type_64bit=none
2844	# See if the compiler knows natively about __int64
2845	AC_TRY_COMPILE(,[__int64 value = (__int64) 0;],
2846	    tcl_type_64bit=__int64, tcl_type_64bit="long long")
2847	# See if we should use long anyway  Note that we substitute in the
2848	# type that is our current guess for a 64-bit type inside this check
2849	# program, so it should be modified only carefully...
2850        AC_TRY_COMPILE(,[switch (0) {
2851            case 1: case (sizeof(]${tcl_type_64bit}[)==sizeof(long)): ;
2852        }],tcl_cv_type_64bit=${tcl_type_64bit})])
2853    if test "${tcl_cv_type_64bit}" = none ; then
2854	AC_DEFINE(TCL_WIDE_INT_IS_LONG, 1, [Are wide integers to be implemented with C 'long's?])
2855	AC_MSG_RESULT([using long])
2856    elif test "${tcl_cv_type_64bit}" = "__int64" \
2857		-a "${TEA_PLATFORM}" = "windows" ; then
2858	# TEA specific: We actually want to use the default tcl.h checks in
2859	# this case to handle both TCL_WIDE_INT_TYPE and TCL_LL_MODIFIER*
2860	AC_MSG_RESULT([using Tcl header defaults])
2861    else
2862	AC_DEFINE_UNQUOTED(TCL_WIDE_INT_TYPE,${tcl_cv_type_64bit},
2863	    [What type should be used to define wide integers?])
2864	AC_MSG_RESULT([${tcl_cv_type_64bit}])
2865
2866	# Now check for auxiliary declarations
2867	AC_CACHE_CHECK([for struct dirent64], tcl_cv_struct_dirent64,[
2868	    AC_TRY_COMPILE([#include <sys/types.h>
2869#include <sys/dirent.h>],[struct dirent64 p;],
2870		tcl_cv_struct_dirent64=yes,tcl_cv_struct_dirent64=no)])
2871	if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then
2872	    AC_DEFINE(HAVE_STRUCT_DIRENT64, 1, [Is 'struct dirent64' in <sys/types.h>?])
2873	fi
2874
2875	AC_CACHE_CHECK([for struct stat64], tcl_cv_struct_stat64,[
2876	    AC_TRY_COMPILE([#include <sys/stat.h>],[struct stat64 p;
2877],
2878		tcl_cv_struct_stat64=yes,tcl_cv_struct_stat64=no)])
2879	if test "x${tcl_cv_struct_stat64}" = "xyes" ; then
2880	    AC_DEFINE(HAVE_STRUCT_STAT64, 1, [Is 'struct stat64' in <sys/stat.h>?])
2881	fi
2882
2883	AC_CHECK_FUNCS(open64 lseek64)
2884	AC_MSG_CHECKING([for off64_t])
2885	AC_CACHE_VAL(tcl_cv_type_off64_t,[
2886	    AC_TRY_COMPILE([#include <sys/types.h>],[off64_t offset;
2887],
2888		tcl_cv_type_off64_t=yes,tcl_cv_type_off64_t=no)])
2889	dnl Define HAVE_TYPE_OFF64_T only when the off64_t type and the
2890	dnl functions lseek64 and open64 are defined.
2891	if test "x${tcl_cv_type_off64_t}" = "xyes" && \
2892	        test "x${ac_cv_func_lseek64}" = "xyes" && \
2893	        test "x${ac_cv_func_open64}" = "xyes" ; then
2894	    AC_DEFINE(HAVE_TYPE_OFF64_T, 1, [Is off64_t in <sys/types.h>?])
2895	    AC_MSG_RESULT([yes])
2896	else
2897	    AC_MSG_RESULT([no])
2898	fi
2899    fi
2900])
2901
2902##
2903## Here ends the standard Tcl configuration bits and starts the
2904## TEA specific functions
2905##
2906
2907#------------------------------------------------------------------------
2908# TEA_INIT --
2909#
2910#	Init various Tcl Extension Architecture (TEA) variables.
2911#	This should be the first called TEA_* macro.
2912#
2913# Arguments:
2914#	none
2915#
2916# Results:
2917#
2918#	Defines and substs the following vars:
2919#		CYGPATH
2920#		EXEEXT
2921#	Defines only:
2922#		TEA_VERSION
2923#		TEA_INITED
2924#		TEA_PLATFORM (windows or unix)
2925#
2926# "cygpath" is used on windows to generate native path names for include
2927# files. These variables should only be used with the compiler and linker
2928# since they generate native path names.
2929#
2930# EXEEXT
2931#	Select the executable extension based on the host type.  This
2932#	is a lightweight replacement for AC_EXEEXT that doesn't require
2933#	a compiler.
2934#------------------------------------------------------------------------
2935
2936AC_DEFUN([TEA_INIT], [
2937    # TEA extensions pass this us the version of TEA they think they
2938    # are compatible with.
2939    TEA_VERSION="3.7"
2940
2941    AC_MSG_CHECKING([for correct TEA configuration])
2942    if test x"${PACKAGE_NAME}" = x ; then
2943	AC_MSG_ERROR([
2944The PACKAGE_NAME variable must be defined by your TEA configure.in])
2945    fi
2946    if test x"$1" = x ; then
2947	AC_MSG_ERROR([
2948TEA version not specified.])
2949    elif test "$1" != "${TEA_VERSION}" ; then
2950	AC_MSG_RESULT([warning: requested TEA version "$1", have "${TEA_VERSION}"])
2951    else
2952	AC_MSG_RESULT([ok (TEA ${TEA_VERSION})])
2953    fi
2954    case "`uname -s`" in
2955	*win32*|*WIN32*|*CYGWIN_NT*|*CYGWIN_9*|*CYGWIN_ME*|*MINGW32_*)
2956	    AC_CHECK_PROG(CYGPATH, cygpath, cygpath -w, echo)
2957	    EXEEXT=".exe"
2958	    TEA_PLATFORM="windows"
2959	    ;;
2960	*)
2961	    CYGPATH=echo
2962	    EXEEXT=""
2963	    TEA_PLATFORM="unix"
2964	    ;;
2965    esac
2966
2967    # Check if exec_prefix is set. If not use fall back to prefix.
2968    # Note when adjusted, so that TEA_PREFIX can correct for this.
2969    # This is needed for recursive configures, since autoconf propagates
2970    # $prefix, but not $exec_prefix (doh!).
2971    if test x$exec_prefix = xNONE ; then
2972	exec_prefix_default=yes
2973	exec_prefix=$prefix
2974    fi
2975
2976    AC_SUBST(EXEEXT)
2977    AC_SUBST(CYGPATH)
2978
2979    # This package name must be replaced statically for AC_SUBST to work
2980    AC_SUBST(PKG_LIB_FILE)
2981    # Substitute STUB_LIB_FILE in case package creates a stub library too.
2982    AC_SUBST(PKG_STUB_LIB_FILE)
2983
2984    # We AC_SUBST these here to ensure they are subst'ed,
2985    # in case the user doesn't call TEA_ADD_...
2986    AC_SUBST(PKG_STUB_SOURCES)
2987    AC_SUBST(PKG_STUB_OBJECTS)
2988    AC_SUBST(PKG_TCL_SOURCES)
2989    AC_SUBST(PKG_HEADERS)
2990    AC_SUBST(PKG_INCLUDES)
2991    AC_SUBST(PKG_LIBS)
2992    AC_SUBST(PKG_CFLAGS)
2993])
2994
2995#------------------------------------------------------------------------
2996# TEA_ADD_SOURCES --
2997#
2998#	Specify one or more source files.  Users should check for
2999#	the right platform before adding to their list.
3000#	It is not important to specify the directory, as long as it is
3001#	in the generic, win or unix subdirectory of $(srcdir).
3002#
3003# Arguments:
3004#	one or more file names
3005#
3006# Results:
3007#
3008#	Defines and substs the following vars:
3009#		PKG_SOURCES
3010#		PKG_OBJECTS
3011#------------------------------------------------------------------------
3012AC_DEFUN([TEA_ADD_SOURCES], [
3013    vars="$@"
3014    for i in $vars; do
3015	case $i in
3016	    [\$]*)
3017		# allow $-var names
3018		PKG_SOURCES="$PKG_SOURCES $i"
3019		PKG_OBJECTS="$PKG_OBJECTS $i"
3020		;;
3021	    *)
3022		# check for existence - allows for generic/win/unix VPATH
3023		# To add more dirs here (like 'src'), you have to update VPATH
3024		# in Makefile.in as well
3025		if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \
3026		    -a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \
3027		    ; then
3028		    AC_MSG_ERROR([could not find source file '$i'])
3029		fi
3030		PKG_SOURCES="$PKG_SOURCES $i"
3031		# this assumes it is in a VPATH dir
3032		i=`basename $i`
3033		# handle user calling this before or after TEA_SETUP_COMPILER
3034		if test x"${OBJEXT}" != x ; then
3035		    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.${OBJEXT}"
3036		else
3037		    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.\${OBJEXT}"
3038		fi
3039		PKG_OBJECTS="$PKG_OBJECTS $j"
3040		;;
3041	esac
3042    done
3043    AC_SUBST(PKG_SOURCES)
3044    AC_SUBST(PKG_OBJECTS)
3045])
3046
3047#------------------------------------------------------------------------
3048# TEA_ADD_STUB_SOURCES --
3049#
3050#	Specify one or more source files.  Users should check for
3051#	the right platform before adding to their list.
3052#	It is not important to specify the directory, as long as it is
3053#	in the generic, win or unix subdirectory of $(srcdir).
3054#
3055# Arguments:
3056#	one or more file names
3057#
3058# Results:
3059#
3060#	Defines and substs the following vars:
3061#		PKG_STUB_SOURCES
3062#		PKG_STUB_OBJECTS
3063#------------------------------------------------------------------------
3064AC_DEFUN([TEA_ADD_STUB_SOURCES], [
3065    vars="$@"
3066    for i in $vars; do
3067	# check for existence - allows for generic/win/unix VPATH
3068	if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \
3069	    -a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \
3070	    ; then
3071	    AC_MSG_ERROR([could not find stub source file '$i'])
3072	fi
3073	PKG_STUB_SOURCES="$PKG_STUB_SOURCES $i"
3074	# this assumes it is in a VPATH dir
3075	i=`basename $i`
3076	# handle user calling this before or after TEA_SETUP_COMPILER
3077	if test x"${OBJEXT}" != x ; then
3078	    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.${OBJEXT}"
3079	else
3080	    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.\${OBJEXT}"
3081	fi
3082	PKG_STUB_OBJECTS="$PKG_STUB_OBJECTS $j"
3083    done
3084    AC_SUBST(PKG_STUB_SOURCES)
3085    AC_SUBST(PKG_STUB_OBJECTS)
3086])
3087
3088#------------------------------------------------------------------------
3089# TEA_ADD_TCL_SOURCES --
3090#
3091#	Specify one or more Tcl source files.  These should be platform
3092#	independent runtime files.
3093#
3094# Arguments:
3095#	one or more file names
3096#
3097# Results:
3098#
3099#	Defines and substs the following vars:
3100#		PKG_TCL_SOURCES
3101#------------------------------------------------------------------------
3102AC_DEFUN([TEA_ADD_TCL_SOURCES], [
3103    vars="$@"
3104    for i in $vars; do
3105	# check for existence, be strict because it is installed
3106	if test ! -f "${srcdir}/$i" ; then
3107	    AC_MSG_ERROR([could not find tcl source file '${srcdir}/$i'])
3108	fi
3109	PKG_TCL_SOURCES="$PKG_TCL_SOURCES $i"
3110    done
3111    AC_SUBST(PKG_TCL_SOURCES)
3112])
3113
3114#------------------------------------------------------------------------
3115# TEA_ADD_HEADERS --
3116#
3117#	Specify one or more source headers.  Users should check for
3118#	the right platform before adding to their list.
3119#
3120# Arguments:
3121#	one or more file names
3122#
3123# Results:
3124#
3125#	Defines and substs the following vars:
3126#		PKG_HEADERS
3127#------------------------------------------------------------------------
3128AC_DEFUN([TEA_ADD_HEADERS], [
3129    vars="$@"
3130    for i in $vars; do
3131	# check for existence, be strict because it is installed
3132	if test ! -f "${srcdir}/$i" ; then
3133	    AC_MSG_ERROR([could not find header file '${srcdir}/$i'])
3134	fi
3135	PKG_HEADERS="$PKG_HEADERS $i"
3136    done
3137    AC_SUBST(PKG_HEADERS)
3138])
3139
3140#------------------------------------------------------------------------
3141# TEA_ADD_INCLUDES --
3142#
3143#	Specify one or more include dirs.  Users should check for
3144#	the right platform before adding to their list.
3145#
3146# Arguments:
3147#	one or more file names
3148#
3149# Results:
3150#
3151#	Defines and substs the following vars:
3152#		PKG_INCLUDES
3153#------------------------------------------------------------------------
3154AC_DEFUN([TEA_ADD_INCLUDES], [
3155    vars="$@"
3156    for i in $vars; do
3157	PKG_INCLUDES="$PKG_INCLUDES $i"
3158    done
3159    AC_SUBST(PKG_INCLUDES)
3160])
3161
3162#------------------------------------------------------------------------
3163# TEA_ADD_LIBS --
3164#
3165#	Specify one or more libraries.  Users should check for
3166#	the right platform before adding to their list.  For Windows,
3167#	libraries provided in "foo.lib" format will be converted to
3168#	"-lfoo" when using GCC (mingw).
3169#
3170# Arguments:
3171#	one or more file names
3172#
3173# Results:
3174#
3175#	Defines and substs the following vars:
3176#		PKG_LIBS
3177#------------------------------------------------------------------------
3178AC_DEFUN([TEA_ADD_LIBS], [
3179    vars="$@"
3180    for i in $vars; do
3181	if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then
3182	    # Convert foo.lib to -lfoo for GCC.  No-op if not *.lib
3183	    i=`echo "$i" | sed -e 's/^\([[^-]].*\)\.lib[$]/-l\1/i'`
3184	fi
3185	PKG_LIBS="$PKG_LIBS $i"
3186    done
3187    AC_SUBST(PKG_LIBS)
3188])
3189
3190#------------------------------------------------------------------------
3191# TEA_ADD_CFLAGS --
3192#
3193#	Specify one or more CFLAGS.  Users should check for
3194#	the right platform before adding to their list.
3195#
3196# Arguments:
3197#	one or more file names
3198#
3199# Results:
3200#
3201#	Defines and substs the following vars:
3202#		PKG_CFLAGS
3203#------------------------------------------------------------------------
3204AC_DEFUN([TEA_ADD_CFLAGS], [
3205    PKG_CFLAGS="$PKG_CFLAGS $@"
3206    AC_SUBST(PKG_CFLAGS)
3207])
3208
3209#------------------------------------------------------------------------
3210# TEA_PREFIX --
3211#
3212#	Handle the --prefix=... option by defaulting to what Tcl gave
3213#
3214# Arguments:
3215#	none
3216#
3217# Results:
3218#
3219#	If --prefix or --exec-prefix was not specified, $prefix and
3220#	$exec_prefix will be set to the values given to Tcl when it was
3221#	configured.
3222#------------------------------------------------------------------------
3223AC_DEFUN([TEA_PREFIX], [
3224    if test "${prefix}" = "NONE"; then
3225	prefix_default=yes
3226	if test x"${TCL_PREFIX}" != x; then
3227	    AC_MSG_NOTICE([--prefix defaulting to TCL_PREFIX ${TCL_PREFIX}])
3228	    prefix=${TCL_PREFIX}
3229	else
3230	    AC_MSG_NOTICE([--prefix defaulting to /usr/local])
3231	    prefix=/usr/local
3232	fi
3233    fi
3234    if test "${exec_prefix}" = "NONE" -a x"${prefix_default}" = x"yes" \
3235	-o x"${exec_prefix_default}" = x"yes" ; then
3236	if test x"${TCL_EXEC_PREFIX}" != x; then
3237	    AC_MSG_NOTICE([--exec-prefix defaulting to TCL_EXEC_PREFIX ${TCL_EXEC_PREFIX}])
3238	    exec_prefix=${TCL_EXEC_PREFIX}
3239	else
3240	    AC_MSG_NOTICE([--exec-prefix defaulting to ${prefix}])
3241	    exec_prefix=$prefix
3242	fi
3243    fi
3244])
3245
3246#------------------------------------------------------------------------
3247# TEA_SETUP_COMPILER_CC --
3248#
3249#	Do compiler checks the way we want.  This is just a replacement
3250#	for AC_PROG_CC in TEA configure.in files to make them cleaner.
3251#
3252# Arguments:
3253#	none
3254#
3255# Results:
3256#
3257#	Sets up CC var and other standard bits we need to make executables.
3258#------------------------------------------------------------------------
3259AC_DEFUN([TEA_SETUP_COMPILER_CC], [
3260    # Don't put any macros that use the compiler (e.g. AC_TRY_COMPILE)
3261    # in this macro, they need to go into TEA_SETUP_COMPILER instead.
3262
3263    # If the user did not set CFLAGS, set it now to keep
3264    # the AC_PROG_CC macro from adding "-g -O2".
3265    if test "${CFLAGS+set}" != "set" ; then
3266	CFLAGS=""
3267    fi
3268
3269    AC_PROG_CC
3270    AC_PROG_CPP
3271
3272    AC_PROG_INSTALL
3273
3274    #--------------------------------------------------------------------
3275    # Checks to see if the make program sets the $MAKE variable.
3276    #--------------------------------------------------------------------
3277
3278    AC_PROG_MAKE_SET
3279
3280    #--------------------------------------------------------------------
3281    # Find ranlib
3282    #--------------------------------------------------------------------
3283
3284    AC_PROG_RANLIB
3285
3286    #--------------------------------------------------------------------
3287    # Determines the correct binary file extension (.o, .obj, .exe etc.)
3288    #--------------------------------------------------------------------
3289
3290    AC_OBJEXT
3291    AC_EXEEXT
3292])
3293
3294#------------------------------------------------------------------------
3295# TEA_SETUP_COMPILER --
3296#
3297#	Do compiler checks that use the compiler.  This must go after
3298#	TEA_SETUP_COMPILER_CC, which does the actual compiler check.
3299#
3300# Arguments:
3301#	none
3302#
3303# Results:
3304#
3305#	Sets up CC var and other standard bits we need to make executables.
3306#------------------------------------------------------------------------
3307AC_DEFUN([TEA_SETUP_COMPILER], [
3308    # Any macros that use the compiler (e.g. AC_TRY_COMPILE) have to go here.
3309    AC_REQUIRE([TEA_SETUP_COMPILER_CC])
3310
3311    #------------------------------------------------------------------------
3312    # If we're using GCC, see if the compiler understands -pipe. If so, use it.
3313    # It makes compiling go faster.  (This is only a performance feature.)
3314    #------------------------------------------------------------------------
3315
3316    if test -z "$no_pipe" -a -n "$GCC"; then
3317	AC_CACHE_CHECK([if the compiler understands -pipe],
3318	    tcl_cv_cc_pipe, [
3319	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -pipe"
3320	    AC_TRY_COMPILE(,, tcl_cv_cc_pipe=yes, tcl_cv_cc_pipe=no)
3321	    CFLAGS=$hold_cflags])
3322	if test $tcl_cv_cc_pipe = yes; then
3323	    CFLAGS="$CFLAGS -pipe"
3324	fi
3325    fi
3326
3327    #--------------------------------------------------------------------
3328    # Common compiler flag setup
3329    #--------------------------------------------------------------------
3330
3331    AC_C_BIGENDIAN
3332    if test "${TEA_PLATFORM}" = "unix" ; then
3333	TEA_TCL_LINK_LIBS
3334	TEA_MISSING_POSIX_HEADERS
3335	# Let the user call this, because if it triggers, they will
3336	# need a compat/strtod.c that is correct.  Users can also
3337	# use Tcl_GetDouble(FromObj) instead.
3338	#TEA_BUGGY_STRTOD
3339    fi
3340])
3341
3342#------------------------------------------------------------------------
3343# TEA_MAKE_LIB --
3344#
3345#	Generate a line that can be used to build a shared/unshared library
3346#	in a platform independent manner.
3347#
3348# Arguments:
3349#	none
3350#
3351#	Requires:
3352#
3353# Results:
3354#
3355#	Defines the following vars:
3356#	CFLAGS -	Done late here to note disturb other AC macros
3357#       MAKE_LIB -      Command to execute to build the Tcl library;
3358#                       differs depending on whether or not Tcl is being
3359#                       compiled as a shared library.
3360#	MAKE_SHARED_LIB	Makefile rule for building a shared library
3361#	MAKE_STATIC_LIB	Makefile rule for building a static library
3362#	MAKE_STUB_LIB	Makefile rule for building a stub library
3363#------------------------------------------------------------------------
3364
3365AC_DEFUN([TEA_MAKE_LIB], [
3366    if test "${TEA_PLATFORM}" = "windows" -a "$GCC" != "yes"; then
3367	MAKE_STATIC_LIB="\${STLIB_LD} -out:\[$]@ \$(PKG_OBJECTS)"
3368	MAKE_SHARED_LIB="\${SHLIB_LD} \${SHLIB_LD_LIBS} \${LDFLAGS_DEFAULT} -out:\[$]@ \$(PKG_OBJECTS)"
3369	MAKE_STUB_LIB="\${STLIB_LD} -out:\[$]@ \$(PKG_STUB_OBJECTS)"
3370    else
3371	MAKE_STATIC_LIB="\${STLIB_LD} \[$]@ \$(PKG_OBJECTS)"
3372	MAKE_SHARED_LIB="\${SHLIB_LD} -o \[$]@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}"
3373	MAKE_STUB_LIB="\${STLIB_LD} \[$]@ \$(PKG_STUB_OBJECTS)"
3374    fi
3375
3376    if test "${SHARED_BUILD}" = "1" ; then
3377	MAKE_LIB="${MAKE_SHARED_LIB} "
3378    else
3379	MAKE_LIB="${MAKE_STATIC_LIB} "
3380    fi
3381
3382    #--------------------------------------------------------------------
3383    # Shared libraries and static libraries have different names.
3384    # Use the double eval to make sure any variables in the suffix is
3385    # substituted. (@@@ Might not be necessary anymore)
3386    #--------------------------------------------------------------------
3387
3388    if test "${TEA_PLATFORM}" = "windows" ; then
3389	if test "${SHARED_BUILD}" = "1" ; then
3390	    # We force the unresolved linking of symbols that are really in
3391	    # the private libraries of Tcl and Tk.
3392	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \"`${CYGPATH} ${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}`\""
3393	    if test x"${TK_BIN_DIR}" != x ; then
3394		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \"`${CYGPATH} ${TK_BIN_DIR}/${TK_STUB_LIB_FILE}`\""
3395	    fi
3396	    eval eval "PKG_LIB_FILE=${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
3397	else
3398	    eval eval "PKG_LIB_FILE=${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
3399	fi
3400	# Some packages build their own stubs libraries
3401	eval eval "PKG_STUB_LIB_FILE=${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}"
3402	if test "$GCC" = "yes"; then
3403	    PKG_STUB_LIB_FILE=lib${PKG_STUB_LIB_FILE}
3404	fi
3405	# These aren't needed on Windows (either MSVC or gcc)
3406	RANLIB=:
3407	RANLIB_STUB=:
3408    else
3409	RANLIB_STUB="${RANLIB}"
3410	if test "${SHARED_BUILD}" = "1" ; then
3411	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} ${TCL_STUB_LIB_SPEC}"
3412	    if test x"${TK_BIN_DIR}" != x ; then
3413		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} ${TK_STUB_LIB_SPEC}"
3414	    fi
3415	    eval eval "PKG_LIB_FILE=lib${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
3416	    RANLIB=:
3417	else
3418	    eval eval "PKG_LIB_FILE=lib${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
3419	fi
3420	# Some packages build their own stubs libraries
3421	eval eval "PKG_STUB_LIB_FILE=lib${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}"
3422    fi
3423
3424    # These are escaped so that only CFLAGS is picked up at configure time.
3425    # The other values will be substituted at make time.
3426    CFLAGS="${CFLAGS} \${CFLAGS_DEFAULT} \${CFLAGS_WARNING}"
3427    if test "${SHARED_BUILD}" = "1" ; then
3428	CFLAGS="${CFLAGS} \${SHLIB_CFLAGS}"
3429    fi
3430
3431    AC_SUBST(MAKE_LIB)
3432    AC_SUBST(MAKE_SHARED_LIB)
3433    AC_SUBST(MAKE_STATIC_LIB)
3434    AC_SUBST(MAKE_STUB_LIB)
3435    AC_SUBST(RANLIB_STUB)
3436])
3437
3438#------------------------------------------------------------------------
3439# TEA_LIB_SPEC --
3440#
3441#	Compute the name of an existing object library located in libdir
3442#	from the given base name and produce the appropriate linker flags.
3443#
3444# Arguments:
3445#	basename	The base name of the library without version
3446#			numbers, extensions, or "lib" prefixes.
3447#	extra_dir	Extra directory in which to search for the
3448#			library.  This location is used first, then
3449#			$prefix/$exec-prefix, then some defaults.
3450#
3451# Requires:
3452#	TEA_INIT and TEA_PREFIX must be called first.
3453#
3454# Results:
3455#
3456#	Defines the following vars:
3457#		${basename}_LIB_NAME	The computed library name.
3458#		${basename}_LIB_SPEC	The computed linker flags.
3459#------------------------------------------------------------------------
3460
3461AC_DEFUN([TEA_LIB_SPEC], [
3462    AC_MSG_CHECKING([for $1 library])
3463
3464    # Look in exec-prefix for the library (defined by TEA_PREFIX).
3465
3466    tea_lib_name_dir="${exec_prefix}/lib"
3467
3468    # Or in a user-specified location.
3469
3470    if test x"$2" != x ; then
3471	tea_extra_lib_dir=$2
3472    else
3473	tea_extra_lib_dir=NONE
3474    fi
3475
3476    for i in \
3477	    `ls -dr ${tea_extra_lib_dir}/$1[[0-9]]*.lib 2>/dev/null ` \
3478	    `ls -dr ${tea_extra_lib_dir}/lib$1[[0-9]]* 2>/dev/null ` \
3479	    `ls -dr ${tea_lib_name_dir}/$1[[0-9]]*.lib 2>/dev/null ` \
3480	    `ls -dr ${tea_lib_name_dir}/lib$1[[0-9]]* 2>/dev/null ` \
3481	    `ls -dr /usr/lib/$1[[0-9]]*.lib 2>/dev/null ` \
3482	    `ls -dr /usr/lib/lib$1[[0-9]]* 2>/dev/null ` \
3483	    `ls -dr /usr/local/lib/$1[[0-9]]*.lib 2>/dev/null ` \
3484	    `ls -dr /usr/local/lib/lib$1[[0-9]]* 2>/dev/null ` ; do
3485	if test -f "$i" ; then
3486	    tea_lib_name_dir=`dirname $i`
3487	    $1_LIB_NAME=`basename $i`
3488	    $1_LIB_PATH_NAME=$i
3489	    break
3490	fi
3491    done
3492
3493    if test "${TEA_PLATFORM}" = "windows"; then
3494	$1_LIB_SPEC=\"`${CYGPATH} ${$1_LIB_PATH_NAME} 2>/dev/null`\"
3495    else
3496	# Strip off the leading "lib" and trailing ".a" or ".so"
3497
3498	tea_lib_name_lib=`echo ${$1_LIB_NAME}|sed -e 's/^lib//' -e 's/\.[[^.]]*$//' -e 's/\.so.*//'`
3499	$1_LIB_SPEC="-L${tea_lib_name_dir} -l${tea_lib_name_lib}"
3500    fi
3501
3502    if test "x${$1_LIB_NAME}" = x ; then
3503	AC_MSG_ERROR([not found])
3504    else
3505	AC_MSG_RESULT([${$1_LIB_SPEC}])
3506    fi
3507])
3508
3509#------------------------------------------------------------------------
3510# TEA_PRIVATE_TCL_HEADERS --
3511#
3512#	Locate the private Tcl include files
3513#
3514# Arguments:
3515#
3516#	Requires:
3517#		TCL_SRC_DIR	Assumes that TEA_LOAD_TCLCONFIG has
3518#				already been called.
3519#
3520# Results:
3521#
3522#	Substs the following vars:
3523#		TCL_TOP_DIR_NATIVE
3524#		TCL_INCLUDES
3525#------------------------------------------------------------------------
3526
3527AC_DEFUN([TEA_PRIVATE_TCL_HEADERS], [
3528    # Allow for --with-tclinclude to take effect and define ${ac_cv_c_tclh}
3529    AC_REQUIRE([TEA_PUBLIC_TCL_HEADERS])
3530    AC_MSG_CHECKING([for Tcl private include files])
3531
3532    TCL_SRC_DIR_NATIVE=`${CYGPATH} ${TCL_SRC_DIR}`
3533    TCL_TOP_DIR_NATIVE=\"${TCL_SRC_DIR_NATIVE}\"
3534
3535    # Check to see if tcl<Plat>Port.h isn't already with the public headers
3536    # Don't look for tclInt.h because that resides with tcl.h in the core
3537    # sources, but the <plat>Port headers are in a different directory
3538    if test "${TEA_PLATFORM}" = "windows" -a \
3539	-f "${ac_cv_c_tclh}/tclWinPort.h"; then
3540	result="private headers found with public headers"
3541    elif test "${TEA_PLATFORM}" = "unix" -a \
3542	-f "${ac_cv_c_tclh}/tclUnixPort.h"; then
3543	result="private headers found with public headers"
3544    else
3545	TCL_GENERIC_DIR_NATIVE=\"${TCL_SRC_DIR_NATIVE}/generic\"
3546	if test "${TEA_PLATFORM}" = "windows"; then
3547	    TCL_PLATFORM_DIR_NATIVE=\"${TCL_SRC_DIR_NATIVE}/win\"
3548	else
3549	    TCL_PLATFORM_DIR_NATIVE=\"${TCL_SRC_DIR_NATIVE}/unix\"
3550	fi
3551	# Overwrite the previous TCL_INCLUDES as this should capture both
3552	# public and private headers in the same set.
3553	# We want to ensure these are substituted so as not to require
3554	# any *_NATIVE vars be defined in the Makefile
3555	TCL_INCLUDES="-I${TCL_GENERIC_DIR_NATIVE} -I${TCL_PLATFORM_DIR_NATIVE}"
3556	if test "`uname -s`" = "Darwin"; then
3557            # If Tcl was built as a framework, attempt to use
3558            # the framework's Headers and PrivateHeaders directories
3559            case ${TCL_DEFS} in
3560	    	*TCL_FRAMEWORK*)
3561		    if test -d "${TCL_BIN_DIR}/Headers" -a \
3562			    -d "${TCL_BIN_DIR}/PrivateHeaders"; then
3563			TCL_INCLUDES="-I\"${TCL_BIN_DIR}/Headers\" -I\"${TCL_BIN_DIR}/PrivateHeaders\" ${TCL_INCLUDES}"
3564		    else
3565			TCL_INCLUDES="${TCL_INCLUDES} ${TCL_INCLUDE_SPEC} `echo "${TCL_INCLUDE_SPEC}" | sed -e 's/Headers/PrivateHeaders/'`"
3566		    fi
3567	            ;;
3568	    esac
3569	    result="Using ${TCL_INCLUDES}"
3570	else
3571	    if test ! -f "${TCL_SRC_DIR}/generic/tclInt.h" ; then
3572		AC_MSG_ERROR([Cannot find private header tclInt.h in ${TCL_SRC_DIR}])
3573	    fi
3574	    result="Using srcdir found in tclConfig.sh: ${TCL_SRC_DIR}"
3575	fi
3576    fi
3577
3578    AC_SUBST(TCL_TOP_DIR_NATIVE)
3579
3580    AC_SUBST(TCL_INCLUDES)
3581    AC_MSG_RESULT([${result}])
3582])
3583
3584#------------------------------------------------------------------------
3585# TEA_PUBLIC_TCL_HEADERS --
3586#
3587#	Locate the installed public Tcl header files
3588#
3589# Arguments:
3590#	None.
3591#
3592# Requires:
3593#	CYGPATH must be set
3594#
3595# Results:
3596#
3597#	Adds a --with-tclinclude switch to configure.
3598#	Result is cached.
3599#
3600#	Substs the following vars:
3601#		TCL_INCLUDES
3602#------------------------------------------------------------------------
3603
3604AC_DEFUN([TEA_PUBLIC_TCL_HEADERS], [
3605    AC_MSG_CHECKING([for Tcl public headers])
3606
3607    AC_ARG_WITH(tclinclude, [  --with-tclinclude       directory containing the public Tcl header files], with_tclinclude=${withval})
3608
3609    AC_CACHE_VAL(ac_cv_c_tclh, [
3610	# Use the value from --with-tclinclude, if it was given
3611
3612	if test x"${with_tclinclude}" != x ; then
3613	    if test -f "${with_tclinclude}/tcl.h" ; then
3614		ac_cv_c_tclh=${with_tclinclude}
3615	    else
3616		AC_MSG_ERROR([${with_tclinclude} directory does not contain tcl.h])
3617	    fi
3618	else
3619	    if test "`uname -s`" = "Darwin"; then
3620		# If Tcl was built as a framework, attempt to use
3621		# the framework's Headers directory
3622		case ${TCL_DEFS} in
3623		    *TCL_FRAMEWORK*)
3624			list="`ls -d ${TCL_BIN_DIR}/Headers 2>/dev/null`"
3625			;;
3626		esac
3627	    fi
3628
3629	    # Look in the source dir only if Tcl is not installed,
3630	    # and in that situation, look there before installed locations.
3631	    if test -f "${TCL_BIN_DIR}/Makefile" ; then
3632		list="$list `ls -d ${TCL_SRC_DIR}/generic 2>/dev/null`"
3633	    fi
3634
3635	    # Check order: pkg --prefix location, Tcl's --prefix location,
3636	    # relative to directory of tclConfig.sh.
3637
3638	    eval "temp_includedir=${includedir}"
3639	    list="$list \
3640		`ls -d ${temp_includedir}        2>/dev/null` \
3641		`ls -d ${TCL_PREFIX}/include     2>/dev/null` \
3642		`ls -d ${TCL_BIN_DIR}/../include 2>/dev/null`"
3643	    if test "${TEA_PLATFORM}" != "windows" -o "$GCC" = "yes"; then
3644		list="$list /usr/local/include /usr/include"
3645		if test x"${TCL_INCLUDE_SPEC}" != x ; then
3646		    d=`echo "${TCL_INCLUDE_SPEC}" | sed -e 's/^-I//'`
3647		    list="$list `ls -d ${d} 2>/dev/null`"
3648		fi
3649	    fi
3650	    for i in $list ; do
3651		if test -f "$i/tcl.h" ; then
3652		    ac_cv_c_tclh=$i
3653		    break
3654		fi
3655	    done
3656	fi
3657    ])
3658
3659    # Print a message based on how we determined the include path
3660
3661    if test x"${ac_cv_c_tclh}" = x ; then
3662	AC_MSG_ERROR([tcl.h not found.  Please specify its location with --with-tclinclude])
3663    else
3664	AC_MSG_RESULT([${ac_cv_c_tclh}])
3665    fi
3666
3667    # Convert to a native path and substitute into the output files.
3668
3669    INCLUDE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tclh}`
3670
3671    TCL_INCLUDES=-I\"${INCLUDE_DIR_NATIVE}\"
3672
3673    AC_SUBST(TCL_INCLUDES)
3674])
3675
3676#------------------------------------------------------------------------
3677# TEA_PRIVATE_TK_HEADERS --
3678#
3679#	Locate the private Tk include files
3680#
3681# Arguments:
3682#
3683#	Requires:
3684#		TK_SRC_DIR	Assumes that TEA_LOAD_TKCONFIG has
3685#				 already been called.
3686#
3687# Results:
3688#
3689#	Substs the following vars:
3690#		TK_INCLUDES
3691#------------------------------------------------------------------------
3692
3693AC_DEFUN([TEA_PRIVATE_TK_HEADERS], [
3694    # Allow for --with-tkinclude to take effect and define ${ac_cv_c_tkh}
3695    AC_REQUIRE([TEA_PUBLIC_TK_HEADERS])
3696    AC_MSG_CHECKING([for Tk private include files])
3697
3698    TK_SRC_DIR_NATIVE=`${CYGPATH} ${TK_SRC_DIR}`
3699    TK_TOP_DIR_NATIVE=\"${TK_SRC_DIR_NATIVE}\"
3700
3701    # Check to see if tk<Plat>Port.h isn't already with the public headers
3702    # Don't look for tkInt.h because that resides with tk.h in the core
3703    # sources, but the <plat>Port headers are in a different directory
3704    if test "${TEA_PLATFORM}" = "windows" -a \
3705	-f "${ac_cv_c_tkh}/tkWinPort.h"; then
3706	result="private headers found with public headers"
3707    elif test "${TEA_PLATFORM}" = "unix" -a \
3708	-f "${ac_cv_c_tkh}/tkUnixPort.h"; then
3709	result="private headers found with public headers"
3710    else
3711	TK_GENERIC_DIR_NATIVE=\"${TK_SRC_DIR_NATIVE}/generic\"
3712	TK_XLIB_DIR_NATIVE=\"${TK_SRC_DIR_NATIVE}/xlib\"
3713	if test "${TEA_PLATFORM}" = "windows"; then
3714	    TK_PLATFORM_DIR_NATIVE=\"${TK_SRC_DIR_NATIVE}/win\"
3715	else
3716	    TK_PLATFORM_DIR_NATIVE=\"${TK_SRC_DIR_NATIVE}/unix\"
3717	fi
3718	# Overwrite the previous TK_INCLUDES as this should capture both
3719	# public and private headers in the same set.
3720	# We want to ensure these are substituted so as not to require
3721	# any *_NATIVE vars be defined in the Makefile
3722	TK_INCLUDES="-I${TK_GENERIC_DIR_NATIVE} -I${TK_PLATFORM_DIR_NATIVE}"
3723	# Detect and add ttk subdir
3724	if test -d "${TK_SRC_DIR}/generic/ttk"; then
3725	   TK_INCLUDES="${TK_INCLUDES} -I\"${TK_SRC_DIR_NATIVE}/generic/ttk\""
3726	fi
3727	if test "${TEA_WINDOWINGSYSTEM}" != "x11"; then
3728	   TK_INCLUDES="${TK_INCLUDES} -I${TK_XLIB_DIR_NATIVE}"
3729	fi
3730	if test "${TEA_WINDOWINGSYSTEM}" = "aqua"; then
3731	   TK_INCLUDES="${TK_INCLUDES} -I\"${TK_SRC_DIR_NATIVE}/macosx\""
3732	fi
3733	if test "`uname -s`" = "Darwin"; then
3734	    # If Tk was built as a framework, attempt to use
3735	    # the framework's Headers and PrivateHeaders directories
3736	    case ${TK_DEFS} in
3737		*TK_FRAMEWORK*)
3738			if test -d "${TK_BIN_DIR}/Headers" -a \
3739				-d "${TK_BIN_DIR}/PrivateHeaders"; then
3740			    TK_INCLUDES="-I\"${TK_BIN_DIR}/Headers\" -I\"${TK_BIN_DIR}/PrivateHeaders\" ${TK_INCLUDES}"
3741			else
3742			    TK_INCLUDES="${TK_INCLUDES} ${TK_INCLUDE_SPEC} `echo "${TK_INCLUDE_SPEC}" | sed -e 's/Headers/PrivateHeaders/'`"
3743			fi
3744			;;
3745	    esac
3746	    result="Using ${TK_INCLUDES}"
3747	else
3748	    if test ! -f "${TK_SRC_DIR}/generic/tkInt.h" ; then
3749	       AC_MSG_ERROR([Cannot find private header tkInt.h in ${TK_SRC_DIR}])
3750	    fi
3751	    result="Using srcdir found in tkConfig.sh: ${TK_SRC_DIR}"
3752	fi
3753    fi
3754
3755    AC_SUBST(TK_TOP_DIR_NATIVE)
3756    AC_SUBST(TK_XLIB_DIR_NATIVE)
3757
3758    AC_SUBST(TK_INCLUDES)
3759    AC_MSG_RESULT([${result}])
3760])
3761
3762#------------------------------------------------------------------------
3763# TEA_PUBLIC_TK_HEADERS --
3764#
3765#	Locate the installed public Tk header files
3766#
3767# Arguments:
3768#	None.
3769#
3770# Requires:
3771#	CYGPATH must be set
3772#
3773# Results:
3774#
3775#	Adds a --with-tkinclude switch to configure.
3776#	Result is cached.
3777#
3778#	Substs the following vars:
3779#		TK_INCLUDES
3780#------------------------------------------------------------------------
3781
3782AC_DEFUN([TEA_PUBLIC_TK_HEADERS], [
3783    AC_MSG_CHECKING([for Tk public headers])
3784
3785    AC_ARG_WITH(tkinclude, [  --with-tkinclude        directory containing the public Tk header files], with_tkinclude=${withval})
3786
3787    AC_CACHE_VAL(ac_cv_c_tkh, [
3788	# Use the value from --with-tkinclude, if it was given
3789
3790	if test x"${with_tkinclude}" != x ; then
3791	    if test -f "${with_tkinclude}/tk.h" ; then
3792		ac_cv_c_tkh=${with_tkinclude}
3793	    else
3794		AC_MSG_ERROR([${with_tkinclude} directory does not contain tk.h])
3795	    fi
3796	else
3797	    if test "`uname -s`" = "Darwin"; then
3798		# If Tk was built as a framework, attempt to use
3799		# the framework's Headers directory.
3800		case ${TK_DEFS} in
3801		    *TK_FRAMEWORK*)
3802			list="`ls -d ${TK_BIN_DIR}/Headers 2>/dev/null`"
3803			;;
3804		esac
3805	    fi
3806
3807	    # Look in the source dir only if Tk is not installed,
3808	    # and in that situation, look there before installed locations.
3809	    if test -f "${TK_BIN_DIR}/Makefile" ; then
3810		list="$list `ls -d ${TK_SRC_DIR}/generic 2>/dev/null`"
3811	    fi
3812
3813	    # Check order: pkg --prefix location, Tk's --prefix location,
3814	    # relative to directory of tkConfig.sh, Tcl's --prefix location,
3815	    # relative to directory of tclConfig.sh.
3816
3817	    eval "temp_includedir=${includedir}"
3818	    list="$list \
3819		`ls -d ${temp_includedir}        2>/dev/null` \
3820		`ls -d ${TK_PREFIX}/include      2>/dev/null` \
3821		`ls -d ${TK_BIN_DIR}/../include  2>/dev/null` \
3822		`ls -d ${TCL_PREFIX}/include     2>/dev/null` \
3823		`ls -d ${TCL_BIN_DIR}/../include 2>/dev/null`"
3824	    if test "${TEA_PLATFORM}" != "windows" -o "$GCC" = "yes"; then
3825		list="$list /usr/local/include /usr/include"
3826	    fi
3827	    for i in $list ; do
3828		if test -f "$i/tk.h" ; then
3829		    ac_cv_c_tkh=$i
3830		    break
3831		fi
3832	    done
3833	fi
3834    ])
3835
3836    # Print a message based on how we determined the include path
3837
3838    if test x"${ac_cv_c_tkh}" = x ; then
3839	AC_MSG_ERROR([tk.h not found.  Please specify its location with --with-tkinclude])
3840    else
3841	AC_MSG_RESULT([${ac_cv_c_tkh}])
3842    fi
3843
3844    # Convert to a native path and substitute into the output files.
3845
3846    INCLUDE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tkh}`
3847
3848    TK_INCLUDES=-I\"${INCLUDE_DIR_NATIVE}\"
3849
3850    AC_SUBST(TK_INCLUDES)
3851
3852    if test "${TEA_WINDOWINGSYSTEM}" != "x11"; then
3853	# On Windows and Aqua, we need the X compat headers
3854	AC_MSG_CHECKING([for X11 header files])
3855	if test ! -r "${INCLUDE_DIR_NATIVE}/X11/Xlib.h"; then
3856	    INCLUDE_DIR_NATIVE="`${CYGPATH} ${TK_SRC_DIR}/xlib`"
3857	    TK_XINCLUDES=-I\"${INCLUDE_DIR_NATIVE}\"
3858	    AC_SUBST(TK_XINCLUDES)
3859	fi
3860	AC_MSG_RESULT([${INCLUDE_DIR_NATIVE}])
3861    fi
3862])
3863
3864#------------------------------------------------------------------------
3865# TEA_PATH_CONFIG --
3866#
3867#	Locate the ${1}Config.sh file and perform a sanity check on
3868#	the ${1} compile flags.  These are used by packages like
3869#	[incr Tk] that load *Config.sh files from more than Tcl and Tk.
3870#
3871# Arguments:
3872#	none
3873#
3874# Results:
3875#
3876#	Adds the following arguments to configure:
3877#		--with-$1=...
3878#
3879#	Defines the following vars:
3880#		$1_BIN_DIR	Full path to the directory containing
3881#				the $1Config.sh file
3882#------------------------------------------------------------------------
3883
3884AC_DEFUN([TEA_PATH_CONFIG], [
3885    #
3886    # Ok, lets find the $1 configuration
3887    # First, look for one uninstalled.
3888    # the alternative search directory is invoked by --with-$1
3889    #
3890
3891    if test x"${no_$1}" = x ; then
3892	# we reset no_$1 in case something fails here
3893	no_$1=true
3894	AC_ARG_WITH($1, [  --with-$1              directory containing $1 configuration ($1Config.sh)], with_$1config=${withval})
3895	AC_MSG_CHECKING([for $1 configuration])
3896	AC_CACHE_VAL(ac_cv_c_$1config,[
3897
3898	    # First check to see if --with-$1 was specified.
3899	    if test x"${with_$1config}" != x ; then
3900		case ${with_$1config} in
3901		    */$1Config.sh )
3902			if test -f ${with_$1config}; then
3903			    AC_MSG_WARN([--with-$1 argument should refer to directory containing $1Config.sh, not to $1Config.sh itself])
3904			    with_$1config=`echo ${with_$1config} | sed 's!/$1Config\.sh$!!'`
3905			fi;;
3906		esac
3907		if test -f "${with_$1config}/$1Config.sh" ; then
3908		    ac_cv_c_$1config=`(cd ${with_$1config}; pwd)`
3909		else
3910		    AC_MSG_ERROR([${with_$1config} directory doesn't contain $1Config.sh])
3911		fi
3912	    fi
3913
3914	    # then check for a private $1 installation
3915	    if test x"${ac_cv_c_$1config}" = x ; then
3916		for i in \
3917			../$1 \
3918			`ls -dr ../$1*[[0-9]].[[0-9]]*.[[0-9]]* 2>/dev/null` \
3919			`ls -dr ../$1*[[0-9]].[[0-9]][[0-9]] 2>/dev/null` \
3920			`ls -dr ../$1*[[0-9]].[[0-9]] 2>/dev/null` \
3921			`ls -dr ../$1*[[0-9]].[[0-9]]* 2>/dev/null` \
3922			../../$1 \
3923			`ls -dr ../../$1*[[0-9]].[[0-9]]*.[[0-9]]* 2>/dev/null` \
3924			`ls -dr ../../$1*[[0-9]].[[0-9]][[0-9]] 2>/dev/null` \
3925			`ls -dr ../../$1*[[0-9]].[[0-9]] 2>/dev/null` \
3926			`ls -dr ../../$1*[[0-9]].[[0-9]]* 2>/dev/null` \
3927			../../../$1 \
3928			`ls -dr ../../../$1*[[0-9]].[[0-9]]*.[[0-9]]* 2>/dev/null` \
3929			`ls -dr ../../../$1*[[0-9]].[[0-9]][[0-9]] 2>/dev/null` \
3930			`ls -dr ../../../$1*[[0-9]].[[0-9]] 2>/dev/null` \
3931			`ls -dr ../../../$1*[[0-9]].[[0-9]]* 2>/dev/null` \
3932			${srcdir}/../$1 \
3933			`ls -dr ${srcdir}/../$1*[[0-9]].[[0-9]]*.[[0-9]]* 2>/dev/null` \
3934			`ls -dr ${srcdir}/../$1*[[0-9]].[[0-9]][[0-9]] 2>/dev/null` \
3935			`ls -dr ${srcdir}/../$1*[[0-9]].[[0-9]] 2>/dev/null` \
3936			`ls -dr ${srcdir}/../$1*[[0-9]].[[0-9]]* 2>/dev/null` \
3937			; do
3938		    if test -f "$i/$1Config.sh" ; then
3939			ac_cv_c_$1config=`(cd $i; pwd)`
3940			break
3941		    fi
3942		    if test -f "$i/unix/$1Config.sh" ; then
3943			ac_cv_c_$1config=`(cd $i/unix; pwd)`
3944			break
3945		    fi
3946		done
3947	    fi
3948
3949	    # check in a few common install locations
3950	    if test x"${ac_cv_c_$1config}" = x ; then
3951		for i in `ls -d ${libdir} 2>/dev/null` \
3952			`ls -d ${exec_prefix}/lib 2>/dev/null` \
3953			`ls -d ${prefix}/lib 2>/dev/null` \
3954			`ls -d /usr/local/lib 2>/dev/null` \
3955			`ls -d /usr/contrib/lib 2>/dev/null` \
3956			`ls -d /usr/lib 2>/dev/null` \
3957			; do
3958		    if test -f "$i/$1Config.sh" ; then
3959			ac_cv_c_$1config=`(cd $i; pwd)`
3960			break
3961		    fi
3962		done
3963	    fi
3964	])
3965
3966	if test x"${ac_cv_c_$1config}" = x ; then
3967	    $1_BIN_DIR="# no $1 configs found"
3968	    AC_MSG_WARN([Cannot find $1 configuration definitions])
3969	    exit 0
3970	else
3971	    no_$1=
3972	    $1_BIN_DIR=${ac_cv_c_$1config}
3973	    AC_MSG_RESULT([found $$1_BIN_DIR/$1Config.sh])
3974	fi
3975    fi
3976])
3977
3978#------------------------------------------------------------------------
3979# TEA_LOAD_CONFIG --
3980#
3981#	Load the $1Config.sh file
3982#
3983# Arguments:
3984#
3985#	Requires the following vars to be set:
3986#		$1_BIN_DIR
3987#
3988# Results:
3989#
3990#	Subst the following vars:
3991#		$1_SRC_DIR
3992#		$1_LIB_FILE
3993#		$1_LIB_SPEC
3994#
3995#------------------------------------------------------------------------
3996
3997AC_DEFUN([TEA_LOAD_CONFIG], [
3998    AC_MSG_CHECKING([for existence of ${$1_BIN_DIR}/$1Config.sh])
3999
4000    if test -f "${$1_BIN_DIR}/$1Config.sh" ; then
4001        AC_MSG_RESULT([loading])
4002	. "${$1_BIN_DIR}/$1Config.sh"
4003    else
4004        AC_MSG_RESULT([file not found])
4005    fi
4006
4007    #
4008    # If the $1_BIN_DIR is the build directory (not the install directory),
4009    # then set the common variable name to the value of the build variables.
4010    # For example, the variable $1_LIB_SPEC will be set to the value
4011    # of $1_BUILD_LIB_SPEC. An extension should make use of $1_LIB_SPEC
4012    # instead of $1_BUILD_LIB_SPEC since it will work with both an
4013    # installed and uninstalled version of Tcl.
4014    #
4015
4016    if test -f "${$1_BIN_DIR}/Makefile" ; then
4017	AC_MSG_WARN([Found Makefile - using build library specs for $1])
4018        $1_LIB_SPEC=${$1_BUILD_LIB_SPEC}
4019        $1_STUB_LIB_SPEC=${$1_BUILD_STUB_LIB_SPEC}
4020        $1_STUB_LIB_PATH=${$1_BUILD_STUB_LIB_PATH}
4021    fi
4022
4023    AC_SUBST($1_VERSION)
4024    AC_SUBST($1_BIN_DIR)
4025    AC_SUBST($1_SRC_DIR)
4026
4027    AC_SUBST($1_LIB_FILE)
4028    AC_SUBST($1_LIB_SPEC)
4029
4030    AC_SUBST($1_STUB_LIB_FILE)
4031    AC_SUBST($1_STUB_LIB_SPEC)
4032    AC_SUBST($1_STUB_LIB_PATH)
4033])
4034
4035#------------------------------------------------------------------------
4036# TEA_PATH_CELIB --
4037#
4038#	Locate Keuchel's celib emulation layer for targeting Win/CE
4039#
4040# Arguments:
4041#	none
4042#
4043# Results:
4044#
4045#	Adds the following arguments to configure:
4046#		--with-celib=...
4047#
4048#	Defines the following vars:
4049#		CELIB_DIR	Full path to the directory containing
4050#				the include and platform lib files
4051#------------------------------------------------------------------------
4052
4053AC_DEFUN([TEA_PATH_CELIB], [
4054    # First, look for one uninstalled.
4055    # the alternative search directory is invoked by --with-celib
4056
4057    if test x"${no_celib}" = x ; then
4058	# we reset no_celib in case something fails here
4059	no_celib=true
4060	AC_ARG_WITH(celib,[  --with-celib=DIR        use Windows/CE support library from DIR], with_celibconfig=${withval})
4061	AC_MSG_CHECKING([for Windows/CE celib directory])
4062	AC_CACHE_VAL(ac_cv_c_celibconfig,[
4063	    # First check to see if --with-celibconfig was specified.
4064	    if test x"${with_celibconfig}" != x ; then
4065		if test -d "${with_celibconfig}/inc" ; then
4066		    ac_cv_c_celibconfig=`(cd ${with_celibconfig}; pwd)`
4067		else
4068		    AC_MSG_ERROR([${with_celibconfig} directory doesn't contain inc directory])
4069		fi
4070	    fi
4071
4072	    # then check for a celib library
4073	    if test x"${ac_cv_c_celibconfig}" = x ; then
4074		for i in \
4075			../celib-palm-3.0 \
4076			../celib \
4077			../../celib-palm-3.0 \
4078			../../celib \
4079			`ls -dr ../celib-*3.[[0-9]]* 2>/dev/null` \
4080			${srcdir}/../celib-palm-3.0 \
4081			${srcdir}/../celib \
4082			`ls -dr ${srcdir}/../celib-*3.[[0-9]]* 2>/dev/null` \
4083			; do
4084		    if test -d "$i/inc" ; then
4085			ac_cv_c_celibconfig=`(cd $i; pwd)`
4086			break
4087		    fi
4088		done
4089	    fi
4090	])
4091	if test x"${ac_cv_c_celibconfig}" = x ; then
4092	    AC_MSG_ERROR([Cannot find celib support library directory])
4093	else
4094	    no_celib=
4095	    CELIB_DIR=${ac_cv_c_celibconfig}
4096	    CELIB_DIR=`echo "$CELIB_DIR" | sed -e 's!\\\!/!g'`
4097	    AC_MSG_RESULT([found $CELIB_DIR])
4098	fi
4099    fi
4100])
4101
4102
4103# Local Variables:
4104# mode: autoconf
4105# End:
4106