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