1# tcl.m4 --
2#
3#	This file provides a set of autoconf macros to help TEA-enable
4#	a Tcl extension.
5#
6# Copyright (c) 1999-2000 Ajuba Solutions.
7# All rights reserved.
8#
9# See the file "license.terms" for information on usage and redistribution
10# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
12#------------------------------------------------------------------------
13# SC_PATH_TCLCONFIG --
14#
15#	Locate the tclConfig.sh file and perform a sanity check on
16#	the Tcl compile flags
17#
18# Arguments:
19#	none
20#
21# Results:
22#
23#	Adds the following arguments to configure:
24#		--with-tcl=...
25#
26#	Defines the following vars:
27#		TCL_BIN_DIR	Full path to the directory containing
28#				the tclConfig.sh file
29#------------------------------------------------------------------------
30
31AC_DEFUN(SC_PATH_TCLCONFIG, [
32    #
33    # Ok, lets find the tcl configuration
34    # First, look for one uninstalled.
35    # the alternative search directory is invoked by --with-tcl
36    #
37
38    if test x"${no_tcl}" = x ; then
39	# we reset no_tcl in case something fails here
40	no_tcl=true
41	AC_ARG_WITH(tcl, [  --with-tcl              directory containing tcl configuration (tclConfig.sh)], with_tclconfig=${withval})
42	AC_MSG_CHECKING([for Tcl configuration])
43	AC_CACHE_VAL(ac_cv_c_tclconfig,[
44
45	    # First check to see if --with-tcl was specified.
46	    if test x"${with_tclconfig}" != x ; then
47		if test -f "${with_tclconfig}/tclConfig.sh" ; then
48		    ac_cv_c_tclconfig=`(cd ${with_tclconfig}; pwd)`
49		else
50		    AC_MSG_ERROR([${with_tclconfig} directory doesn't contain tclConfig.sh])
51		fi
52	    fi
53
54	    # then check for a private Tcl installation
55	    if test x"${ac_cv_c_tclconfig}" = x ; then
56		for i in \
57			../tcl \
58			`ls -dr ../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
59			../../tcl \
60			`ls -dr ../../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
61			../../../tcl \
62			`ls -dr ../../../tcl[[8-9]].[[0-9]]* 2>/dev/null` ; do
63		    if test -f "$i/unix/tclConfig.sh" ; then
64			ac_cv_c_tclconfig=`(cd $i/unix; pwd)`
65			break
66		    fi
67		done
68	    fi
69
70	    # check in a few common install locations
71	    if test x"${ac_cv_c_tclconfig}" = x ; then
72		for i in `ls -d ${prefix}/lib 2>/dev/null` \
73			`ls -d /usr/lib 2>/dev/null` \
74			`ls -d /usr/local/lib 2>/dev/null` ; do
75		    if test -f "$i/tclConfig.sh" ; then
76			ac_cv_c_tclconfig=`(cd $i; pwd)`
77			break
78		    fi
79		done
80	    fi
81
82	    # check in a few other private locations
83	    if test x"${ac_cv_c_tclconfig}" = x ; then
84		for i in \
85			${srcdir}/../tcl \
86			`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]]* 2>/dev/null` ; do
87		    if test -f "$i/unix/tclConfig.sh" ; then
88		    ac_cv_c_tclconfig=`(cd $i/unix; pwd)`
89		    break
90		fi
91		done
92	    fi
93	])
94
95	if test x"${ac_cv_c_tclconfig}" = x ; then
96	    TCL_BIN_DIR="# no Tcl configs found"
97	    AC_MSG_WARN(Can't find Tcl configuration definitions)
98	    exit 0
99	else
100	    no_tcl=
101	    TCL_BIN_DIR=${ac_cv_c_tclconfig}
102	    AC_MSG_RESULT(found $TCL_BIN_DIR/tclConfig.sh)
103	fi
104    fi
105])
106
107#------------------------------------------------------------------------
108# SC_PATH_TKCONFIG --
109#
110#	Locate the tkConfig.sh file
111#
112# Arguments:
113#	none
114#
115# Results:
116#
117#	Adds the following arguments to configure:
118#		--with-tk=...
119#
120#	Defines the following vars:
121#		TK_BIN_DIR	Full path to the directory containing
122#				the tkConfig.sh file
123#------------------------------------------------------------------------
124
125AC_DEFUN(SC_PATH_TKCONFIG, [
126    #
127    # Ok, lets find the tk configuration
128    # First, look for one uninstalled.
129    # the alternative search directory is invoked by --with-tk
130    #
131
132    if test x"${no_tk}" = x ; then
133	# we reset no_tk in case something fails here
134	no_tk=true
135	AC_ARG_WITH(tk, [  --with-tk               directory containing tk configuration (tkConfig.sh)], with_tkconfig=${withval})
136	AC_MSG_CHECKING([for Tk configuration])
137	AC_CACHE_VAL(ac_cv_c_tkconfig,[
138
139	    # First check to see if --with-tkconfig was specified.
140	    if test x"${with_tkconfig}" != x ; then
141		if test -f "${with_tkconfig}/tkConfig.sh" ; then
142		    ac_cv_c_tkconfig=`(cd ${with_tkconfig}; pwd)`
143		else
144		    AC_MSG_ERROR([${with_tkconfig} directory doesn't contain tkConfig.sh])
145		fi
146	    fi
147
148	    # then check for a private Tk library
149	    if test x"${ac_cv_c_tkconfig}" = x ; then
150		for i in \
151			../tk \
152			`ls -dr ../tk[[8-9]].[[0-9]]* 2>/dev/null` \
153			../../tk \
154			`ls -dr ../../tk[[8-9]].[[0-9]]* 2>/dev/null` \
155			../../../tk \
156			`ls -dr ../../../tk[[8-9]].[[0-9]]* 2>/dev/null` ; do
157		    if test -f "$i/unix/tkConfig.sh" ; then
158			ac_cv_c_tkconfig=`(cd $i/unix; pwd)`
159			break
160		    fi
161		done
162	    fi
163	    # check in a few common install locations
164	    if test x"${ac_cv_c_tkconfig}" = x ; then
165		for i in `ls -d ${prefix}/lib 2>/dev/null` \
166			`ls -d /usr/lib 2>/dev/null` \
167			`ls -d /usr/local/lib 2>/dev/null` ; do
168		    if test -f "$i/tkConfig.sh" ; then
169			ac_cv_c_tkconfig=`(cd $i; pwd)`
170			break
171		    fi
172		done
173	    fi
174	    # check in a few other private locations
175	    if test x"${ac_cv_c_tkconfig}" = x ; then
176		for i in \
177			${srcdir}/../tk \
178			`ls -dr ${srcdir}/../tk[[8-9]].[[0-9]]* 2>/dev/null` ; do
179		    if test -f "$i/unix/tkConfig.sh" ; then
180			ac_cv_c_tkconfig=`(cd $i/unix; pwd)`
181			break
182		    fi
183		done
184	    fi
185	])
186	if test x"${ac_cv_c_tkconfig}" = x ; then
187	    TK_BIN_DIR="# no Tk configs found"
188	    AC_MSG_WARN(Can't find Tk configuration definitions)
189	    exit 0
190	else
191	    no_tk=
192	    TK_BIN_DIR=${ac_cv_c_tkconfig}
193	    AC_MSG_RESULT(found $TK_BIN_DIR/tkConfig.sh)
194	fi
195    fi
196
197])
198
199#------------------------------------------------------------------------
200# SC_LOAD_TCLCONFIG --
201#
202#	Load the tclConfig.sh file
203#
204# Arguments:
205#	
206#	Requires the following vars to be set:
207#		TCL_BIN_DIR
208#
209# Results:
210#
211#	Subst the following vars:
212#		TCL_BIN_DIR
213#		TCL_SRC_DIR
214#		TCL_LIB_FILE
215#
216#------------------------------------------------------------------------
217
218AC_DEFUN(SC_LOAD_TCLCONFIG, [
219    AC_MSG_CHECKING([for existence of $TCL_BIN_DIR/tclConfig.sh])
220
221    if test -f "$TCL_BIN_DIR/tclConfig.sh" ; then
222        AC_MSG_RESULT([loading])
223	. $TCL_BIN_DIR/tclConfig.sh
224    else
225        AC_MSG_RESULT([file not found])
226    fi
227
228    #
229    # The eval is required to do the TCL_DBGX substitution in the
230    # TCL_LIB_FILE variable
231    #
232
233    eval TCL_LIB_FILE=${TCL_LIB_FILE}
234    eval TCL_LIB_FLAG=${TCL_LIB_FLAG}
235
236    AC_SUBST(TCL_DBGX)
237    AC_SUBST(TCL_BIN_DIR)
238    AC_SUBST(TCL_SRC_DIR)
239    AC_SUBST(TCL_LIB_FILE)
240    AC_SUBST(TCL_LIBS)
241    AC_SUBST(TCL_DEFS)
242    AC_SUBST(TCL_SHLIB_LD_LIBS)
243    AC_SUBST(TCL_EXTRA_CFLAGS)
244    AC_SUBST(TCL_LD_FLAGS)
245    AC_SUBST(TCL_LIB_FILE)
246    AC_SUBST(TCL_STUB_LIB_FILE)
247    AC_SUBST(TCL_LIB_SPEC)
248    AC_SUBST(TCL_BUILD_LIB_SPEC)
249    AC_SUBST(TCL_STUB_LIB_SPEC)
250    AC_SUBST(TCL_BUILD_STUB_LIB_SPEC)
251])
252
253#------------------------------------------------------------------------
254# SC_LOAD_TKCONFIG --
255#
256#	Load the tkConfig.sh file
257#
258# Arguments:
259#	
260#	Requires the following vars to be set:
261#		TK_BIN_DIR
262#
263# Results:
264#
265#	Sets the following vars that should be in tkConfig.sh:
266#		TK_BIN_DIR
267#------------------------------------------------------------------------
268
269AC_DEFUN(SC_LOAD_TKCONFIG, [
270    AC_MSG_CHECKING([for existence of $TK_BIN_DIR/tkConfig.sh])
271
272    if test -f "$TK_BIN_DIR/tkConfig.sh" ; then
273        AC_MSG_RESULT([loading])
274	. $TK_BIN_DIR/tkConfig.sh
275    else
276        AC_MSG_RESULT([could not find $TK_BIN_DIR/tkConfig.sh])
277    fi
278
279    AC_SUBST(TK_BIN_DIR)
280    AC_SUBST(TK_SRC_DIR)
281    AC_SUBST(TK_LIB_FILE)
282    AC_SUBST(TK_XINCLUDES)
283])
284
285#------------------------------------------------------------------------
286# SC_ENABLE_GCC --
287#
288#	Allows the use of GCC if available
289#
290# Arguments:
291#	none
292#	
293# Results:
294#
295#	Adds the following arguments to configure:
296#		--enable-gcc
297#
298#	Sets the following vars:
299#		CC	Command to use for the compiler
300#------------------------------------------------------------------------
301
302AC_DEFUN(SC_ENABLE_GCC, [
303    AC_ARG_ENABLE(gcc, [  --enable-gcc            allow use of gcc if available [--disable-gcc]],
304	[ok=$enableval], [ok=no])
305    if test "$ok" = "yes"; then
306	CC=gcc
307    else
308	case "`uname -s`" in
309	    *win32* | *WIN32* | *CYGWIN_NT* | *CYGWIN_98* | *CYGWIN_95*)
310		CC=cl
311	    ;;
312	    *)
313		CC=${CC-cc}
314	    ;;
315	esac
316    fi
317    AC_PROG_CC
318])
319
320#------------------------------------------------------------------------
321# SC_ENABLE_SHARED --
322#
323#	Allows the building of shared libraries
324#
325# Arguments:
326#	none
327#	
328# Results:
329#
330#	Adds the following arguments to configure:
331#		--enable-shared=yes|no
332#
333#	Defines the following vars:
334#		STATIC_BUILD	Used for building import/export libraries
335#				on Windows.
336#
337#	Sets the following vars:
338#		SHARED_BUILD	Value of 1 or 0
339#------------------------------------------------------------------------
340
341AC_DEFUN(SC_ENABLE_SHARED, [
342    AC_MSG_CHECKING([how to build libraries])
343    AC_ARG_ENABLE(shared,
344	[  --enable-shared         build and link with shared libraries [--enable-shared]],
345	[tcl_ok=$enableval], [tcl_ok=yes])
346
347    if test "${enable_shared+set}" = set; then
348	enableval="$enable_shared"
349	tcl_ok=$enableval
350    else
351	tcl_ok=yes
352    fi
353
354    if test "$tcl_ok" = "yes" ; then
355	AC_MSG_RESULT([shared])
356	SHARED_BUILD=1
357    else
358	AC_MSG_RESULT([static])
359	SHARED_BUILD=0
360	AC_DEFINE(STATIC_BUILD)
361    fi
362])
363
364#------------------------------------------------------------------------
365# SC_ENABLE_THREADS --
366#
367#	Specify if thread support should be enabled
368#
369# Arguments:
370#	none
371#	
372# Results:
373#
374#	Adds the following arguments to configure:
375#		--enable-threads
376#
377#	Sets the following vars:
378#		THREADS_LIBS	Thread library(s)
379#
380#	Defines the following vars:
381#		TCL_THREADS
382#		_REENTRANT
383#
384#------------------------------------------------------------------------
385
386AC_DEFUN(SC_ENABLE_THREADS, [
387    AC_MSG_CHECKING(for building with threads)
388    AC_ARG_ENABLE(threads, [  --enable-threads        build with threads],
389	[tcl_ok=$enableval], [tcl_ok=no])
390
391    if test "$tcl_ok" = "yes"; then
392	TCL_THREADS=1
393	AC_DEFINE(TCL_THREADS)
394	AC_DEFINE(_REENTRANT)
395
396	case "`uname -s`" in
397	    *win32* | *WIN32* | *CYGWIN_NT* | *CYGWIN_98* | *CYGWIN_95*)
398		    AC_MSG_RESULT(yes)
399		;;
400	    *)
401		AC_CHECK_LIB(pthread,pthread_mutex_init,tcl_ok=yes,tcl_ok=no)
402		if test "$tcl_ok" = "yes"; then
403		    # The space is needed
404		    THREADS_LIBS=" -lpthread"
405		    AC_MSG_RESULT(yes)
406		else
407		    TCL_THREADS=0
408		    AC_MSG_RESULT(no)
409		    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...")
410		fi
411		;;
412	esac
413    else
414	TCL_THREADS=0
415	AC_MSG_RESULT(no (default))
416    fi
417
418])
419
420#------------------------------------------------------------------------
421# SC_ENABLE_SYMBOLS --
422#
423#	Specify if debugging symbols should be used
424#
425# Arguments:
426#	none
427#	
428#	Requires the following vars to be set:
429#		CFLAGS_DEBUG
430#		CFLAGS_OPTIMIZE
431#		LDFLAGS_DEBUG
432#		LDFLAGS_OPTIMIZE
433#	
434# Results:
435#
436#	Adds the following arguments to configure:
437#		--enable-symbols
438#
439#	Defines the following vars:
440#		CFLAGS_DEFAULT	Sets to CFLAGS_DEBUG if true
441#				Sets to CFLAGS_OPTIMIZE if false
442#		LDFLAGS_DEFAULT	Sets to LDFLAGS_DEBUG if true
443#				Sets to LDFLAGS_OPTIMIZE if false
444#		DBGX		Debug library extension
445#
446#------------------------------------------------------------------------
447
448AC_DEFUN(SC_ENABLE_SYMBOLS, [
449    case "`uname -s`" in
450	*win32* | *WIN32* | *CYGWIN_NT* | *CYGWIN_98* | *CYGWIN_95*)
451	    tcl_dbgx=d
452	;;
453	*)
454	    tcl_dbgx=g
455	;;
456    esac
457
458    AC_MSG_CHECKING([for build with symbols])
459    AC_ARG_ENABLE(symbols, [  --enable-symbols        build with debugging symbols [--disable-symbols]],    [tcl_ok=$enableval], [tcl_ok=no])
460    if test "$tcl_ok" = "yes"; then
461	CFLAGS_DEFAULT="${CFLAGS_DEBUG}"
462	LDFLAGS_DEFAULT="${LDFLAGS_DEBUG}"
463	DBGX=${tcl_dbgx}
464	TCL_DBGX=${tcl_dbgx}
465	AC_MSG_RESULT([yes])
466    else
467	CFLAGS_DEFAULT="${CFLAGS_OPTIMIZE}"
468	LDFLAGS_DEFAULT="${LDFLAGS_OPTIMIZE}"
469	DBGX=""
470	TCL_DBGX=""
471	AC_MSG_RESULT([no])
472    fi
473
474    AC_SUBST(TCL_DBGX)
475    AC_SUBST(CFLAGS_DEFAULT)
476    AC_SUBST(LDFLAGS_DEFAULT)
477])
478
479#--------------------------------------------------------------------
480# SC_CONFIG_CFLAGS
481#
482#	Try to determine the proper flags to pass to the compiler
483#	for building shared libraries and other such nonsense.
484#
485# Arguments:
486#	none
487#
488# Results:
489#
490#	Defines the following vars:
491#
492#       DL_OBJS -       Name of the object file that implements dynamic
493#                       loading for Tcl on this system.
494#       DL_LIBS -       Library file(s) to include in tclsh and other base
495#                       applications in order for the "load" command to work.
496#       LDFLAGS -      Flags to pass to the compiler when linking object
497#                       files into an executable application binary such
498#                       as tclsh.
499#       LD_SEARCH_FLAGS-Flags to pass to ld, such as "-R /usr/local/tcl/lib",
500#                       that tell the run-time dynamic linker where to look
501#                       for shared libraries such as libtcl.so.  Depends on
502#                       the variable LIB_RUNTIME_DIR in the Makefile.
503#       MAKE_LIB -      Command to execute to build the Tcl library;
504#                       differs depending on whether or not Tcl is being
505#                       compiled as a shared library.
506#       SHLIB_CFLAGS -  Flags to pass to cc when compiling the components
507#                       of a shared library (may request position-independent
508#                       code, among other things).
509#       SHLIB_LD -      Base command to use for combining object files
510#                       into a shared library.
511#       SHLIB_LD_LIBS - Dependent libraries for the linker to scan when
512#                       creating shared libraries.  This symbol typically
513#                       goes at the end of the "ld" commands that build
514#                       shared libraries. The value of the symbol is
515#                       "${LIBS}" if all of the dependent libraries should
516#                       be specified when creating a shared library.  If
517#                       dependent libraries should not be specified (as on
518#                       SunOS 4.x, where they cause the link to fail, or in
519#                       general if Tcl and Tk aren't themselves shared
520#                       libraries), then this symbol has an empty string
521#                       as its value.
522#       SHLIB_SUFFIX -  Suffix to use for the names of dynamically loadable
523#                       extensions.  An empty string means we don't know how
524#                       to use shared libraries on this platform.
525#       TCL_LIB_FILE -  Name of the file that contains the Tcl library, such
526#                       as libtcl7.8.so or libtcl7.8.a.
527#       TCL_LIB_SUFFIX -Specifies everything that comes after the "libtcl"
528#                       in the shared library name, using the $VERSION variable
529#                       to put the version in the right place.  This is used
530#                       by platforms that need non-standard library names.
531#                       Examples:  ${VERSION}.so.1.1 on NetBSD, since it needs
532#                       to have a version after the .so, and ${VERSION}.a
533#                       on AIX, since the Tcl shared library needs to have
534#                       a .a extension whereas shared objects for loadable
535#                       extensions have a .so extension.  Defaults to
536#                       ${VERSION}${SHLIB_SUFFIX}.
537#       TCL_NEEDS_EXP_FILE -
538#                       1 means that an export file is needed to link to a
539#                       shared library.
540#       TCL_EXP_FILE -  The name of the installed export / import file which
541#                       should be used to link to the Tcl shared library.
542#                       Empty if Tcl is unshared.
543#       TCL_BUILD_EXP_FILE -
544#                       The name of the built export / import file which
545#                       should be used to link to the Tcl shared library.
546#                       Empty if Tcl is unshared.
547#	CFLAGS_DEBUG -
548#			Flags used when running the compiler in debug mode
549#	CFLAGS_OPTIMIZE -
550#			Flags used when running the compiler in optimize mode
551#
552#	EXTRA_CFLAGS
553#
554#	Subst's the following vars:
555#		DL_LIBS
556#		CFLAGS_DEBUG
557#		CFLAGS_OPTIMIZE
558#--------------------------------------------------------------------
559
560AC_DEFUN(SC_CONFIG_CFLAGS, [
561
562    # Step 0: Enable 64 bit support?
563
564    AC_MSG_CHECKING([if 64bit support is enabled])
565    AC_ARG_ENABLE(64bit,[  --enable-64bit          enable 64bit support],,enableval="no")
566
567    if test "$enableval" = "yes"; then
568	AC_MSG_RESULT(Will compile with 64bit support)
569	do64bit=yes
570    else
571	do64bit=no
572    fi
573    AC_MSG_RESULT($do64bit)
574 
575    # Step 1: set the variable "system" to hold the name and version number
576    # for the system.  This can usually be done via the "uname" command, but
577    # there are a few systems, like Next, where this doesn't work.
578
579    AC_MSG_CHECKING([system version (for dynamic loading)])
580    if test -f /usr/lib/NextStep/software_version; then
581	system=NEXTSTEP-`awk '/3/,/3/' /usr/lib/NextStep/software_version`
582    else
583	system=`uname -s`-`uname -r`
584	if test "$?" -ne 0 ; then
585	    AC_MSG_RESULT([unknown (can't find uname command)])
586	    system=unknown
587	else
588	    # Special check for weird MP-RAS system (uname returns weird
589	    # results, and the version is kept in special file).
590	
591	    if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
592		system=MP-RAS-`awk '{print $3}' /etc/.relid'`
593	    fi
594	    if test "`uname -s`" = "AIX" ; then
595		system=AIX-`uname -v`.`uname -r`
596	    fi
597	    AC_MSG_RESULT($system)
598	fi
599    fi
600
601    # Step 2: check for existence of -ldl library.  This is needed because
602    # Linux can use either -ldl or -ldld for dynamic loading.
603
604    AC_CHECK_LIB(dl, dlopen, have_dl=yes, have_dl=no)
605
606    # Step 3: set configuration options based on system name and version.
607
608    do64bit_ok=no
609    fullSrcDir=`cd $srcdir; pwd`
610    EXTRA_CFLAGS=""
611    TCL_EXPORT_FILE_SUFFIX=""
612    UNSHARED_LIB_SUFFIX=""
613    TCL_TRIM_DOTS='`echo ${VERSION} | tr -d .`'
614    ECHO_VERSION='`echo ${VERSION}`'
615    TCL_LIB_VERSIONS_OK=ok
616    CFLAGS_DEBUG=-g
617    CFLAGS_OPTIMIZE=-O
618    TCL_NEEDS_EXP_FILE=0
619    TCL_BUILD_EXP_FILE=""
620    TCL_EXP_FILE=""
621    STLIB_LD="ar cr"
622    case $system in
623	AIX-4.[[2-9]])
624	    SHLIB_CFLAGS=""
625	    SHLIB_LD="$fullSrcDir/ldAix /bin/ld -bhalt:4 -bM:SRE -bE:lib.exp -H512 -T512 -bnoentry"
626	    SHLIB_LD_LIBS='${LIBS}'
627	    SHLIB_SUFFIX=".so"
628	    DL_OBJS="tclLoadDl.o"
629	    DL_LIBS="-ldl"
630	    LDFLAGS=""
631	    LD_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
632	    TCL_NEEDS_EXP_FILE=1
633	    TCL_EXPORT_FILE_SUFFIX='${VERSION}\$\{DBGX\}.exp'
634	    ;;
635	AIX-*)
636	    SHLIB_CFLAGS=""
637	    SHLIB_LD="$fullSrcDir/ldAix /bin/ld -bhalt:4 -bM:SRE -bE:lib.exp -H512 -T512"
638	    SHLIB_LD_LIBS='${LIBS}'
639	    SHLIB_SUFFIX=".so"
640	    DL_OBJS="tclLoadDl.o"
641	    LIBOBJS="$LIBOBJS tclLoadAix.o"
642	    DL_LIBS="-lld"
643	    LDFLAGS=""
644	    LD_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
645	    TCL_NEEDS_EXP_FILE=1
646	    TCL_EXPORT_FILE_SUFFIX='${VERSION}\$\{DBGX\}.exp'
647	    ;;
648	BSD/OS-2.1*|BSD/OS-3*)
649	    SHLIB_CFLAGS=""
650	    SHLIB_LD="shlicc -r"
651	    SHLIB_LD_LIBS='${LIBS}'
652	    SHLIB_SUFFIX=".so"
653	    DL_OBJS="tclLoadDl.o"
654	    DL_LIBS="-ldl"
655	    LDFLAGS=""
656	    LD_SEARCH_FLAGS=""
657	    ;;
658	BSD/OS-4.*)
659	    SHLIB_CFLAGS="-export-dynamic -fPIC"
660	    SHLIB_LD="cc -shared"
661	    SHLIB_LD_LIBS='${LIBS}'
662	    SHLIB_SUFFIX=".so"
663	    DL_OBJS="tclLoadDl.o"
664	    DL_LIBS="-ldl"
665	    LDFLAGS="-export-dynamic"
666	    LD_SEARCH_FLAGS=""
667	    ;;
668	*win32*|*WIN32*|CYGWIN_NT*|cygwin_nt*|*CYGWIN_98*|*CYGWIN_95*)
669	    CFLAGS_DEBUG="-nologo -Z7 -Od -WX ${runtime}d"
670	    CFLAGS_OPTIMIZE="-nologo -Oti -Gs -GD ${runtime}"
671	    LDFLAGS_CONSOLE="-subsystem:console"
672	    LDFLAGS_WINDOW="-subsystem:windows"
673	    LDFLAGS_DEBUG="-debug:full -debugtype:cv"
674	    LDFLAGS_OPTIMIZE="-release"
675	    EXTRA_CFLAGS="-YX"
676	    PATHTYPE=-w
677	    STLIB_LD="lib -nologo"
678	    SHLIB_LD="link -dll -nologo"
679	    SHLIB_LD_LIBS="user32.lib advapi32.lib"
680	    RC="rc"
681	    ;;
682	dgux*)
683	    SHLIB_CFLAGS="-K PIC"
684	    SHLIB_LD="cc -G"
685	    SHLIB_LD_LIBS=""
686	    SHLIB_SUFFIX=".so"
687	    DL_OBJS="tclLoadDl.o"
688	    DL_LIBS="-ldl"
689	    LDFLAGS=""
690	    LD_SEARCH_FLAGS=""
691	    ;;
692	HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*|HP-UX-*.11.*)
693	    SHLIB_SUFFIX=".sl"
694	    AC_CHECK_LIB(dld, shl_load, tcl_ok=yes, tcl_ok=no)
695	    if test "$tcl_ok" = yes; then
696		SHLIB_CFLAGS="+z"
697		SHLIB_LD="ld -b"
698		SHLIB_LD_LIBS=""
699		DL_OBJS="tclLoadShl.o"
700		DL_LIBS="-ldld"
701		LDFLAGS="-Wl,-E"
702		LD_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.'
703	    fi
704	    ;;
705	IRIX-4.*)
706	    SHLIB_CFLAGS="-G 0"
707	    SHLIB_SUFFIX=".a"
708	    SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0"
709	    SHLIB_LD_LIBS='${LIBS}'
710	    DL_OBJS="tclLoadAout.o"
711	    DL_LIBS=""
712	    LDFLAGS="-Wl,-D,08000000"
713	    LD_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
714	    SHARED_LIB_SUFFIX='${VERSION}\$\{DBGX\}.a'
715	    ;;
716	IRIX-5.*|IRIX-6.*|IRIX64-6.5*)
717	    SHLIB_CFLAGS=""
718	    SHLIB_LD="ld -n32 -shared -rdata_shared"
719	    SHLIB_LD_LIBS=""
720	    SHLIB_SUFFIX=".so"
721	    DL_OBJS="tclLoadDl.o"
722	    DL_LIBS=""
723	    LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
724	    if test "$CC" = "gcc" -o `$CC -v 2>&1 | grep -c gcc` != "0" ; then
725		EXTRA_CFLAGS="-mabi=n32"
726		LDFLAGS="-mabi=n32"
727	    else
728		case $system in
729		    IRIX-6.3)
730			# Use to build 6.2 compatible binaries on 6.3.
731			EXTRA_CFLAGS="-n32 -D_OLD_TERMIOS"
732			;;
733		    *)
734			EXTRA_CFLAGS="-n32"
735			;;
736		esac
737		LDFLAGS="-n32"
738	    fi
739	    ;;
740	IRIX64-6.*)
741	    SHLIB_CFLAGS=""
742	    SHLIB_LD="ld -32 -shared -rdata_shared"
743	    SHLIB_LD_LIBS='${LIBS}'
744	    SHLIB_SUFFIX=".so"
745	    DL_OBJS="tclLoadDl.o"
746	    DL_LIBS=""
747	    LDFLAGS=""
748	    LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
749	    ;;
750	Linux*)
751	    SHLIB_CFLAGS="-fPIC"
752	    SHLIB_LD_LIBS='${LIBS}'
753	    SHLIB_SUFFIX=".so"
754
755	    # egcs-2.91.66 on Redhat Linux 6.0 generates lots of warnings 
756	    # when you inline the string and math operations.  Turn this off to
757	    # get rid of the warnings.
758
759	    CFLAGS_OPTIMIZE="${CFLAGS_OPTIMIZE} -D__NO_STRING_INLINES -D__NO_MATH_INLINES"
760
761	    if test "$have_dl" = yes; then
762		SHLIB_LD="${CC} -shared"
763		DL_OBJS="tclLoadDl.o"
764		DL_LIBS="-ldl"
765		LDFLAGS="-rdynamic"
766		LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
767	    else
768		AC_CHECK_HEADER(dld.h, [
769		    SHLIB_LD="ld -shared"
770		    DL_OBJS="tclLoadDld.o"
771		    DL_LIBS="-ldld"
772		    LDFLAGS=""
773		    LD_SEARCH_FLAGS=""])
774	    fi
775	    if test "`uname -m`" = "alpha" ; then
776		EXTRA_CFLAGS="-mieee"
777	    fi
778	    ;;
779	MP-RAS-02*)
780	    SHLIB_CFLAGS="-K PIC"
781	    SHLIB_LD="cc -G"
782	    SHLIB_LD_LIBS=""
783	    SHLIB_SUFFIX=".so"
784	    DL_OBJS="tclLoadDl.o"
785	    DL_LIBS="-ldl"
786	    LDFLAGS=""
787	    LD_SEARCH_FLAGS=""
788	    ;;
789	MP-RAS-*)
790	    SHLIB_CFLAGS="-K PIC"
791	    SHLIB_LD="cc -G"
792	    SHLIB_LD_LIBS=""
793	    SHLIB_SUFFIX=".so"
794	    DL_OBJS="tclLoadDl.o"
795	    DL_LIBS="-ldl"
796	    LDFLAGS="-Wl,-Bexport"
797	    LD_SEARCH_FLAGS=""
798	    ;;
799	NetBSD-*|FreeBSD-[[12]].*|OpenBSD-*)
800	    # Not available on all versions:  check for include file.
801	    AC_CHECK_HEADER(dlfcn.h, [
802		SHLIB_CFLAGS="-fpic"
803		SHLIB_LD="ld -Bshareable -x"
804		SHLIB_LD_LIBS=""
805		SHLIB_SUFFIX=".so"
806		DL_OBJS="tclLoadDl.o"
807		DL_LIBS=""
808		LDFLAGS=""
809		LD_SEARCH_FLAGS=""
810		SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1.0'
811	    ], [
812		SHLIB_CFLAGS=""
813		SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r"
814		SHLIB_LD_LIBS='${LIBS}'
815		SHLIB_SUFFIX=".a"
816		DL_OBJS="tclLoadAout.o"
817		DL_LIBS=""
818		LDFLAGS=""
819		LD_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
820		SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a'
821	    ])
822
823	    # FreeBSD doesn't handle version numbers with dots.
824
825	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a'
826	    TCL_LIB_VERSIONS_OK=nodots
827	    ;;
828	FreeBSD-*)
829	    # FreeBSD 3.* and greater have ELF.
830	    SHLIB_CFLAGS="-fpic"
831	    SHLIB_LD="ld -Bshareable -x"
832	    SHLIB_LD_LIBS=""
833	    SHLIB_SUFFIX=".so"
834	    DL_OBJS="tclLoadDl.o"
835	    DL_LIBS=""
836	    LDFLAGS=""
837	    LD_SEARCH_FLAGS=""
838	    ;;
839	NEXTSTEP-*)
840	    SHLIB_CFLAGS=""
841	    SHLIB_LD="cc -nostdlib -r"
842	    SHLIB_LD_LIBS=""
843	    SHLIB_SUFFIX=".so"
844	    DL_OBJS="tclLoadNext.o"
845	    DL_LIBS=""
846	    LDFLAGS=""
847	    LD_SEARCH_FLAGS=""
848	    ;;
849	OS/390-*)
850	    CFLAGS_OPTIMIZE=""      # Optimizer is buggy
851	    AC_DEFINE(_OE_SOCKETS)  # needed in sys/socket.h
852	    ;;      
853	OSF1-1.0|OSF1-1.1|OSF1-1.2)
854	    # OSF/1 1.[012] from OSF, and derivatives, including Paragon OSF/1
855	    SHLIB_CFLAGS=""
856	    # Hack: make package name same as library name
857	    SHLIB_LD='ld -R -export $@:'
858	    SHLIB_LD_LIBS=""
859	    SHLIB_SUFFIX=".so"
860	    DL_OBJS="tclLoadOSF.o"
861	    DL_LIBS=""
862	    LDFLAGS=""
863	    LD_SEARCH_FLAGS=""
864	    ;;
865	OSF1-1.*)
866	    # OSF/1 1.3 from OSF using ELF, and derivatives, including AD2
867	    SHLIB_CFLAGS="-fpic"
868	    SHLIB_LD="ld -shared"
869	    SHLIB_LD_LIBS=""
870	    SHLIB_SUFFIX=".so"
871	    DL_OBJS="tclLoadDl.o"
872	    DL_LIBS=""
873	    LDFLAGS=""
874	    LD_SEARCH_FLAGS=""
875	    ;;
876	OSF1-V*)
877	    # Digital OSF/1
878	    SHLIB_CFLAGS=""
879	    SHLIB_LD='ld -shared -expect_unresolved "*"'
880	    SHLIB_LD_LIBS=""
881	    SHLIB_SUFFIX=".so"
882	    DL_OBJS="tclLoadDl.o"
883	    DL_LIBS=""
884	    LDFLAGS=""
885	    LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
886	    ;;
887	RISCos-*)
888	    SHLIB_CFLAGS="-G 0"
889	    SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0"
890	    SHLIB_LD_LIBS='${LIBS}'
891	    SHLIB_SUFFIX=".a"
892	    DL_OBJS="tclLoadAout.o"
893	    DL_LIBS=""
894	    LDFLAGS="-Wl,-D,08000000"
895	    LD_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
896	    ;;
897	SCO_SV-3.2*)
898	    # Note, dlopen is available only on SCO 3.2.5 and greater.  However,
899	    # this test works, since "uname -s" was non-standard in 3.2.4 and
900	    # below.
901	    SHLIB_CFLAGS="-Kpic -belf"
902	    SHLIB_LD="ld -G"
903	    SHLIB_LD_LIBS=""
904	    SHLIB_SUFFIX=".so"
905	    DL_OBJS="tclLoadDl.o"
906	    DL_LIBS=""
907	    LDFLAGS="-belf -Wl,-Bexport"
908	    LD_SEARCH_FLAGS=""
909	    ;;
910	SINIX*5.4*)
911	    SHLIB_CFLAGS="-K PIC"
912	    SHLIB_LD="cc -G"
913	    SHLIB_LD_LIBS=""
914	    SHLIB_SUFFIX=".so"
915	    DL_OBJS="tclLoadDl.o"
916	    DL_LIBS="-ldl"
917	    LDFLAGS=""
918	    LD_SEARCH_FLAGS=""
919	    ;;
920	SunOS-4*)
921	    SHLIB_CFLAGS="-PIC"
922	    SHLIB_LD="ld"
923	    SHLIB_LD_LIBS=""
924	    SHLIB_SUFFIX=".so"
925	    DL_OBJS="tclLoadDl.o"
926	    DL_LIBS="-ldl"
927	    LDFLAGS=""
928	    LD_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
929
930	    # SunOS can't handle version numbers with dots in them in library
931	    # specs, like -ltcl7.5, so use -ltcl75 instead.  Also, it
932	    # requires an extra version number at the end of .so file names.
933	    # So, the library has to have a name like libtcl75.so.1.0
934
935	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1.0'
936	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a'
937	    TCL_LIB_VERSIONS_OK=nodots
938	    ;;
939	SunOS-5.[[0-6]]*)
940	    SHLIB_CFLAGS="-KPIC"
941	    SHLIB_LD="/usr/ccs/bin/ld -G -z text"
942
943	    # Note: need the LIBS below, otherwise Tk won't find Tcl's
944	    # symbols when dynamically loaded into tclsh.
945
946	    SHLIB_LD_LIBS='${LIBS}'
947	    SHLIB_SUFFIX=".so"
948	    DL_OBJS="tclLoadDl.o"
949	    DL_LIBS="-ldl"
950	    LDFLAGS=""
951	    LD_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
952	    ;;
953	SunOS-5*)
954	    SHLIB_CFLAGS="-KPIC"
955	    SHLIB_LD="/usr/ccs/bin/ld -G -z text"
956	    LDFLAGS=""
957    
958	    do64bit_ok=no
959	    if test "$do64bit" = "yes" ; then
960	    arch=`isainfo`
961	    if test "$arch" = "sparcv9 sparc" ; then
962		if test "$CC" != "gcc" -a `$CC -v 2>&1 | grep -c gcc` = "0" ; then
963		do64bit_ok=yes
964		EXTRA_CFLAGS="-xarch=v9"
965		LDFLAGS="-xarch=v9"
966		else 
967		AC_MSG_WARN("64bit mode not supported using GCC on $system")
968		fi
969	    else
970		AC_MSG_WARN("64bit mode only supported sparcv9 system")
971	    fi
972	    fi
973	    
974	    # Note: need the LIBS below, otherwise Tk won't find Tcl's
975	    # symbols when dynamically loaded into tclsh.
976
977	    SHLIB_LD_LIBS='${LIBS}'
978	    SHLIB_SUFFIX=".so"
979	    DL_OBJS="tclLoadDl.o"
980	    DL_LIBS="-ldl"
981	    if test "$CC" = "gcc" -o `$CC -v 2>&1 | grep -c gcc` != "0" ; then
982		LD_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
983	    else
984		LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}'
985	    fi
986	    ;;
987	ULTRIX-4.*)
988	    SHLIB_CFLAGS="-G 0"
989	    SHLIB_SUFFIX=".a"
990	    SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r -G 0"
991	    SHLIB_LD_LIBS='${LIBS}'
992	    DL_OBJS="tclLoadAout.o"
993	    DL_LIBS=""
994	    LDFLAGS="-Wl,-D,08000000"
995	    LD_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
996	    ;;
997	UNIX_SV* | UnixWare-5*)
998	    SHLIB_CFLAGS="-KPIC"
999	    SHLIB_LD="cc -G"
1000	    SHLIB_LD_LIBS=""
1001	    SHLIB_SUFFIX=".so"
1002	    DL_OBJS="tclLoadDl.o"
1003	    DL_LIBS="-ldl"
1004	    # Some UNIX_SV* systems (unixware 1.1.2 for example) have linkers
1005	    # that don't grok the -Bexport option.  Test that it does.
1006	    hold_ldflags=$LDFLAGS
1007	    AC_MSG_CHECKING(for ld accepts -Bexport flag)
1008	    LDFLAGS="${LDFLAGS} -Wl,-Bexport"
1009	    AC_TRY_LINK(, [int i;], found=yes, found=no)
1010	    LDFLAGS=$hold_ldflags
1011	    AC_MSG_RESULT($found)
1012	    if test $found = yes; then
1013	    LDFLAGS="-Wl,-Bexport"
1014	    else
1015	    LDFLAGS=""
1016	    fi
1017	    LD_SEARCH_FLAGS=""
1018	    ;;
1019    esac
1020
1021    if test "$do64bit" = "yes" -a "$do64bit_ok" = "no" ; then
1022    AC_MSG_WARN("64bit support being disabled -- not supported on this platform")
1023    fi
1024
1025    # Step 4: If pseudo-static linking is in use (see K. B. Kenny, "Dynamic
1026    # Loading for Tcl -- What Became of It?".  Proc. 2nd Tcl/Tk Workshop,
1027    # New Orleans, LA, Computerized Processes Unlimited, 1994), then we need
1028    # to determine which of several header files defines the a.out file
1029    # format (a.out.h, sys/exec.h, or sys/exec_aout.h).  At present, we
1030    # support only a file format that is more or less version-7-compatible. 
1031    # In particular,
1032    #	- a.out files must begin with `struct exec'.
1033    #	- the N_TXTOFF on the `struct exec' must compute the seek address
1034    #	  of the text segment
1035    #	- The `struct exec' must contain a_magic, a_text, a_data, a_bss
1036    #	  and a_entry fields.
1037    # The following compilation should succeed if and only if either sys/exec.h
1038    # or a.out.h is usable for the purpose.
1039    #
1040    # Note that the modified COFF format used on MIPS Ultrix 4.x is usable; the
1041    # `struct exec' includes a second header that contains information that
1042    # duplicates the v7 fields that are needed.
1043
1044    if test "x$DL_OBJS" = "xtclLoadAout.o" ; then
1045	AC_MSG_CHECKING(sys/exec.h)
1046	AC_TRY_COMPILE([#include <sys/exec.h>],[
1047	    struct exec foo;
1048	    unsigned long seek;
1049	    int flag;
1050#if defined(__mips) || defined(mips)
1051	    seek = N_TXTOFF (foo.ex_f, foo.ex_o);
1052#else
1053	    seek = N_TXTOFF (foo);
1054#endif
1055	    flag = (foo.a_magic == OMAGIC);
1056	    return foo.a_text + foo.a_data + foo.a_bss + foo.a_entry;
1057    ], tcl_ok=usable, tcl_ok=unusable)
1058	AC_MSG_RESULT($tcl_ok)
1059	if test $tcl_ok = usable; then
1060	    AC_DEFINE(USE_SYS_EXEC_H)
1061	else
1062	    AC_MSG_CHECKING(a.out.h)
1063	    AC_TRY_COMPILE([#include <a.out.h>],[
1064		struct exec foo;
1065		unsigned long seek;
1066		int flag;
1067#if defined(__mips) || defined(mips)
1068		seek = N_TXTOFF (foo.ex_f, foo.ex_o);
1069#else
1070		seek = N_TXTOFF (foo);
1071#endif
1072		flag = (foo.a_magic == OMAGIC);
1073		return foo.a_text + foo.a_data + foo.a_bss + foo.a_entry;
1074	    ], tcl_ok=usable, tcl_ok=unusable)
1075	    AC_MSG_RESULT($tcl_ok)
1076	    if test $tcl_ok = usable; then
1077		AC_DEFINE(USE_A_OUT_H)
1078	    else
1079		AC_MSG_CHECKING(sys/exec_aout.h)
1080		AC_TRY_COMPILE([#include <sys/exec_aout.h>],[
1081		    struct exec foo;
1082		    unsigned long seek;
1083		    int flag;
1084#if defined(__mips) || defined(mips)
1085		    seek = N_TXTOFF (foo.ex_f, foo.ex_o);
1086#else
1087		    seek = N_TXTOFF (foo);
1088#endif
1089		    flag = (foo.a_midmag == OMAGIC);
1090		    return foo.a_text + foo.a_data + foo.a_bss + foo.a_entry;
1091		], tcl_ok=usable, tcl_ok=unusable)
1092		AC_MSG_RESULT($tcl_ok)
1093		if test $tcl_ok = usable; then
1094		    AC_DEFINE(USE_SYS_EXEC_AOUT_H)
1095		else
1096		    DL_OBJS=""
1097		fi
1098	    fi
1099	fi
1100    fi
1101
1102    # Step 5: disable dynamic loading if requested via a command-line switch.
1103
1104    AC_ARG_ENABLE(load, [  --disable-load          disallow dynamic loading and "load" command],
1105	[tcl_ok=$enableval], [tcl_ok=yes])
1106    if test "$tcl_ok" = "no"; then
1107	DL_OBJS=""
1108    fi
1109
1110    if test "x$DL_OBJS" != "x" ; then
1111	BUILD_DLTEST="\$(DLTEST_TARGETS)"
1112    else
1113	echo "Can't figure out how to do dynamic loading or shared libraries"
1114	echo "on this system."
1115	SHLIB_CFLAGS=""
1116	SHLIB_LD=""
1117	SHLIB_SUFFIX=""
1118	DL_OBJS="tclLoadNone.o"
1119	DL_LIBS=""
1120	LDFLAGS=""
1121	LD_SEARCH_FLAGS=""
1122	BUILD_DLTEST=""
1123    fi
1124
1125    # If we're running gcc, then change the C flags for compiling shared
1126    # libraries to the right flags for gcc, instead of those for the
1127    # standard manufacturer compiler.
1128
1129    if test "$DL_OBJS" != "tclLoadNone.o" ; then
1130	if test "$CC" = "gcc" -o `$CC -v 2>&1 | grep -c gcc` != "0" ; then
1131	    case $system in
1132		AIX-*)
1133		    ;;
1134		BSD/OS*)
1135		    ;;
1136		IRIX*)
1137		    ;;
1138		NetBSD-*|FreeBSD-*|OpenBSD-*)
1139		    ;;
1140		RISCos-*)
1141		    ;;
1142		ULTRIX-4.*)
1143		    ;;
1144		*)
1145		    SHLIB_CFLAGS="-fPIC"
1146		    ;;
1147	    esac
1148	fi
1149    fi
1150
1151    if test "$SHARED_LIB_SUFFIX" = "" ; then
1152	SHARED_LIB_SUFFIX='${VERSION}\$\{DBGX\}${SHLIB_SUFFIX}'
1153    fi
1154    if test "$UNSHARED_LIB_SUFFIX" = "" ; then
1155	UNSHARED_LIB_SUFFIX='${VERSION}\$\{DBGX\}.a'
1156    fi
1157
1158    AC_SUBST(STLIB_LD)
1159    AC_SUBST(SHLIB_LD)
1160    AC_SUBST(SHLIB_CFLAGS)
1161    AC_SUBST(SHLIB_LDFLAGS)
1162    AC_SUBST(DL_LIBS)
1163    AC_SUBST(CFLAGS_DEBUG)
1164    AC_SUBST(CFLAGS_OPTIMIZE)
1165    AC_SUBST(LDFLAGS_DEBUG)
1166    AC_SUBST(LDFLAGS_OPTIMIZE)
1167])
1168
1169#--------------------------------------------------------------------
1170# SC_SERIAL_PORT
1171#
1172#	Determine which interface to use to talk to the serial port.
1173#	Note that #include lines must begin in leftmost column for
1174#	some compilers to recognize them as preprocessor directives.
1175#
1176# Arguments:
1177#	none
1178#	
1179# Results:
1180#
1181#	Defines only one of the following vars:
1182#		USE_TERMIOS
1183#		USE_TERMIO
1184#		USE_SGTTY
1185#
1186#--------------------------------------------------------------------
1187
1188AC_DEFUN(SC_SERIAL_PORT, [
1189    AC_MSG_CHECKING([termios vs. termio vs. sgtty])
1190
1191    AC_TRY_RUN([
1192#include <termios.h>
1193
1194main()
1195{
1196    struct termios t;
1197    if (tcgetattr(0, &t) == 0) {
1198	cfsetospeed(&t, 0);
1199	t.c_cflag |= PARENB | PARODD | CSIZE | CSTOPB;
1200	return 0;
1201    }
1202    return 1;
1203}], tk_ok=termios, tk_ok=no, tk_ok=no)
1204
1205    if test $tk_ok = termios; then
1206	AC_DEFINE(USE_TERMIOS)
1207    else
1208	AC_TRY_RUN([
1209#include <termio.h>
1210
1211main()
1212{
1213    struct termio t;
1214    if (ioctl(0, TCGETA, &t) == 0) {
1215	t.c_cflag |= CBAUD | PARENB | PARODD | CSIZE | CSTOPB;
1216	return 0;
1217    }
1218    return 1;
1219    }], tk_ok=termio, tk_ok=no, tk_ok=no)
1220
1221    if test $tk_ok = termio; then
1222	AC_DEFINE(USE_TERMIO)
1223    else
1224	AC_TRY_RUN([
1225#include <sgtty.h>
1226
1227main()
1228{
1229    struct sgttyb t;
1230    if (ioctl(0, TIOCGETP, &t) == 0) {
1231	t.sg_ospeed = 0;
1232	t.sg_flags |= ODDP | EVENP | RAW;
1233	return 0;
1234    }
1235    return 1;
1236}], tk_ok=sgtty, tk_ok=none, tk_ok=none)
1237    if test $tk_ok = sgtty; then
1238	AC_DEFINE(USE_SGTTY)
1239    fi
1240    fi
1241    fi
1242    AC_MSG_RESULT($tk_ok)
1243])
1244
1245#--------------------------------------------------------------------
1246# SC_MISSING_POSIX_HEADERS
1247#
1248#	Supply substitutes for missing POSIX header files.  Special
1249#	notes:
1250#	    - stdlib.h doesn't define strtol, strtoul, or
1251#	      strtod insome versions of SunOS
1252#	    - some versions of string.h don't declare procedures such
1253#	      as strstr
1254#
1255# Arguments:
1256#	none
1257#	
1258# Results:
1259#
1260#	Defines some of the following vars:
1261#		NO_DIRENT_H
1262#		NO_ERRNO_H
1263#		NO_VALUES_H
1264#		NO_LIMITS_H
1265#		NO_STDLIB_H
1266#		NO_STRING_H
1267#		NO_SYS_WAIT_H
1268#		NO_DLFCN_H
1269#		HAVE_UNISTD_H
1270#		HAVE_SYS_PARAM_H
1271#
1272#		HAVE_STRING_H ?
1273#
1274#--------------------------------------------------------------------
1275
1276AC_DEFUN(SC_MISSING_POSIX_HEADERS, [
1277
1278    AC_MSG_CHECKING(dirent.h)
1279    AC_TRY_LINK([#include <sys/types.h>
1280#include <dirent.h>], [
1281#ifndef _POSIX_SOURCE
1282#   ifdef __Lynx__
1283	/*
1284	 * Generate compilation error to make the test fail:  Lynx headers
1285	 * are only valid if really in the POSIX environment.
1286	 */
1287
1288	missing_procedure();
1289#   endif
1290#endif
1291DIR *d;
1292struct dirent *entryPtr;
1293char *p;
1294d = opendir("foobar");
1295entryPtr = readdir(d);
1296p = entryPtr->d_name;
1297closedir(d);
1298], tcl_ok=yes, tcl_ok=no)
1299
1300    if test $tcl_ok = no; then
1301	AC_DEFINE(NO_DIRENT_H)
1302    fi
1303
1304    AC_MSG_RESULT($tcl_ok)
1305    AC_CHECK_HEADER(errno.h, , AC_DEFINE(NO_ERRNO_H))
1306    AC_CHECK_HEADER(float.h, , AC_DEFINE(NO_FLOAT_H))
1307    AC_CHECK_HEADER(values.h, , AC_DEFINE(NO_VALUES_H))
1308    AC_CHECK_HEADER(limits.h, , AC_DEFINE(NO_LIMITS_H))
1309    AC_CHECK_HEADER(stdlib.h, tcl_ok=1, tcl_ok=0)
1310    AC_EGREP_HEADER(strtol, stdlib.h, , tcl_ok=0)
1311    AC_EGREP_HEADER(strtoul, stdlib.h, , tcl_ok=0)
1312    AC_EGREP_HEADER(strtod, stdlib.h, , tcl_ok=0)
1313    if test $tcl_ok = 0; then
1314	AC_DEFINE(NO_STDLIB_H)
1315    fi
1316    AC_CHECK_HEADER(string.h, tcl_ok=1, tcl_ok=0)
1317    AC_EGREP_HEADER(strstr, string.h, , tcl_ok=0)
1318    AC_EGREP_HEADER(strerror, string.h, , tcl_ok=0)
1319
1320    # See also memmove check below for a place where NO_STRING_H can be
1321    # set and why.
1322
1323    if test $tcl_ok = 0; then
1324	AC_DEFINE(NO_STRING_H)
1325    fi
1326
1327    AC_CHECK_HEADER(sys/wait.h, , AC_DEFINE(NO_SYS_WAIT_H))
1328    AC_CHECK_HEADER(dlfcn.h, , AC_DEFINE(NO_DLFCN_H))
1329
1330    # OS/390 lacks sys/param.h (and doesn't need it, by chance).
1331
1332    AC_HAVE_HEADERS(unistd.h sys/param.h)
1333
1334])
1335
1336#--------------------------------------------------------------------
1337# SC_PATH_X
1338#
1339#	Locate the X11 header files and the X11 library archive.  Try
1340#	the ac_path_x macro first, but if it doesn't find the X stuff
1341#	(e.g. because there's no xmkmf program) then check through
1342#	a list of possible directories.  Under some conditions the
1343#	autoconf macro will return an include directory that contains
1344#	no include files, so double-check its result just to be safe.
1345#
1346# Arguments:
1347#	none
1348#	
1349# Results:
1350#
1351#	Sets the the following vars:
1352#		XINCLUDES
1353#		XLIBSW
1354#
1355#--------------------------------------------------------------------
1356
1357AC_DEFUN(SC_PATH_X, [
1358    AC_PATH_X
1359    not_really_there=""
1360    if test "$no_x" = ""; then
1361	if test "$x_includes" = ""; then
1362	    AC_TRY_CPP([#include <X11/XIntrinsic.h>], , not_really_there="yes")
1363	else
1364	    if test ! -r $x_includes/X11/Intrinsic.h; then
1365		not_really_there="yes"
1366	    fi
1367	fi
1368    fi
1369    if test "$no_x" = "yes" -o "$not_really_there" = "yes"; then
1370	AC_MSG_CHECKING(for X11 header files)
1371	XINCLUDES="# no special path needed"
1372	AC_TRY_CPP([#include <X11/Intrinsic.h>], , XINCLUDES="nope")
1373	if test "$XINCLUDES" = nope; then
1374	    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"
1375	    for i in $dirs ; do
1376		if test -r $i/X11/Intrinsic.h; then
1377		    AC_MSG_RESULT($i)
1378		    XINCLUDES=" -I$i"
1379		    break
1380		fi
1381	    done
1382	fi
1383    else
1384	if test "$x_includes" != ""; then
1385	    XINCLUDES=-I$x_includes
1386	else
1387	    XINCLUDES="# no special path needed"
1388	fi
1389    fi
1390    if test "$XINCLUDES" = nope; then
1391	AC_MSG_RESULT(couldn't find any!)
1392	XINCLUDES="# no include files found"
1393    fi
1394
1395    if test "$no_x" = yes; then
1396	AC_MSG_CHECKING(for X11 libraries)
1397	XLIBSW=nope
1398	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"
1399	for i in $dirs ; do
1400	    if test -r $i/libX11.a -o -r $i/libX11.so -o -r $i/libX11.sl; then
1401		AC_MSG_RESULT($i)
1402		XLIBSW="-L$i -lX11"
1403		x_libraries="$i"
1404		break
1405	    fi
1406	done
1407    else
1408	if test "$x_libraries" = ""; then
1409	    XLIBSW=-lX11
1410	else
1411	    XLIBSW="-L$x_libraries -lX11"
1412	fi
1413    fi
1414    if test "$XLIBSW" = nope ; then
1415	AC_CHECK_LIB(Xwindow, XCreateWindow, XLIBSW=-lXwindow)
1416    fi
1417    if test "$XLIBSW" = nope ; then
1418	AC_MSG_RESULT(couldn't find any!  Using -lX11.)
1419	XLIBSW=-lX11
1420    fi
1421])
1422#--------------------------------------------------------------------
1423# SC_BLOCKING_STYLE
1424#
1425#	The statements below check for systems where POSIX-style
1426#	non-blocking I/O (O_NONBLOCK) doesn't work or is unimplemented. 
1427#	On these systems (mostly older ones), use the old BSD-style
1428#	FIONBIO approach instead.
1429#
1430# Arguments:
1431#	none
1432#	
1433# Results:
1434#
1435#	Defines some of the following vars:
1436#		HAVE_SYS_IOCTL_H
1437#		HAVE_SYS_FILIO_H
1438#		USE_FIONBIO
1439#		O_NONBLOCK
1440#
1441#--------------------------------------------------------------------
1442
1443AC_DEFUN(SC_BLOCKING_STYLE, [
1444    AC_CHECK_HEADERS(sys/ioctl.h)
1445    AC_CHECK_HEADERS(sys/filio.h)
1446    AC_MSG_CHECKING([FIONBIO vs. O_NONBLOCK for nonblocking I/O])
1447    if test -f /usr/lib/NextStep/software_version; then
1448	system=NEXTSTEP-`awk '/3/,/3/' /usr/lib/NextStep/software_version`
1449    else
1450	system=`uname -s`-`uname -r`
1451	if test "$?" -ne 0 ; then
1452	    system=unknown
1453	else
1454	    # Special check for weird MP-RAS system (uname returns weird
1455	    # results, and the version is kept in special file).
1456	
1457	    if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
1458		system=MP-RAS-`awk '{print $3}' /etc/.relid'`
1459	    fi
1460	    if test "`uname -s`" = "AIX" ; then
1461		system=AIX-`uname -v`.`uname -r`
1462	    fi
1463	fi
1464    fi
1465    case $system in
1466	# There used to be code here to use FIONBIO under AIX.  However, it
1467	# was reported that FIONBIO doesn't work under AIX 3.2.5.  Since
1468	# using O_NONBLOCK seems fine under AIX 4.*, I removed the FIONBIO
1469	# code (JO, 5/31/97).
1470
1471	OSF*)
1472	    AC_DEFINE(USE_FIONBIO)
1473	    AC_MSG_RESULT(FIONBIO)
1474	    ;;
1475	SunOS-4*)
1476	    AC_DEFINE(USE_FIONBIO)
1477	    AC_MSG_RESULT(FIONBIO)
1478	    ;;
1479	ULTRIX-4.*)
1480	    AC_DEFINE(USE_FIONBIO)
1481	    AC_MSG_RESULT(FIONBIO)
1482	    ;;
1483	*)
1484	    AC_MSG_RESULT(O_NONBLOCK)
1485	    ;;
1486    esac
1487])
1488
1489#--------------------------------------------------------------------
1490# SC_HAVE_VFORK
1491#
1492#	Check to see whether the system provides a vfork kernel call.
1493#	If not, then use fork instead.  Also, check for a problem with
1494#	vforks and signals that can cause core dumps if a vforked child
1495#	resets a signal handler.  If the problem exists, then use fork
1496#	instead of vfork.
1497#
1498# Arguments:
1499#	none
1500#	
1501# Results:
1502#
1503#	Defines some of the following vars:
1504#		vfork (=fork)
1505#
1506#--------------------------------------------------------------------
1507
1508AC_DEFUN(SC_HAVE_VFORK, [
1509    AC_TYPE_SIGNAL()
1510    AC_CHECK_FUNC(vfork, tcl_ok=1, tcl_ok=0)
1511    if test "$tcl_ok" = 1; then
1512	AC_MSG_CHECKING([vfork/signal bug]);
1513	AC_TRY_RUN([
1514#include <stdio.h>
1515#include <signal.h>
1516#include <sys/wait.h>
1517int gotSignal = 0;
1518sigProc(sig)
1519    int sig;
1520{
1521    gotSignal = 1;
1522}
1523main()
1524{
1525    int pid, sts;
1526    (void) signal(SIGCHLD, sigProc);
1527    pid = vfork();
1528    if (pid <  0) {
1529	exit(1);
1530    } else if (pid == 0) {
1531	(void) signal(SIGCHLD, SIG_DFL);
1532	_exit(0);
1533    } else {
1534	(void) wait(&sts);
1535    }
1536    exit((gotSignal) ? 0 : 1);
1537}], tcl_ok=1, tcl_ok=0, tcl_ok=0)
1538
1539	if test "$tcl_ok" = 1; then
1540	    AC_MSG_RESULT(ok)
1541	else
1542	    AC_MSG_RESULT([buggy, using fork instead])
1543	fi
1544    fi
1545    rm -f core
1546    if test "$tcl_ok" = 0; then
1547	AC_DEFINE(vfork, fork)
1548    fi
1549])
1550
1551#--------------------------------------------------------------------
1552# SC_TIME_HANLDER
1553#
1554#	Checks how the system deals with time.h, what time structures
1555#	are used on the system, and what fields the structures have.
1556#
1557# Arguments:
1558#	none
1559#	
1560# Results:
1561#
1562#	Defines some of the following vars:
1563#		USE_DELTA_FOR_TZ
1564#		HAVE_TM_GMTOFF
1565#		HAVE_TM_TZADJ
1566#		HAVE_TIMEZONE_VAR
1567#
1568#--------------------------------------------------------------------
1569
1570AC_DEFUN(SC_TIME_HANDLER, [
1571    AC_CHECK_HEADERS(sys/time.h)
1572    AC_HEADER_TIME
1573    AC_STRUCT_TIMEZONE
1574
1575    AC_MSG_CHECKING([tm_tzadj in struct tm])
1576    AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_tzadj;],
1577	    [AC_DEFINE(HAVE_TM_TZADJ)
1578	    AC_MSG_RESULT(yes)],
1579	    AC_MSG_RESULT(no))
1580
1581    AC_MSG_CHECKING([tm_gmtoff in struct tm])
1582    AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_gmtoff;],
1583	    [AC_DEFINE(HAVE_TM_GMTOFF)
1584	    AC_MSG_RESULT(yes)],
1585	    AC_MSG_RESULT(no))
1586
1587    #
1588    # Its important to include time.h in this check, as some systems
1589    # (like convex) have timezone functions, etc.
1590    #
1591    have_timezone=no
1592    AC_MSG_CHECKING([long timezone variable])
1593    AC_TRY_COMPILE([#include <time.h>],
1594	    [extern long timezone;
1595	    timezone += 1;
1596	    exit (0);],
1597	    [have_timezone=yes
1598	    AC_DEFINE(HAVE_TIMEZONE_VAR)
1599	    AC_MSG_RESULT(yes)],
1600	    AC_MSG_RESULT(no))
1601
1602    #
1603    # On some systems (eg IRIX 6.2), timezone is a time_t and not a long.
1604    #
1605    if test "$have_timezone" = no; then
1606    AC_MSG_CHECKING([time_t timezone variable])
1607    AC_TRY_COMPILE([#include <time.h>],
1608	    [extern time_t timezone;
1609	    timezone += 1;
1610	    exit (0);],
1611	    [AC_DEFINE(HAVE_TIMEZONE_VAR)
1612	    AC_MSG_RESULT(yes)],
1613	    AC_MSG_RESULT(no))
1614    fi
1615
1616    #
1617    # AIX does not have a timezone field in struct tm. When the AIX bsd
1618    # library is used, the timezone global and the gettimeofday methods are
1619    # to be avoided for timezone deduction instead, we deduce the timezone
1620    # by comparing the localtime result on a known GMT value.
1621    #
1622
1623    if test "`uname -s`" = "AIX" ; then
1624	AC_CHECK_LIB(bsd, gettimeofday, libbsd=yes)
1625	if test $libbsd = yes; then
1626	    AC_DEFINE(USE_DELTA_FOR_TZ)
1627	fi
1628    fi
1629])
1630
1631#--------------------------------------------------------------------
1632# SC_BUGGY_STRTOD
1633#
1634#	Under Solaris 2.4, strtod returns the wrong value for the
1635#	terminating character under some conditions.  Check for this
1636#	and if the problem exists use a substitute procedure
1637#	"fixstrtod" (provided by Tcl) that corrects the error.
1638#
1639# Arguments:
1640#	none
1641#	
1642# Results:
1643#
1644#	Might defines some of the following vars:
1645#		strtod (=fixstrtod)
1646#
1647#--------------------------------------------------------------------
1648
1649AC_DEFUN(SC_BUGGY_STRTOD, [
1650    AC_CHECK_FUNC(strtod, tk_strtod=1, tk_strtod=0)
1651    if test "$tk_strtod" = 1; then
1652	AC_MSG_CHECKING([for Solaris 2.4 strtod bug])
1653	AC_TRY_RUN([
1654	    extern double strtod();
1655	    int main()
1656	    {
1657		char *string = "NaN";
1658		char *term;
1659		strtod(string, &term);
1660		if ((term != string) && (term[-1] == 0)) {
1661		    exit(1);
1662		}
1663		exit(0);
1664	    }], tk_ok=1, tk_ok=0, tk_ok=0)
1665	if test "$tk_ok" = 1; then
1666	    AC_MSG_RESULT(ok)
1667	else
1668	    AC_MSG_RESULT(buggy)
1669	    AC_DEFINE(strtod, fixstrtod)
1670	fi
1671    fi
1672])
1673
1674#--------------------------------------------------------------------
1675# SC_TCL_LINK_LIBS
1676#
1677#	Search for the libraries needed to link the Tcl shell.
1678#	Things like the math library (-lm) and socket stuff (-lsocket vs.
1679#	-lnsl) are dealt with here.
1680#
1681# Arguments:
1682#	Requires the following vars to be set in the Makefile:
1683#		DL_LIBS
1684#		LIBS
1685#		MATH_LIBS
1686#	
1687# Results:
1688#
1689#	Subst's the following var:
1690#		TCL_LIBS
1691#		MATH_LIBS
1692#
1693#	Might append to the following vars:
1694#		LIBS
1695#
1696#	Might define the following vars:
1697#		HAVE_NET_ERRNO_H
1698#
1699#--------------------------------------------------------------------
1700
1701AC_DEFUN(SC_TCL_LINK_LIBS, [
1702    #--------------------------------------------------------------------
1703    # On a few very rare systems, all of the libm.a stuff is
1704    # already in libc.a.  Set compiler flags accordingly.
1705    # Also, Linux requires the "ieee" library for math to work
1706    # right (and it must appear before "-lm").
1707    #--------------------------------------------------------------------
1708
1709    AC_CHECK_FUNC(sin, MATH_LIBS="", MATH_LIBS="-lm")
1710    AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"])
1711
1712    #--------------------------------------------------------------------
1713    # On AIX systems, libbsd.a has to be linked in to support
1714    # non-blocking file IO.  This library has to be linked in after
1715    # the MATH_LIBS or it breaks the pow() function.  The way to
1716    # insure proper sequencing, is to add it to the tail of MATH_LIBS.
1717    # This library also supplies gettimeofday.
1718    #--------------------------------------------------------------------
1719
1720    libbsd=no
1721    if test "`uname -s`" = "AIX" ; then
1722	AC_CHECK_LIB(bsd, gettimeofday, libbsd=yes)
1723	if test $libbsd = yes; then
1724	    MATH_LIBS="$MATH_LIBS -lbsd"
1725	fi
1726    fi
1727
1728
1729    #--------------------------------------------------------------------
1730    # Interactive UNIX requires -linet instead of -lsocket, plus it
1731    # needs net/errno.h to define the socket-related error codes.
1732    #--------------------------------------------------------------------
1733
1734    AC_CHECK_LIB(inet, main, [LIBS="$LIBS -linet"])
1735    AC_CHECK_HEADER(net/errno.h, AC_DEFINE(HAVE_NET_ERRNO_H))
1736
1737    #--------------------------------------------------------------------
1738    #	Check for the existence of the -lsocket and -lnsl libraries.
1739    #	The order here is important, so that they end up in the right
1740    #	order in the command line generated by make.  Here are some
1741    #	special considerations:
1742    #	1. Use "connect" and "accept" to check for -lsocket, and
1743    #	   "gethostbyname" to check for -lnsl.
1744    #	2. Use each function name only once:  can't redo a check because
1745    #	   autoconf caches the results of the last check and won't redo it.
1746    #	3. Use -lnsl and -lsocket only if they supply procedures that
1747    #	   aren't already present in the normal libraries.  This is because
1748    #	   IRIX 5.2 has libraries, but they aren't needed and they're
1749    #	   bogus:  they goof up name resolution if used.
1750    #	4. On some SVR4 systems, can't use -lsocket without -lnsl too.
1751    #	   To get around this problem, check for both libraries together
1752    #	   if -lsocket doesn't work by itself.
1753    #--------------------------------------------------------------------
1754
1755    tcl_checkBoth=0
1756    AC_CHECK_FUNC(connect, tcl_checkSocket=0, tcl_checkSocket=1)
1757    if test "$tcl_checkSocket" = 1; then
1758	AC_CHECK_LIB(socket, main, LIBS="$LIBS -lsocket", tcl_checkBoth=1)
1759    fi
1760    if test "$tcl_checkBoth" = 1; then
1761	tk_oldLibs=$LIBS
1762	LIBS="$LIBS -lsocket -lnsl"
1763	AC_CHECK_FUNC(accept, tcl_checkNsl=0, [LIBS=$tk_oldLibs])
1764    fi
1765    AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main,
1766	    [LIBS="$LIBS -lnsl"]))
1767    
1768    # Don't perform the eval of the libraries here because DL_LIBS
1769    # won't be set until we call SC_CONFIG_CFLAGS
1770
1771    TCL_LIBS='${DL_LIBS} ${LIBS} ${MATH_LIBS}'
1772    AC_SUBST(TCL_LIBS)
1773    AC_SUBST(MATH_LIBS)
1774])
1775
1776#------------------------------------------------------------------------
1777# SC_MAKE_LIB --
1778#
1779#	Generate a line that can be used to build a shared/unshared library
1780#	in a platform independent manner.
1781#
1782# Arguments:
1783#	none
1784#
1785#	Requires:
1786#
1787# Results:
1788#
1789#	Defines the following vars:
1790#		MAKE_LIB	Makefile rule for building a library
1791#		MAKE_SHARED_LIB	Makefile rule for building a shared library
1792#		MAKE_UNSHARED_LIB	Makefile rule for building a static
1793#				library
1794#------------------------------------------------------------------------
1795
1796AC_DEFUN(SC_MAKE_LIB, [
1797    case "`uname -s`" in
1798	*win32* | *WIN32* | *CYGWIN_NT* |*CYGWIN_98*|*CYGWIN_95*)
1799	    if test "${CC-cc}" = "cl"; then
1800		MAKE_STATIC_LIB="\${STLIB_LD} -out:\[$]@ \$(\[$]@_OBJECTS) "
1801		MAKE_SHARED_LIB="\${SHLIB_LD} \${SHLIB_LDFLAGS} \${SHLIB_LD_LIBS} \$(LDFLAGS) -out:\[$]@ \$(\[$]@_OBJECTS) "
1802	    fi
1803	    ;;
1804	*)
1805	    MAKE_STATIC_LIB="\${STLIB_LD} \[$]@ \$(\[$]@_OBJECTS)"
1806	    MAKE_SHARED_LIB="\${SHLIB_LD} -o \[$]@ \$(\[$]@_OBJECTS) \${SHLIB_LDFLAGS} \${SHLIB_LD_LIBS}"
1807	    ;;
1808    esac
1809
1810    if test "${SHARED_BUILD}" = "1" ; then
1811	MAKE_LIB=${MAKE_SHARED_LIB}
1812    else
1813	MAKE_LIB=${MAKE_STATIC_LIB}
1814    fi
1815
1816    AC_SUBST(MAKE_LIB)
1817    AC_SUBST(MAKE_SHARED_LIB)
1818    AC_SUBST(MAKE_STATIC_LIB)
1819])
1820
1821#------------------------------------------------------------------------
1822# SC_LIB_SPEC --
1823#
1824#	Compute the name of an existing object library located in libdir
1825#	from the given base name and produce the appropriate linker flags.
1826#
1827# Arguments:
1828#	basename	The base name of the library without version
1829#			numbers, extensions, or "lib" prefixes.
1830#	extra_dir	Extra directory in which to search for the
1831#			library.  This location is used first, then
1832#			$prefix/$exec-prefix, then some defaults.
1833#
1834# Requires:
1835#	CYGPATH		command used to generate native style paths
1836#
1837# Results:
1838#
1839#	Defines the following vars:
1840#		${basename}_LIB_NAME	The computed library name.
1841#		${basename}_LIB_SPEC	The computed linker flags.
1842#------------------------------------------------------------------------
1843
1844AC_DEFUN(SC_LIB_SPEC, [
1845    AC_MSG_CHECKING(for $1 library)
1846
1847    # Look in exec-prefix and prefix for the library.  If neither of
1848    # these were specified, look in libdir.  It doesn't matter if libdir
1849    # wasn't specified since a search in the unspecified directory will
1850    # fail (NONE/lib)
1851
1852    if test x"${exec_prefix}" != x"NONE" ; then
1853	sc_lib_name_dir="${exec_prefix}/lib"
1854    elif test x"${prefix}" != "NONE" ; then
1855	sc_lib_name_dir="${prefix}/lib"
1856    else
1857	eval "sc_lib_name_dir=${libdir}"
1858    fi
1859
1860    if test x"$2" != x ; then
1861	sc_extra_lib_dir=$2
1862    else
1863	sc_extra_lib_dir=NONE
1864    fi
1865
1866    for i in \
1867	    `ls -dr ${sc_extra_lib_dir}/$1[[0-9]]*.lib 2>/dev/null ` \
1868	    `ls -dr ${sc_extra_lib_dir}/$1.lib 2>/dev/null ` \
1869	    `ls -dr ${sc_extra_lib_dir}/lib$1[[0-9]]* 2>/dev/null ` \
1870	    `ls -dr ${sc_extra_lib_dir}/lib$1.* 2>/dev/null ` \
1871	    `ls -dr ${sc_lib_name_dir}/$1[[0-9]]*.lib 2>/dev/null ` \
1872	    `ls -dr ${sc_lib_name_dir}/$1.lib 2>/dev/null ` \
1873	    `ls -dr ${sc_lib_name_dir}/lib$1[[0-9]]* 2>/dev/null ` \
1874	    `ls -dr ${sc_lib_name_dir}/lib$1.* 2>/dev/null ` \
1875	    `ls -dr /usr/lib/$1[[0-9]]*.lib 2>/dev/null ` \
1876	    `ls -dr /usr/lib/$1.lib 2>/dev/null ` \
1877	    `ls -dr /usr/lib/lib$1[[0-9]]* 2>/dev/null ` \
1878	    `ls -dr /usr/lib/lib$1.* 2>/dev/null ` \
1879	    `ls -dr /usr/local/lib/$1[[0-9]]*.lib 2>/dev/null ` \
1880	    `ls -dr /usr/local/lib/$1.lib 2>/dev/null ` \
1881	    `ls -dr /usr/local/lib/lib$1[[0-9]]* 2>/dev/null ` \
1882	    `ls -dr /usr/local/lib/lib$1.* 2>/dev/null ` ; do
1883	if test -f "$i" ; then
1884
1885	    sc_lib_name_dir=`dirname $i`
1886	    $1_LIB_NAME=`basename $i`
1887	    $1_LIB_PATH_NAME=$i
1888	    break
1889	fi
1890    done
1891
1892    case "`uname -s`" in
1893	*win32* | *WIN32* | *CYGWIN_NT* |*CYGWIN_98*|*CYGWIN_95*)
1894	    $1_LIB_SPEC=\"`${CYGPATH} ${$1_LIB_PATH_NAME}`\"
1895	    ;;
1896	*)
1897	    # Strip off the leading "lib" and trailing ".a" or ".so"
1898
1899	    sc_lib_name_lib=`echo ${$1_LIB_NAME}|sed -e 's/^lib//' -e 's/\.[[^.]]*$//' -e 's/\.so.*//'`
1900	    $1_LIB_SPEC="-L${sc_lib_name_dir} -l${sc_lib_name_lib}"
1901	    ;;
1902    esac
1903
1904    if test "x${$1_LIB_NAME}" = x ; then
1905	AC_MSG_ERROR(not found)
1906    else
1907	AC_MSG_RESULT(${$1_LIB_SPEC})
1908    fi
1909])
1910
1911#------------------------------------------------------------------------
1912# SC_PRIVATE_TCL_HEADERS --
1913#
1914#	Locate the private Tcl include files
1915#
1916# Arguments:
1917#
1918#	Requires:
1919#		TCL_SRC_DIR	Assumes that SC_LOAD_TCLCONFIG has
1920#				 already been called.
1921#
1922# Results:
1923#
1924#	Substs the following vars:
1925#		TCL_TOP_DIR_NATIVE
1926#		TCL_GENERIC_DIR_NATIVE
1927#		TCL_UNIX_DIR_NATIVE
1928#		TCL_WIN_DIR_NATIVE
1929#		TCL_BMAP_DIR_NATIVE
1930#		TCL_TOOL_DIR_NATIVE
1931#		TCL_PLATFORM_DIR_NATIVE
1932#		TCL_BIN_DIR_NATIVE
1933#		TCL_INCLUDES
1934#------------------------------------------------------------------------
1935
1936AC_DEFUN(SC_PRIVATE_TCL_HEADERS, [
1937    AC_MSG_CHECKING(for Tcl private include files)
1938
1939    case "`uname -s`" in
1940	*win32* | *WIN32* | *CYGWIN_NT* |*CYGWIN_98*|*CYGWIN_95*)
1941	    TCL_TOP_DIR_NATIVE=\"`${CYGPATH} ${TCL_SRC_DIR}`\"
1942	    TCL_GENERIC_DIR_NATIVE=\"`${CYGPATH} ${TCL_SRC_DIR}/generic`\"
1943	    TCL_UNIX_DIR_NATIVE=\"`${CYGPATH} ${TCL_SRC_DIR}/unix`\"
1944	    TCL_WIN_DIR_NATIVE=\"`${CYGPATH} ${TCL_SRC_DIR}/win`\"
1945	    TCL_BMAP_DIR_NATIVE=\"`${CYGPATH} ${TCL_SRC_DIR}/bitmaps`\"
1946	    TCL_TOOL_DIR_NATIVE=\"`${CYGPATH} ${TCL_SRC_DIR}/tools`\"
1947	    TCL_COMPAT_DIR_NATIVE=\"`${CYGPATH} ${TCL_SRC_DIR}/compat`\"
1948	    TCL_PLATFORM_DIR_NATIVE=${TCL_WIN_DIR_NATIVE}
1949	;;
1950	*)
1951	    TCL_TOP_DIR_NATIVE='$(TCL_SRC_DIR)'
1952	    TCL_GENERIC_DIR_NATIVE='$(TCL_TOP_DIR_NATIVE)/generic'
1953	    TCL_UNIX_DIR_NATIVE='$(TCL_TOP_DIR_NATIVE)/unix'
1954	    TCL_WIN_DIR_NATIVE='$(TCL_TOP_DIR_NATIVE)/win'
1955	    TCL_BMAP_DIR_NATIVE='$(TCL_TOP_DIR_NATIVE)/bitmaps'
1956	    TCL_TOOL_DIR_NATIVE='$(TCL_TOP_DIR_NATIVE)/tools'
1957	    TCL_COMPAT_DIR_NATIVE='$(TCL_TOP_DIR_NATIVE)/compat'
1958	    TCL_PLATFORM_DIR_NATIVE=${TCL_UNIX_DIR_NATIVE}
1959	;;
1960    esac
1961
1962    AC_SUBST(TCL_TOP_DIR_NATIVE)
1963    AC_SUBST(TCL_GENERIC_DIR_NATIVE)
1964    AC_SUBST(TCL_UNIX_DIR_NATIVE)
1965    AC_SUBST(TCL_WIN_DIR_NATIVE)
1966    AC_SUBST(TCL_BMAP_DIR_NATIVE)
1967    AC_SUBST(TCL_TOOL_DIR_NATIVE)
1968    AC_SUBST(TCL_PLATFORM_DIR_NATIVE)
1969
1970    TCL_INCLUDES="-I${TCL_GENERIC_DIR_NATIVE} -I${TCL_PLATFORM_DIR_NATIVE}"
1971    AC_SUBST(TCL_INCLUDES)
1972    AC_MSG_RESULT(Using srcdir found in tclConfig.sh)
1973])
1974
1975#------------------------------------------------------------------------
1976# SC_PUBLIC_TCL_HEADERS --
1977#
1978#	Locate the installed public Tcl header files
1979#
1980# Arguments:
1981#	None.
1982#
1983# Requires:
1984#	CYGPATH must be set
1985#
1986# Results:
1987#
1988#	Adds a --with-tclinclude switch to configure.
1989#	Result is cached.
1990#
1991#	Substs the following vars:
1992#		TCL_INCLUDES
1993#------------------------------------------------------------------------
1994
1995AC_DEFUN(SC_PUBLIC_TCL_HEADERS, [
1996    AC_MSG_CHECKING(for Tcl public headers)
1997
1998    AC_ARG_WITH(tclinclude, [ --with-tclinclude      directory containing the public Tcl header files.], with_tclinclude=${withval})
1999
2000    if test x"${with_tclinclude}" != x ; then
2001	if test -f "${with_tclinclude}/tcl.h" ; then
2002	    ac_cv_c_tclh=${with_tclinclude}
2003	else
2004	    AC_MSG_ERROR([${with_tclinclude} directory does not contain Tcl public header file tcl.h])
2005	fi
2006    else
2007	AC_CACHE_VAL(ac_cv_c_tclh, [
2008	    # Use the value from --with-tclinclude, if it was given
2009
2010	    if test x"${with_tclinclude}" != x ; then
2011		ac_cv_c_tclh=${with_tclinclude}
2012	    else
2013		# Check in the includedir, if --prefix was specified
2014
2015		eval "temp_includedir=${includedir}"
2016		for i in \
2017			`ls -d ${TCL_PREFIX}/include 2>/dev/null` \
2018			`ls -d ${temp_includedir} 2>/dev/null` \
2019			`ls -d ${TCL_BIN_DIR}/../include 2>/dev/null` \
2020			/usr/local/include /usr/include ; do
2021		    if test -f "$i/tcl.h" ; then
2022			ac_cv_c_tclh=$i
2023			break
2024		    fi
2025		done
2026	    fi
2027	])
2028    fi
2029
2030    # Print a message based on how we determined the include path
2031
2032    if test x"${ac_cv_c_tclh}" = x ; then
2033	AC_MSG_ERROR(tcl.h not found.  Please specify its location with --with-tclinclude)
2034    else
2035	AC_MSG_RESULT(${ac_cv_c_tclh})
2036    fi
2037
2038    # Convert to a native path and substitute into the output files.
2039
2040    INCLUDE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tclh}`
2041
2042    TCL_INCLUDES=-I\"${INCLUDE_DIR_NATIVE}\"
2043
2044    AC_SUBST(TCL_INCLUDES)
2045])
2046
2047#------------------------------------------------------------------------
2048# SC_PRIVATE_TK_HEADERS --
2049#
2050#	Locate the private Tk include files
2051#
2052# Arguments:
2053#
2054#	Requires:
2055#		TK_SRC_DIR	Assumes that SC_LOAD_TKCONFIG has
2056#				 already been called.
2057#
2058# Results:
2059#
2060#	Substs the following vars:
2061#		TK_INCLUDES
2062#------------------------------------------------------------------------
2063
2064AC_DEFUN(SC_PRIVATE_TK_HEADERS, [
2065    AC_MSG_CHECKING(for Tk private include files)
2066
2067    case "`uname -s`" in
2068	*win32* | *WIN32* | *CYGWIN_NT* |*CYGWIN_98*|*CYGWIN_95*)
2069	    TK_TOP_DIR_NATIVE=\"`${CYGPATH} ${TK_SRC_DIR}`\"
2070	    TK_UNIX_DIR_NATIVE=\"`${CYGPATH} ${TK_SRC_DIR}/unix`\"
2071	    TK_WIN_DIR_NATIVE=\"`${CYGPATH} ${TK_SRC_DIR}/win`\"
2072	    TK_GENERIC_DIR_NATIVE=\"`${CYGPATH} ${TK_SRC_DIR}/generic`\"
2073	    TK_XLIB_DIR_NATIVE=\"`${CYGPATH} ${TK_SRC_DIR}/xlib`\"
2074	    TK_PLATFORM_DIR_NATIVE=${TK_WIN_DIR_NATIVE}
2075
2076	    TK_INCLUDES="-I${TK_GENERIC_DIR_NATIVE} -I${TK_PLATFORM_DIR_NATIVE} -I${TK_XLIB_DIR_NATIVE}"
2077	;;
2078	*)
2079	    TK_TOP_DIR_NATIVE='$(TK_SRC_DIR)'
2080	    TK_GENERIC_DIR_NATIVE='$(TK_TOP_DIR_NATIVE)/generic'
2081	    TK_UNIX_DIR_NATIVE='$(TK_TOP_DIR_NATIVE)/unix'
2082	    TK_WIN_DIR_NATIVE='$(TK_TOP_DIR_NATIVE)/win'
2083	    TK_PLATFORM_DIR_NATIVE=${TK_UNIX_DIR_NATIVE}
2084
2085	    TK_INCLUDES="-I${TK_GENERIC_DIR_NATIVE} -I${TK_PLATFORM_DIR_NATIVE}"
2086	;;
2087    esac
2088
2089    AC_SUBST(TK_TOP_DIR_NATIVE)
2090    AC_SUBST(TK_UNIX_DIR_NATIVE)
2091    AC_SUBST(TK_WIN_DIR_NATIVE)
2092    AC_SUBST(TK_GENERIC_DIR_NATIVE)
2093    AC_SUBST(TK_XLIB_DIR_NATIVE)
2094    AC_SUBST(TK_PLATFORM_DIR_NATIVE)
2095
2096    AC_SUBST(TK_INCLUDES)
2097    AC_MSG_RESULT(Using srcdir found in tkConfig.sh)
2098])
2099
2100#------------------------------------------------------------------------
2101# SC_PUBLIC_TK_HEADERS --
2102#
2103#	Locate the installed public Tk header files
2104#
2105# Arguments:
2106#	None.
2107#
2108# Requires:
2109#	CYGPATH must be set
2110#
2111# Results:
2112#
2113#	Adds a --with-tkinclude switch to configure.
2114#	Result is cached.
2115#
2116#	Substs the following vars:
2117#		TK_INCLUDES
2118#------------------------------------------------------------------------
2119
2120AC_DEFUN(SC_PUBLIC_TK_HEADERS, [
2121    AC_MSG_CHECKING(for Tk public headers)
2122
2123    AC_ARG_WITH(tkinclude, [ --with-tkinclude      directory containing the public Tk header files.], with_tkinclude=${withval})
2124
2125    if test x"${with_tkinclude}" != x ; then
2126	if test -f "${with_tkinclude}/tk.h" ; then
2127	    ac_cv_c_tkh=${with_tkinclude}
2128	else
2129	    AC_MSG_ERROR([${with_tkinclude} directory does not contain Tk public header file tk.h])
2130	fi
2131    else
2132	AC_CACHE_VAL(ac_cv_c_tkh, [
2133	    # Use the value from --with-tkinclude, if it was given
2134
2135	    if test x"${with_tkinclude}" != x ; then
2136		ac_cv_c_tkh=${with_tkinclude}
2137	    else
2138		# Check in the includedir, if --prefix was specified
2139
2140		eval "temp_includedir=${includedir}"
2141		for i in \
2142			`ls -d ${TCL_PREFIX}/include 2>/dev/null` \
2143			`ls -d ${temp_includedir} 2>/dev/null` \
2144			`ls -d ${TCL_BIN_DIR}/../include 2>/dev/null` \
2145			/usr/local/include /usr/include ; do
2146		    if test -f "$i/tk.h" ; then
2147			ac_cv_c_tkh=$i
2148			break
2149		    fi
2150		done
2151	    fi
2152	])
2153    fi
2154
2155    # Print a message based on how we determined the include path
2156
2157    if test x"${ac_cv_c_tkh}" = x ; then
2158	AC_MSG_ERROR(tk.h not found.  Please specify its location with --with-tkinclude)
2159    else
2160	AC_MSG_RESULT(${ac_cv_c_tkh})
2161    fi
2162
2163    # Convert to a native path and substitute into the output files.
2164
2165    INCLUDE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tkh}`
2166
2167    TK_INCLUDES=-I\"${INCLUDE_DIR_NATIVE}\"
2168
2169    AC_SUBST(TK_INCLUDES)
2170])
2171
2172#------------------------------------------------------------------------
2173# SC_SIMPLE_EXEEXT
2174#	Select the executable extension based on the host type.  This
2175#	is a lightweight replacement for AC_EXEEXT that doesn't require
2176#	a compiler.
2177#
2178# Arguments
2179#	none
2180#
2181# Results
2182#	Subst's the following values:
2183#		EXEEXT
2184#------------------------------------------------------------------------
2185
2186AC_DEFUN(SC_SIMPLE_EXEEXT, [
2187    AC_MSG_CHECKING(executable extension based on host type)
2188
2189    case "`uname -s`" in
2190	*win32* | *WIN32* | *CYGWIN_NT* |*CYGWIN_98*|*CYGWIN_95*)
2191	    EXEEXT=".exe"
2192	;;
2193	*)
2194	    EXEEXT=""
2195	;;
2196    esac
2197
2198    AC_MSG_RESULT(${EXEEXT})
2199    AC_SUBST(EXEEXT)
2200])
2201
2202#------------------------------------------------------------------------
2203# SC_PROG_TCLSH
2204#	Locate a tclsh shell in the following directories:
2205#		${exec_prefix}/bin
2206#		${prefix}/bin
2207#		${TCL_BIN_DIR}
2208#		${TCL_BIN_DIR}/../bin
2209#		${PATH}
2210#
2211# Arguments
2212#	none
2213#
2214# Results
2215#	Subst's the following values:
2216#		TCLSH_PROG
2217#------------------------------------------------------------------------
2218
2219AC_DEFUN(SC_PROG_TCLSH, [
2220    AC_MSG_CHECKING([for tclsh])
2221
2222    AC_CACHE_VAL(ac_cv_path_tclsh, [
2223	search_path=`echo ${exec_prefix}/bin:${prefix}/bin:${TCL_BIN_DIR}:${TCL_BIN_DIR}/../bin:${PATH} | sed -e 's/:/ /g'`
2224	for dir in $search_path ; do
2225	    for j in `ls -r $dir/tclsh[[8-9]]*${EXEEXT} 2> /dev/null` \
2226		    `ls -r $dir/tclsh*${EXEEXT} 2> /dev/null` ; do
2227		if test x"$ac_cv_path_tclsh" = x ; then
2228		    if test -f "$j" ; then
2229			ac_cv_path_tclsh=$j
2230			break
2231		    fi
2232		fi
2233	    done
2234	done
2235    ])
2236
2237    if test -f "$ac_cv_path_tclsh" ; then
2238	TCLSH_PROG=$ac_cv_path_tclsh
2239	AC_MSG_RESULT($TCLSH_PROG)
2240    else
2241	AC_MSG_ERROR(No tclsh found in PATH:  $search_path)
2242    fi
2243    AC_SUBST(TCLSH_PROG)
2244])
2245
2246#------------------------------------------------------------------------
2247# SC_PROG_WISH
2248#	Locate a wish shell in the following directories:
2249#		${exec_prefix}/bin
2250#		${prefix}/bin
2251#		${TCL_BIN_DIR}
2252#		${TCL_BIN_DIR}/../bin
2253#		${PATH}
2254#
2255# Arguments
2256#	none
2257#
2258# Results
2259#	Subst's the following values:
2260#		WISH_PROG
2261#------------------------------------------------------------------------
2262
2263AC_DEFUN(SC_PROG_WISH, [
2264    AC_MSG_CHECKING([for wish])
2265
2266    AC_CACHE_VAL(ac_cv_path_wish, [
2267	search_path=`echo ${exec_prefix}/bin:${prefix}/bin:${TCL_BIN_DIR}:${TCL_BIN_DIR}/../bin:${PATH} | sed -e 's/:/ /g'`
2268	for dir in $search_path ; do
2269	    for j in `ls -r $dir/wish[[8-9]]*${EXEEXT} 2> /dev/null` \
2270		    `ls -r $dir/wish*${EXEEXT} 2> /dev/null` ; do
2271		if test x"$ac_cv_path_wish" = x ; then
2272		    if test -f "$j" ; then
2273			ac_cv_path_wish=$j
2274			break
2275		    fi
2276		fi
2277	    done
2278	done
2279    ])
2280
2281    if test -f "$ac_cv_path_wish" ; then
2282	WISH_PROG=$ac_cv_path_wish
2283	AC_MSG_RESULT($WISH_PROG)
2284    else
2285	AC_MSG_ERROR(No wish found in PATH:  $search_path)
2286    fi
2287    AC_SUBST(WISH_PROG)
2288])
2289
2290