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