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