1#------------------------------------------------------------------------
2# SC_PATH_TCLCONFIG --
3#
4#	Locate the tclConfig.sh file and perform a sanity check on
5#	the Tcl compile flags
6#
7# Arguments:
8#	none
9#
10# Results:
11#
12#	Adds the following arguments to configure:
13#		--with-tcl=...
14#
15#	Defines the following vars:
16#		TCL_BIN_DIR	Full path to the directory containing
17#				the tclConfig.sh file
18#------------------------------------------------------------------------
19
20AC_DEFUN([SC_PATH_TCLCONFIG], [
21    #
22    # Ok, lets find the tcl configuration
23    # First, look for one uninstalled.
24    # the alternative search directory is invoked by --with-tcl
25    #
26
27    if test x"${no_tcl}" = x ; then
28	# we reset no_tcl in case something fails here
29	no_tcl=true
30	AC_ARG_WITH(tcl,
31	    AC_HELP_STRING([--with-tcl],
32		[directory containing tcl configuration (tclConfig.sh)]),
33	    with_tclconfig="${withval}")
34	AC_MSG_CHECKING([for Tcl configuration])
35	AC_CACHE_VAL(ac_cv_c_tclconfig,[
36
37	    # First check to see if --with-tcl was specified.
38	    if test x"${with_tclconfig}" != x ; then
39		case "${with_tclconfig}" in
40		    */tclConfig.sh )
41			if test -f "${with_tclconfig}"; then
42			    AC_MSG_WARN([--with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself])
43			    with_tclconfig="`echo "${with_tclconfig}" | sed 's!/tclConfig\.sh$!!'`"
44			fi ;;
45		esac
46		if test -f "${with_tclconfig}/tclConfig.sh" ; then
47		    ac_cv_c_tclconfig="`(cd "${with_tclconfig}"; pwd)`"
48		else
49		    AC_MSG_ERROR([${with_tclconfig} directory doesn't contain tclConfig.sh])
50		fi
51	    fi
52
53	    # then check for a private Tcl installation
54	    if test x"${ac_cv_c_tclconfig}" = x ; then
55		for i in \
56			../tcl \
57			`ls -dr ../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
58			`ls -dr ../tcl[[8-9]].[[0-9]] 2>/dev/null` \
59			`ls -dr ../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
60			../../tcl \
61			`ls -dr ../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
62			`ls -dr ../../tcl[[8-9]].[[0-9]] 2>/dev/null` \
63			`ls -dr ../../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
64			../../../tcl \
65			`ls -dr ../../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
66			`ls -dr ../../../tcl[[8-9]].[[0-9]] 2>/dev/null` \
67			`ls -dr ../../../tcl[[8-9]].[[0-9]]* 2>/dev/null` ; do
68		    if test -f "$i/unix/tclConfig.sh" ; then
69			ac_cv_c_tclconfig="`(cd $i/unix; pwd)`"
70			break
71		    fi
72		done
73	    fi
74
75	    # on Darwin, check in Framework installation locations
76	    if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tclconfig}" = x ; then
77		for i in `ls -d ~/Library/Frameworks 2>/dev/null` \
78			`ls -d /Library/Frameworks 2>/dev/null` \
79			`ls -d /Network/Library/Frameworks 2>/dev/null` \
80			`ls -d /System/Library/Frameworks 2>/dev/null` \
81			; do
82		    if test -f "$i/Tcl.framework/tclConfig.sh" ; then
83			ac_cv_c_tclconfig="`(cd $i/Tcl.framework; pwd)`"
84			break
85		    fi
86		done
87	    fi
88
89	    # check in a few common install locations
90	    if test x"${ac_cv_c_tclconfig}" = x ; then
91		for i in `ls -d ${libdir} 2>/dev/null` \
92			`ls -d ${exec_prefix}/lib 2>/dev/null` \
93			`ls -d ${prefix}/lib 2>/dev/null` \
94			`ls -d /usr/local/lib 2>/dev/null` \
95			`ls -d /usr/contrib/lib 2>/dev/null` \
96			`ls -d /usr/lib 2>/dev/null` \
97			`ls -d /usr/lib64 2>/dev/null` \
98			; do
99		    if test -f "$i/tclConfig.sh" ; then
100			ac_cv_c_tclconfig="`(cd $i; pwd)`"
101			break
102		    fi
103		done
104	    fi
105
106	    # check in a few other private locations
107	    if test x"${ac_cv_c_tclconfig}" = x ; then
108		for i in \
109			${srcdir}/../tcl \
110			`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
111			`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]] 2>/dev/null` \
112			`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]]* 2>/dev/null` ; do
113		    if test -f "$i/unix/tclConfig.sh" ; then
114		    ac_cv_c_tclconfig="`(cd $i/unix; pwd)`"
115		    break
116		fi
117		done
118	    fi
119	])
120
121	if test x"${ac_cv_c_tclconfig}" = x ; then
122	    TCL_BIN_DIR="# no Tcl configs found"
123	    AC_MSG_WARN([Can't find Tcl configuration definitions])
124	    exit 0
125	else
126	    no_tcl=
127	    TCL_BIN_DIR="${ac_cv_c_tclconfig}"
128	    AC_MSG_RESULT([found ${TCL_BIN_DIR}/tclConfig.sh])
129	fi
130    fi
131])
132
133#------------------------------------------------------------------------
134# SC_PATH_TKCONFIG --
135#
136#	Locate the tkConfig.sh file
137#
138# Arguments:
139#	none
140#
141# Results:
142#
143#	Adds the following arguments to configure:
144#		--with-tk=...
145#
146#	Defines the following vars:
147#		TK_BIN_DIR	Full path to the directory containing
148#				the tkConfig.sh file
149#------------------------------------------------------------------------
150
151AC_DEFUN([SC_PATH_TKCONFIG], [
152    #
153    # Ok, lets find the tk configuration
154    # First, look for one uninstalled.
155    # the alternative search directory is invoked by --with-tk
156    #
157
158    if test x"${no_tk}" = x ; then
159	# we reset no_tk in case something fails here
160	no_tk=true
161	AC_ARG_WITH(tk,
162	    AC_HELP_STRING([--with-tk],
163		[directory containing tk configuration (tkConfig.sh)]),
164	    with_tkconfig="${withval}")
165	AC_MSG_CHECKING([for Tk configuration])
166	AC_CACHE_VAL(ac_cv_c_tkconfig,[
167
168	    # First check to see if --with-tkconfig was specified.
169	    if test x"${with_tkconfig}" != x ; then
170		case "${with_tkconfig}" in
171		    */tkConfig.sh )
172			if test -f "${with_tkconfig}"; then
173			    AC_MSG_WARN([--with-tk argument should refer to directory containing tkConfig.sh, not to tkConfig.sh itself])
174			    with_tkconfig="`echo "${with_tkconfig}" | sed 's!/tkConfig\.sh$!!'`"
175			fi ;;
176		esac
177		if test -f "${with_tkconfig}/tkConfig.sh" ; then
178		    ac_cv_c_tkconfig="`(cd "${with_tkconfig}"; pwd)`"
179		else
180		    AC_MSG_ERROR([${with_tkconfig} directory doesn't contain tkConfig.sh])
181		fi
182	    fi
183
184	    # then check for a private Tk library
185	    if test x"${ac_cv_c_tkconfig}" = x ; then
186		for i in \
187			../tk \
188			`ls -dr ../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
189			`ls -dr ../tk[[8-9]].[[0-9]] 2>/dev/null` \
190			`ls -dr ../tk[[8-9]].[[0-9]]* 2>/dev/null` \
191			../../tk \
192			`ls -dr ../../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
193			`ls -dr ../../tk[[8-9]].[[0-9]] 2>/dev/null` \
194			`ls -dr ../../tk[[8-9]].[[0-9]]* 2>/dev/null` \
195			../../../tk \
196			`ls -dr ../../../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
197			`ls -dr ../../../tk[[8-9]].[[0-9]] 2>/dev/null` \
198			`ls -dr ../../../tk[[8-9]].[[0-9]]* 2>/dev/null` ; do
199		    if test -f "$i/unix/tkConfig.sh" ; then
200			ac_cv_c_tkconfig="`(cd $i/unix; pwd)`"
201			break
202		    fi
203		done
204	    fi
205
206	    # on Darwin, check in Framework installation locations
207	    if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tkconfig}" = x ; then
208		for i in `ls -d ~/Library/Frameworks 2>/dev/null` \
209			`ls -d /Library/Frameworks 2>/dev/null` \
210			`ls -d /Network/Library/Frameworks 2>/dev/null` \
211			`ls -d /System/Library/Frameworks 2>/dev/null` \
212			; do
213		    if test -f "$i/Tk.framework/tkConfig.sh" ; then
214			ac_cv_c_tkconfig="`(cd $i/Tk.framework; pwd)`"
215			break
216		    fi
217		done
218	    fi
219
220	    # check in a few common install locations
221	    if test x"${ac_cv_c_tkconfig}" = x ; then
222		for i in `ls -d ${libdir} 2>/dev/null` \
223			`ls -d ${exec_prefix}/lib 2>/dev/null` \
224			`ls -d ${prefix}/lib 2>/dev/null` \
225			`ls -d /usr/local/lib 2>/dev/null` \
226			`ls -d /usr/contrib/lib 2>/dev/null` \
227			`ls -d /usr/lib 2>/dev/null` \
228			`ls -d /usr/lib64 2>/dev/null` \
229			; do
230		    if test -f "$i/tkConfig.sh" ; then
231			ac_cv_c_tkconfig="`(cd $i; pwd)`"
232			break
233		    fi
234		done
235	    fi
236
237	    # check in a few other private locations
238	    if test x"${ac_cv_c_tkconfig}" = x ; then
239		for i in \
240			${srcdir}/../tk \
241			`ls -dr ${srcdir}/../tk[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
242			`ls -dr ${srcdir}/../tk[[8-9]].[[0-9]] 2>/dev/null` \
243			`ls -dr ${srcdir}/../tk[[8-9]].[[0-9]]* 2>/dev/null` ; do
244		    if test -f "$i/unix/tkConfig.sh" ; then
245			ac_cv_c_tkconfig="`(cd $i/unix; pwd)`"
246			break
247		    fi
248		done
249	    fi
250	])
251
252	if test x"${ac_cv_c_tkconfig}" = x ; then
253	    TK_BIN_DIR="# no Tk configs found"
254	    AC_MSG_WARN([Can't find Tk configuration definitions])
255	    exit 0
256	else
257	    no_tk=
258	    TK_BIN_DIR="${ac_cv_c_tkconfig}"
259	    AC_MSG_RESULT([found ${TK_BIN_DIR}/tkConfig.sh])
260	fi
261    fi
262])
263
264#------------------------------------------------------------------------
265# SC_LOAD_TCLCONFIG --
266#
267#	Load the tclConfig.sh file
268#
269# Arguments:
270#
271#	Requires the following vars to be set:
272#		TCL_BIN_DIR
273#
274# Results:
275#
276#	Subst the following vars:
277#		TCL_BIN_DIR
278#		TCL_SRC_DIR
279#		TCL_LIB_FILE
280#
281#------------------------------------------------------------------------
282
283AC_DEFUN([SC_LOAD_TCLCONFIG], [
284    AC_MSG_CHECKING([for existence of ${TCL_BIN_DIR}/tclConfig.sh])
285
286    if test -f "${TCL_BIN_DIR}/tclConfig.sh" ; then
287        AC_MSG_RESULT([loading])
288	. "${TCL_BIN_DIR}/tclConfig.sh"
289    else
290        AC_MSG_RESULT([could not find ${TCL_BIN_DIR}/tclConfig.sh])
291    fi
292
293    # eval is required to do the TCL_DBGX substitution
294    eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
295    eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""
296
297    # If the TCL_BIN_DIR is the build directory (not the install directory),
298    # then set the common variable name to the value of the build variables.
299    # For example, the variable TCL_LIB_SPEC will be set to the value
300    # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC
301    # instead of TCL_BUILD_LIB_SPEC since it will work with both an
302    # installed and uninstalled version of Tcl.
303    if test -f "${TCL_BIN_DIR}/Makefile" ; then
304        TCL_LIB_SPEC="${TCL_BUILD_LIB_SPEC}"
305        TCL_STUB_LIB_SPEC="${TCL_BUILD_STUB_LIB_SPEC}"
306        TCL_STUB_LIB_PATH="${TCL_BUILD_STUB_LIB_PATH}"
307    elif test "`uname -s`" = "Darwin"; then
308	# If Tcl was built as a framework, attempt to use the libraries
309	# from the framework at the given location so that linking works
310	# against Tcl.framework installed in an arbitary location.
311	case ${TCL_DEFS} in
312	    *TCL_FRAMEWORK*)
313		if test -f "${TCL_BIN_DIR}/${TCL_LIB_FILE}"; then
314		    for i in "`cd "${TCL_BIN_DIR}"; pwd`" \
315			     "`cd "${TCL_BIN_DIR}"/../..; pwd`"; do
316			if test "`basename "$i"`" = "${TCL_LIB_FILE}.framework"; then
317			    TCL_LIB_SPEC="-F`dirname "$i" | sed -e 's/ /\\\\ /g'` -framework ${TCL_LIB_FILE}"
318			    break
319			fi
320		    done
321		fi
322		if test -f "${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}"; then
323		    TCL_STUB_LIB_SPEC="-L`echo "${TCL_BIN_DIR}"  | sed -e 's/ /\\\\ /g'` ${TCL_STUB_LIB_FLAG}"
324		    TCL_STUB_LIB_PATH="${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}"
325		fi
326		;;
327	esac
328    fi
329
330    # eval is required to do the TCL_DBGX substitution
331    eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
332    eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""
333    eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
334    eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""
335
336    AC_SUBST(TCL_VERSION)
337    AC_SUBST(TCL_PATCH_LEVEL)
338    AC_SUBST(TCL_BIN_DIR)
339    AC_SUBST(TCL_SRC_DIR)
340
341    AC_SUBST(TCL_LIB_FILE)
342    AC_SUBST(TCL_LIB_FLAG)
343    AC_SUBST(TCL_LIB_SPEC)
344
345    AC_SUBST(TCL_STUB_LIB_FILE)
346    AC_SUBST(TCL_STUB_LIB_FLAG)
347    AC_SUBST(TCL_STUB_LIB_SPEC)
348])
349
350#------------------------------------------------------------------------
351# SC_LOAD_TKCONFIG --
352#
353#	Load the tkConfig.sh file
354#
355# Arguments:
356#
357#	Requires the following vars to be set:
358#		TK_BIN_DIR
359#
360# Results:
361#
362#	Sets the following vars that should be in tkConfig.sh:
363#		TK_BIN_DIR
364#------------------------------------------------------------------------
365
366AC_DEFUN([SC_LOAD_TKCONFIG], [
367    AC_MSG_CHECKING([for existence of ${TK_BIN_DIR}/tkConfig.sh])
368
369    if test -f "${TK_BIN_DIR}/tkConfig.sh" ; then
370        AC_MSG_RESULT([loading])
371	. "${TK_BIN_DIR}/tkConfig.sh"
372    else
373        AC_MSG_RESULT([could not find ${TK_BIN_DIR}/tkConfig.sh])
374    fi
375
376    # eval is required to do the TK_DBGX substitution
377    eval "TK_LIB_FILE=\"${TK_LIB_FILE}\""
378    eval "TK_STUB_LIB_FILE=\"${TK_STUB_LIB_FILE}\""
379
380    # If the TK_BIN_DIR is the build directory (not the install directory),
381    # then set the common variable name to the value of the build variables.
382    # For example, the variable TK_LIB_SPEC will be set to the value
383    # of TK_BUILD_LIB_SPEC. An extension should make use of TK_LIB_SPEC
384    # instead of TK_BUILD_LIB_SPEC since it will work with both an
385    # installed and uninstalled version of Tcl.
386    if test -f "${TK_BIN_DIR}/Makefile" ; then
387        TK_LIB_SPEC="${TK_BUILD_LIB_SPEC}"
388        TK_STUB_LIB_SPEC="${TK_BUILD_STUB_LIB_SPEC}"
389        TK_STUB_LIB_PATH="${TK_BUILD_STUB_LIB_PATH}"
390    elif test "`uname -s`" = "Darwin"; then
391	# If Tk was built as a framework, attempt to use the libraries
392	# from the framework at the given location so that linking works
393	# against Tk.framework installed in an arbitary location.
394	case ${TK_DEFS} in
395	    *TK_FRAMEWORK*)
396		if test -f "${TK_BIN_DIR}/${TK_LIB_FILE}"; then
397		    for i in "`cd "${TK_BIN_DIR}"; pwd`" \
398			     "`cd "${TK_BIN_DIR}"/../..; pwd`"; do
399			if test "`basename "$i"`" = "${TK_LIB_FILE}.framework"; then
400			    TK_LIB_SPEC="-F`dirname "$i" | sed -e 's/ /\\\\ /g'` -framework ${TK_LIB_FILE}"
401			    break
402			fi
403		    done
404		fi
405		if test -f "${TK_BIN_DIR}/${TK_STUB_LIB_FILE}"; then
406		    TK_STUB_LIB_SPEC="-L` echo "${TK_BIN_DIR}"  | sed -e 's/ /\\\\ /g'` ${TK_STUB_LIB_FLAG}"
407		    TK_STUB_LIB_PATH="${TK_BIN_DIR}/${TK_STUB_LIB_FILE}"
408		fi
409		;;
410	esac
411    fi
412
413    # eval is required to do the TK_DBGX substitution
414    eval "TK_LIB_FLAG=\"${TK_LIB_FLAG}\""
415    eval "TK_LIB_SPEC=\"${TK_LIB_SPEC}\""
416    eval "TK_STUB_LIB_FLAG=\"${TK_STUB_LIB_FLAG}\""
417    eval "TK_STUB_LIB_SPEC=\"${TK_STUB_LIB_SPEC}\""
418
419    AC_SUBST(TK_VERSION)
420    AC_SUBST(TK_BIN_DIR)
421    AC_SUBST(TK_SRC_DIR)
422
423    AC_SUBST(TK_LIB_FILE)
424    AC_SUBST(TK_LIB_FLAG)
425    AC_SUBST(TK_LIB_SPEC)
426
427    AC_SUBST(TK_STUB_LIB_FILE)
428    AC_SUBST(TK_STUB_LIB_FLAG)
429    AC_SUBST(TK_STUB_LIB_SPEC)
430])
431
432#------------------------------------------------------------------------
433# SC_PROG_TCLSH
434#	Locate a tclsh shell installed on the system path. This macro
435#	will only find a Tcl shell that already exists on the system.
436#	It will not find a Tcl shell in the Tcl build directory or
437#	a Tcl shell that has been installed from the Tcl build directory.
438#	If a Tcl shell can't be located on the PATH, then TCLSH_PROG will
439#	be set to "". Extensions should take care not to create Makefile
440#	rules that are run by default and depend on TCLSH_PROG. An
441#	extension can't assume that an executable Tcl shell exists at
442#	build time.
443#
444# Arguments
445#	none
446#
447# Results
448#	Subst's the following values:
449#		TCLSH_PROG
450#------------------------------------------------------------------------
451
452AC_DEFUN([SC_PROG_TCLSH], [
453    AC_MSG_CHECKING([for tclsh])
454    AC_CACHE_VAL(ac_cv_path_tclsh, [
455	search_path=`echo ${PATH} | sed -e 's/:/ /g'`
456	for dir in $search_path ; do
457	    for j in `ls -r $dir/tclsh[[8-9]]* 2> /dev/null` \
458		    `ls -r $dir/tclsh* 2> /dev/null` ; do
459		if test x"$ac_cv_path_tclsh" = x ; then
460		    if test -f "$j" ; then
461			ac_cv_path_tclsh=$j
462			break
463		    fi
464		fi
465	    done
466	done
467    ])
468
469    if test -f "$ac_cv_path_tclsh" ; then
470	TCLSH_PROG="$ac_cv_path_tclsh"
471	AC_MSG_RESULT([$TCLSH_PROG])
472    else
473	# It is not an error if an installed version of Tcl can't be located.
474	TCLSH_PROG=""
475	AC_MSG_RESULT([No tclsh found on PATH])
476    fi
477    AC_SUBST(TCLSH_PROG)
478])
479
480#------------------------------------------------------------------------
481# SC_BUILD_TCLSH
482#	Determine the fully qualified path name of the tclsh executable
483#	in the Tcl build directory. This macro will correctly determine
484#	the name of the tclsh executable even if tclsh has not yet
485#	been built in the build directory. The build tclsh must be used
486#	when running tests from an extension build directory. It is not
487#	correct to use the TCLSH_PROG in cases like this.
488#
489# Arguments
490#	none
491#
492# Results
493#	Subst's the following values:
494#		BUILD_TCLSH
495#------------------------------------------------------------------------
496
497AC_DEFUN([SC_BUILD_TCLSH], [
498    AC_MSG_CHECKING([for tclsh in Tcl build directory])
499    BUILD_TCLSH="${TCL_BIN_DIR}"/tclsh
500    AC_MSG_RESULT([$BUILD_TCLSH])
501    AC_SUBST(BUILD_TCLSH)
502])
503
504#------------------------------------------------------------------------
505# SC_ENABLE_SHARED --
506#
507#	Allows the building of shared libraries
508#
509# Arguments:
510#	none
511#
512# Results:
513#
514#	Adds the following arguments to configure:
515#		--enable-shared=yes|no
516#
517#	Defines the following vars:
518#		STATIC_BUILD	Used for building import/export libraries
519#				on Windows.
520#
521#	Sets the following vars:
522#		SHARED_BUILD	Value of 1 or 0
523#------------------------------------------------------------------------
524
525AC_DEFUN([SC_ENABLE_SHARED], [
526    AC_MSG_CHECKING([how to build libraries])
527    AC_ARG_ENABLE(shared,
528	AC_HELP_STRING([--enable-shared],
529	    [build and link with shared libraries (default: on)]),
530	[tcl_ok=$enableval], [tcl_ok=yes])
531
532    if test "${enable_shared+set}" = set; then
533	enableval="$enable_shared"
534	tcl_ok=$enableval
535    else
536	tcl_ok=yes
537    fi
538
539    if test "$tcl_ok" = "yes" ; then
540	AC_MSG_RESULT([shared])
541	SHARED_BUILD=1
542    else
543	AC_MSG_RESULT([static])
544	SHARED_BUILD=0
545	AC_DEFINE(STATIC_BUILD, 1, [Is this a static build?])
546    fi
547])
548
549#------------------------------------------------------------------------
550# SC_ENABLE_FRAMEWORK --
551#
552#	Allows the building of shared libraries into frameworks
553#
554# Arguments:
555#	none
556#
557# Results:
558#
559#	Adds the following arguments to configure:
560#		--enable-framework=yes|no
561#
562#	Sets the following vars:
563#		FRAMEWORK_BUILD	Value of 1 or 0
564#------------------------------------------------------------------------
565
566AC_DEFUN([SC_ENABLE_FRAMEWORK], [
567    if test "`uname -s`" = "Darwin" ; then
568	AC_MSG_CHECKING([how to package libraries])
569	AC_ARG_ENABLE(framework,
570	    AC_HELP_STRING([--enable-framework],
571		[package shared libraries in MacOSX frameworks (default: off)]),
572	    [enable_framework=$enableval], [enable_framework=no])
573	if test $enable_framework = yes; then
574	    if test $SHARED_BUILD = 0; then
575		AC_MSG_WARN([Frameworks can only be built if --enable-shared is yes])
576		enable_framework=no
577	    fi
578	    if test $tcl_corefoundation = no; then
579		AC_MSG_WARN([Frameworks can only be used when CoreFoundation is available])
580		enable_framework=no
581	    fi
582	fi
583	if test $enable_framework = yes; then
584	    AC_MSG_RESULT([framework])
585	    FRAMEWORK_BUILD=1
586	else
587	    if test $SHARED_BUILD = 1; then
588		AC_MSG_RESULT([shared library])
589	    else
590		AC_MSG_RESULT([static library])
591	    fi
592	    FRAMEWORK_BUILD=0
593	fi
594    fi
595])
596
597#------------------------------------------------------------------------
598# SC_ENABLE_THREADS --
599#
600#	Specify if thread support should be enabled
601#
602# Arguments:
603#	none
604#
605# Results:
606#
607#	Adds the following arguments to configure:
608#		--enable-threads
609#
610#	Sets the following vars:
611#		THREADS_LIBS	Thread library(s)
612#
613#	Defines the following vars:
614#		TCL_THREADS
615#		_REENTRANT
616#		_THREAD_SAFE
617#
618#------------------------------------------------------------------------
619
620AC_DEFUN([SC_ENABLE_THREADS], [
621    AC_ARG_ENABLE(threads,
622	AC_HELP_STRING([--enable-threads],
623	    [build with threads (default: off)]),
624	[tcl_ok=$enableval], [tcl_ok=no])
625
626    if test "${TCL_THREADS}" = 1; then
627	tcl_threaded_core=1;
628    fi
629
630    if test "$tcl_ok" = "yes" -o "${TCL_THREADS}" = 1; then
631	TCL_THREADS=1
632	# USE_THREAD_ALLOC tells us to try the special thread-based
633	# allocator that significantly reduces lock contention
634	AC_DEFINE(USE_THREAD_ALLOC, 1,
635	    [Do we want to use the threaded memory allocator?])
636	AC_DEFINE(_REENTRANT, 1, [Do we want the reentrant OS API?])
637	if test "`uname -s`" = "SunOS" ; then
638	    AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1,
639		    [Do we really want to follow the standard? Yes we do!])
640	fi
641	AC_DEFINE(_THREAD_SAFE, 1, [Do we want the thread-safe OS API?])
642	AC_CHECK_LIB(pthread,pthread_mutex_init,tcl_ok=yes,tcl_ok=no)
643	if test "$tcl_ok" = "no"; then
644	    # Check a little harder for __pthread_mutex_init in the same
645	    # library, as some systems hide it there until pthread.h is
646	    # defined.  We could alternatively do an AC_TRY_COMPILE with
647	    # pthread.h, but that will work with libpthread really doesn't
648	    # exist, like AIX 4.2.  [Bug: 4359]
649	    AC_CHECK_LIB(pthread, __pthread_mutex_init,
650		tcl_ok=yes, tcl_ok=no)
651	fi
652
653	if test "$tcl_ok" = "yes"; then
654	    # The space is needed
655	    THREADS_LIBS=" -lpthread"
656	else
657	    AC_CHECK_LIB(pthreads, pthread_mutex_init,
658		tcl_ok=yes, tcl_ok=no)
659	    if test "$tcl_ok" = "yes"; then
660		# The space is needed
661		THREADS_LIBS=" -lpthreads"
662	    else
663		AC_CHECK_LIB(c, pthread_mutex_init,
664		    tcl_ok=yes, tcl_ok=no)
665		if test "$tcl_ok" = "no"; then
666		    AC_CHECK_LIB(c_r, pthread_mutex_init,
667			tcl_ok=yes, tcl_ok=no)
668		    if test "$tcl_ok" = "yes"; then
669			# The space is needed
670			THREADS_LIBS=" -pthread"
671		    else
672			TCL_THREADS=0
673			AC_MSG_WARN([Don't know how to find pthread lib on your system - you must disable thread support or edit the LIBS in the Makefile...])
674		    fi
675		fi
676	    fi
677	fi
678
679	# Does the pthread-implementation provide
680	# 'pthread_attr_setstacksize' ?
681
682	ac_saved_libs=$LIBS
683	LIBS="$LIBS $THREADS_LIBS"
684	AC_CHECK_FUNCS(pthread_attr_setstacksize)
685	AC_CHECK_FUNC(pthread_attr_get_np,tcl_ok=yes,tcl_ok=no)
686	if test $tcl_ok = yes ; then
687	    AC_DEFINE(HAVE_PTHREAD_ATTR_GET_NP, 1,
688		[Do we want a BSD-like thread-attribute interface?])
689	    AC_CACHE_CHECK([for pthread_attr_get_np declaration],
690		tcl_cv_grep_pthread_attr_get_np, [
691		AC_EGREP_HEADER(pthread_attr_get_np, pthread.h,
692		    tcl_cv_grep_pthread_attr_get_np=present,
693		    tcl_cv_grep_pthread_attr_get_np=missing)])
694	    if test $tcl_cv_grep_pthread_attr_get_np = missing ; then
695		AC_DEFINE(ATTRGETNP_NOT_DECLARED, 1,
696		    [Is pthread_attr_get_np() declared in <pthread.h>?])
697	    fi
698	else
699	    AC_CHECK_FUNC(pthread_getattr_np,tcl_ok=yes,tcl_ok=no)
700	    if test $tcl_ok = yes ; then
701		AC_DEFINE(HAVE_PTHREAD_GETATTR_NP, 1,
702		    [Do we want a Linux-like thread-attribute interface?])
703		AC_CACHE_CHECK([for pthread_getattr_np declaration],
704		    tcl_cv_grep_pthread_getattr_np, [
705		    AC_EGREP_HEADER(pthread_getattr_np, pthread.h,
706			tcl_cv_grep_pthread_getattr_np=present,
707			tcl_cv_grep_pthread_getattr_np=missing)])
708		if test $tcl_cv_grep_pthread_getattr_np = missing ; then
709		    AC_DEFINE(GETATTRNP_NOT_DECLARED, 1,
710			[Is pthread_getattr_np declared in <pthread.h>?])
711		fi
712	    fi
713	fi
714	if test $tcl_ok = no; then
715	    # Darwin thread stacksize API
716	    AC_CHECK_FUNCS(pthread_get_stacksize_np)
717	fi
718	LIBS=$ac_saved_libs
719    else
720	TCL_THREADS=0
721    fi
722    # Do checking message here to not mess up interleaved configure output
723    AC_MSG_CHECKING([for building with threads])
724    if test "${TCL_THREADS}" = 1; then
725	AC_DEFINE(TCL_THREADS, 1, [Are we building with threads enabled?])
726	if test "${tcl_threaded_core}" = 1; then
727	    AC_MSG_RESULT([yes (threaded core)])
728	else
729	    AC_MSG_RESULT([yes])
730	fi
731    else
732	AC_MSG_RESULT([no (default)])
733    fi
734
735    AC_SUBST(TCL_THREADS)
736])
737
738#------------------------------------------------------------------------
739# SC_ENABLE_SYMBOLS --
740#
741#	Specify if debugging symbols should be used.
742#	Memory (TCL_MEM_DEBUG) and compile (TCL_COMPILE_DEBUG) debugging
743#	can also be enabled.
744#
745# Arguments:
746#	none
747#
748#	Requires the following vars to be set in the Makefile:
749#		CFLAGS_DEBUG
750#		CFLAGS_OPTIMIZE
751#		LDFLAGS_DEBUG
752#		LDFLAGS_OPTIMIZE
753#
754# Results:
755#
756#	Adds the following arguments to configure:
757#		--enable-symbols
758#
759#	Defines the following vars:
760#		CFLAGS_DEFAULT	Sets to $(CFLAGS_DEBUG) if true
761#				Sets to $(CFLAGS_OPTIMIZE) if false
762#		LDFLAGS_DEFAULT	Sets to $(LDFLAGS_DEBUG) if true
763#				Sets to $(LDFLAGS_OPTIMIZE) if false
764#		DBGX		Formerly used as debug library extension;
765#				always blank now.
766#
767#------------------------------------------------------------------------
768
769AC_DEFUN([SC_ENABLE_SYMBOLS], [
770    AC_MSG_CHECKING([for build with symbols])
771    AC_ARG_ENABLE(symbols,
772	AC_HELP_STRING([--enable-symbols],
773	    [build with debugging symbols (default: off)]),
774	[tcl_ok=$enableval], [tcl_ok=no])
775# FIXME: Currently, LDFLAGS_DEFAULT is not used, it should work like CFLAGS_DEFAULT.
776    DBGX=""
777    if test "$tcl_ok" = "no"; then
778	CFLAGS_DEFAULT='$(CFLAGS_OPTIMIZE)'
779	LDFLAGS_DEFAULT='$(LDFLAGS_OPTIMIZE)'
780	AC_MSG_RESULT([no])
781	AC_DEFINE(TCL_CFG_OPTIMIZED, 1, [Is this an optimized build?])
782    else
783	CFLAGS_DEFAULT='$(CFLAGS_DEBUG)'
784	LDFLAGS_DEFAULT='$(LDFLAGS_DEBUG)'
785	if test "$tcl_ok" = "yes"; then
786	    AC_MSG_RESULT([yes (standard debugging)])
787	fi
788    fi
789    AC_SUBST(CFLAGS_DEFAULT)
790    AC_SUBST(LDFLAGS_DEFAULT)
791    ### FIXME: Surely TCL_CFG_DEBUG should be set to whether we're debugging?
792    AC_DEFINE(TCL_CFG_DEBUG, 1, [Is debugging enabled?])
793
794    if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then
795	AC_DEFINE(TCL_MEM_DEBUG, 1, [Is memory debugging enabled?])
796    fi
797
798    ifelse($1,bccdebug,dnl Only enable 'compile' for the Tcl core itself
799	if test "$tcl_ok" = "compile" -o "$tcl_ok" = "all"; then
800	    AC_DEFINE(TCL_COMPILE_DEBUG, 1, [Is bytecode debugging enabled?])
801	    AC_DEFINE(TCL_COMPILE_STATS, 1, [Are bytecode statistics enabled?])
802	fi)
803
804    if test "$tcl_ok" != "yes" -a "$tcl_ok" != "no"; then
805	if test "$tcl_ok" = "all"; then
806	    AC_MSG_RESULT([enabled symbols mem ]ifelse($1,bccdebug,[compile ])[debugging])
807	else
808	    AC_MSG_RESULT([enabled $tcl_ok debugging])
809	fi
810    fi
811])
812
813#------------------------------------------------------------------------
814# SC_ENABLE_LANGINFO --
815#
816#	Allows use of modern nl_langinfo check for better l10n.
817#	This is only relevant for Unix.
818#
819# Arguments:
820#	none
821#
822# Results:
823#
824#	Adds the following arguments to configure:
825#		--enable-langinfo=yes|no (default is yes)
826#
827#	Defines the following vars:
828#		HAVE_LANGINFO	Triggers use of nl_langinfo if defined.
829#
830#------------------------------------------------------------------------
831
832AC_DEFUN([SC_ENABLE_LANGINFO], [
833    AC_ARG_ENABLE(langinfo,
834	AC_HELP_STRING([--enable-langinfo],
835	    [use nl_langinfo if possible to determine encoding at startup, otherwise use old heuristic (default: on)]),
836	[langinfo_ok=$enableval], [langinfo_ok=yes])
837
838    HAVE_LANGINFO=0
839    if test "$langinfo_ok" = "yes"; then
840	AC_CHECK_HEADER(langinfo.h,[langinfo_ok=yes],[langinfo_ok=no])
841    fi
842    AC_MSG_CHECKING([whether to use nl_langinfo])
843    if test "$langinfo_ok" = "yes"; then
844	AC_CACHE_VAL(tcl_cv_langinfo_h, [
845	    AC_TRY_COMPILE([#include <langinfo.h>], [nl_langinfo(CODESET);],
846		    [tcl_cv_langinfo_h=yes],[tcl_cv_langinfo_h=no])])
847	AC_MSG_RESULT([$tcl_cv_langinfo_h])
848	if test $tcl_cv_langinfo_h = yes; then
849	    AC_DEFINE(HAVE_LANGINFO, 1, [Do we have nl_langinfo()?])
850	fi
851    else
852	AC_MSG_RESULT([$langinfo_ok])
853    fi
854])
855
856#--------------------------------------------------------------------
857# SC_CONFIG_MANPAGES
858#
859#	Decide whether to use symlinks for linking the manpages,
860#	whether to compress the manpages after installation, and
861#	whether to add a package name suffix to the installed
862#	manpages to avoidfile name clashes.
863#	If compression is enabled also find out what file name suffix
864#	the given compression program is using.
865#
866# Arguments:
867#	none
868#
869# Results:
870#
871#	Adds the following arguments to configure:
872#		--enable-man-symlinks
873#		--enable-man-compression=PROG
874#		--enable-man-suffix[=STRING]
875#
876#	Defines the following variable:
877#
878#	MAN_FLAGS -	The apropriate flags for installManPage
879#			according to the user's selection.
880#
881#--------------------------------------------------------------------
882
883AC_DEFUN([SC_CONFIG_MANPAGES], [
884    AC_MSG_CHECKING([whether to use symlinks for manpages])
885    AC_ARG_ENABLE(man-symlinks,
886	AC_HELP_STRING([--enable-man-symlinks],
887	    [use symlinks for the manpages (default: off)]),
888	test "$enableval" != "no" && MAN_FLAGS="$MAN_FLAGS --symlinks",
889	enableval="no")
890    AC_MSG_RESULT([$enableval])
891
892    AC_MSG_CHECKING([whether to compress the manpages])
893    AC_ARG_ENABLE(man-compression,
894	AC_HELP_STRING([--enable-man-compression=PROG],
895	    [compress the manpages with PROG (default: off)]),
896	[case $enableval in
897	    yes) AC_MSG_ERROR([missing argument to --enable-man-compression]);;
898	    no)  ;;
899	    *)   MAN_FLAGS="$MAN_FLAGS --compress $enableval";;
900	esac],
901	enableval="no")
902    AC_MSG_RESULT([$enableval])
903    if test "$enableval" != "no"; then
904	AC_MSG_CHECKING([for compressed file suffix])
905	touch TeST
906	$enableval TeST
907	Z=`ls TeST* | sed 's/^....//'`
908	rm -f TeST*
909	MAN_FLAGS="$MAN_FLAGS --extension $Z"
910	AC_MSG_RESULT([$Z])
911    fi
912
913    AC_MSG_CHECKING([whether to add a package name suffix for the manpages])
914    AC_ARG_ENABLE(man-suffix,
915	AC_HELP_STRING([--enable-man-suffix=STRING],
916	    [use STRING as a suffix to manpage file names (default: no, AC_PACKAGE_NAME if enabled without specifying STRING)]),
917	[case $enableval in
918	    yes) enableval="AC_PACKAGE_NAME" MAN_FLAGS="$MAN_FLAGS --suffix $enableval";;
919	    no)  ;;
920	    *)   MAN_FLAGS="$MAN_FLAGS --suffix $enableval";;
921	esac],
922	enableval="no")
923    AC_MSG_RESULT([$enableval])
924
925    AC_SUBST(MAN_FLAGS)
926])
927
928#--------------------------------------------------------------------
929# SC_CONFIG_SYSTEM
930#
931#	Determine what the system is (some things cannot be easily checked
932#	on a feature-driven basis, alas). This can usually be done via the
933#	"uname" command, but there are a few systems, like Next, where
934#	this doesn't work.
935#
936# Arguments:
937#	none
938#
939# Results:
940#	Defines the following var:
941#
942#	system -	System/platform/version identification code.
943#
944#--------------------------------------------------------------------
945
946AC_DEFUN([SC_CONFIG_SYSTEM], [
947    AC_CACHE_CHECK([system version], tcl_cv_sys_version, [
948	if test -f /usr/lib/NextStep/software_version; then
949	    tcl_cv_sys_version=NEXTSTEP-`awk '/3/,/3/' /usr/lib/NextStep/software_version`
950	else
951	    tcl_cv_sys_version=`uname -s`-`uname -r`
952	    if test "$?" -ne 0 ; then
953		AC_MSG_WARN([can't find uname command])
954		tcl_cv_sys_version=unknown
955	    else
956		# Special check for weird MP-RAS system (uname returns weird
957		# results, and the version is kept in special file).
958
959		if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
960		    tcl_cv_sys_version=MP-RAS-`awk '{print $[3]}' /etc/.relid`
961		fi
962		if test "`uname -s`" = "AIX" ; then
963		    tcl_cv_sys_version=AIX-`uname -v`.`uname -r`
964		fi
965	    fi
966	fi
967    ])
968    system=$tcl_cv_sys_version
969])
970
971#--------------------------------------------------------------------
972# SC_CONFIG_CFLAGS
973#
974#	Try to determine the proper flags to pass to the compiler
975#	for building shared libraries and other such nonsense.
976#
977# Arguments:
978#	none
979#
980# Results:
981#
982#	Defines and substitutes the following vars:
983#
984#       DL_OBJS -       Name of the object file that implements dynamic
985#                       loading for Tcl on this system.
986#       DL_LIBS -       Library file(s) to include in tclsh and other base
987#                       applications in order for the "load" command to work.
988#       LDFLAGS -      Flags to pass to the compiler when linking object
989#                       files into an executable application binary such
990#                       as tclsh.
991#       LD_SEARCH_FLAGS-Flags to pass to ld, such as "-R /usr/local/tcl/lib",
992#                       that tell the run-time dynamic linker where to look
993#                       for shared libraries such as libtcl.so.  Depends on
994#                       the variable LIB_RUNTIME_DIR in the Makefile. Could
995#                       be the same as CC_SEARCH_FLAGS if ${CC} is used to link.
996#       CC_SEARCH_FLAGS-Flags to pass to ${CC}, such as "-Wl,-rpath,/usr/local/tcl/lib",
997#                       that tell the run-time dynamic linker where to look
998#                       for shared libraries such as libtcl.so.  Depends on
999#                       the variable LIB_RUNTIME_DIR in the Makefile.
1000#       MAKE_LIB -      Command to execute to build the a library;
1001#                       differs when building shared or static.
1002#       MAKE_STUB_LIB -
1003#                       Command to execute to build a stub library.
1004#       INSTALL_LIB -   Command to execute to install a library;
1005#                       differs when building shared or static.
1006#       INSTALL_STUB_LIB -
1007#                       Command to execute to install a stub library.
1008#       STLIB_LD -      Base command to use for combining object files
1009#                       into a static library.
1010#       SHLIB_CFLAGS -  Flags to pass to cc when compiling the components
1011#                       of a shared library (may request position-independent
1012#                       code, among other things).
1013#       SHLIB_LD -      Base command to use for combining object files
1014#                       into a shared library.
1015#       SHLIB_LD_LIBS - Dependent libraries for the linker to scan when
1016#                       creating shared libraries.  This symbol typically
1017#                       goes at the end of the "ld" commands that build
1018#                       shared libraries. The value of the symbol is
1019#                       "${LIBS}" if all of the dependent libraries should
1020#                       be specified when creating a shared library.  If
1021#                       dependent libraries should not be specified (as on
1022#                       SunOS 4.x, where they cause the link to fail, or in
1023#                       general if Tcl and Tk aren't themselves shared
1024#                       libraries), then this symbol has an empty string
1025#                       as its value.
1026#       SHLIB_SUFFIX -  Suffix to use for the names of dynamically loadable
1027#                       extensions.  An empty string means we don't know how
1028#                       to use shared libraries on this platform.
1029# TCL_SHLIB_LD_EXTRAS - Additional element which are added to SHLIB_LD_LIBS
1030#  TK_SHLIB_LD_EXTRAS   for the build of Tcl and Tk, but not recorded in the
1031#                       tclConfig.sh, since they are only used for the build
1032#                       of Tcl and Tk.
1033#                       Examples: MacOS X records the library version and
1034#                       compatibility version in the shared library.  But
1035#                       of course the Tcl version of this is only used for Tcl.
1036#       LIB_SUFFIX -    Specifies everything that comes after the "libfoo"
1037#                       in a static or shared library name, using the $VERSION variable
1038#                       to put the version in the right place.  This is used
1039#                       by platforms that need non-standard library names.
1040#                       Examples:  ${VERSION}.so.1.1 on NetBSD, since it needs
1041#                       to have a version after the .so, and ${VERSION}.a
1042#                       on AIX, since a shared library needs to have
1043#                       a .a extension whereas shared objects for loadable
1044#                       extensions have a .so extension.  Defaults to
1045#                       ${VERSION}${SHLIB_SUFFIX}.
1046#       TCL_LIBS -
1047#                       Libs to use when linking Tcl shell or some other
1048#                       shell that includes Tcl libs.
1049#	CFLAGS_DEBUG -
1050#			Flags used when running the compiler in debug mode
1051#	CFLAGS_OPTIMIZE -
1052#			Flags used when running the compiler in optimize mode
1053#	CFLAGS -	Additional CFLAGS added as necessary (usually 64-bit)
1054#
1055#--------------------------------------------------------------------
1056
1057AC_DEFUN([SC_CONFIG_CFLAGS], [
1058
1059    # Step 0.a: Enable 64 bit support?
1060
1061    AC_MSG_CHECKING([if 64bit support is requested])
1062    AC_ARG_ENABLE(64bit,
1063	AC_HELP_STRING([--enable-64bit],
1064	    [enable 64bit support (default: off)]),
1065	[do64bit=$enableval], [do64bit=no])
1066    AC_MSG_RESULT([$do64bit])
1067
1068    # Step 0.b: Enable Solaris 64 bit VIS support?
1069
1070    AC_MSG_CHECKING([if 64bit Sparc VIS support is requested])
1071    AC_ARG_ENABLE(64bit-vis,
1072	AC_HELP_STRING([--enable-64bit-vis],
1073	    [enable 64bit Sparc VIS support (default: off)]),
1074	[do64bitVIS=$enableval], [do64bitVIS=no])
1075    AC_MSG_RESULT([$do64bitVIS])
1076    # Force 64bit on with VIS
1077    AS_IF([test "$do64bitVIS" = "yes"], [do64bit=yes])
1078
1079    # Step 0.c: Check if visibility support is available. Do this here so
1080    # that platform specific alternatives can be used below if this fails.
1081
1082    AC_CACHE_CHECK([if compiler supports visibility "hidden"],
1083	tcl_cv_cc_visibility_hidden, [
1084	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
1085	AC_TRY_LINK([
1086	    extern __attribute__((__visibility__("hidden"))) void f(void);
1087	    void f(void) {}], [f();], tcl_cv_cc_visibility_hidden=yes,
1088	    tcl_cv_cc_visibility_hidden=no)
1089	CFLAGS=$hold_cflags])
1090    AS_IF([test $tcl_cv_cc_visibility_hidden = yes], [
1091	AC_DEFINE(MODULE_SCOPE,
1092	    [extern __attribute__((__visibility__("hidden")))],
1093	    [Compiler support for module scope symbols])
1094    ])
1095
1096    # Step 0.d: Disable -rpath support?
1097
1098    AC_MSG_CHECKING([if rpath support is requested])
1099    AC_ARG_ENABLE(rpath,
1100	AC_HELP_STRING([--disable-rpath],
1101	    [disable rpath support (default: on)]),
1102	[doRpath=$enableval], [doRpath=yes])
1103    AC_MSG_RESULT([$doRpath])
1104
1105    # Step 1: set the variable "system" to hold the name and version number
1106    # for the system.
1107
1108    SC_CONFIG_SYSTEM
1109
1110    # Step 2: check for existence of -ldl library.  This is needed because
1111    # Linux can use either -ldl or -ldld for dynamic loading.
1112
1113    AC_CHECK_LIB(dl, dlopen, have_dl=yes, have_dl=no)
1114
1115    # Require ranlib early so we can override it in special cases below.
1116    AS_IF([test x"${SHLIB_VERSION}" = x], [SHLIB_VERSION="1.0"])
1117
1118    AC_REQUIRE([AC_PROG_RANLIB])
1119
1120    # Step 3: set configuration options based on system name and version.
1121
1122    do64bit_ok=no
1123    LDFLAGS_ORIG="$LDFLAGS"
1124    # When ld needs options to work in 64-bit mode, put them in
1125    # LDFLAGS_ARCH so they eventually end up in LDFLAGS even if [load]
1126    # is disabled by the user. [Bug 1016796]
1127    LDFLAGS_ARCH=""
1128    UNSHARED_LIB_SUFFIX=""
1129    TCL_TRIM_DOTS='`echo ${VERSION} | tr -d .`'
1130    ECHO_VERSION='`echo ${VERSION}`'
1131    TCL_LIB_VERSIONS_OK=ok
1132    CFLAGS_DEBUG=-g
1133    CFLAGS_OPTIMIZE=-O
1134    AS_IF([test "$GCC" = yes], [
1135	CFLAGS_WARNING="-Wall"
1136    ], [CFLAGS_WARNING=""])
1137dnl FIXME: Replace AC_CHECK_PROG with AC_CHECK_TOOL once cross compiling is fixed.
1138dnl AC_CHECK_TOOL(AR, ar)
1139    AC_CHECK_PROG(AR, ar, ar)
1140    AS_IF([test "${AR}" = ""], [
1141	AC_MSG_ERROR([Required archive tool 'ar' not found on PATH.])
1142    ])
1143    STLIB_LD='${AR} cr'
1144    LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH"
1145    PLAT_OBJS=""
1146    PLAT_SRCS=""
1147    LDAIX_SRC=""
1148    case $system in
1149	AIX-*)
1150	    AS_IF([test "${TCL_THREADS}" = "1" -a "$GCC" != "yes"], [
1151		# AIX requires the _r compiler when gcc isn't being used
1152		case "${CC}" in
1153		    *_r|*_r\ *)
1154			# ok ...
1155			;;
1156		    *)
1157			# Make sure only first arg gets _r
1158		    	CC=`echo "$CC" | sed -e 's/^\([[^ ]]*\)/\1_r/'`
1159			;;
1160		esac
1161		AC_MSG_RESULT([Using $CC for compiling with threads])
1162	    ])
1163	    LIBS="$LIBS -lc"
1164	    SHLIB_CFLAGS=""
1165	    # Note: need the LIBS below, otherwise Tk won't find Tcl's
1166	    # symbols when dynamically loaded into tclsh.
1167	    SHLIB_LD_LIBS='${LIBS}'
1168	    SHLIB_SUFFIX=".so"
1169
1170	    DL_OBJS="tclLoadDl.o"
1171	    LD_LIBRARY_PATH_VAR="LIBPATH"
1172
1173	    # ldAix No longer needed with use of -bexpall/-brtl
1174	    # but some extensions may still reference it
1175	    LDAIX_SRC='$(UNIX_DIR)/ldAix'
1176
1177	    # Check to enable 64-bit flags for compiler/linker
1178	    AS_IF([test "$do64bit" = yes], [
1179		AS_IF([test "$GCC" = yes], [
1180		    AC_MSG_WARN([64bit mode not supported with GCC on $system])
1181		], [
1182		    do64bit_ok=yes
1183		    CFLAGS="$CFLAGS -q64"
1184		    LDFLAGS_ARCH="-q64"
1185		    RANLIB="${RANLIB} -X64"
1186		    AR="${AR} -X64"
1187		    SHLIB_LD_FLAGS="-b64"
1188		])
1189	    ])
1190
1191	    AS_IF([test "`uname -m`" = ia64], [
1192		# AIX-5 uses ELF style dynamic libraries on IA-64, but not PPC
1193		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
1194		# AIX-5 has dl* in libc.so
1195		DL_LIBS=""
1196		AS_IF([test "$GCC" = yes], [
1197		    CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
1198		], [
1199		    CC_SEARCH_FLAGS='-R${LIB_RUNTIME_DIR}'
1200		])
1201		LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}'
1202	    ], [
1203		AS_IF([test "$GCC" = yes], [
1204		    SHLIB_LD='${CC} -shared -Wl,-bexpall'
1205		], [
1206		    SHLIB_LD="/bin/ld -bhalt:4 -bM:SRE -bexpall -H512 -T512 -bnoentry"
1207		    LDFLAGS="$LDFLAGS -brtl"
1208		])
1209		SHLIB_LD="${SHLIB_LD} ${SHLIB_LD_FLAGS}"
1210		DL_LIBS="-ldl"
1211		CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
1212		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1213	    ])
1214	    ;;
1215	BeOS*)
1216	    SHLIB_CFLAGS="-fPIC"
1217	    SHLIB_LD='${CC} -nostart'
1218	    SHLIB_LD_LIBS='${LIBS}'
1219	    SHLIB_SUFFIX=".so"
1220	    DL_OBJS="tclLoadDl.o"
1221	    DL_LIBS="-ldl"
1222
1223	    #-----------------------------------------------------------
1224	    # Check for inet_ntoa in -lbind, for BeOS (which also needs
1225	    # -lsocket, even if the network functions are in -lnet which
1226	    # is always linked to, for compatibility.
1227	    #-----------------------------------------------------------
1228	    AC_CHECK_LIB(bind, inet_ntoa, [LIBS="$LIBS -lbind -lsocket"])
1229	    ;;
1230	BSD/OS-2.1*|BSD/OS-3*)
1231	    SHLIB_CFLAGS=""
1232	    SHLIB_LD="shlicc -r"
1233	    SHLIB_LD_LIBS='${LIBS}'
1234	    SHLIB_SUFFIX=".so"
1235	    DL_OBJS="tclLoadDl.o"
1236	    DL_LIBS="-ldl"
1237	    CC_SEARCH_FLAGS=""
1238	    LD_SEARCH_FLAGS=""
1239	    ;;
1240	BSD/OS-4.*)
1241	    SHLIB_CFLAGS="-export-dynamic -fPIC"
1242	    SHLIB_LD='${CC} -shared'
1243	    SHLIB_LD_LIBS='${LIBS}'
1244	    SHLIB_SUFFIX=".so"
1245	    DL_OBJS="tclLoadDl.o"
1246	    DL_LIBS="-ldl"
1247	    LDFLAGS="$LDFLAGS -export-dynamic"
1248	    CC_SEARCH_FLAGS=""
1249	    LD_SEARCH_FLAGS=""
1250	    ;;
1251	CYGWIN_*)
1252	    SHLIB_CFLAGS=""
1253	    SHLIB_LD='${CC} -shared'
1254	    SHLIB_LD_LIBS='${LIBS}'
1255	    SHLIB_SUFFIX=".dll"
1256	    DL_OBJS="tclLoadDl.o"
1257	    DL_LIBS="-ldl"
1258	    CC_SEARCH_FLAGS=""
1259	    LD_SEARCH_FLAGS=""
1260	    ;;
1261	dgux*)
1262	    SHLIB_CFLAGS="-K PIC"
1263	    SHLIB_LD='${CC} -G'
1264	    SHLIB_LD_LIBS=""
1265	    SHLIB_SUFFIX=".so"
1266	    DL_OBJS="tclLoadDl.o"
1267	    DL_LIBS="-ldl"
1268	    CC_SEARCH_FLAGS=""
1269	    LD_SEARCH_FLAGS=""
1270	    ;;
1271	Haiku*)
1272	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
1273	    SHLIB_CFLAGS="-fPIC"
1274	    SHLIB_LD_LIBS='${LIBS}'
1275	    SHLIB_SUFFIX=".so"
1276	    SHLIB_LD='${CC} -shared ${CFLAGS} ${LDFLAGS}'
1277	    DL_OBJS="tclLoadDl.o"
1278	    DL_LIBS="-lroot"
1279	    AC_CHECK_LIB(network, inet_ntoa, [LIBS="$LIBS -lnetwork"])
1280	    ;;
1281	HP-UX-*.11.*)
1282	    # Use updated header definitions where possible
1283	    AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, [Do we want to use the XOPEN network library?])
1284	    AC_DEFINE(_XOPEN_SOURCE, 1, [Do we want to use the XOPEN network library?])
1285	    LIBS="$LIBS -lxnet"               # Use the XOPEN network library
1286
1287	    AS_IF([test "`uname -m`" = ia64], [
1288		SHLIB_SUFFIX=".so"
1289	    ], [
1290		SHLIB_SUFFIX=".sl"
1291	    ])
1292	    AC_CHECK_LIB(dld, shl_load, tcl_ok=yes, tcl_ok=no)
1293	    AS_IF([test "$tcl_ok" = yes], [
1294		SHLIB_CFLAGS="+z"
1295		SHLIB_LD="ld -b"
1296		SHLIB_LD_LIBS='${LIBS}'
1297		DL_OBJS="tclLoadShl.o"
1298		DL_LIBS="-ldld"
1299		LDFLAGS="$LDFLAGS -Wl,-E"
1300		CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.'
1301		LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:.'
1302		LD_LIBRARY_PATH_VAR="SHLIB_PATH"
1303	    ])
1304	    AS_IF([test "$GCC" = yes], [
1305		SHLIB_LD='${CC} -shared'
1306		SHLIB_LD_LIBS='${LIBS}'
1307		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1308	    ])
1309
1310	    # Users may want PA-RISC 1.1/2.0 portable code - needs HP cc
1311	    #CFLAGS="$CFLAGS +DAportable"
1312
1313	    # Check to enable 64-bit flags for compiler/linker
1314	    AS_IF([test "$do64bit" = "yes"], [
1315		AS_IF([test "$GCC" = yes], [
1316		    case `${CC} -dumpmachine` in
1317			hppa64*)
1318			    # 64-bit gcc in use.  Fix flags for GNU ld.
1319			    do64bit_ok=yes
1320			    SHLIB_LD='${CC} -shared'
1321			    SHLIB_LD_LIBS='${LIBS}'
1322			    AS_IF([test $doRpath = yes], [
1323				CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
1324			    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1325			    ;;
1326			*)
1327			    AC_MSG_WARN([64bit mode not supported with GCC on $system])
1328			    ;;
1329		    esac
1330		], [
1331		    do64bit_ok=yes
1332		    CFLAGS="$CFLAGS +DD64"
1333		    LDFLAGS_ARCH="+DD64"
1334		])
1335	    ]) ;;
1336	HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*)
1337	    SHLIB_SUFFIX=".sl"
1338	    AC_CHECK_LIB(dld, shl_load, tcl_ok=yes, tcl_ok=no)
1339	    AS_IF([test "$tcl_ok" = yes], [
1340		SHLIB_CFLAGS="+z"
1341		SHLIB_LD="ld -b"
1342		SHLIB_LD_LIBS=""
1343		DL_OBJS="tclLoadShl.o"
1344		DL_LIBS="-ldld"
1345		LDFLAGS="$LDFLAGS -Wl,-E"
1346		CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.'
1347		LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:.'
1348		LD_LIBRARY_PATH_VAR="SHLIB_PATH"
1349	    ]) ;;
1350	IRIX-5.*)
1351	    SHLIB_CFLAGS=""
1352	    SHLIB_LD="ld -shared -rdata_shared"
1353	    SHLIB_LD_LIBS='${LIBS}'
1354	    SHLIB_SUFFIX=".so"
1355	    DL_OBJS="tclLoadDl.o"
1356	    DL_LIBS=""
1357	    AS_IF([test $doRpath = yes], [
1358		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1359		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1360	    ;;
1361	IRIX-6.*)
1362	    SHLIB_CFLAGS=""
1363	    SHLIB_LD="ld -n32 -shared -rdata_shared"
1364	    SHLIB_LD_LIBS='${LIBS}'
1365	    SHLIB_SUFFIX=".so"
1366	    DL_OBJS="tclLoadDl.o"
1367	    DL_LIBS=""
1368	    AS_IF([test $doRpath = yes], [
1369		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1370		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1371	    AS_IF([test "$GCC" = yes], [
1372		CFLAGS="$CFLAGS -mabi=n32"
1373		LDFLAGS="$LDFLAGS -mabi=n32"
1374	    ], [
1375		case $system in
1376		    IRIX-6.3)
1377			# Use to build 6.2 compatible binaries on 6.3.
1378			CFLAGS="$CFLAGS -n32 -D_OLD_TERMIOS"
1379			;;
1380		    *)
1381			CFLAGS="$CFLAGS -n32"
1382			;;
1383		esac
1384		LDFLAGS="$LDFLAGS -n32"
1385	    ])
1386	    ;;
1387	IRIX64-6.*)
1388	    SHLIB_CFLAGS=""
1389	    SHLIB_LD="ld -n32 -shared -rdata_shared"
1390	    SHLIB_LD_LIBS='${LIBS}'
1391	    SHLIB_SUFFIX=".so"
1392	    DL_OBJS="tclLoadDl.o"
1393	    DL_LIBS=""
1394	    AS_IF([test $doRpath = yes], [
1395		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1396		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1397
1398	    # Check to enable 64-bit flags for compiler/linker
1399
1400	    AS_IF([test "$do64bit" = yes], [
1401	        AS_IF([test "$GCC" = yes], [
1402	            AC_MSG_WARN([64bit mode not supported by gcc])
1403	        ], [
1404	            do64bit_ok=yes
1405	            SHLIB_LD="ld -64 -shared -rdata_shared"
1406	            CFLAGS="$CFLAGS -64"
1407	            LDFLAGS_ARCH="-64"
1408	        ])
1409	    ])
1410	    ;;
1411	Linux*)
1412	    SHLIB_CFLAGS="-fPIC"
1413	    SHLIB_LD_LIBS='${LIBS}'
1414	    SHLIB_SUFFIX=".so"
1415
1416	    CFLAGS_OPTIMIZE="-O2"
1417	    # egcs-2.91.66 on Redhat Linux 6.0 generates lots of warnings
1418	    # when you inline the string and math operations.  Turn this off to
1419	    # get rid of the warnings.
1420	    #CFLAGS_OPTIMIZE="${CFLAGS_OPTIMIZE} -D__NO_STRING_INLINES -D__NO_MATH_INLINES"
1421
1422	    SHLIB_LD='${CC} -shared ${CFLAGS} ${LDFLAGS}'
1423	    DL_OBJS="tclLoadDl.o"
1424	    DL_LIBS="-ldl"
1425	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
1426	    AS_IF([test $doRpath = yes], [
1427		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
1428	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1429	    AS_IF([test "`uname -m`" = "alpha"], [CFLAGS="$CFLAGS -mieee"])
1430	    AS_IF([test $do64bit = yes], [
1431		AC_CACHE_CHECK([if compiler accepts -m64 flag], tcl_cv_cc_m64, [
1432		    hold_cflags=$CFLAGS
1433		    CFLAGS="$CFLAGS -m64"
1434		    AC_TRY_LINK(,, tcl_cv_cc_m64=yes, tcl_cv_cc_m64=no)
1435		    CFLAGS=$hold_cflags])
1436		AS_IF([test $tcl_cv_cc_m64 = yes], [
1437		    CFLAGS="$CFLAGS -m64"
1438		    do64bit_ok=yes
1439		])
1440	   ])
1441
1442	    # The combo of gcc + glibc has a bug related to inlining of
1443	    # functions like strtod(). The -fno-builtin flag should address
1444	    # this problem but it does not work. The -fno-inline flag is kind
1445	    # of overkill but it works. Disable inlining only when one of the
1446	    # files in compat/*.c is being linked in.
1447
1448	    AS_IF([test x"${USE_COMPAT}" != x],[CFLAGS="$CFLAGS -fno-inline"])
1449	    ;;
1450	GNU*)
1451	    SHLIB_CFLAGS="-fPIC"
1452	    SHLIB_LD_LIBS='${LIBS}'
1453	    SHLIB_SUFFIX=".so"
1454
1455	    SHLIB_LD='${CC} -shared'
1456	    DL_OBJS=""
1457	    DL_LIBS="-ldl"
1458	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
1459	    CC_SEARCH_FLAGS=""
1460	    LD_SEARCH_FLAGS=""
1461	    AS_IF([test "`uname -m`" = "alpha"], [CFLAGS="$CFLAGS -mieee"])
1462	    ;;
1463	Lynx*)
1464	    SHLIB_CFLAGS="-fPIC"
1465	    SHLIB_LD_LIBS='${LIBS}'
1466	    SHLIB_SUFFIX=".so"
1467	    CFLAGS_OPTIMIZE=-02
1468	    SHLIB_LD='${CC} -shared'
1469	    DL_OBJS="tclLoadDl.o"
1470	    DL_LIBS="-mshared -ldl"
1471	    LD_FLAGS="-Wl,--export-dynamic"
1472	    AS_IF([test $doRpath = yes], [
1473		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1474		LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
1475	    ;;
1476	MP-RAS-02*)
1477	    SHLIB_CFLAGS="-K PIC"
1478	    SHLIB_LD='${CC} -G'
1479	    SHLIB_LD_LIBS=""
1480	    SHLIB_SUFFIX=".so"
1481	    DL_OBJS="tclLoadDl.o"
1482	    DL_LIBS="-ldl"
1483	    CC_SEARCH_FLAGS=""
1484	    LD_SEARCH_FLAGS=""
1485	    ;;
1486	MP-RAS-*)
1487	    SHLIB_CFLAGS="-K PIC"
1488	    SHLIB_LD='${CC} -G'
1489	    SHLIB_LD_LIBS=""
1490	    SHLIB_SUFFIX=".so"
1491	    DL_OBJS="tclLoadDl.o"
1492	    DL_LIBS="-ldl"
1493	    LDFLAGS="$LDFLAGS -Wl,-Bexport"
1494	    CC_SEARCH_FLAGS=""
1495	    LD_SEARCH_FLAGS=""
1496	    ;;
1497	NetBSD-1.*|FreeBSD-[[1-2]].*)
1498	    SHLIB_CFLAGS="-fPIC"
1499	    SHLIB_LD="ld -Bshareable -x"
1500	    SHLIB_LD_LIBS='${LIBS}'
1501	    SHLIB_SUFFIX=".so"
1502	    DL_OBJS="tclLoadDl.o"
1503	    DL_LIBS=""
1504	    AS_IF([test $doRpath = yes], [
1505		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1506		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1507	    AC_CACHE_CHECK([for ELF], tcl_cv_ld_elf, [
1508		AC_EGREP_CPP(yes, [
1509#ifdef __ELF__
1510	yes
1511#endif
1512		], tcl_cv_ld_elf=yes, tcl_cv_ld_elf=no)])
1513	    AS_IF([test $tcl_cv_ld_elf = yes], [
1514		SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so'
1515	    ], [
1516		SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.${SHLIB_VERSION}'
1517	    ])
1518
1519	    # Ancient FreeBSD doesn't handle version numbers with dots.
1520
1521	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1522	    TCL_LIB_VERSIONS_OK=nodots
1523	    ;;
1524	OpenBSD-*)
1525	    CFLAGS_OPTIMIZE='-O2'
1526	    SHLIB_CFLAGS="-fPIC"
1527	    SHLIB_LD='${CC} -shared ${SHLIB_CFLAGS}'
1528	    SHLIB_LD_LIBS='${LIBS}'
1529	    SHLIB_SUFFIX=".so"
1530	    DL_OBJS="tclLoadDl.o"
1531	    DL_LIBS=""
1532	    AS_IF([test $doRpath = yes], [
1533		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
1534	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1535	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.${SHLIB_VERSION}'
1536	    AC_CACHE_CHECK([for ELF], tcl_cv_ld_elf, [
1537		AC_EGREP_CPP(yes, [
1538#ifdef __ELF__
1539	yes
1540#endif
1541		], tcl_cv_ld_elf=yes, tcl_cv_ld_elf=no)])
1542	    AS_IF([test $tcl_cv_ld_elf = yes], [
1543		LDFLAGS=-Wl,-export-dynamic
1544	    ], [LDFLAGS=""])
1545	    AS_IF([test "${TCL_THREADS}" = "1"], [
1546		# OpenBSD builds and links with -pthread, never -lpthread.
1547		LIBS=`echo $LIBS | sed s/-lpthread//`
1548		CFLAGS="$CFLAGS -pthread"
1549		SHLIB_CFLAGS="$SHLIB_CFLAGS -pthread"
1550	    ])
1551	    # OpenBSD doesn't do version numbers with dots.
1552	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1553	    TCL_LIB_VERSIONS_OK=nodots
1554	    ;;
1555	NetBSD-*|FreeBSD-[[3-4]].*)
1556	    # FreeBSD 3.* and greater have ELF.
1557	    # NetBSD 2.* has ELF and can use 'cc -shared' to build shared libs
1558	    SHLIB_CFLAGS="-fPIC"
1559	    SHLIB_LD='${CC} -shared ${SHLIB_CFLAGS}'
1560	    SHLIB_LD_LIBS='${LIBS}'
1561	    SHLIB_SUFFIX=".so"
1562	    DL_OBJS="tclLoadDl.o"
1563	    DL_LIBS=""
1564	    LDFLAGS="$LDFLAGS -export-dynamic"
1565	    AS_IF([test $doRpath = yes], [
1566		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
1567	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1568	    AS_IF([test "${TCL_THREADS}" = "1"], [
1569		# The -pthread needs to go in the CFLAGS, not LIBS
1570		LIBS=`echo $LIBS | sed s/-pthread//`
1571		CFLAGS="$CFLAGS -pthread"
1572	    	LDFLAGS="$LDFLAGS -pthread"
1573	    ])
1574	    case $system in
1575	    FreeBSD-3.*)
1576	    	# FreeBSD-3 doesn't handle version numbers with dots.
1577	    	UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1578	    	SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so'
1579	    	TCL_LIB_VERSIONS_OK=nodots
1580		;;
1581	    esac
1582	    ;;
1583	FreeBSD-*)
1584	    # This configuration from FreeBSD Ports.
1585	    SHLIB_CFLAGS="-fPIC"
1586	    SHLIB_LD="${CC} -shared"
1587	    TCL_SHLIB_LD_EXTRAS="-soname \$[@]"
1588	    SHLIB_LD_LIBS='${LIBS}'
1589	    SHLIB_SUFFIX=".so"
1590	    DL_OBJS="tclLoadDl.o"
1591	    DL_LIBS=""
1592	    LDFLAGS=""
1593	    AS_IF([test $doRpath = yes], [
1594		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1595		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1596	    AS_IF([test "${TCL_THREADS}" = "1"], [
1597		# The -pthread needs to go in the LDFLAGS, not LIBS
1598		LIBS=`echo $LIBS | sed s/-pthread//`
1599		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1600		LDFLAGS="$LDFLAGS $PTHREAD_LIBS"])
1601	    # Version numbers are dot-stripped by system policy.
1602	    TCL_TRIM_DOTS=`echo ${VERSION} | tr -d .`
1603	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1604	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1'
1605	    TCL_LIB_VERSIONS_OK=nodots
1606	    ;;
1607	Darwin-*)
1608	    CFLAGS_OPTIMIZE="-Os"
1609	    SHLIB_CFLAGS="-fno-common"
1610	    # To avoid discrepancies between what headers configure sees during
1611	    # preprocessing tests and compiling tests, move any -isysroot and
1612	    # -mmacosx-version-min flags from CFLAGS to CPPFLAGS:
1613	    CPPFLAGS="${CPPFLAGS} `echo " ${CFLAGS}" | \
1614		awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \
1615		if ([$]i~/^(isysroot|mmacosx-version-min)/) print "-"[$]i}'`"
1616	    CFLAGS="`echo " ${CFLAGS}" | \
1617		awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \
1618		if (!([$]i~/^(isysroot|mmacosx-version-min)/)) print "-"[$]i}'`"
1619	    AS_IF([test $do64bit = yes], [
1620		case `arch` in
1621		    ppc)
1622			AC_CACHE_CHECK([if compiler accepts -arch ppc64 flag],
1623				tcl_cv_cc_arch_ppc64, [
1624			    hold_cflags=$CFLAGS
1625			    CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
1626			    AC_TRY_LINK(,, tcl_cv_cc_arch_ppc64=yes,
1627				    tcl_cv_cc_arch_ppc64=no)
1628			    CFLAGS=$hold_cflags])
1629			AS_IF([test $tcl_cv_cc_arch_ppc64 = yes], [
1630			    CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
1631			    do64bit_ok=yes
1632			]);;
1633		    i386)
1634			AC_CACHE_CHECK([if compiler accepts -arch x86_64 flag],
1635				tcl_cv_cc_arch_x86_64, [
1636			    hold_cflags=$CFLAGS
1637			    CFLAGS="$CFLAGS -arch x86_64"
1638			    AC_TRY_LINK(,, tcl_cv_cc_arch_x86_64=yes,
1639				    tcl_cv_cc_arch_x86_64=no)
1640			    CFLAGS=$hold_cflags])
1641			AS_IF([test $tcl_cv_cc_arch_x86_64 = yes], [
1642			    CFLAGS="$CFLAGS -arch x86_64"
1643			    do64bit_ok=yes
1644			]);;
1645		    *)
1646			AC_MSG_WARN([Don't know how enable 64-bit on architecture `arch`]);;
1647		esac
1648	    ], [
1649		# Check for combined 32-bit and 64-bit fat build
1650		AS_IF([echo "$CFLAGS " |grep -E -q -- '-arch (ppc64|x86_64) ' \
1651		    && echo "$CFLAGS " |grep -E -q -- '-arch (ppc|i386) '], [
1652		    fat_32_64=yes])
1653	    ])
1654	    SHLIB_LD='${CC} -dynamiclib ${CFLAGS} ${LDFLAGS}'
1655	    AC_CACHE_CHECK([if ld accepts -single_module flag], tcl_cv_ld_single_module, [
1656		hold_ldflags=$LDFLAGS
1657		LDFLAGS="$LDFLAGS -dynamiclib -Wl,-single_module"
1658		AC_TRY_LINK(, [int i;], tcl_cv_ld_single_module=yes, tcl_cv_ld_single_module=no)
1659		LDFLAGS=$hold_ldflags])
1660	    AS_IF([test $tcl_cv_ld_single_module = yes], [
1661		SHLIB_LD="${SHLIB_LD} -Wl,-single_module"
1662	    ])
1663	    SHLIB_LD_LIBS='${LIBS}'
1664	    SHLIB_SUFFIX=".dylib"
1665	    DL_OBJS="tclLoadDyld.o"
1666	    DL_LIBS=""
1667	    # Don't use -prebind when building for Mac OS X 10.4 or later only:
1668	    AS_IF([test "`echo "${MACOSX_DEPLOYMENT_TARGET}" | awk -F '10\\.' '{print int([$]2)}'`" -lt 4 -a \
1669		"`echo "${CPPFLAGS}" | awk -F '-mmacosx-version-min=10\\.' '{print int([$]2)}'`" -lt 4], [
1670		LDFLAGS="$LDFLAGS -prebind"])
1671	    LDFLAGS="$LDFLAGS -headerpad_max_install_names"
1672	    AC_CACHE_CHECK([if ld accepts -search_paths_first flag],
1673		    tcl_cv_ld_search_paths_first, [
1674		hold_ldflags=$LDFLAGS
1675		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
1676		AC_TRY_LINK(, [int i;], tcl_cv_ld_search_paths_first=yes,
1677			tcl_cv_ld_search_paths_first=no)
1678		LDFLAGS=$hold_ldflags])
1679	    AS_IF([test $tcl_cv_ld_search_paths_first = yes], [
1680		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
1681	    ])
1682	    AS_IF([test "$tcl_cv_cc_visibility_hidden" != yes], [
1683		AC_DEFINE(MODULE_SCOPE, [__private_extern__],
1684		    [Compiler support for module scope symbols])
1685	    ])
1686	    CC_SEARCH_FLAGS=""
1687	    LD_SEARCH_FLAGS=""
1688	    LD_LIBRARY_PATH_VAR="DYLD_LIBRARY_PATH"
1689	    AC_DEFINE(MAC_OSX_TCL, 1, [Is this a Mac I see before me?])
1690	    PLAT_OBJS='${MAC_OSX_OBJS}'
1691	    PLAT_SRCS='${MAC_OSX_SRCS}'
1692	    AC_MSG_CHECKING([whether to use CoreFoundation])
1693	    AC_ARG_ENABLE(corefoundation,
1694		AC_HELP_STRING([--enable-corefoundation],
1695		    [use CoreFoundation API on MacOSX (default: on)]),
1696		[tcl_corefoundation=$enableval], [tcl_corefoundation=yes])
1697	    AC_MSG_RESULT([$tcl_corefoundation])
1698	    AS_IF([test $tcl_corefoundation = yes], [
1699		AC_CACHE_CHECK([for CoreFoundation.framework],
1700			tcl_cv_lib_corefoundation, [
1701		    hold_libs=$LIBS
1702		    AS_IF([test "$fat_32_64" = yes], [
1703			for v in CFLAGS CPPFLAGS LDFLAGS; do
1704			    # On Tiger there is no 64-bit CF, so remove 64-bit
1705			    # archs from CFLAGS et al. while testing for
1706			    # presence of CF. 64-bit CF is disabled in
1707			    # tclUnixPort.h if necessary.
1708			    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc64 / /g" -e "s/-arch x86_64 / /g"`"'
1709			done])
1710		    LIBS="$LIBS -framework CoreFoundation"
1711		    AC_TRY_LINK([#include <CoreFoundation/CoreFoundation.h>],
1712			[CFBundleRef b = CFBundleGetMainBundle();],
1713			tcl_cv_lib_corefoundation=yes,
1714			tcl_cv_lib_corefoundation=no)
1715		    AS_IF([test "$fat_32_64" = yes], [
1716			for v in CFLAGS CPPFLAGS LDFLAGS; do
1717			    eval $v'="$hold_'$v'"'
1718		        done])
1719		    LIBS=$hold_libs])
1720		AS_IF([test $tcl_cv_lib_corefoundation = yes], [
1721		    LIBS="$LIBS -framework CoreFoundation"
1722		    AC_DEFINE(HAVE_COREFOUNDATION, 1,
1723			[Do we have access to Darwin CoreFoundation.framework?])
1724		], [tcl_corefoundation=no])
1725		AS_IF([test "$fat_32_64" = yes -a $tcl_corefoundation = yes],[
1726		    AC_CACHE_CHECK([for 64-bit CoreFoundation],
1727			    tcl_cv_lib_corefoundation_64, [
1728			for v in CFLAGS CPPFLAGS LDFLAGS; do
1729			    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"'
1730			done
1731			AC_TRY_LINK([#include <CoreFoundation/CoreFoundation.h>],
1732			    [CFBundleRef b = CFBundleGetMainBundle();],
1733			    tcl_cv_lib_corefoundation_64=yes,
1734			    tcl_cv_lib_corefoundation_64=no)
1735			for v in CFLAGS CPPFLAGS LDFLAGS; do
1736			    eval $v'="$hold_'$v'"'
1737			done])
1738		    AS_IF([test $tcl_cv_lib_corefoundation_64 = no], [
1739			AC_DEFINE(NO_COREFOUNDATION_64, 1,
1740			    [Is Darwin CoreFoundation unavailable for 64-bit?])
1741                        LDFLAGS="$LDFLAGS -Wl,-no_arch_warnings"
1742		    ])
1743		])
1744	    ])
1745	    ;;
1746	NEXTSTEP-*)
1747	    SHLIB_CFLAGS=""
1748	    SHLIB_LD='${CC} -nostdlib -r'
1749	    SHLIB_LD_LIBS=""
1750	    SHLIB_SUFFIX=".so"
1751	    DL_OBJS="tclLoadNext.o"
1752	    DL_LIBS=""
1753	    CC_SEARCH_FLAGS=""
1754	    LD_SEARCH_FLAGS=""
1755	    ;;
1756	OS/390-*)
1757	    CFLAGS_OPTIMIZE=""		# Optimizer is buggy
1758	    AC_DEFINE(_OE_SOCKETS, 1,	# needed in sys/socket.h
1759		[Should OS/390 do the right thing with sockets?])
1760	    ;;
1761	OSF1-1.0|OSF1-1.1|OSF1-1.2)
1762	    # OSF/1 1.[012] from OSF, and derivatives, including Paragon OSF/1
1763	    SHLIB_CFLAGS=""
1764	    # Hack: make package name same as library name
1765	    SHLIB_LD='ld -R -export $@:'
1766	    SHLIB_LD_LIBS=""
1767	    SHLIB_SUFFIX=".so"
1768	    DL_OBJS="tclLoadOSF.o"
1769	    DL_LIBS=""
1770	    CC_SEARCH_FLAGS=""
1771	    LD_SEARCH_FLAGS=""
1772	    ;;
1773	OSF1-1.*)
1774	    # OSF/1 1.3 from OSF using ELF, and derivatives, including AD2
1775	    SHLIB_CFLAGS="-fPIC"
1776	    AS_IF([test "$SHARED_BUILD" = 1], [SHLIB_LD="ld -shared"], [
1777	        SHLIB_LD="ld -non_shared"
1778	    ])
1779	    SHLIB_LD_LIBS=""
1780	    SHLIB_SUFFIX=".so"
1781	    DL_OBJS="tclLoadDl.o"
1782	    DL_LIBS=""
1783	    CC_SEARCH_FLAGS=""
1784	    LD_SEARCH_FLAGS=""
1785	    ;;
1786	OSF1-V*)
1787	    # Digital OSF/1
1788	    SHLIB_CFLAGS=""
1789	    AS_IF([test "$SHARED_BUILD" = 1], [
1790	        SHLIB_LD='ld -shared -expect_unresolved "*"'
1791	    ], [
1792	        SHLIB_LD='ld -non_shared -expect_unresolved "*"'
1793	    ])
1794	    SHLIB_LD_LIBS='${LIBS}'
1795	    SHLIB_SUFFIX=".so"
1796	    DL_OBJS="tclLoadDl.o"
1797	    DL_LIBS=""
1798	    AS_IF([test $doRpath = yes], [
1799		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
1800		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
1801	    AS_IF([test "$GCC" = yes], [CFLAGS="$CFLAGS -mieee"], [
1802		CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee"])
1803	    # see pthread_intro(3) for pthread support on osf1, k.furukawa
1804	    AS_IF([test "${TCL_THREADS}" = 1], [
1805		CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE"
1806		CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64"
1807		LIBS=`echo $LIBS | sed s/-lpthreads//`
1808		AS_IF([test "$GCC" = yes], [
1809		    LIBS="$LIBS -lpthread -lmach -lexc"
1810		], [
1811		    CFLAGS="$CFLAGS -pthread"
1812		    LDFLAGS="$LDFLAGS -pthread"
1813		])
1814	    ])
1815	    ;;
1816	QNX-6*)
1817	    # QNX RTP
1818	    # This may work for all QNX, but it was only reported for v6.
1819	    SHLIB_CFLAGS="-fPIC"
1820	    SHLIB_LD="ld -Bshareable -x"
1821	    SHLIB_LD_LIBS=""
1822	    SHLIB_SUFFIX=".so"
1823	    DL_OBJS="tclLoadDl.o"
1824	    # dlopen is in -lc on QNX
1825	    DL_LIBS=""
1826	    CC_SEARCH_FLAGS=""
1827	    LD_SEARCH_FLAGS=""
1828	    ;;
1829	SCO_SV-3.2*)
1830	    # Note, dlopen is available only on SCO 3.2.5 and greater. However,
1831	    # this test works, since "uname -s" was non-standard in 3.2.4 and
1832	    # below.
1833	    AS_IF([test "$GCC" = yes], [
1834	    	SHLIB_CFLAGS="-fPIC -melf"
1835	    	LDFLAGS="$LDFLAGS -melf -Wl,-Bexport"
1836	    ], [
1837	    	SHLIB_CFLAGS="-Kpic -belf"
1838	    	LDFLAGS="$LDFLAGS -belf -Wl,-Bexport"
1839	    ])
1840	    SHLIB_LD="ld -G"
1841	    SHLIB_LD_LIBS=""
1842	    SHLIB_SUFFIX=".so"
1843	    DL_OBJS="tclLoadDl.o"
1844	    DL_LIBS=""
1845	    CC_SEARCH_FLAGS=""
1846	    LD_SEARCH_FLAGS=""
1847	    ;;
1848	SINIX*5.4*)
1849	    SHLIB_CFLAGS="-K PIC"
1850	    SHLIB_LD='${CC} -G'
1851	    SHLIB_LD_LIBS=""
1852	    SHLIB_SUFFIX=".so"
1853	    DL_OBJS="tclLoadDl.o"
1854	    DL_LIBS="-ldl"
1855	    CC_SEARCH_FLAGS=""
1856	    LD_SEARCH_FLAGS=""
1857	    ;;
1858	SunOS-4*)
1859	    SHLIB_CFLAGS="-PIC"
1860	    SHLIB_LD="ld"
1861	    SHLIB_LD_LIBS=""
1862	    SHLIB_SUFFIX=".so"
1863	    DL_OBJS="tclLoadDl.o"
1864	    DL_LIBS="-ldl"
1865	    CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
1866	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1867
1868	    # SunOS can't handle version numbers with dots in them in library
1869	    # specs, like -ltcl7.5, so use -ltcl75 instead.  Also, it
1870	    # requires an extra version number at the end of .so file names.
1871	    # So, the library has to have a name like libtcl75.so.1.0
1872
1873	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.${SHLIB_VERSION}'
1874	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1875	    TCL_LIB_VERSIONS_OK=nodots
1876	    ;;
1877	SunOS-5.[[0-6]])
1878	    # Careful to not let 5.10+ fall into this case
1879
1880	    # Note: If _REENTRANT isn't defined, then Solaris
1881	    # won't define thread-safe library routines.
1882
1883	    AC_DEFINE(_REENTRANT, 1, [Do we want the reentrant OS API?])
1884	    AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1,
1885		[Do we really want to follow the standard? Yes we do!])
1886
1887	    SHLIB_CFLAGS="-KPIC"
1888
1889	    # Note: need the LIBS below, otherwise Tk won't find Tcl's
1890	    # symbols when dynamically loaded into tclsh.
1891
1892	    SHLIB_LD_LIBS='${LIBS}'
1893	    SHLIB_SUFFIX=".so"
1894	    DL_OBJS="tclLoadDl.o"
1895	    DL_LIBS="-ldl"
1896	    AS_IF([test "$GCC" = yes], [
1897		SHLIB_LD='${CC} -shared'
1898		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
1899		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1900	    ], [
1901		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
1902		CC_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}'
1903		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1904	    ])
1905	    ;;
1906	SunOS-5*)
1907	    # Note: If _REENTRANT isn't defined, then Solaris
1908	    # won't define thread-safe library routines.
1909
1910	    AC_DEFINE(_REENTRANT, 1, [Do we want the reentrant OS API?])
1911	    AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1,
1912		[Do we really want to follow the standard? Yes we do!])
1913
1914	    SHLIB_CFLAGS="-KPIC"
1915
1916	    # Check to enable 64-bit flags for compiler/linker
1917	    AS_IF([test "$do64bit" = yes], [
1918		arch=`isainfo`
1919		AS_IF([test "$arch" = "sparcv9 sparc"], [
1920		    AS_IF([test "$GCC" = yes], [
1921			AS_IF([test "`${CC} -dumpversion | awk -F. '{print [$]1}'`" -lt 3], [
1922			    AC_MSG_WARN([64bit mode not supported with GCC < 3.2 on $system])
1923			], [
1924			    do64bit_ok=yes
1925			    CFLAGS="$CFLAGS -m64 -mcpu=v9"
1926			    LDFLAGS="$LDFLAGS -m64 -mcpu=v9"
1927			    SHLIB_CFLAGS="-fPIC"
1928			])
1929		    ], [
1930			do64bit_ok=yes
1931			AS_IF([test "$do64bitVIS" = yes], [
1932			    CFLAGS="$CFLAGS -xarch=v9a"
1933			    LDFLAGS_ARCH="-xarch=v9a"
1934			], [
1935			    CFLAGS="$CFLAGS -xarch=v9"
1936			    LDFLAGS_ARCH="-xarch=v9"
1937			])
1938			# Solaris 64 uses this as well
1939			#LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH_64"
1940		    ])
1941		], [AS_IF([test "$arch" = "amd64 i386"], [
1942		    AS_IF([test "$GCC" = yes], [
1943			case $system in
1944			    SunOS-5.1[[1-9]]*|SunOS-5.[[2-9]][[0-9]]*)
1945				do64bit_ok=yes
1946				CFLAGS="$CFLAGS -m64"
1947				LDFLAGS="$LDFLAGS -m64";;
1948			    *)
1949				AC_MSG_WARN([64bit mode not supported with GCC on $system]);;
1950			esac
1951		    ], [
1952			do64bit_ok=yes
1953			case $system in
1954			    SunOS-5.1[[1-9]]*|SunOS-5.[[2-9]][[0-9]]*)
1955				CFLAGS="$CFLAGS -m64"
1956				LDFLAGS="$LDFLAGS -m64";;
1957			    *)
1958				CFLAGS="$CFLAGS -xarch=amd64"
1959				LDFLAGS="$LDFLAGS -xarch=amd64";;
1960			esac
1961		    ])
1962		], [AC_MSG_WARN([64bit mode not supported for $arch])])])
1963	    ])
1964
1965	    #--------------------------------------------------------------------
1966	    # On Solaris 5.x i386 with the sunpro compiler we need to link
1967	    # with sunmath to get floating point rounding control
1968	    #--------------------------------------------------------------------
1969	    AS_IF([test "$GCC" = yes],[use_sunmath=no],[
1970		arch=`isainfo`
1971		AC_MSG_CHECKING([whether to use -lsunmath for fp rounding control])
1972		AS_IF([test "$arch" = "amd64 i386"], [
1973			AC_MSG_RESULT([yes])
1974			MATH_LIBS="-lsunmath $MATH_LIBS"
1975			AC_CHECK_HEADER(sunmath.h)
1976			use_sunmath=yes
1977			], [
1978			AC_MSG_RESULT([no])
1979			use_sunmath=no
1980		])
1981	    ])
1982
1983	    # Note: need the LIBS below, otherwise Tk won't find Tcl's
1984	    # symbols when dynamically loaded into tclsh.
1985
1986	    SHLIB_LD_LIBS='${LIBS}'
1987	    SHLIB_SUFFIX=".so"
1988	    DL_OBJS="tclLoadDl.o"
1989	    DL_LIBS="-ldl"
1990	    AS_IF([test "$GCC" = yes], [
1991		SHLIB_LD='${CC} -shared'
1992		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
1993		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1994		AS_IF([test "$do64bit_ok" = yes], [
1995		    AS_IF([test "$arch" = "sparcv9 sparc"], [
1996			# We need to specify -static-libgcc or we need to
1997			# add the path to the sparv9 libgcc.
1998			SHLIB_LD="$SHLIB_LD -m64 -mcpu=v9 -static-libgcc"
1999			# for finding sparcv9 libgcc, get the regular libgcc
2000			# path, remove so name and append 'sparcv9'
2001			#v9gcclibdir="`gcc -print-file-name=libgcc_s.so` | ..."
2002			#CC_SEARCH_FLAGS="${CC_SEARCH_FLAGS},-R,$v9gcclibdir"
2003		    ], [AS_IF([test "$arch" = "amd64 i386"], [
2004			SHLIB_LD="$SHLIB_LD -m64 -static-libgcc"
2005		    ])])
2006		])
2007	    ], [
2008		AS_IF([test "$use_sunmath" = yes], [textmode=textoff],[textmode=text])
2009		case $system in
2010		    SunOS-5.[[1-9]][[0-9]]*)
2011			SHLIB_LD="\${CC} -G -z $textmode \${LDFLAGS}";;
2012		    *)
2013			SHLIB_LD="/usr/ccs/bin/ld -G -z $textmode";;
2014		esac
2015		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
2016		LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}'
2017	    ])
2018	    ;;
2019	UNIX_SV* | UnixWare-5*)
2020	    SHLIB_CFLAGS="-KPIC"
2021	    SHLIB_LD='${CC} -G'
2022	    SHLIB_LD_LIBS=""
2023	    SHLIB_SUFFIX=".so"
2024	    DL_OBJS="tclLoadDl.o"
2025	    DL_LIBS="-ldl"
2026	    # Some UNIX_SV* systems (unixware 1.1.2 for example) have linkers
2027	    # that don't grok the -Bexport option.  Test that it does.
2028	    AC_CACHE_CHECK([for ld accepts -Bexport flag], tcl_cv_ld_Bexport, [
2029		hold_ldflags=$LDFLAGS
2030		LDFLAGS="$LDFLAGS -Wl,-Bexport"
2031		AC_TRY_LINK(, [int i;], tcl_cv_ld_Bexport=yes, tcl_cv_ld_Bexport=no)
2032	        LDFLAGS=$hold_ldflags])
2033	    AS_IF([test $tcl_cv_ld_Bexport = yes], [
2034		LDFLAGS="$LDFLAGS -Wl,-Bexport"
2035	    ])
2036	    CC_SEARCH_FLAGS=""
2037	    LD_SEARCH_FLAGS=""
2038	    ;;
2039    esac
2040
2041    AS_IF([test "$do64bit" = yes -a "$do64bit_ok" = no], [
2042	AC_MSG_WARN([64bit support being disabled -- don't know magic for this platform])
2043    ])
2044
2045    AS_IF([test "$do64bit" = yes -a "$do64bit_ok" = yes], [
2046	AC_DEFINE(TCL_CFG_DO64BIT, 1, [Is this a 64-bit build?])
2047    ])
2048
2049dnl # Add any CPPFLAGS set in the environment to our CFLAGS, but delay doing so
2050dnl # until the end of configure, as configure's compile and link tests use
2051dnl # both CPPFLAGS and CFLAGS (unlike our compile and link) but configure's
2052dnl # preprocessing tests use only CPPFLAGS.
2053    AC_CONFIG_COMMANDS_PRE([CFLAGS="${CFLAGS} ${CPPFLAGS}"; CPPFLAGS=""])
2054
2055    # Step 4: disable dynamic loading if requested via a command-line switch.
2056
2057    AC_ARG_ENABLE(load,
2058	AC_HELP_STRING([--enable-load],
2059	    [allow dynamic loading and "load" command (default: on)]),
2060	[tcl_ok=$enableval], [tcl_ok=yes])
2061    AS_IF([test "$tcl_ok" = no], [DL_OBJS=""])
2062
2063    AS_IF([test "x$DL_OBJS" != x], [BUILD_DLTEST="\$(DLTEST_TARGETS)"], [
2064	AC_MSG_WARN([Can't figure out how to do dynamic loading or shared libraries on this system.])
2065	SHLIB_CFLAGS=""
2066	SHLIB_LD=""
2067	SHLIB_SUFFIX=""
2068	DL_OBJS="tclLoadNone.o"
2069	DL_LIBS=""
2070	LDFLAGS="$LDFLAGS_ORIG"
2071	CC_SEARCH_FLAGS=""
2072	LD_SEARCH_FLAGS=""
2073	BUILD_DLTEST=""
2074    ])
2075    LDFLAGS="$LDFLAGS $LDFLAGS_ARCH"
2076
2077    # If we're running gcc, then change the C flags for compiling shared
2078    # libraries to the right flags for gcc, instead of those for the
2079    # standard manufacturer compiler.
2080
2081    AS_IF([test "$DL_OBJS" != "tclLoadNone.o" -a "$GCC" = yes], [
2082	case $system in
2083	    AIX-*) ;;
2084	    BSD/OS*) ;;
2085	    CYGWIN_*) ;;
2086	    IRIX*) ;;
2087	    NetBSD-*|FreeBSD-*|OpenBSD-*) ;;
2088	    Darwin-*) ;;
2089	    SCO_SV-3.2*) ;;
2090	    *) SHLIB_CFLAGS="-fPIC" ;;
2091	esac])
2092
2093    AS_IF([test "$SHARED_LIB_SUFFIX" = ""], [
2094	SHARED_LIB_SUFFIX='${VERSION}${SHLIB_SUFFIX}'])
2095    AS_IF([test "$UNSHARED_LIB_SUFFIX" = ""], [
2096	UNSHARED_LIB_SUFFIX='${VERSION}.a'])
2097
2098    AS_IF([test "${SHARED_BUILD}" = 1 -a "${SHLIB_SUFFIX}" != ""], [
2099        LIB_SUFFIX=${SHARED_LIB_SUFFIX}
2100        MAKE_LIB='${SHLIB_LD} -o [$]@ ${OBJS} ${SHLIB_LD_LIBS} ${TCL_SHLIB_LD_EXTRAS} ${TK_SHLIB_LD_EXTRAS} ${LD_SEARCH_FLAGS}'
2101        INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)"/$(LIB_FILE)'
2102    ], [
2103        LIB_SUFFIX=${UNSHARED_LIB_SUFFIX}
2104
2105        AS_IF([test "$RANLIB" = ""], [
2106            MAKE_LIB='$(STLIB_LD) [$]@ ${OBJS}'
2107            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)"/$(LIB_FILE)'
2108        ], [
2109            MAKE_LIB='${STLIB_LD} [$]@ ${OBJS} ; ${RANLIB} [$]@'
2110            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)"/$(LIB_FILE) ; (cd "$(LIB_INSTALL_DIR)" ; $(RANLIB) $(LIB_FILE))'
2111        ])
2112    ])
2113
2114    # Stub lib does not depend on shared/static configuration
2115    AS_IF([test "$RANLIB" = ""], [
2116        MAKE_STUB_LIB='${STLIB_LD} [$]@ ${STUB_LIB_OBJS}'
2117        INSTALL_STUB_LIB='$(INSTALL_LIBRARY) $(STUB_LIB_FILE) "$(LIB_INSTALL_DIR)/$(STUB_LIB_FILE)"'
2118    ], [
2119        MAKE_STUB_LIB='${STLIB_LD} [$]@ ${STUB_LIB_OBJS} ; ${RANLIB} [$]@'
2120        INSTALL_STUB_LIB='$(INSTALL_LIBRARY) $(STUB_LIB_FILE) "$(LIB_INSTALL_DIR)"/$(STUB_LIB_FILE) ; (cd "$(LIB_INSTALL_DIR)" ; $(RANLIB) $(STUB_LIB_FILE))'
2121    ])
2122
2123    # Define TCL_LIBS now that we know what DL_LIBS is.
2124    # The trick here is that we don't want to change the value of TCL_LIBS if
2125    # it is already set when tclConfig.sh had been loaded by Tk.
2126    AS_IF([test "x${TCL_LIBS}" = x], [
2127        TCL_LIBS="${DL_LIBS} ${LIBS} ${MATH_LIBS}"])
2128    AC_SUBST(TCL_LIBS)
2129
2130    # FIXME: This subst was left in only because the TCL_DL_LIBS
2131    # entry in tclConfig.sh uses it. It is not clear why someone
2132    # would use TCL_DL_LIBS instead of TCL_LIBS.
2133    AC_SUBST(DL_LIBS)
2134
2135    AC_SUBST(DL_OBJS)
2136    AC_SUBST(PLAT_OBJS)
2137    AC_SUBST(PLAT_SRCS)
2138    AC_SUBST(LDAIX_SRC)
2139    AC_SUBST(CFLAGS)
2140    AC_SUBST(CFLAGS_DEBUG)
2141    AC_SUBST(CFLAGS_OPTIMIZE)
2142    AC_SUBST(CFLAGS_WARNING)
2143
2144    AC_SUBST(LDFLAGS)
2145    AC_SUBST(LDFLAGS_DEBUG)
2146    AC_SUBST(LDFLAGS_OPTIMIZE)
2147    AC_SUBST(CC_SEARCH_FLAGS)
2148    AC_SUBST(LD_SEARCH_FLAGS)
2149
2150    AC_SUBST(STLIB_LD)
2151    AC_SUBST(SHLIB_LD)
2152    AC_SUBST(TCL_SHLIB_LD_EXTRAS)
2153    AC_SUBST(TK_SHLIB_LD_EXTRAS)
2154    AC_SUBST(SHLIB_LD_LIBS)
2155    AC_SUBST(SHLIB_CFLAGS)
2156    AC_SUBST(SHLIB_SUFFIX)
2157    AC_DEFINE_UNQUOTED(TCL_SHLIB_EXT,"${SHLIB_SUFFIX}",
2158	[What is the default extension for shared libraries?])
2159
2160    AC_SUBST(MAKE_LIB)
2161    AC_SUBST(MAKE_STUB_LIB)
2162    AC_SUBST(INSTALL_LIB)
2163    AC_SUBST(INSTALL_STUB_LIB)
2164    AC_SUBST(RANLIB)
2165])
2166
2167#--------------------------------------------------------------------
2168# SC_SERIAL_PORT
2169#
2170#	Determine which interface to use to talk to the serial port.
2171#	Note that #include lines must begin in leftmost column for
2172#	some compilers to recognize them as preprocessor directives,
2173#	and some build environments have stdin not pointing at a
2174#	pseudo-terminal (usually /dev/null instead.)
2175#
2176# Arguments:
2177#	none
2178#
2179# Results:
2180#
2181#	Defines only one of the following vars:
2182#		HAVE_SYS_MODEM_H
2183#		USE_TERMIOS
2184#		USE_TERMIO
2185#		USE_SGTTY
2186#
2187#--------------------------------------------------------------------
2188
2189AC_DEFUN([SC_SERIAL_PORT], [
2190    AC_CHECK_HEADERS(sys/modem.h)
2191    AC_CACHE_CHECK([termios vs. termio vs. sgtty], tcl_cv_api_serial, [
2192    AC_TRY_RUN([
2193#include <termios.h>
2194
2195int main() {
2196    struct termios t;
2197    if (tcgetattr(0, &t) == 0) {
2198	cfsetospeed(&t, 0);
2199	t.c_cflag |= PARENB | PARODD | CSIZE | CSTOPB;
2200	return 0;
2201    }
2202    return 1;
2203}], tcl_cv_api_serial=termios, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2204    if test $tcl_cv_api_serial = no ; then
2205	AC_TRY_RUN([
2206#include <termio.h>
2207
2208int main() {
2209    struct termio t;
2210    if (ioctl(0, TCGETA, &t) == 0) {
2211	t.c_cflag |= CBAUD | PARENB | PARODD | CSIZE | CSTOPB;
2212	return 0;
2213    }
2214    return 1;
2215}], tcl_cv_api_serial=termio, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2216    fi
2217    if test $tcl_cv_api_serial = no ; then
2218	AC_TRY_RUN([
2219#include <sgtty.h>
2220
2221int main() {
2222    struct sgttyb t;
2223    if (ioctl(0, TIOCGETP, &t) == 0) {
2224	t.sg_ospeed = 0;
2225	t.sg_flags |= ODDP | EVENP | RAW;
2226	return 0;
2227    }
2228    return 1;
2229}], tcl_cv_api_serial=sgtty, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2230    fi
2231    if test $tcl_cv_api_serial = no ; then
2232	AC_TRY_RUN([
2233#include <termios.h>
2234#include <errno.h>
2235
2236int main() {
2237    struct termios t;
2238    if (tcgetattr(0, &t) == 0
2239	|| errno == ENOTTY || errno == ENXIO || errno == EINVAL) {
2240	cfsetospeed(&t, 0);
2241	t.c_cflag |= PARENB | PARODD | CSIZE | CSTOPB;
2242	return 0;
2243    }
2244    return 1;
2245}], tcl_cv_api_serial=termios, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2246    fi
2247    if test $tcl_cv_api_serial = no; then
2248	AC_TRY_RUN([
2249#include <termio.h>
2250#include <errno.h>
2251
2252int main() {
2253    struct termio t;
2254    if (ioctl(0, TCGETA, &t) == 0
2255	|| errno == ENOTTY || errno == ENXIO || errno == EINVAL) {
2256	t.c_cflag |= CBAUD | PARENB | PARODD | CSIZE | CSTOPB;
2257	return 0;
2258    }
2259    return 1;
2260    }], tcl_cv_api_serial=termio, tcl_cv_api_serial=no, tcl_cv_api_serial=no)
2261    fi
2262    if test $tcl_cv_api_serial = no; then
2263	AC_TRY_RUN([
2264#include <sgtty.h>
2265#include <errno.h>
2266
2267int main() {
2268    struct sgttyb t;
2269    if (ioctl(0, TIOCGETP, &t) == 0
2270	|| errno == ENOTTY || errno == ENXIO || errno == EINVAL) {
2271	t.sg_ospeed = 0;
2272	t.sg_flags |= ODDP | EVENP | RAW;
2273	return 0;
2274    }
2275    return 1;
2276}], tcl_cv_api_serial=sgtty, tcl_cv_api_serial=none, tcl_cv_api_serial=none)
2277    fi])
2278    case $tcl_cv_api_serial in
2279	termios) AC_DEFINE(USE_TERMIOS, 1, [Use the termios API for serial lines]);;
2280	termio)  AC_DEFINE(USE_TERMIO, 1, [Use the termio API for serial lines]);;
2281	sgtty)   AC_DEFINE(USE_SGTTY, 1, [Use the sgtty API for serial lines]);;
2282    esac
2283])
2284
2285#--------------------------------------------------------------------
2286# SC_MISSING_POSIX_HEADERS
2287#
2288#	Supply substitutes for missing POSIX header files.  Special
2289#	notes:
2290#	    - stdlib.h doesn't define strtol, strtoul, or
2291#	      strtod insome versions of SunOS
2292#	    - some versions of string.h don't declare procedures such
2293#	      as strstr
2294#
2295# Arguments:
2296#	none
2297#
2298# Results:
2299#
2300#	Defines some of the following vars:
2301#		NO_DIRENT_H
2302#		NO_VALUES_H
2303#		HAVE_LIMITS_H or NO_LIMITS_H
2304#		NO_STDLIB_H
2305#		NO_STRING_H
2306#		NO_SYS_WAIT_H
2307#		NO_DLFCN_H
2308#		HAVE_SYS_PARAM_H
2309#
2310#		HAVE_STRING_H ?
2311#
2312#--------------------------------------------------------------------
2313
2314AC_DEFUN([SC_MISSING_POSIX_HEADERS], [
2315    AC_CACHE_CHECK([dirent.h], tcl_cv_dirent_h, [
2316    AC_TRY_LINK([#include <sys/types.h>
2317#include <dirent.h>], [
2318#ifndef _POSIX_SOURCE
2319#   ifdef __Lynx__
2320	/*
2321	 * Generate compilation error to make the test fail:  Lynx headers
2322	 * are only valid if really in the POSIX environment.
2323	 */
2324
2325	missing_procedure();
2326#   endif
2327#endif
2328DIR *d;
2329struct dirent *entryPtr;
2330char *p;
2331d = opendir("foobar");
2332entryPtr = readdir(d);
2333p = entryPtr->d_name;
2334closedir(d);
2335], tcl_cv_dirent_h=yes, tcl_cv_dirent_h=no)])
2336
2337    if test $tcl_cv_dirent_h = no; then
2338	AC_DEFINE(NO_DIRENT_H, 1, [Do we have <dirent.h>?])
2339    fi
2340
2341    AC_CHECK_HEADER(float.h, , [AC_DEFINE(NO_FLOAT_H, 1, [Do we have <float.h>?])])
2342    AC_CHECK_HEADER(values.h, , [AC_DEFINE(NO_VALUES_H, 1, [Do we have <values.h>?])])
2343    AC_CHECK_HEADER(limits.h,
2344	[AC_DEFINE(HAVE_LIMITS_H, 1, [Do we have <limits.h>?])],
2345	[AC_DEFINE(NO_LIMITS_H, 1, [Do we have <limits.h>?])])
2346    AC_CHECK_HEADER(stdlib.h, tcl_ok=1, tcl_ok=0)
2347    AC_EGREP_HEADER(strtol, stdlib.h, , tcl_ok=0)
2348    AC_EGREP_HEADER(strtoul, stdlib.h, , tcl_ok=0)
2349    AC_EGREP_HEADER(strtod, stdlib.h, , tcl_ok=0)
2350    if test $tcl_ok = 0; then
2351	AC_DEFINE(NO_STDLIB_H, 1, [Do we have <stdlib.h>?])
2352    fi
2353    AC_CHECK_HEADER(string.h, tcl_ok=1, tcl_ok=0)
2354    AC_EGREP_HEADER(strstr, string.h, , tcl_ok=0)
2355    AC_EGREP_HEADER(strerror, string.h, , tcl_ok=0)
2356
2357    # See also memmove check below for a place where NO_STRING_H can be
2358    # set and why.
2359
2360    if test $tcl_ok = 0; then
2361	AC_DEFINE(NO_STRING_H, 1, [Do we have <string.h>?])
2362    fi
2363
2364    AC_CHECK_HEADER(sys/wait.h, , [AC_DEFINE(NO_SYS_WAIT_H, 1, [Do we have <sys/wait.h>?])])
2365    AC_CHECK_HEADER(dlfcn.h, , [AC_DEFINE(NO_DLFCN_H, 1, [Do we have <dlfcn.h>?])])
2366
2367    # OS/390 lacks sys/param.h (and doesn't need it, by chance).
2368    AC_HAVE_HEADERS(sys/param.h)
2369])
2370
2371#--------------------------------------------------------------------
2372# SC_PATH_X
2373#
2374#	Locate the X11 header files and the X11 library archive.  Try
2375#	the ac_path_x macro first, but if it doesn't find the X stuff
2376#	(e.g. because there's no xmkmf program) then check through
2377#	a list of possible directories.  Under some conditions the
2378#	autoconf macro will return an include directory that contains
2379#	no include files, so double-check its result just to be safe.
2380#
2381# Arguments:
2382#	none
2383#
2384# Results:
2385#
2386#	Sets the the following vars:
2387#		XINCLUDES
2388#		XLIBSW
2389#
2390#--------------------------------------------------------------------
2391
2392AC_DEFUN([SC_PATH_X], [
2393    AC_PATH_X
2394    not_really_there=""
2395    if test "$no_x" = ""; then
2396	if test "$x_includes" = ""; then
2397	    AC_TRY_CPP([#include <X11/XIntrinsic.h>], , not_really_there="yes")
2398	else
2399	    if test ! -r $x_includes/X11/Intrinsic.h; then
2400		not_really_there="yes"
2401	    fi
2402	fi
2403    fi
2404    if test "$no_x" = "yes" -o "$not_really_there" = "yes"; then
2405	AC_MSG_CHECKING([for X11 header files])
2406	found_xincludes="no"
2407	AC_TRY_CPP([#include <X11/Intrinsic.h>], found_xincludes="yes", found_xincludes="no")
2408	if test "$found_xincludes" = "no"; then
2409	    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"
2410	    for i in $dirs ; do
2411		if test -r $i/X11/Intrinsic.h; then
2412		    AC_MSG_RESULT([$i])
2413		    XINCLUDES=" -I$i"
2414		    found_xincludes="yes"
2415		    break
2416		fi
2417	    done
2418	fi
2419    else
2420	if test "$x_includes" != ""; then
2421	    XINCLUDES="-I$x_includes"
2422	    found_xincludes="yes"
2423	fi
2424    fi
2425    if test "$found_xincludes" = "no"; then
2426	AC_MSG_RESULT([couldn't find any!])
2427    fi
2428
2429    if test "$no_x" = yes; then
2430	AC_MSG_CHECKING([for X11 libraries])
2431	XLIBSW=nope
2432	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"
2433	for i in $dirs ; do
2434	    if test -r $i/libX11.a -o -r $i/libX11.so -o -r $i/libX11.sl -o -r $i/libX11.dylib; then
2435		AC_MSG_RESULT([$i])
2436		XLIBSW="-L$i -lX11"
2437		x_libraries="$i"
2438		break
2439	    fi
2440	done
2441    else
2442	if test "$x_libraries" = ""; then
2443	    XLIBSW=-lX11
2444	else
2445	    XLIBSW="-L$x_libraries -lX11"
2446	fi
2447    fi
2448    if test "$XLIBSW" = nope ; then
2449	AC_CHECK_LIB(Xwindow, XCreateWindow, XLIBSW=-lXwindow)
2450    fi
2451    if test "$XLIBSW" = nope ; then
2452	AC_MSG_RESULT([could not find any!  Using -lX11.])
2453	XLIBSW=-lX11
2454    fi
2455])
2456
2457#--------------------------------------------------------------------
2458# SC_BLOCKING_STYLE
2459#
2460#	The statements below check for systems where POSIX-style
2461#	non-blocking I/O (O_NONBLOCK) doesn't work or is unimplemented.
2462#	On these systems (mostly older ones), use the old BSD-style
2463#	FIONBIO approach instead.
2464#
2465# Arguments:
2466#	none
2467#
2468# Results:
2469#
2470#	Defines some of the following vars:
2471#		HAVE_SYS_IOCTL_H
2472#		HAVE_SYS_FILIO_H
2473#		USE_FIONBIO
2474#		O_NONBLOCK
2475#
2476#--------------------------------------------------------------------
2477
2478AC_DEFUN([SC_BLOCKING_STYLE], [
2479    AC_CHECK_HEADERS(sys/ioctl.h)
2480    AC_CHECK_HEADERS(sys/filio.h)
2481    SC_CONFIG_SYSTEM
2482    AC_MSG_CHECKING([FIONBIO vs. O_NONBLOCK for nonblocking I/O])
2483    case $system in
2484	# There used to be code here to use FIONBIO under AIX.  However, it
2485	# was reported that FIONBIO doesn't work under AIX 3.2.5.  Since
2486	# using O_NONBLOCK seems fine under AIX 4.*, I removed the FIONBIO
2487	# code (JO, 5/31/97).
2488
2489	OSF*)
2490	    AC_DEFINE(USE_FIONBIO, 1, [Should we use FIONBIO?])
2491	    AC_MSG_RESULT([FIONBIO])
2492	    ;;
2493	SunOS-4*)
2494	    AC_DEFINE(USE_FIONBIO, 1, [Should we use FIONBIO?])
2495	    AC_MSG_RESULT([FIONBIO])
2496	    ;;
2497	*)
2498	    AC_MSG_RESULT([O_NONBLOCK])
2499	    ;;
2500    esac
2501])
2502
2503#--------------------------------------------------------------------
2504# SC_TIME_HANLDER
2505#
2506#	Checks how the system deals with time.h, what time structures
2507#	are used on the system, and what fields the structures have.
2508#
2509# Arguments:
2510#	none
2511#
2512# Results:
2513#
2514#	Defines some of the following vars:
2515#		USE_DELTA_FOR_TZ
2516#		HAVE_TM_GMTOFF
2517#		HAVE_TM_TZADJ
2518#		HAVE_TIMEZONE_VAR
2519#
2520#--------------------------------------------------------------------
2521
2522AC_DEFUN([SC_TIME_HANDLER], [
2523    AC_CHECK_HEADERS(sys/time.h)
2524    AC_HEADER_TIME
2525
2526    AC_CHECK_FUNCS(gmtime_r localtime_r mktime)
2527
2528    AC_CACHE_CHECK([tm_tzadj in struct tm], tcl_cv_member_tm_tzadj, [
2529	AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_tzadj;],
2530	    tcl_cv_member_tm_tzadj=yes, tcl_cv_member_tm_tzadj=no)])
2531    if test $tcl_cv_member_tm_tzadj = yes ; then
2532	AC_DEFINE(HAVE_TM_TZADJ, 1, [Should we use the tm_tzadj field of struct tm?])
2533    fi
2534
2535    AC_CACHE_CHECK([tm_gmtoff in struct tm], tcl_cv_member_tm_gmtoff, [
2536	AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_gmtoff;],
2537	    tcl_cv_member_tm_gmtoff=yes, tcl_cv_member_tm_gmtoff=no)])
2538    if test $tcl_cv_member_tm_gmtoff = yes ; then
2539	AC_DEFINE(HAVE_TM_GMTOFF, 1, [Should we use the tm_gmtoff field of struct tm?])
2540    fi
2541
2542    #
2543    # Its important to include time.h in this check, as some systems
2544    # (like convex) have timezone functions, etc.
2545    #
2546    AC_CACHE_CHECK([long timezone variable], tcl_cv_timezone_long, [
2547	AC_TRY_COMPILE([#include <time.h>],
2548	    [extern long timezone;
2549	    timezone += 1;
2550	    exit (0);],
2551	    tcl_cv_timezone_long=yes, tcl_cv_timezone_long=no)])
2552    if test $tcl_cv_timezone_long = yes ; then
2553	AC_DEFINE(HAVE_TIMEZONE_VAR, 1, [Should we use the global timezone variable?])
2554    else
2555	#
2556	# On some systems (eg IRIX 6.2), timezone is a time_t and not a long.
2557	#
2558	AC_CACHE_CHECK([time_t timezone variable], tcl_cv_timezone_time, [
2559	    AC_TRY_COMPILE([#include <time.h>],
2560		[extern time_t timezone;
2561		timezone += 1;
2562		exit (0);],
2563		tcl_cv_timezone_time=yes, tcl_cv_timezone_time=no)])
2564	if test $tcl_cv_timezone_time = yes ; then
2565	    AC_DEFINE(HAVE_TIMEZONE_VAR, 1, [Should we use the global timezone variable?])
2566	fi
2567    fi
2568])
2569
2570#--------------------------------------------------------------------
2571# SC_BUGGY_STRTOD
2572#
2573#	Under Solaris 2.4, strtod returns the wrong value for the
2574#	terminating character under some conditions.  Check for this
2575#	and if the problem exists use a substitute procedure
2576#	"fixstrtod" (provided by Tcl) that corrects the error.
2577#	Also, on Compaq's Tru64 Unix 5.0,
2578#	strtod(" ") returns 0.0 instead of a failure to convert.
2579#
2580# Arguments:
2581#	none
2582#
2583# Results:
2584#
2585#	Might defines some of the following vars:
2586#		strtod (=fixstrtod)
2587#
2588#--------------------------------------------------------------------
2589
2590AC_DEFUN([SC_BUGGY_STRTOD], [
2591    AC_CHECK_FUNC(strtod, tcl_strtod=1, tcl_strtod=0)
2592    if test "$tcl_strtod" = 1; then
2593	AC_CACHE_CHECK([for Solaris2.4/Tru64 strtod bugs], tcl_cv_strtod_buggy,[
2594	    AC_TRY_RUN([
2595		extern double strtod();
2596		int main() {
2597		    char *infString="Inf", *nanString="NaN", *spaceString=" ";
2598		    char *term;
2599		    double value;
2600		    value = strtod(infString, &term);
2601		    if ((term != infString) && (term[-1] == 0)) {
2602			exit(1);
2603		    }
2604		    value = strtod(nanString, &term);
2605		    if ((term != nanString) && (term[-1] == 0)) {
2606			exit(1);
2607		    }
2608		    value = strtod(spaceString, &term);
2609		    if (term == (spaceString+1)) {
2610			exit(1);
2611		    }
2612		    exit(0);
2613		}], tcl_cv_strtod_buggy=ok, tcl_cv_strtod_buggy=buggy,
2614		    tcl_cv_strtod_buggy=buggy)])
2615	if test "$tcl_cv_strtod_buggy" = buggy; then
2616	    AC_LIBOBJ([fixstrtod])
2617	    USE_COMPAT=1
2618	    AC_DEFINE(strtod, fixstrtod, [Do we want to use the strtod() in compat?])
2619	fi
2620    fi
2621])
2622
2623#--------------------------------------------------------------------
2624# SC_TCL_LINK_LIBS
2625#
2626#	Search for the libraries needed to link the Tcl shell.
2627#	Things like the math library (-lm) and socket stuff (-lsocket vs.
2628#	-lnsl) are dealt with here.
2629#
2630# Arguments:
2631#	None.
2632#
2633# Results:
2634#
2635#	Might append to the following vars:
2636#		LIBS
2637#		MATH_LIBS
2638#
2639#	Might define the following vars:
2640#		HAVE_NET_ERRNO_H
2641#
2642#--------------------------------------------------------------------
2643
2644AC_DEFUN([SC_TCL_LINK_LIBS], [
2645    #--------------------------------------------------------------------
2646    # On a few very rare systems, all of the libm.a stuff is
2647    # already in libc.a.  Set compiler flags accordingly.
2648    # Also, Linux requires the "ieee" library for math to work
2649    # right (and it must appear before "-lm").
2650    #--------------------------------------------------------------------
2651
2652    AC_CHECK_FUNC(sin, MATH_LIBS="", MATH_LIBS="-lm")
2653    AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"])
2654
2655    #--------------------------------------------------------------------
2656    # Interactive UNIX requires -linet instead of -lsocket, plus it
2657    # needs net/errno.h to define the socket-related error codes.
2658    #--------------------------------------------------------------------
2659
2660    AC_CHECK_LIB(inet, main, [LIBS="$LIBS -linet"])
2661    AC_CHECK_HEADER(net/errno.h, [
2662	AC_DEFINE(HAVE_NET_ERRNO_H, 1, [Do we have <net/errno.h>?])])
2663
2664    #--------------------------------------------------------------------
2665    #	Check for the existence of the -lsocket and -lnsl libraries.
2666    #	The order here is important, so that they end up in the right
2667    #	order in the command line generated by make.  Here are some
2668    #	special considerations:
2669    #	1. Use "connect" and "accept" to check for -lsocket, and
2670    #	   "gethostbyname" to check for -lnsl.
2671    #	2. Use each function name only once:  can't redo a check because
2672    #	   autoconf caches the results of the last check and won't redo it.
2673    #	3. Use -lnsl and -lsocket only if they supply procedures that
2674    #	   aren't already present in the normal libraries.  This is because
2675    #	   IRIX 5.2 has libraries, but they aren't needed and they're
2676    #	   bogus:  they goof up name resolution if used.
2677    #	4. On some SVR4 systems, can't use -lsocket without -lnsl too.
2678    #	   To get around this problem, check for both libraries together
2679    #	   if -lsocket doesn't work by itself.
2680    #--------------------------------------------------------------------
2681
2682    tcl_checkBoth=0
2683    AC_CHECK_FUNC(connect, tcl_checkSocket=0, tcl_checkSocket=1)
2684    if test "$tcl_checkSocket" = 1; then
2685	AC_CHECK_FUNC(setsockopt, , [AC_CHECK_LIB(socket, setsockopt,
2686	    LIBS="$LIBS -lsocket", tcl_checkBoth=1)])
2687    fi
2688    if test "$tcl_checkBoth" = 1; then
2689	tk_oldLibs=$LIBS
2690	LIBS="$LIBS -lsocket -lnsl"
2691	AC_CHECK_FUNC(accept, tcl_checkNsl=0, [LIBS=$tk_oldLibs])
2692    fi
2693    AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(nsl, gethostbyname,
2694	    [LIBS="$LIBS -lnsl"])])
2695])
2696
2697#--------------------------------------------------------------------
2698# SC_TCL_EARLY_FLAGS
2699#
2700#	Check for what flags are needed to be passed so the correct OS
2701#	features are available.
2702#
2703# Arguments:
2704#	None
2705#
2706# Results:
2707#
2708#	Might define the following vars:
2709#		_ISOC99_SOURCE
2710#		_LARGEFILE64_SOURCE
2711#		_LARGEFILE_SOURCE64
2712#
2713#--------------------------------------------------------------------
2714
2715AC_DEFUN([SC_TCL_EARLY_FLAG],[
2716    AC_CACHE_VAL([tcl_cv_flag_]translit($1,[A-Z],[a-z]),
2717	AC_TRY_COMPILE([$2], $3, [tcl_cv_flag_]translit($1,[A-Z],[a-z])=no,
2718	    AC_TRY_COMPILE([[#define ]$1[ 1
2719]$2], $3,
2720		[tcl_cv_flag_]translit($1,[A-Z],[a-z])=yes,
2721		[tcl_cv_flag_]translit($1,[A-Z],[a-z])=no)))
2722    if test ["x${tcl_cv_flag_]translit($1,[A-Z],[a-z])[}" = "xyes"] ; then
2723	AC_DEFINE($1, 1, [Add the ]$1[ flag when building])
2724	tcl_flags="$tcl_flags $1"
2725    fi
2726])
2727
2728AC_DEFUN([SC_TCL_EARLY_FLAGS],[
2729    AC_MSG_CHECKING([for required early compiler flags])
2730    tcl_flags=""
2731    SC_TCL_EARLY_FLAG(_ISOC99_SOURCE,[#include <stdlib.h>],
2732	[char *p = (char *)strtoll; char *q = (char *)strtoull;])
2733    SC_TCL_EARLY_FLAG(_LARGEFILE64_SOURCE,[#include <sys/stat.h>],
2734	[struct stat64 buf; int i = stat64("/", &buf);])
2735    SC_TCL_EARLY_FLAG(_LARGEFILE_SOURCE64,[#include <sys/stat.h>],
2736	[char *p = (char *)open64;])
2737    if test "x${tcl_flags}" = "x" ; then
2738	AC_MSG_RESULT([none])
2739    else
2740	AC_MSG_RESULT([${tcl_flags}])
2741    fi
2742])
2743
2744#--------------------------------------------------------------------
2745# SC_TCL_64BIT_FLAGS
2746#
2747#	Check for what is defined in the way of 64-bit features.
2748#
2749# Arguments:
2750#	None
2751#
2752# Results:
2753#
2754#	Might define the following vars:
2755#		TCL_WIDE_INT_IS_LONG
2756#		TCL_WIDE_INT_TYPE
2757#		HAVE_STRUCT_DIRENT64
2758#		HAVE_STRUCT_STAT64
2759#		HAVE_TYPE_OFF64_T
2760#
2761#--------------------------------------------------------------------
2762
2763AC_DEFUN([SC_TCL_64BIT_FLAGS], [
2764    AC_MSG_CHECKING([for 64-bit integer type])
2765    AC_CACHE_VAL(tcl_cv_type_64bit,[
2766	tcl_cv_type_64bit=none
2767	# See if the compiler knows natively about __int64
2768	AC_TRY_COMPILE(,[__int64 value = (__int64) 0;],
2769	    tcl_type_64bit=__int64, tcl_type_64bit="long long")
2770	# See if we should use long anyway  Note that we substitute in the
2771	# type that is our current guess for a 64-bit type inside this check
2772	# program, so it should be modified only carefully...
2773        AC_TRY_COMPILE(,[switch (0) {
2774            case 1: case (sizeof(]${tcl_type_64bit}[)==sizeof(long)): ;
2775        }],tcl_cv_type_64bit=${tcl_type_64bit})])
2776    if test "${tcl_cv_type_64bit}" = none ; then
2777	AC_DEFINE(TCL_WIDE_INT_IS_LONG, 1, [Are wide integers to be implemented with C 'long's?])
2778	AC_MSG_RESULT([using long])
2779    else
2780	AC_DEFINE_UNQUOTED(TCL_WIDE_INT_TYPE,${tcl_cv_type_64bit},
2781	    [What type should be used to define wide integers?])
2782	AC_MSG_RESULT([${tcl_cv_type_64bit}])
2783
2784	# Now check for auxiliary declarations
2785	AC_CACHE_CHECK([for struct dirent64], tcl_cv_struct_dirent64,[
2786	    AC_TRY_COMPILE([#include <sys/types.h>
2787#include <sys/dirent.h>],[struct dirent64 p;],
2788		tcl_cv_struct_dirent64=yes,tcl_cv_struct_dirent64=no)])
2789	if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then
2790	    AC_DEFINE(HAVE_STRUCT_DIRENT64, 1, [Is 'struct dirent64' in <sys/types.h>?])
2791	fi
2792
2793	AC_CACHE_CHECK([for struct stat64], tcl_cv_struct_stat64,[
2794	    AC_TRY_COMPILE([#include <sys/stat.h>],[struct stat64 p;
2795],
2796		tcl_cv_struct_stat64=yes,tcl_cv_struct_stat64=no)])
2797	if test "x${tcl_cv_struct_stat64}" = "xyes" ; then
2798	    AC_DEFINE(HAVE_STRUCT_STAT64, 1, [Is 'struct stat64' in <sys/stat.h>?])
2799	fi
2800
2801	AC_CHECK_FUNCS(open64 lseek64)
2802	AC_MSG_CHECKING([for off64_t])
2803	AC_CACHE_VAL(tcl_cv_type_off64_t,[
2804	    AC_TRY_COMPILE([#include <sys/types.h>],[off64_t offset;
2805],
2806		tcl_cv_type_off64_t=yes,tcl_cv_type_off64_t=no)])
2807	dnl Define HAVE_TYPE_OFF64_T only when the off64_t type and the
2808	dnl functions lseek64 and open64 are defined.
2809	if test "x${tcl_cv_type_off64_t}" = "xyes" && \
2810	        test "x${ac_cv_func_lseek64}" = "xyes" && \
2811	        test "x${ac_cv_func_open64}" = "xyes" ; then
2812	    AC_DEFINE(HAVE_TYPE_OFF64_T, 1, [Is off64_t in <sys/types.h>?])
2813	    AC_MSG_RESULT([yes])
2814	else
2815	    AC_MSG_RESULT([no])
2816	fi
2817    fi
2818])
2819
2820#--------------------------------------------------------------------
2821# SC_TCL_CFG_ENCODING	TIP #59
2822#
2823#	Declare the encoding to use for embedded configuration information.
2824#
2825# Arguments:
2826#	None.
2827#
2828# Results:
2829#	Might append to the following vars:
2830#		DEFS	(implicit)
2831#
2832#	Will define the following vars:
2833#		TCL_CFGVAL_ENCODING
2834#
2835#--------------------------------------------------------------------
2836
2837AC_DEFUN([SC_TCL_CFG_ENCODING], [
2838    AC_ARG_WITH(encoding,
2839	AC_HELP_STRING([--with-encoding],
2840	    [encoding for configuration values (default: iso8859-1)]),
2841	with_tcencoding=${withval})
2842
2843    if test x"${with_tcencoding}" != x ; then
2844	AC_DEFINE_UNQUOTED(TCL_CFGVAL_ENCODING,"${with_tcencoding}",
2845	    [What encoding should be used for embedded configuration info?])
2846    else
2847	AC_DEFINE(TCL_CFGVAL_ENCODING,"iso8859-1",
2848	    [What encoding should be used for embedded configuration info?])
2849    fi
2850])
2851
2852#--------------------------------------------------------------------
2853# SC_TCL_CHECK_BROKEN_FUNC
2854#
2855#	Check for broken function.
2856#
2857# Arguments:
2858#	funcName - function to test for
2859#	advancedTest - the advanced test to run if the function is present
2860#
2861# Results:
2862#	Might cause compatability versions of the function to be used.
2863#	Might affect the following vars:
2864#		USE_COMPAT	(implicit)
2865#
2866#--------------------------------------------------------------------
2867
2868AC_DEFUN([SC_TCL_CHECK_BROKEN_FUNC],[
2869    AC_CHECK_FUNC($1, tcl_ok=1, tcl_ok=0)
2870    if test ["$tcl_ok"] = 1; then
2871	AC_CACHE_CHECK([proper ]$1[ implementation], [tcl_cv_]$1[_unbroken],
2872	    AC_TRY_RUN([[int main() {]$2[}]],[tcl_cv_]$1[_unbroken]=ok,
2873		[tcl_cv_]$1[_unbroken]=broken,[tcl_cv_]$1[_unbroken]=unknown))
2874	if test ["$tcl_cv_]$1[_unbroken"] = "ok"; then
2875	    tcl_ok=1
2876	else
2877	    tcl_ok=0
2878	fi
2879    fi
2880    if test ["$tcl_ok"] = 0; then
2881	AC_LIBOBJ($1)
2882	USE_COMPAT=1
2883    fi
2884])
2885
2886#--------------------------------------------------------------------
2887# SC_TCL_GETHOSTBYADDR_R
2888#
2889#	Check if we have MT-safe variant of gethostbyaddr().
2890#
2891# Arguments:
2892#	None
2893#
2894# Results:
2895#
2896#	Might define the following vars:
2897#		HAVE_GETHOSTBYADDR_R
2898#		HAVE_GETHOSTBYADDR_R_7
2899#		HAVE_GETHOSTBYADDR_R_8
2900#
2901#--------------------------------------------------------------------
2902
2903AC_DEFUN([SC_TCL_GETHOSTBYADDR_R], [AC_CHECK_FUNC(gethostbyaddr_r, [
2904    AC_CACHE_CHECK([for gethostbyaddr_r with 7 args], tcl_cv_api_gethostbyaddr_r_7, [
2905    AC_TRY_COMPILE([
2906	#include <netdb.h>
2907    ], [
2908	char *addr;
2909	int length;
2910	int type;
2911	struct hostent *result;
2912	char buffer[2048];
2913	int buflen = 2048;
2914	int h_errnop;
2915
2916	(void) gethostbyaddr_r(addr, length, type, result, buffer, buflen,
2917			       &h_errnop);
2918    ], tcl_cv_api_gethostbyaddr_r_7=yes, tcl_cv_api_gethostbyaddr_r_7=no)])
2919    tcl_ok=$tcl_cv_api_gethostbyaddr_r_7
2920    if test "$tcl_ok" = yes; then
2921	AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1,
2922	    [Define to 1 if gethostbyaddr_r takes 7 args.])
2923    else
2924	AC_CACHE_CHECK([for gethostbyaddr_r with 8 args], tcl_cv_api_gethostbyaddr_r_8, [
2925	AC_TRY_COMPILE([
2926	    #include <netdb.h>
2927	], [
2928	    char *addr;
2929	    int length;
2930	    int type;
2931	    struct hostent *result, *resultp;
2932	    char buffer[2048];
2933	    int buflen = 2048;
2934	    int h_errnop;
2935
2936	    (void) gethostbyaddr_r(addr, length, type, result, buffer, buflen,
2937				   &resultp, &h_errnop);
2938	], tcl_cv_api_gethostbyaddr_r_8=yes, tcl_cv_api_gethostbyaddr_r_8=no)])
2939	tcl_ok=$tcl_cv_api_gethostbyaddr_r_8
2940	if test "$tcl_ok" = yes; then
2941	    AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1,
2942		[Define to 1 if gethostbyaddr_r takes 8 args.])
2943	fi
2944    fi
2945    if test "$tcl_ok" = yes; then
2946	AC_DEFINE(HAVE_GETHOSTBYADDR_R, 1,
2947	    [Define to 1 if gethostbyaddr_r is available.])
2948    fi
2949])])
2950
2951#--------------------------------------------------------------------
2952# SC_TCL_GETHOSTBYNAME_R
2953#
2954#	Check to see what variant of gethostbyname_r() we have.
2955#	Based on David Arnold's example from the comp.programming.threads
2956#	FAQ Q213
2957#
2958# Arguments:
2959#	None
2960#
2961# Results:
2962#
2963#	Might define the following vars:
2964#		HAVE_GETHOSTBYADDR_R
2965#		HAVE_GETHOSTBYADDR_R_3
2966#		HAVE_GETHOSTBYADDR_R_5
2967#		HAVE_GETHOSTBYADDR_R_6
2968#
2969#--------------------------------------------------------------------
2970
2971AC_DEFUN([SC_TCL_GETHOSTBYNAME_R], [AC_CHECK_FUNC(gethostbyname_r, [
2972    AC_CACHE_CHECK([for gethostbyname_r with 6 args], tcl_cv_api_gethostbyname_r_6, [
2973    AC_TRY_COMPILE([
2974	#include <netdb.h>
2975    ], [
2976	char *name;
2977	struct hostent *he, *res;
2978	char buffer[2048];
2979	int buflen = 2048;
2980	int h_errnop;
2981
2982	(void) gethostbyname_r(name, he, buffer, buflen, &res, &h_errnop);
2983    ], tcl_cv_api_gethostbyname_r_6=yes, tcl_cv_api_gethostbyname_r_6=no)])
2984    tcl_ok=$tcl_cv_api_gethostbyname_r_6
2985    if test "$tcl_ok" = yes; then
2986	AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1,
2987	    [Define to 1 if gethostbyname_r takes 6 args.])
2988    else
2989	AC_CACHE_CHECK([for gethostbyname_r with 5 args], tcl_cv_api_gethostbyname_r_5, [
2990	AC_TRY_COMPILE([
2991	    #include <netdb.h>
2992	], [
2993	    char *name;
2994	    struct hostent *he;
2995	    char buffer[2048];
2996	    int buflen = 2048;
2997	    int h_errnop;
2998
2999	    (void) gethostbyname_r(name, he, buffer, buflen, &h_errnop);
3000	], tcl_cv_api_gethostbyname_r_5=yes, tcl_cv_api_gethostbyname_r_5=no)])
3001	tcl_ok=$tcl_cv_api_gethostbyname_r_5
3002	if test "$tcl_ok" = yes; then
3003	    AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1,
3004		[Define to 1 if gethostbyname_r takes 5 args.])
3005	else
3006	    AC_CACHE_CHECK([for gethostbyname_r with 3 args], tcl_cv_api_gethostbyname_r_3, [
3007	    AC_TRY_COMPILE([
3008		#include <netdb.h>
3009	    ], [
3010		char *name;
3011		struct hostent *he;
3012		struct hostent_data data;
3013
3014		(void) gethostbyname_r(name, he, &data);
3015	    ], tcl_cv_api_gethostbyname_r_3=yes, tcl_cv_api_gethostbyname_r_3=no)])
3016	    tcl_ok=$tcl_cv_api_gethostbyname_r_3
3017	    if test "$tcl_ok" = yes; then
3018		AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1,
3019		    [Define to 1 if gethostbyname_r takes 3 args.])
3020	    fi
3021	fi
3022    fi
3023    if test "$tcl_ok" = yes; then
3024	AC_DEFINE(HAVE_GETHOSTBYNAME_R, 1,
3025	    [Define to 1 if gethostbyname_r is available.])
3026    fi
3027])])
3028
3029#--------------------------------------------------------------------
3030# SC_TCL_GETADDRINFO
3031#
3032#	Check if we have 'getaddrinfo'
3033#
3034# Arguments:
3035#	None
3036#
3037# Results:
3038#	Might define the following vars:
3039#		HAVE_GETADDRINFO
3040#
3041#--------------------------------------------------------------------
3042
3043AC_DEFUN([SC_TCL_GETADDRINFO], [AC_CHECK_FUNC(getaddrinfo, [
3044    AC_CACHE_CHECK([for working getaddrinfo], tcl_cv_api_getaddrinfo, [
3045    AC_TRY_COMPILE([
3046	#include <netdb.h>
3047    ], [
3048	const char *name, *port;
3049	struct addrinfo *aiPtr, hints;
3050	(void)getaddrinfo(name,port, &hints, &aiPtr);
3051	(void)freeaddrinfo(aiPtr);
3052    ], tcl_cv_api_getaddrinfo=yes, tcl_cv_getaddrinfo=no)])
3053    tcl_ok=$tcl_cv_api_getaddrinfo
3054    if test "$tcl_ok" = yes; then
3055	AC_DEFINE(HAVE_GETADDRINFO, 1,
3056	    [Define to 1 if getaddrinfo is available.])
3057    fi
3058])])
3059
3060#--------------------------------------------------------------------
3061# SC_TCL_GETPWUID_R
3062#
3063#	Check if we have MT-safe variant of getpwuid() and if yes,
3064#	which one exactly.
3065#
3066# Arguments:
3067#	None
3068#
3069# Results:
3070#
3071#	Might define the following vars:
3072#		HAVE_GETPWUID_R
3073#		HAVE_GETPWUID_R_4
3074#		HAVE_GETPWUID_R_5
3075#
3076#--------------------------------------------------------------------
3077
3078AC_DEFUN([SC_TCL_GETPWUID_R], [AC_CHECK_FUNC(getpwuid_r, [
3079    AC_CACHE_CHECK([for getpwuid_r with 5 args], tcl_cv_api_getpwuid_r_5, [
3080    AC_TRY_COMPILE([
3081	#include <sys/types.h>
3082	#include <pwd.h>
3083    ], [
3084	uid_t uid;
3085	struct passwd pw, *pwp;
3086	char buf[512];
3087	int buflen = 512;
3088
3089	(void) getpwuid_r(uid, &pw, buf, buflen, &pwp);
3090    ], tcl_cv_api_getpwuid_r_5=yes, tcl_cv_api_getpwuid_r_5=no)])
3091    tcl_ok=$tcl_cv_api_getpwuid_r_5
3092    if test "$tcl_ok" = yes; then
3093	AC_DEFINE(HAVE_GETPWUID_R_5, 1,
3094	    [Define to 1 if getpwuid_r takes 5 args.])
3095    else
3096	AC_CACHE_CHECK([for getpwuid_r with 4 args], tcl_cv_api_getpwuid_r_4, [
3097	AC_TRY_COMPILE([
3098	    #include <sys/types.h>
3099	    #include <pwd.h>
3100	], [
3101	    uid_t uid;
3102	    struct passwd pw;
3103	    char buf[512];
3104	    int buflen = 512;
3105
3106	    (void)getpwnam_r(uid, &pw, buf, buflen);
3107	], tcl_cv_api_getpwuid_r_4=yes, tcl_cv_api_getpwuid_r_4=no)])
3108	tcl_ok=$tcl_cv_api_getpwuid_r_4
3109	if test "$tcl_ok" = yes; then
3110	    AC_DEFINE(HAVE_GETPWUID_R_4, 1,
3111		[Define to 1 if getpwuid_r takes 4 args.])
3112	fi
3113    fi
3114    if test "$tcl_ok" = yes; then
3115	AC_DEFINE(HAVE_GETPWUID_R, 1,
3116	    [Define to 1 if getpwuid_r is available.])
3117    fi
3118])])
3119
3120#--------------------------------------------------------------------
3121# SC_TCL_GETPWNAM_R
3122#
3123#	Check if we have MT-safe variant of getpwnam() and if yes,
3124#	which one exactly.
3125#
3126# Arguments:
3127#	None
3128#
3129# Results:
3130#
3131#	Might define the following vars:
3132#		HAVE_GETPWNAM_R
3133#		HAVE_GETPWNAM_R_4
3134#		HAVE_GETPWNAM_R_5
3135#
3136#--------------------------------------------------------------------
3137
3138AC_DEFUN([SC_TCL_GETPWNAM_R], [AC_CHECK_FUNC(getpwnam_r, [
3139    AC_CACHE_CHECK([for getpwnam_r with 5 args], tcl_cv_api_getpwnam_r_5, [
3140    AC_TRY_COMPILE([
3141	#include <sys/types.h>
3142	#include <pwd.h>
3143    ], [
3144	char *name;
3145	struct passwd pw, *pwp;
3146	char buf[512];
3147	int buflen = 512;
3148
3149	(void) getpwnam_r(name, &pw, buf, buflen, &pwp);
3150    ], tcl_cv_api_getpwnam_r_5=yes, tcl_cv_api_getpwnam_r_5=no)])
3151    tcl_ok=$tcl_cv_api_getpwnam_r_5
3152    if test "$tcl_ok" = yes; then
3153	AC_DEFINE(HAVE_GETPWNAM_R_5, 1,
3154	    [Define to 1 if getpwnam_r takes 5 args.])
3155    else
3156	AC_CACHE_CHECK([for getpwnam_r with 4 args], tcl_cv_api_getpwnam_r_4, [
3157	AC_TRY_COMPILE([
3158	    #include <sys/types.h>
3159	    #include <pwd.h>
3160	], [
3161	    char *name;
3162	    struct passwd pw;
3163	    char buf[512];
3164	    int buflen = 512;
3165
3166	    (void)getpwnam_r(name, &pw, buf, buflen);
3167	], tcl_cv_api_getpwnam_r_4=yes, tcl_cv_api_getpwnam_r_4=no)])
3168	tcl_ok=$tcl_cv_api_getpwnam_r_4
3169	if test "$tcl_ok" = yes; then
3170	    AC_DEFINE(HAVE_GETPWNAM_R_4, 1,
3171		[Define to 1 if getpwnam_r takes 4 args.])
3172	fi
3173    fi
3174    if test "$tcl_ok" = yes; then
3175	AC_DEFINE(HAVE_GETPWNAM_R, 1,
3176	    [Define to 1 if getpwnam_r is available.])
3177    fi
3178])])
3179
3180#--------------------------------------------------------------------
3181# SC_TCL_GETGRGID_R
3182#
3183#	Check if we have MT-safe variant of getgrgid() and if yes,
3184#	which one exactly.
3185#
3186# Arguments:
3187#	None
3188#
3189# Results:
3190#
3191#	Might define the following vars:
3192#		HAVE_GETGRGID_R
3193#		HAVE_GETGRGID_R_4
3194#		HAVE_GETGRGID_R_5
3195#
3196#--------------------------------------------------------------------
3197
3198AC_DEFUN([SC_TCL_GETGRGID_R], [AC_CHECK_FUNC(getgrgid_r, [
3199    AC_CACHE_CHECK([for getgrgid_r with 5 args], tcl_cv_api_getgrgid_r_5, [
3200    AC_TRY_COMPILE([
3201	#include <sys/types.h>
3202	#include <grp.h>
3203    ], [
3204	gid_t gid;
3205	struct group gr, *grp;
3206	char buf[512];
3207	int buflen = 512;
3208
3209	(void) getgrgid_r(gid, &gr, buf, buflen, &grp);
3210    ], tcl_cv_api_getgrgid_r_5=yes, tcl_cv_api_getgrgid_r_5=no)])
3211    tcl_ok=$tcl_cv_api_getgrgid_r_5
3212    if test "$tcl_ok" = yes; then
3213	AC_DEFINE(HAVE_GETGRGID_R_5, 1,
3214	    [Define to 1 if getgrgid_r takes 5 args.])
3215    else
3216	AC_CACHE_CHECK([for getgrgid_r with 4 args], tcl_cv_api_getgrgid_r_4, [
3217	AC_TRY_COMPILE([
3218	    #include <sys/types.h>
3219	    #include <grp.h>
3220	], [
3221	    gid_t gid;
3222	    struct group gr;
3223	    char buf[512];
3224	    int buflen = 512;
3225
3226	    (void)getgrgid_r(gid, &gr, buf, buflen);
3227	], tcl_cv_api_getgrgid_r_4=yes, tcl_cv_api_getgrgid_r_4=no)])
3228	tcl_ok=$tcl_cv_api_getgrgid_r_4
3229	if test "$tcl_ok" = yes; then
3230	    AC_DEFINE(HAVE_GETGRGID_R_4, 1,
3231		[Define to 1 if getgrgid_r takes 4 args.])
3232	fi
3233    fi
3234    if test "$tcl_ok" = yes; then
3235	AC_DEFINE(HAVE_GETGRGID_R, 1,
3236	    [Define to 1 if getgrgid_r is available.])
3237    fi
3238])])
3239
3240#--------------------------------------------------------------------
3241# SC_TCL_GETGRNAM_R
3242#
3243#	Check if we have MT-safe variant of getgrnam() and if yes,
3244#	which one exactly.
3245#
3246# Arguments:
3247#	None
3248#
3249# Results:
3250#
3251#	Might define the following vars:
3252#		HAVE_GETGRNAM_R
3253#		HAVE_GETGRNAM_R_4
3254#		HAVE_GETGRNAM_R_5
3255#
3256#--------------------------------------------------------------------
3257
3258AC_DEFUN([SC_TCL_GETGRNAM_R], [AC_CHECK_FUNC(getgrnam_r, [
3259    AC_CACHE_CHECK([for getgrnam_r with 5 args], tcl_cv_api_getgrnam_r_5, [
3260    AC_TRY_COMPILE([
3261	#include <sys/types.h>
3262	#include <grp.h>
3263    ], [
3264	char *name;
3265	struct group gr, *grp;
3266	char buf[512];
3267	int buflen = 512;
3268
3269	(void) getgrnam_r(name, &gr, buf, buflen, &grp);
3270    ], tcl_cv_api_getgrnam_r_5=yes, tcl_cv_api_getgrnam_r_5=no)])
3271    tcl_ok=$tcl_cv_api_getgrnam_r_5
3272    if test "$tcl_ok" = yes; then
3273	AC_DEFINE(HAVE_GETGRNAM_R_5, 1,
3274	    [Define to 1 if getgrnam_r takes 5 args.])
3275    else
3276	AC_CACHE_CHECK([for getgrnam_r with 4 args], tcl_cv_api_getgrnam_r_4, [
3277	AC_TRY_COMPILE([
3278	    #include <sys/types.h>
3279	    #include <grp.h>
3280	], [
3281	    char *name;
3282	    struct group gr;
3283	    char buf[512];
3284	    int buflen = 512;
3285
3286	    (void)getgrnam_r(name, &gr, buf, buflen);
3287	], tcl_cv_api_getgrnam_r_4=yes, tcl_cv_api_getgrnam_r_4=no)])
3288	tcl_ok=$tcl_cv_api_getgrnam_r_4
3289	if test "$tcl_ok" = yes; then
3290	    AC_DEFINE(HAVE_GETGRNAM_R_4, 1,
3291		[Define to 1 if getgrnam_r takes 4 args.])
3292	fi
3293    fi
3294    if test "$tcl_ok" = yes; then
3295	AC_DEFINE(HAVE_GETGRNAM_R, 1,
3296	    [Define to 1 if getgrnam_r is available.])
3297    fi
3298])])
3299
3300# Local Variables:
3301# mode: autoconf
3302# End:
3303