1# aclocal.m4 - autoconf support, copied from TEA and customized for pgtcl-ng
2#
3# The reason for the customization is that TEA has no apparent way to add a
4# shared library path, which is needed for PostgreSQL libpq. Earlier efforts
5# replaced TEA_CONFIG_CFLAGS with PGTCL_CONFIG_FLAGS which added the
6# library path. But that doesn't work with newer TEA because another
7# macro calls TEA_CONFIG_CFLAGS and undoes the customization.
8
9# Changes include:
10#   Stripping out some of the Windows support. Pgtcl-ng is built
11# on Windows without autoconf, so doesn't need this.
12#   Remove TK support, Serial, X11.
13# Add LIB_PGTCL_RUNTIME_DIR as another "rpath" directory.
14# NOTE: TEA_CONFIG_FLAGS has the additional directory coded only for
15# some architectures, and the syntax is untested except for Linux.
16
17AC_PREREQ(2.60)
18
19#------------------------------------------------------------------------
20# TEA_PATH_TCLCONFIG --
21#
22#	Locate the tclConfig.sh file and perform a sanity check on
23#	the Tcl compile flags
24#
25# Arguments:
26#	none
27#
28# Results:
29#
30#	Adds the following arguments to configure:
31#		--with-tcl=...
32#
33#	Defines the following vars:
34#		TCL_BIN_DIR	Full path to the directory containing
35#				the tclConfig.sh file
36#------------------------------------------------------------------------
37
38AC_DEFUN([TEA_PATH_TCLCONFIG], [
39    dnl Make sure we are initialized
40    AC_REQUIRE([TEA_INIT])
41    #
42    # Ok, lets find the tcl configuration
43    # First, look for one uninstalled.
44    # the alternative search directory is invoked by --with-tcl
45    #
46
47    if test x"${no_tcl}" = x ; then
48	# we reset no_tcl in case something fails here
49	no_tcl=true
50	AC_ARG_WITH(tcl,
51	    AC_HELP_STRING([--with-tcl],
52		[directory containing tcl configuration (tclConfig.sh)]),
53	    with_tclconfig=${withval})
54	AC_MSG_CHECKING([for Tcl configuration])
55	AC_CACHE_VAL(ac_cv_c_tclconfig,[
56
57	    # First check to see if --with-tcl was specified.
58	    if test x"${with_tclconfig}" != x ; then
59		case ${with_tclconfig} in
60		    */tclConfig.sh )
61			if test -f ${with_tclconfig}; then
62			    AC_MSG_WARN([--with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself])
63			    with_tclconfig=`echo ${with_tclconfig} | sed 's!/tclConfig\.sh$!!'`
64			fi ;;
65		esac
66		if test -f "${with_tclconfig}/tclConfig.sh" ; then
67		    ac_cv_c_tclconfig=`(cd ${with_tclconfig}; pwd)`
68		else
69		    AC_MSG_ERROR([${with_tclconfig} directory doesn't contain tclConfig.sh])
70		fi
71	    fi
72
73	    # then check for a private Tcl installation
74	    if test x"${ac_cv_c_tclconfig}" = x ; then
75		for i in \
76			../tcl \
77			`ls -dr ../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
78			`ls -dr ../tcl[[8-9]].[[0-9]] 2>/dev/null` \
79			`ls -dr ../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
80			../../tcl \
81			`ls -dr ../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
82			`ls -dr ../../tcl[[8-9]].[[0-9]] 2>/dev/null` \
83			`ls -dr ../../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
84			../../../tcl \
85			`ls -dr ../../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
86			`ls -dr ../../../tcl[[8-9]].[[0-9]] 2>/dev/null` \
87			`ls -dr ../../../tcl[[8-9]].[[0-9]]* 2>/dev/null` ; do
88		    if test -f "$i/unix/tclConfig.sh" ; then
89			ac_cv_c_tclconfig=`(cd $i/unix; pwd)`
90			break
91		    fi
92		done
93	    fi
94
95	    # on Darwin, check in Framework installation locations
96	    if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tclconfig}" = x ; then
97		for i in `ls -d ~/Library/Frameworks 2>/dev/null` \
98			`ls -d /Library/Frameworks 2>/dev/null` \
99			`ls -d /Network/Library/Frameworks 2>/dev/null` \
100			`ls -d /System/Library/Frameworks 2>/dev/null` \
101			; do
102		    if test -f "$i/Tcl.framework/tclConfig.sh" ; then
103			ac_cv_c_tclconfig=`(cd $i/Tcl.framework; pwd)`
104			break
105		    fi
106		done
107	    fi
108
109	    # on Windows, check in common installation locations
110	    if test "${TEA_PLATFORM}" = "windows" \
111		-a x"${ac_cv_c_tclconfig}" = x ; then
112		for i in `ls -d C:/Tcl/lib 2>/dev/null` \
113			`ls -d C:/Progra~1/Tcl/lib 2>/dev/null` \
114			; do
115		    if test -f "$i/tclConfig.sh" ; then
116			ac_cv_c_tclconfig=`(cd $i; pwd)`
117			break
118		    fi
119		done
120	    fi
121
122	    # check in a few common install locations
123	    if test x"${ac_cv_c_tclconfig}" = x ; then
124		for i in `ls -d ${libdir} 2>/dev/null` \
125			`ls -d ${exec_prefix}/lib 2>/dev/null` \
126			`ls -d ${prefix}/lib 2>/dev/null` \
127			`ls -d /usr/local/lib 2>/dev/null` \
128			`ls -d /usr/contrib/lib 2>/dev/null` \
129			`ls -d /usr/lib 2>/dev/null` \
130			; do
131		    if test -f "$i/tclConfig.sh" ; then
132			ac_cv_c_tclconfig=`(cd $i; pwd)`
133			break
134		    fi
135		done
136	    fi
137
138	    # check in a few other private locations
139	    if test x"${ac_cv_c_tclconfig}" = x ; then
140		for i in \
141			${srcdir}/../tcl \
142			`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
143			`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]] 2>/dev/null` \
144			`ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]]* 2>/dev/null` ; do
145		    if test -f "$i/unix/tclConfig.sh" ; then
146		    ac_cv_c_tclconfig=`(cd $i/unix; pwd)`
147		    break
148		fi
149		done
150	    fi
151	])
152
153	if test x"${ac_cv_c_tclconfig}" = x ; then
154	    TCL_BIN_DIR="# no Tcl configs found"
155	    AC_MSG_WARN([Can't find Tcl configuration definitions])
156	    exit 0
157	else
158	    no_tcl=
159	    TCL_BIN_DIR=${ac_cv_c_tclconfig}
160	    AC_MSG_RESULT([found ${TCL_BIN_DIR}/tclConfig.sh])
161	fi
162    fi
163])
164
165#------------------------------------------------------------------------
166# TEA_LOAD_TCLCONFIG --
167#
168#	Load the tclConfig.sh file
169#
170# Arguments:
171#
172#	Requires the following vars to be set:
173#		TCL_BIN_DIR
174#
175# Results:
176#
177#	Subst the following vars:
178#		TCL_BIN_DIR
179#		TCL_SRC_DIR
180#		TCL_LIB_FILE
181#
182#------------------------------------------------------------------------
183
184AC_DEFUN([TEA_LOAD_TCLCONFIG], [
185    AC_MSG_CHECKING([for existence of ${TCL_BIN_DIR}/tclConfig.sh])
186
187    if test -f "${TCL_BIN_DIR}/tclConfig.sh" ; then
188        AC_MSG_RESULT([loading])
189	. ${TCL_BIN_DIR}/tclConfig.sh
190    else
191        AC_MSG_RESULT([could not find ${TCL_BIN_DIR}/tclConfig.sh])
192    fi
193
194    # eval is required to do the TCL_DBGX substitution
195    eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
196    eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""
197
198    # If the TCL_BIN_DIR is the build directory (not the install directory),
199    # then set the common variable name to the value of the build variables.
200    # For example, the variable TCL_LIB_SPEC will be set to the value
201    # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC
202    # instead of TCL_BUILD_LIB_SPEC since it will work with both an
203    # installed and uninstalled version of Tcl.
204    if test -f ${TCL_BIN_DIR}/Makefile ; then
205        TCL_LIB_SPEC=${TCL_BUILD_LIB_SPEC}
206        TCL_STUB_LIB_SPEC=${TCL_BUILD_STUB_LIB_SPEC}
207        TCL_STUB_LIB_PATH=${TCL_BUILD_STUB_LIB_PATH}
208    elif test "`uname -s`" = "Darwin"; then
209	# If Tcl was built as a framework, attempt to use the libraries
210	# from the framework at the given location so that linking works
211	# against Tcl.framework installed in an arbitary location.
212	case ${TCL_DEFS} in
213	    *TCL_FRAMEWORK*)
214		if test -f ${TCL_BIN_DIR}/${TCL_LIB_FILE}; then
215		    for i in "`cd ${TCL_BIN_DIR}; pwd`" \
216			     "`cd ${TCL_BIN_DIR}/../..; pwd`"; do
217			if test "`basename "$i"`" = "${TCL_LIB_FILE}.framework"; then
218			    TCL_LIB_SPEC="-F`dirname "$i"` -framework ${TCL_LIB_FILE}"
219			    break
220			fi
221		    done
222		fi
223		if test -f ${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}; then
224		    TCL_STUB_LIB_SPEC="-L${TCL_BIN_DIR} ${TCL_STUB_LIB_FLAG}"
225		    TCL_STUB_LIB_PATH="${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}"
226		fi
227		;;
228	esac
229    fi
230
231    # eval is required to do the TCL_DBGX substitution
232    eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
233    eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""
234    eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
235    eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""
236
237    AC_SUBST(TCL_VERSION)
238    AC_SUBST(TCL_BIN_DIR)
239    AC_SUBST(TCL_SRC_DIR)
240
241    AC_SUBST(TCL_LIB_FILE)
242    AC_SUBST(TCL_LIB_FLAG)
243    AC_SUBST(TCL_LIB_SPEC)
244
245    AC_SUBST(TCL_STUB_LIB_FILE)
246    AC_SUBST(TCL_STUB_LIB_FLAG)
247    AC_SUBST(TCL_STUB_LIB_SPEC)
248
249    AC_SUBST(TCL_LIBS)
250    AC_SUBST(TCL_DEFS)
251    AC_SUBST(TCL_EXTRA_CFLAGS)
252    AC_SUBST(TCL_LD_FLAGS)
253    AC_SUBST(TCL_SHLIB_LD_LIBS)
254])
255
256#------------------------------------------------------------------------
257# TEA_ENABLE_SHARED --
258#
259#	Allows the building of shared libraries
260#
261# Arguments:
262#	none
263#
264# Results:
265#
266#	Adds the following arguments to configure:
267#		--enable-shared=yes|no
268#
269#	Defines the following vars:
270#		STATIC_BUILD	Used for building import/export libraries
271#				on Windows.
272#
273#	Sets the following vars:
274#		SHARED_BUILD	Value of 1 or 0
275#------------------------------------------------------------------------
276
277AC_DEFUN([TEA_ENABLE_SHARED], [
278    AC_MSG_CHECKING([how to build libraries])
279    AC_ARG_ENABLE(shared,
280	AC_HELP_STRING([--enable-shared],
281	    [build and link with shared libraries (default: on)]),
282	[tcl_ok=$enableval], [tcl_ok=yes])
283
284    if test "${enable_shared+set}" = set; then
285	enableval="$enable_shared"
286	tcl_ok=$enableval
287    else
288	tcl_ok=yes
289    fi
290
291    if test "$tcl_ok" = "yes" ; then
292	AC_MSG_RESULT([shared])
293	SHARED_BUILD=1
294    else
295	AC_MSG_RESULT([static])
296	SHARED_BUILD=0
297	AC_DEFINE(STATIC_BUILD, 1, [Is this a static build?])
298    fi
299    AC_SUBST(SHARED_BUILD)
300])
301
302#------------------------------------------------------------------------
303# TEA_ENABLE_SYMBOLS --
304#
305#	Specify if debugging symbols should be used.
306#	Memory (TCL_MEM_DEBUG) debugging can also be enabled.
307#
308# Arguments:
309#	none
310#
311#	TEA varies from core Tcl in that C|LDFLAGS_DEFAULT receives
312#	the value of C|LDFLAGS_OPTIMIZE|DEBUG already substituted.
313#	Requires the following vars to be set in the Makefile:
314#		CFLAGS_DEFAULT
315#		LDFLAGS_DEFAULT
316#
317# Results:
318#
319#	Adds the following arguments to configure:
320#		--enable-symbols
321#
322#	Defines the following vars:
323#		CFLAGS_DEFAULT	Sets to $(CFLAGS_DEBUG) if true
324#				Sets to $(CFLAGS_OPTIMIZE) if false
325#		LDFLAGS_DEFAULT	Sets to $(LDFLAGS_DEBUG) if true
326#				Sets to $(LDFLAGS_OPTIMIZE) if false
327#		DBGX		Formerly used as debug library extension;
328#				always blank now.
329#
330#------------------------------------------------------------------------
331
332AC_DEFUN([TEA_ENABLE_SYMBOLS], [
333    dnl Make sure we are initialized
334    AC_REQUIRE([TEA_CONFIG_CFLAGS])
335    AC_MSG_CHECKING([for build with symbols])
336    AC_ARG_ENABLE(symbols,
337	AC_HELP_STRING([--enable-symbols],
338	    [build with debugging symbols (default: off)]),
339	[tcl_ok=$enableval], [tcl_ok=no])
340    DBGX=""
341    if test "$tcl_ok" = "no"; then
342	CFLAGS_DEFAULT="${CFLAGS_OPTIMIZE}"
343	LDFLAGS_DEFAULT="${LDFLAGS_OPTIMIZE}"
344	AC_MSG_RESULT([no])
345    else
346	CFLAGS_DEFAULT="${CFLAGS_DEBUG}"
347	LDFLAGS_DEFAULT="${LDFLAGS_DEBUG}"
348	if test "$tcl_ok" = "yes"; then
349	    AC_MSG_RESULT([yes (standard debugging)])
350	fi
351    fi
352    if test "${TEA_PLATFORM}" != "windows" ; then
353	LDFLAGS_DEFAULT="${LDFLAGS}"
354    fi
355
356    AC_SUBST(TCL_DBGX)
357    AC_SUBST(CFLAGS_DEFAULT)
358    AC_SUBST(LDFLAGS_DEFAULT)
359
360    if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then
361	AC_DEFINE(TCL_MEM_DEBUG, 1, [Is memory debugging enabled?])
362    fi
363
364    if test "$tcl_ok" != "yes" -a "$tcl_ok" != "no"; then
365	if test "$tcl_ok" = "all"; then
366	    AC_MSG_RESULT([enabled symbols mem debugging])
367	else
368	    AC_MSG_RESULT([enabled $tcl_ok debugging])
369	fi
370    fi
371])
372
373#--------------------------------------------------------------------
374# TEA_CONFIG_SYSTEM
375#
376#	Determine what the system is (some things cannot be easily checked
377#	on a feature-driven basis, alas). This can usually be done via the
378#	"uname" command, but there are a few systems, like Next, where
379#	this doesn't work.
380#
381# Arguments:
382#	none
383#
384# Results:
385#	Defines the following var:
386#
387#	system -	System/platform/version identification code.
388#
389#--------------------------------------------------------------------
390
391AC_DEFUN([TEA_CONFIG_SYSTEM], [
392    AC_CACHE_CHECK([system version], tcl_cv_sys_version, [
393	if test "${TEA_PLATFORM}" = "windows" ; then
394	    tcl_cv_sys_version=windows
395	elif test -f /usr/lib/NextStep/software_version; then
396	    tcl_cv_sys_version=NEXTSTEP-`awk '/3/,/3/' /usr/lib/NextStep/software_version`
397	else
398	    tcl_cv_sys_version=`uname -s`-`uname -r`
399	    if test "$?" -ne 0 ; then
400		AC_MSG_WARN([can't find uname command])
401		tcl_cv_sys_version=unknown
402	    else
403		# Special check for weird MP-RAS system (uname returns weird
404		# results, and the version is kept in special file).
405
406		if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
407		    tcl_cv_sys_version=MP-RAS-`awk '{print [$]3}' /etc/.relid`
408		fi
409		if test "`uname -s`" = "AIX" ; then
410		    tcl_cv_sys_version=AIX-`uname -v`.`uname -r`
411		fi
412	    fi
413	fi
414    ])
415    system=$tcl_cv_sys_version
416])
417
418#--------------------------------------------------------------------
419# TEA_CONFIG_CFLAGS
420#
421#	Try to determine the proper flags to pass to the compiler
422#	for building shared libraries and other such nonsense.
423#
424# Modified for pgtcl-ng to add the PostgreSQL library search path.
425#
426# Arguments:
427#	none
428#
429# Results:
430#
431#	Defines and substitutes the following vars:
432#
433#       DL_OBJS -       Name of the object file that implements dynamic
434#                       loading for Tcl on this system.
435#       DL_LIBS -       Library file(s) to include in tclsh and other base
436#                       applications in order for the "load" command to work.
437#       LDFLAGS -      Flags to pass to the compiler when linking object
438#                       files into an executable application binary such
439#                       as tclsh.
440#       LD_SEARCH_FLAGS-Flags to pass to ld, such as "-R /usr/local/tcl/lib",
441#                       that tell the run-time dynamic linker where to look
442#                       for shared libraries such as libtcl.so.  Depends on
443#                       the variable LIB_RUNTIME_DIR in the Makefile. Could
444#                       be the same as CC_SEARCH_FLAGS if ${CC} is used to link.
445#       CC_SEARCH_FLAGS-Flags to pass to ${CC}, such as "-Wl,-rpath,/usr/local/tcl/lib",
446#                       that tell the run-time dynamic linker where to look
447#                       for shared libraries such as libtcl.so.  Depends on
448#                       the variable LIB_RUNTIME_DIR in the Makefile.
449#       SHLIB_CFLAGS -  Flags to pass to cc when compiling the components
450#                       of a shared library (may request position-independent
451#                       code, among other things).
452#       SHLIB_LD -      Base command to use for combining object files
453#                       into a shared library.
454#       SHLIB_LD_LIBS - Dependent libraries for the linker to scan when
455#                       creating shared libraries.  This symbol typically
456#                       goes at the end of the "ld" commands that build
457#                       shared libraries. The value of the symbol is
458#                       "${LIBS}" if all of the dependent libraries should
459#                       be specified when creating a shared library.  If
460#                       dependent libraries should not be specified (as on
461#                       SunOS 4.x, where they cause the link to fail, or in
462#                       general if Tcl and Tk aren't themselves shared
463#                       libraries), then this symbol has an empty string
464#                       as its value.
465#       SHLIB_SUFFIX -  Suffix to use for the names of dynamically loadable
466#                       extensions.  An empty string means we don't know how
467#                       to use shared libraries on this platform.
468#       LIB_SUFFIX -    Specifies everything that comes after the "libfoo"
469#                       in a static or shared library name, using the $VERSION variable
470#                       to put the version in the right place.  This is used
471#                       by platforms that need non-standard library names.
472#                       Examples:  ${VERSION}.so.1.1 on NetBSD, since it needs
473#                       to have a version after the .so, and ${VERSION}.a
474#                       on AIX, since a shared library needs to have
475#                       a .a extension whereas shared objects for loadable
476#                       extensions have a .so extension.  Defaults to
477#                       ${VERSION}${SHLIB_SUFFIX}.
478#       TCL_NEEDS_EXP_FILE -
479#                       1 means that an export file is needed to link to a
480#                       shared library.
481#       TCL_EXP_FILE -  The name of the installed export / import file which
482#                       should be used to link to the Tcl shared library.
483#                       Empty if Tcl is unshared.
484#       TCL_BUILD_EXP_FILE -
485#                       The name of the built export / import file which
486#                       should be used to link to the Tcl shared library.
487#                       Empty if Tcl is unshared.
488#	CFLAGS_DEBUG -
489#			Flags used when running the compiler in debug mode
490#	CFLAGS_OPTIMIZE -
491#			Flags used when running the compiler in optimize mode
492#	CFLAGS -	Additional CFLAGS added as necessary (usually 64-bit)
493#
494#--------------------------------------------------------------------
495
496AC_DEFUN([TEA_CONFIG_CFLAGS], [
497    dnl Make sure we are initialized
498    AC_REQUIRE([TEA_INIT])
499
500    # Step 0.a: Enable 64 bit support?
501
502    AC_MSG_CHECKING([if 64bit support is requested])
503    AC_ARG_ENABLE(64bit,
504	AC_HELP_STRING([--enable-64bit],
505	    [enable 64bit support (default: off)]),
506	[do64bit=$enableval], [do64bit=no])
507    AC_MSG_RESULT([$do64bit])
508
509    # Step 0.b: Enable Solaris 64 bit VIS support?
510
511    AC_MSG_CHECKING([if 64bit Sparc VIS support is requested])
512    AC_ARG_ENABLE(64bit-vis,
513	AC_HELP_STRING([--enable-64bit-vis],
514	    [enable 64bit Sparc VIS support (default: off)]),
515	[do64bitVIS=$enableval], [do64bitVIS=no])
516    AC_MSG_RESULT([$do64bitVIS])
517
518    if test "$do64bitVIS" = "yes"; then
519	# Force 64bit on with VIS
520	do64bit=yes
521    fi
522
523    # Step 0.c: Cross-compiling options for Windows/CE builds?
524
525    if test "${TEA_PLATFORM}" = "windows" ; then
526	AC_MSG_CHECKING([if Windows/CE build is requested])
527	AC_ARG_ENABLE(wince,[  --enable-wince          enable Win/CE support (where applicable)], [doWince=$enableval], [doWince=no])
528	AC_MSG_RESULT([$doWince])
529    fi
530
531    # Step 1: set the variable "system" to hold the name and version number
532    # for the system.
533
534    TEA_CONFIG_SYSTEM
535
536    # Step 2: check for existence of -ldl library.  This is needed because
537    # Linux can use either -ldl or -ldld for dynamic loading.
538
539    AC_CHECK_LIB(dl, dlopen, have_dl=yes, have_dl=no)
540
541    # Require ranlib early so we can override it in special cases below.
542
543    AC_REQUIRE([AC_PROG_RANLIB])
544
545    # Step 3: set configuration options based on system name and version.
546
547    do64bit_ok=no
548    LDFLAGS_ORIG="$LDFLAGS"
549    # When ld needs options to work in 64-bit mode, put them in
550    # LDFLAGS_ARCH so they eventually end up in LDFLAGS even if [load]
551    # is disabled by the user. [Bug 1016796]
552    LDFLAGS_ARCH=""
553    TCL_EXPORT_FILE_SUFFIX=""
554    UNSHARED_LIB_SUFFIX=""
555    TCL_TRIM_DOTS='`echo ${PACKAGE_VERSION} | tr -d .`'
556    ECHO_VERSION='`echo ${PACKAGE_VERSION}`'
557    TCL_LIB_VERSIONS_OK=ok
558    CFLAGS_DEBUG=-g
559    CFLAGS_OPTIMIZE=-O
560    if test "$GCC" = "yes" ; then
561	CFLAGS_OPTIMIZE=-O2
562	CFLAGS_WARNING="-Wall -Wno-implicit-int"
563    else
564	CFLAGS_WARNING=""
565    fi
566    TCL_NEEDS_EXP_FILE=0
567    TCL_BUILD_EXP_FILE=""
568    TCL_EXP_FILE=""
569dnl FIXME: Replace AC_CHECK_PROG with AC_CHECK_TOOL once cross compiling is fixed.
570dnl AC_CHECK_TOOL(AR, ar)
571    AC_CHECK_PROG(AR, ar, ar)
572    STLIB_LD='${AR} cr'
573    LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH"
574    case $system in
575
576	AIX-*)
577	    if test "${TCL_THREADS}" = "1" -a "$GCC" != "yes" ; then
578		# AIX requires the _r compiler when gcc isn't being used
579		case "${CC}" in
580		    *_r)
581			# ok ...
582			;;
583		    *)
584			CC=${CC}_r
585			;;
586		esac
587		AC_MSG_RESULT([Using $CC for compiling with threads])
588	    fi
589	    LIBS="$LIBS -lc"
590	    SHLIB_CFLAGS=""
591	    SHLIB_LD_LIBS='${LIBS}'
592	    SHLIB_SUFFIX=".so"
593
594	    DL_OBJS="tclLoadDl.o"
595	    LD_LIBRARY_PATH_VAR="LIBPATH"
596
597	    # Check to enable 64-bit flags for compiler/linker on AIX 4+
598	    if test "$do64bit" = "yes" -a "`uname -v`" -gt "3" ; then
599		if test "$GCC" = "yes" ; then
600		    AC_MSG_WARN([64bit mode not supported with GCC on $system])
601		else
602		    do64bit_ok=yes
603		    CFLAGS="$CFLAGS -q64"
604		    LDFLAGS_ARCH="-q64"
605		    RANLIB="${RANLIB} -X64"
606		    AR="${AR} -X64"
607		    SHLIB_LD_FLAGS="-b64"
608		fi
609	    fi
610
611	    if test "`uname -m`" = "ia64" ; then
612		# AIX-5 uses ELF style dynamic libraries on IA-64, but not PPC
613		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
614		# AIX-5 has dl* in libc.so
615		DL_LIBS=""
616		if test "$GCC" = "yes" ; then
617		    CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR},-R,${LIB_PGTCL_RUNTIME_DIR}'
618		else
619		    CC_SEARCH_FLAGS='-R${LIB_RUNTIME_DIR} -R${LIB_PGTCL_RUNTIME_DIR}'
620		fi
621		LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR} -R ${LIB_PGTCL_RUNTIME_DIR}'
622	    else
623		if test "$GCC" = "yes" ; then
624		    SHLIB_LD="gcc -shared"
625		else
626		    SHLIB_LD="/bin/ld -bhalt:4 -bM:SRE -bE:lib.exp -H512 -T512 -bnoentry"
627		fi
628		SHLIB_LD="${TCL_SRC_DIR}/unix/ldAix ${SHLIB_LD} ${SHLIB_LD_FLAGS}"
629		DL_LIBS="-ldl"
630		CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
631		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
632		TCL_NEEDS_EXP_FILE=1
633		TCL_EXPORT_FILE_SUFFIX='${PACKAGE_VERSION}.exp'
634	    fi
635
636	    # AIX v<=4.1 has some different flags than 4.2+
637	    if test "$system" = "AIX-4.1" -o "`uname -v`" -lt "4" ; then
638		AC_LIBOBJ([tclLoadAix])
639		DL_LIBS="-lld"
640	    fi
641
642	    # On AIX <=v4 systems, libbsd.a has to be linked in to support
643	    # non-blocking file IO.  This library has to be linked in after
644	    # the MATH_LIBS or it breaks the pow() function.  The way to
645	    # insure proper sequencing, is to add it to the tail of MATH_LIBS.
646	    # This library also supplies gettimeofday.
647	    #
648	    # AIX does not have a timezone field in struct tm. When the AIX
649	    # bsd library is used, the timezone global and the gettimeofday
650	    # methods are to be avoided for timezone deduction instead, we
651	    # deduce the timezone by comparing the localtime result on a
652	    # known GMT value.
653
654	    AC_CHECK_LIB(bsd, gettimeofday, libbsd=yes, libbsd=no)
655	    if test $libbsd = yes; then
656	    	MATH_LIBS="$MATH_LIBS -lbsd"
657	    	AC_DEFINE(USE_DELTA_FOR_TZ, 1, [Do we need a special AIX hack for timezones?])
658	    fi
659	    ;;
660	BeOS*)
661	    SHLIB_CFLAGS="-fPIC"
662	    SHLIB_LD="${CC} -nostart"
663	    SHLIB_LD_LIBS='${LIBS}'
664	    SHLIB_SUFFIX=".so"
665	    DL_OBJS="tclLoadDl.o"
666	    DL_LIBS="-ldl"
667
668	    #-----------------------------------------------------------
669	    # Check for inet_ntoa in -lbind, for BeOS (which also needs
670	    # -lsocket, even if the network functions are in -lnet which
671	    # is always linked to, for compatibility.
672	    #-----------------------------------------------------------
673	    AC_CHECK_LIB(bind, inet_ntoa, [LIBS="$LIBS -lbind -lsocket"])
674	    ;;
675	BSD/OS-2.1*|BSD/OS-3*)
676	    SHLIB_CFLAGS=""
677	    SHLIB_LD="shlicc -r"
678	    SHLIB_LD_LIBS='${LIBS}'
679	    SHLIB_SUFFIX=".so"
680	    DL_OBJS="tclLoadDl.o"
681	    DL_LIBS="-ldl"
682	    CC_SEARCH_FLAGS=""
683	    LD_SEARCH_FLAGS=""
684	    ;;
685	BSD/OS-4.*)
686	    SHLIB_CFLAGS="-export-dynamic -fPIC"
687	    SHLIB_LD="cc -shared"
688	    SHLIB_LD_LIBS='${LIBS}'
689	    SHLIB_SUFFIX=".so"
690	    DL_OBJS="tclLoadDl.o"
691	    DL_LIBS="-ldl"
692	    LDFLAGS="$LDFLAGS -export-dynamic"
693	    CC_SEARCH_FLAGS=""
694	    LD_SEARCH_FLAGS=""
695	    ;;
696	dgux*)
697	    SHLIB_CFLAGS="-K PIC"
698	    SHLIB_LD="cc -G"
699	    SHLIB_LD_LIBS=""
700	    SHLIB_SUFFIX=".so"
701	    DL_OBJS="tclLoadDl.o"
702	    DL_LIBS="-ldl"
703	    CC_SEARCH_FLAGS=""
704	    LD_SEARCH_FLAGS=""
705	    ;;
706	HP-UX-*.11.*)
707	    # Use updated header definitions where possible
708	    AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, [Do we want to use the XOPEN network library?])
709	    # Needed by Tcl, but not most extensions
710	    #AC_DEFINE(_XOPEN_SOURCE, 1, [Do we want to use the XOPEN network library?])
711	    #LIBS="$LIBS -lxnet"               # Use the XOPEN network library
712
713	    SHLIB_SUFFIX=".sl"
714	    AC_CHECK_LIB(dld, shl_load, tcl_ok=yes, tcl_ok=no)
715	    if test "$tcl_ok" = yes; then
716		SHLIB_CFLAGS="+z"
717		SHLIB_LD="ld -b"
718		SHLIB_LD_LIBS='${LIBS}'
719		DL_OBJS="tclLoadShl.o"
720		DL_LIBS="-ldld"
721		LDFLAGS="$LDFLAGS -Wl,-E"
722		CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:${LIB_PGTCL_RUNTIME_DIR}:.'
723		LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:${LIB_PGTCL_RUNTIME_DIR}:.'
724		LD_LIBRARY_PATH_VAR="SHLIB_PATH"
725	    fi
726	    if test "$GCC" = "yes" ; then
727		SHLIB_LD="gcc -shared"
728		SHLIB_LD_LIBS='${LIBS}'
729		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
730	    fi
731
732	    # Users may want PA-RISC 1.1/2.0 portable code - needs HP cc
733	    #CFLAGS="$CFLAGS +DAportable"
734
735	    # Check to enable 64-bit flags for compiler/linker
736	    if test "$do64bit" = "yes" ; then
737		if test "$GCC" = "yes" ; then
738		    hpux_arch=`${CC} -dumpmachine`
739		    case $hpux_arch in
740			hppa64*)
741			    # 64-bit gcc in use.  Fix flags for GNU ld.
742			    do64bit_ok=yes
743			    SHLIB_LD="${CC} -shared"
744			    SHLIB_LD_LIBS='${LIBS}'
745			    CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
746			    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
747			    ;;
748			*)
749			    AC_MSG_WARN([64bit mode not supported with GCC on $system])
750			    ;;
751		    esac
752		else
753		    do64bit_ok=yes
754		    CFLAGS="$CFLAGS +DD64"
755		    LDFLAGS_ARCH="+DD64"
756		fi
757	    fi
758	    ;;
759	HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*)
760	    SHLIB_SUFFIX=".sl"
761	    AC_CHECK_LIB(dld, shl_load, tcl_ok=yes, tcl_ok=no)
762	    if test "$tcl_ok" = yes; then
763		SHLIB_CFLAGS="+z"
764		SHLIB_LD="ld -b"
765		SHLIB_LD_LIBS=""
766		DL_OBJS="tclLoadShl.o"
767		DL_LIBS="-ldld"
768		LDFLAGS="$LDFLAGS -Wl,-E"
769		CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:${LIB_PGTCL_RUNTIME_DIR}:.'
770		LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:${LIB_PGTCL_RUNTIME_DIR}:.'
771		LD_LIBRARY_PATH_VAR="SHLIB_PATH"
772	    fi
773	    ;;
774	IRIX-5.*)
775	    SHLIB_CFLAGS=""
776	    SHLIB_LD="ld -shared -rdata_shared"
777	    SHLIB_LD_LIBS='${LIBS}'
778	    SHLIB_SUFFIX=".so"
779	    DL_OBJS="tclLoadDl.o"
780	    DL_LIBS=""
781	    CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR},-rpath,${LIB_PGTCL_RUNTIME_DIR}'
782	    LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR} -rpath ${LIB_PGTCL_RUNTIME_DIR}'
783	    ;;
784	IRIX-6.*)
785	    SHLIB_CFLAGS=""
786	    SHLIB_LD="ld -n32 -shared -rdata_shared"
787	    SHLIB_LD_LIBS='${LIBS}'
788	    SHLIB_SUFFIX=".so"
789	    DL_OBJS="tclLoadDl.o"
790	    DL_LIBS=""
791	    CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR},-rpath,${LIB_PGTCL_RUNTIME_DIR}'
792	    LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR} -rpath ${LIB_PGTCL_RUNTIME_DIR}'
793	    if test "$GCC" = "yes" ; then
794		CFLAGS="$CFLAGS -mabi=n32"
795		LDFLAGS="$LDFLAGS -mabi=n32"
796	    else
797		case $system in
798		    IRIX-6.3)
799			# Use to build 6.2 compatible binaries on 6.3.
800			CFLAGS="$CFLAGS -n32 -D_OLD_TERMIOS"
801			;;
802		    *)
803			CFLAGS="$CFLAGS -n32"
804			;;
805		esac
806		LDFLAGS="$LDFLAGS -n32"
807	    fi
808	    ;;
809	IRIX64-6.*)
810	    SHLIB_CFLAGS=""
811	    SHLIB_LD="ld -n32 -shared -rdata_shared"
812	    SHLIB_LD_LIBS='${LIBS}'
813	    SHLIB_SUFFIX=".so"
814	    DL_OBJS="tclLoadDl.o"
815	    DL_LIBS=""
816	    CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR},-rpath,${LIB_PGTCL_RUNTIME_DIR}'
817	    LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR} -rpath ${LIB_PGTCL_RUNTIME_DIR}'
818
819	    # Check to enable 64-bit flags for compiler/linker
820
821	    if test "$do64bit" = "yes" ; then
822	        if test "$GCC" = "yes" ; then
823	            AC_MSG_WARN([64bit mode not supported by gcc])
824	        else
825	            do64bit_ok=yes
826	            SHLIB_LD="ld -64 -shared -rdata_shared"
827	            CFLAGS="$CFLAGS -64"
828	            LDFLAGS_ARCH="-64"
829	        fi
830	    fi
831	    ;;
832	Linux*)
833	    SHLIB_CFLAGS="-fPIC"
834	    SHLIB_LD_LIBS='${LIBS}'
835	    SHLIB_SUFFIX=".so"
836
837	    CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer"
838	    # egcs-2.91.66 on Redhat Linux 6.0 generates lots of warnings
839	    # when you inline the string and math operations.  Turn this off to
840	    # get rid of the warnings.
841	    #CFLAGS_OPTIMIZE="${CFLAGS_OPTIMIZE} -D__NO_STRING_INLINES -D__NO_MATH_INLINES"
842
843	    SHLIB_LD="${CC} -shared"
844	    DL_OBJS="tclLoadDl.o"
845	    DL_LIBS="-ldl"
846	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
847	    CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR},-rpath,${LIB_PGTCL_RUNTIME_DIR}'
848	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
849	    if test "`uname -m`" = "alpha" ; then
850		CFLAGS="$CFLAGS -mieee"
851	    fi
852
853	    # The combo of gcc + glibc has a bug related
854	    # to inlining of functions like strtod(). The
855	    # -fno-builtin flag should address this problem
856	    # but it does not work. The -fno-inline flag
857	    # is kind of overkill but it works.
858	    # Disable inlining only when one of the
859	    # files in compat/*.c is being linked in.
860	    if test x"${USE_COMPAT}" != x ; then
861	        CFLAGS="$CFLAGS -fno-inline"
862	    fi
863
864	    ;;
865	GNU*)
866	    SHLIB_CFLAGS="-fPIC"
867	    SHLIB_LD_LIBS='${LIBS}'
868	    SHLIB_SUFFIX=".so"
869
870	    SHLIB_LD="${CC} -shared"
871	    DL_OBJS=""
872	    DL_LIBS="-ldl"
873	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
874	    CC_SEARCH_FLAGS=""
875	    LD_SEARCH_FLAGS=""
876	    if test "`uname -m`" = "alpha" ; then
877		CFLAGS="$CFLAGS -mieee"
878	    fi
879	    ;;
880	Lynx*)
881	    SHLIB_CFLAGS="-fPIC"
882	    SHLIB_LD_LIBS='${LIBS}'
883	    SHLIB_SUFFIX=".so"
884	    CFLAGS_OPTIMIZE=-02
885	    SHLIB_LD="${CC} -shared "
886	    DL_OBJS="tclLoadDl.o"
887	    DL_LIBS="-mshared -ldl"
888	    LD_FLAGS="-Wl,--export-dynamic"
889	    CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
890	    LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
891	    ;;
892	MP-RAS-02*)
893	    SHLIB_CFLAGS="-K PIC"
894	    SHLIB_LD="cc -G"
895	    SHLIB_LD_LIBS=""
896	    SHLIB_SUFFIX=".so"
897	    DL_OBJS="tclLoadDl.o"
898	    DL_LIBS="-ldl"
899	    CC_SEARCH_FLAGS=""
900	    LD_SEARCH_FLAGS=""
901	    ;;
902	MP-RAS-*)
903	    SHLIB_CFLAGS="-K PIC"
904	    SHLIB_LD="cc -G"
905	    SHLIB_LD_LIBS=""
906	    SHLIB_SUFFIX=".so"
907	    DL_OBJS="tclLoadDl.o"
908	    DL_LIBS="-ldl"
909	    LDFLAGS="$LDFLAGS -Wl,-Bexport"
910	    CC_SEARCH_FLAGS=""
911	    LD_SEARCH_FLAGS=""
912	    ;;
913	NetBSD-*|FreeBSD-[[1-2]].*)
914	    # NetBSD/SPARC needs -fPIC, -fpic will not do.
915	    SHLIB_CFLAGS="-fPIC"
916	    SHLIB_LD="ld -Bshareable -x"
917	    SHLIB_LD_LIBS='${LIBS}'
918	    SHLIB_SUFFIX=".so"
919	    DL_OBJS="tclLoadDl.o"
920	    DL_LIBS=""
921	    CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR},-rpath,${LIB_PGTCL_RUNTIME_DIR}'
922	    LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR} -rpath ${LIB_PGTCL_RUNTIME_DIR}'
923	    AC_CACHE_CHECK([for ELF], tcl_cv_ld_elf, [
924		AC_EGREP_CPP(yes, [
925#ifdef __ELF__
926	yes
927#endif
928		], tcl_cv_ld_elf=yes, tcl_cv_ld_elf=no)])
929	    if test $tcl_cv_ld_elf = yes; then
930		SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so'
931	    else
932		SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.1.0'
933	    fi
934
935	    # Ancient FreeBSD doesn't handle version numbers with dots.
936
937	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
938	    TCL_LIB_VERSIONS_OK=nodots
939	    ;;
940	OpenBSD-*)
941	    # OpenBSD/SPARC[64] needs -fPIC, -fpic will not do.
942	    case `machine` in
943	    sparc|sparc64)
944		SHLIB_CFLAGS="-fPIC";;
945	    *)
946		SHLIB_CFLAGS="-fpic";;
947	    esac
948	    SHLIB_LD="${CC} -shared ${SHLIB_CFLAGS}"
949	    SHLIB_LD_LIBS='${LIBS}'
950	    SHLIB_SUFFIX=".so"
951	    DL_OBJS="tclLoadDl.o"
952	    DL_LIBS=""
953	    CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR},-rpath,${LIB_PGTCL_RUNTIME_DIR}'
954	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
955	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.1.0'
956	    AC_CACHE_CHECK([for ELF], tcl_cv_ld_elf, [
957		AC_EGREP_CPP(yes, [
958#ifdef __ELF__
959	yes
960#endif
961		], tcl_cv_ld_elf=yes, tcl_cv_ld_elf=no)])
962	    if test $tcl_cv_ld_elf = yes; then
963		LDFLAGS=-Wl,-export-dynamic
964	    else
965		LDFLAGS=""
966	    fi
967
968	    # OpenBSD doesn't do version numbers with dots.
969	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
970	    TCL_LIB_VERSIONS_OK=nodots
971	    ;;
972	FreeBSD-*)
973	    # FreeBSD 3.* and greater have ELF.
974	    SHLIB_CFLAGS="-fPIC"
975	    SHLIB_LD="ld -Bshareable -x"
976	    SHLIB_LD_LIBS='${LIBS}'
977	    SHLIB_SUFFIX=".so"
978	    DL_OBJS="tclLoadDl.o"
979	    DL_LIBS=""
980	    LDFLAGS="$LDFLAGS -export-dynamic"
981	    CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR},-rpath,${LIB_PGTCL_RUNTIME_DIR}'
982	    LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR} -rpath ${LIB_PGTCL_RUNTIME_DIR}'
983	    if test "${TCL_THREADS}" = "1" ; then
984		# The -pthread needs to go in the CFLAGS, not LIBS
985		LIBS=`echo $LIBS | sed s/-pthread//`
986		CFLAGS="$CFLAGS -pthread"
987	    	LDFLAGS="$LDFLAGS -pthread"
988	    fi
989	    case $system in
990	    FreeBSD-3.*)
991	    	# FreeBSD-3 doesn't handle version numbers with dots.
992	    	UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
993	    	SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so'
994	    	TCL_LIB_VERSIONS_OK=nodots
995		;;
996	    esac
997	    ;;
998	Darwin-*)
999	    CFLAGS_OPTIMIZE="-Os"
1000	    SHLIB_CFLAGS="-fno-common"
1001	    if test $do64bit = yes; then
1002	        do64bit_ok=yes
1003	        CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
1004	    fi
1005	    # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS here:
1006	    SHLIB_LD='${CC} -dynamiclib ${CFLAGS} ${LDFLAGS_DEFAULT}'
1007	    AC_CACHE_CHECK([if ld accepts -single_module flag], tcl_cv_ld_single_module, [
1008	        hold_ldflags=$LDFLAGS
1009	        LDFLAGS="$LDFLAGS -dynamiclib -Wl,-single_module"
1010	        AC_TRY_LINK(, [int i;], tcl_cv_ld_single_module=yes, tcl_cv_ld_single_module=no)
1011	        LDFLAGS=$hold_ldflags])
1012	    if test $tcl_cv_ld_single_module = yes; then
1013	        SHLIB_LD="${SHLIB_LD} -Wl,-single_module"
1014	    fi
1015	    SHLIB_LD_LIBS='${LIBS}'
1016	    SHLIB_SUFFIX=".dylib"
1017	    DL_OBJS="tclLoadDyld.o"
1018	    DL_LIBS=""
1019	    # Don't use -prebind when building for Mac OS X 10.4 or later only:
1020	    test -z "${MACOSX_DEPLOYMENT_TARGET}" || \
1021		test "`echo "${MACOSX_DEPLOYMENT_TARGET}" | awk -F. '{print [$]2}'`" -lt 4 && \
1022		LDFLAGS="$LDFLAGS -prebind"
1023	    LDFLAGS="$LDFLAGS -headerpad_max_install_names"
1024	    AC_CACHE_CHECK([if ld accepts -search_paths_first flag], tcl_cv_ld_search_paths_first, [
1025	        hold_ldflags=$LDFLAGS
1026	        LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
1027	        AC_TRY_LINK(, [int i;], tcl_cv_ld_search_paths_first=yes, tcl_cv_ld_search_paths_first=no)
1028	        LDFLAGS=$hold_ldflags])
1029	    if test $tcl_cv_ld_search_paths_first = yes; then
1030	        LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
1031	    fi
1032	    CC_SEARCH_FLAGS=""
1033	    LD_SEARCH_FLAGS=""
1034	    LD_LIBRARY_PATH_VAR="DYLD_LIBRARY_PATH"
1035
1036	    # TEA specific: for Tk extensions, remove -arch ppc64 from CFLAGS
1037	    # for fat builds, as neither TkAqua nor TkX11 can be built for 64bit
1038	    # at present (no 64bit GUI libraries).
1039	    test $do64bit_ok = no && test -n "${TK_BIN_DIR}" && \
1040	        CFLAGS="`echo "$CFLAGS" | sed -e 's/-arch ppc64/-arch ppc/g'`"
1041	    ;;
1042	NEXTSTEP-*)
1043	    SHLIB_CFLAGS=""
1044	    SHLIB_LD="cc -nostdlib -r"
1045	    SHLIB_LD_LIBS=""
1046	    SHLIB_SUFFIX=".so"
1047	    DL_OBJS="tclLoadNext.o"
1048	    DL_LIBS=""
1049	    CC_SEARCH_FLAGS=""
1050	    LD_SEARCH_FLAGS=""
1051	    ;;
1052	OS/390-*)
1053	    CFLAGS_OPTIMIZE=""		# Optimizer is buggy
1054	    AC_DEFINE(_OE_SOCKETS, 1,	# needed in sys/socket.h
1055		[Should OS/390 do the right thing with sockets?])
1056	    ;;
1057	OSF1-1.0|OSF1-1.1|OSF1-1.2)
1058	    # OSF/1 1.[012] from OSF, and derivatives, including Paragon OSF/1
1059	    SHLIB_CFLAGS=""
1060	    # Hack: make package name same as library name
1061	    SHLIB_LD='ld -R -export $@:'
1062	    SHLIB_LD_LIBS=""
1063	    SHLIB_SUFFIX=".so"
1064	    DL_OBJS="tclLoadOSF.o"
1065	    DL_LIBS=""
1066	    CC_SEARCH_FLAGS=""
1067	    LD_SEARCH_FLAGS=""
1068	    ;;
1069	OSF1-1.*)
1070	    # OSF/1 1.3 from OSF using ELF, and derivatives, including AD2
1071	    SHLIB_CFLAGS="-fPIC"
1072	    if test "$SHARED_BUILD" = "1" ; then
1073	        SHLIB_LD="ld -shared"
1074	    else
1075	        SHLIB_LD="ld -non_shared"
1076	    fi
1077	    SHLIB_LD_LIBS=""
1078	    SHLIB_SUFFIX=".so"
1079	    DL_OBJS="tclLoadDl.o"
1080	    DL_LIBS=""
1081	    CC_SEARCH_FLAGS=""
1082	    LD_SEARCH_FLAGS=""
1083	    ;;
1084	OSF1-V*)
1085	    # Digital OSF/1
1086	    SHLIB_CFLAGS=""
1087	    if test "$SHARED_BUILD" = "1" ; then
1088	        SHLIB_LD='ld -shared -expect_unresolved "*"'
1089	    else
1090	        SHLIB_LD='ld -non_shared -expect_unresolved "*"'
1091	    fi
1092	    SHLIB_LD_LIBS=""
1093	    SHLIB_SUFFIX=".so"
1094	    DL_OBJS="tclLoadDl.o"
1095	    DL_LIBS=""
1096	    CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR},-rpath,${LIB_PGTCL_RUNTIME_DIR}'
1097	    LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR} -rpath ${LIB_PGTCL_RUNTIME_DIR}'
1098	    if test "$GCC" = "yes" ; then
1099		CFLAGS="$CFLAGS -mieee"
1100            else
1101		CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee"
1102	    fi
1103	    # see pthread_intro(3) for pthread support on osf1, k.furukawa
1104	    if test "${TCL_THREADS}" = "1" ; then
1105		CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE"
1106		CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64"
1107		LIBS=`echo $LIBS | sed s/-lpthreads//`
1108		if test "$GCC" = "yes" ; then
1109		    LIBS="$LIBS -lpthread -lmach -lexc"
1110		else
1111		    CFLAGS="$CFLAGS -pthread"
1112		    LDFLAGS="$LDFLAGS -pthread"
1113		fi
1114	    fi
1115
1116	    ;;
1117	QNX-6*)
1118	    # QNX RTP
1119	    # This may work for all QNX, but it was only reported for v6.
1120	    SHLIB_CFLAGS="-fPIC"
1121	    SHLIB_LD="ld -Bshareable -x"
1122	    SHLIB_LD_LIBS=""
1123	    SHLIB_SUFFIX=".so"
1124	    DL_OBJS="tclLoadDl.o"
1125	    # dlopen is in -lc on QNX
1126	    DL_LIBS=""
1127	    CC_SEARCH_FLAGS=""
1128	    LD_SEARCH_FLAGS=""
1129	    ;;
1130	SCO_SV-3.2*)
1131	    # Note, dlopen is available only on SCO 3.2.5 and greater. However,
1132	    # this test works, since "uname -s" was non-standard in 3.2.4 and
1133	    # below.
1134	    if test "$GCC" = "yes" ; then
1135	    	SHLIB_CFLAGS="-fPIC -melf"
1136	    	LDFLAGS="$LDFLAGS -melf -Wl,-Bexport"
1137	    else
1138	    	SHLIB_CFLAGS="-Kpic -belf"
1139	    	LDFLAGS="$LDFLAGS -belf -Wl,-Bexport"
1140	    fi
1141	    SHLIB_LD="ld -G"
1142	    SHLIB_LD_LIBS=""
1143	    SHLIB_SUFFIX=".so"
1144	    DL_OBJS="tclLoadDl.o"
1145	    DL_LIBS=""
1146	    CC_SEARCH_FLAGS=""
1147	    LD_SEARCH_FLAGS=""
1148	    ;;
1149	SINIX*5.4*)
1150	    SHLIB_CFLAGS="-K PIC"
1151	    SHLIB_LD="cc -G"
1152	    SHLIB_LD_LIBS=""
1153	    SHLIB_SUFFIX=".so"
1154	    DL_OBJS="tclLoadDl.o"
1155	    DL_LIBS="-ldl"
1156	    CC_SEARCH_FLAGS=""
1157	    LD_SEARCH_FLAGS=""
1158	    ;;
1159	SunOS-4*)
1160	    SHLIB_CFLAGS="-PIC"
1161	    SHLIB_LD="ld"
1162	    SHLIB_LD_LIBS=""
1163	    SHLIB_SUFFIX=".so"
1164	    DL_OBJS="tclLoadDl.o"
1165	    DL_LIBS="-ldl"
1166	    CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR} -L${LIB_PGTCL_RUNTIME_DIR}'
1167	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1168
1169	    # SunOS can't handle version numbers with dots in them in library
1170	    # specs, like -ltcl7.5, so use -ltcl75 instead.  Also, it
1171	    # requires an extra version number at the end of .so file names.
1172	    # So, the library has to have a name like libtcl75.so.1.0
1173
1174	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.1.0'
1175	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
1176	    TCL_LIB_VERSIONS_OK=nodots
1177	    ;;
1178	SunOS-5.[[0-6]])
1179	    # Careful to not let 5.10+ fall into this case
1180
1181	    # Note: If _REENTRANT isn't defined, then Solaris
1182	    # won't define thread-safe library routines.
1183
1184	    AC_DEFINE(_REENTRANT, 1, [Do we want the reentrant OS API?])
1185	    AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1,
1186		[Do we really want to follow the standard? Yes we do!])
1187
1188	    SHLIB_CFLAGS="-KPIC"
1189
1190	    # Note: need the LIBS below, otherwise Tk won't find Tcl's
1191	    # symbols when dynamically loaded into tclsh.
1192
1193	    SHLIB_LD_LIBS='${LIBS}'
1194	    SHLIB_SUFFIX=".so"
1195	    DL_OBJS="tclLoadDl.o"
1196	    DL_LIBS="-ldl"
1197	    if test "$GCC" = "yes" ; then
1198		SHLIB_LD="$CC -shared"
1199		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR},-R,${LIB_PGTCL_RUNTIME_DIR}'
1200		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1201	    else
1202		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
1203		CC_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR} -R ${LIB_PGTCL_RUNTIME_DIR}'
1204		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1205	    fi
1206	    ;;
1207	SunOS-5*)
1208	    # Note: If _REENTRANT isn't defined, then Solaris
1209	    # won't define thread-safe library routines.
1210
1211	    AC_DEFINE(_REENTRANT, 1, [Do we want the reentrant OS API?])
1212	    AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1,
1213		[Do we really want to follow the standard? Yes we do!])
1214
1215	    SHLIB_CFLAGS="-KPIC"
1216
1217	    # Check to enable 64-bit flags for compiler/linker
1218	    if test "$do64bit" = "yes" ; then
1219		arch=`isainfo`
1220		if test "$arch" = "sparcv9 sparc" ; then
1221			if test "$GCC" = "yes" ; then
1222			    if test "`gcc -dumpversion | awk -F. '{print [$]1}'`" -lt "3" ; then
1223				AC_MSG_WARN([64bit mode not supported with GCC < 3.2 on $system])
1224			    else
1225				do64bit_ok=yes
1226				CFLAGS="$CFLAGS -m64 -mcpu=v9"
1227				LDFLAGS="$LDFLAGS -m64 -mcpu=v9"
1228				SHLIB_CFLAGS="-fPIC"
1229			    fi
1230			else
1231			    do64bit_ok=yes
1232			    if test "$do64bitVIS" = "yes" ; then
1233				CFLAGS="$CFLAGS -xarch=v9a"
1234			    	LDFLAGS_ARCH="-xarch=v9a"
1235			    else
1236				CFLAGS="$CFLAGS -xarch=v9"
1237			    	LDFLAGS_ARCH="-xarch=v9"
1238			    fi
1239			    # Solaris 64 uses this as well
1240			    #LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH_64"
1241			fi
1242		elif test "$arch" = "amd64 i386" ; then
1243		    if test "$GCC" = "yes" ; then
1244			AC_MSG_WARN([64bit mode not supported with GCC on $system])
1245		    else
1246			do64bit_ok=yes
1247			CFLAGS="$CFLAGS -xarch=amd64"
1248			LDFLAGS="$LDFLAGS -xarch=amd64"
1249		    fi
1250		else
1251		    AC_MSG_WARN([64bit mode not supported for $arch])
1252		fi
1253	    fi
1254
1255	    # Note: need the LIBS below, otherwise Tk won't find Tcl's
1256	    # symbols when dynamically loaded into tclsh.
1257
1258	    SHLIB_LD_LIBS='${LIBS}'
1259	    SHLIB_SUFFIX=".so"
1260	    DL_OBJS="tclLoadDl.o"
1261	    DL_LIBS="-ldl"
1262	    if test "$GCC" = "yes" ; then
1263		SHLIB_LD="$CC -shared"
1264		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR},-R,${LIB_PGTCL_RUNTIME_DIR}'
1265		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
1266		if test "$do64bit_ok" = "yes" ; then
1267		    # We need to specify -static-libgcc or we need to
1268		    # add the path to the sparv9 libgcc.
1269		    # JH: static-libgcc is necessary for core Tcl, but may
1270		    # not be necessary for extensions.
1271		    SHLIB_LD="$SHLIB_LD -m64 -mcpu=v9 -static-libgcc"
1272		    # for finding sparcv9 libgcc, get the regular libgcc
1273		    # path, remove so name and append 'sparcv9'
1274		    #v9gcclibdir="`gcc -print-file-name=libgcc_s.so` | ..."
1275		    #CC_SEARCH_FLAGS="${CC_SEARCH_FLAGS},-R,$v9gcclibdir"
1276		fi
1277	    else
1278		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
1279		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR},-R,${LIB_PGTCL_RUNTIME_DIR}'
1280		LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR} -R ${LIB_PGTCL_RUNTIME_DIR}'
1281	    fi
1282	    ;;
1283	UNIX_SV* | UnixWare-5*)
1284	    SHLIB_CFLAGS="-KPIC"
1285	    SHLIB_LD="cc -G"
1286	    SHLIB_LD_LIBS=""
1287	    SHLIB_SUFFIX=".so"
1288	    DL_OBJS="tclLoadDl.o"
1289	    DL_LIBS="-ldl"
1290	    # Some UNIX_SV* systems (unixware 1.1.2 for example) have linkers
1291	    # that don't grok the -Bexport option.  Test that it does.
1292	    AC_CACHE_CHECK([for ld accepts -Bexport flag], tcl_cv_ld_Bexport, [
1293		hold_ldflags=$LDFLAGS
1294		LDFLAGS="$LDFLAGS -Wl,-Bexport"
1295		AC_TRY_LINK(, [int i;], tcl_cv_ld_Bexport=yes, tcl_cv_ld_Bexport=no)
1296	        LDFLAGS=$hold_ldflags])
1297	    if test $tcl_cv_ld_Bexport = yes; then
1298		LDFLAGS="$LDFLAGS -Wl,-Bexport"
1299	    fi
1300	    CC_SEARCH_FLAGS=""
1301	    LD_SEARCH_FLAGS=""
1302	    ;;
1303    esac
1304
1305    if test "$do64bit" = "yes" -a "$do64bit_ok" = "no" ; then
1306	AC_MSG_WARN([64bit support being disabled -- don't know magic for this platform])
1307    fi
1308
1309    # Step 4: disable dynamic loading if requested via a command-line switch.
1310
1311    AC_ARG_ENABLE(load,
1312	AC_HELP_STRING([--disable-load],
1313	    [disallow dynamic loading and "load" command (default: enabled)]),
1314	[tcl_ok=$enableval], [tcl_ok=yes])
1315    if test "$tcl_ok" = "no"; then
1316	DL_OBJS=""
1317    fi
1318
1319    if test "x$DL_OBJS" != "x" ; then
1320	BUILD_DLTEST="\$(DLTEST_TARGETS)"
1321    else
1322	echo "Can't figure out how to do dynamic loading or shared libraries"
1323	echo "on this system."
1324	SHLIB_CFLAGS=""
1325	SHLIB_LD=""
1326	SHLIB_SUFFIX=""
1327	DL_OBJS="tclLoadNone.o"
1328	DL_LIBS=""
1329	LDFLAGS="$LDFLAGS_ORIG"
1330	CC_SEARCH_FLAGS=""
1331	LD_SEARCH_FLAGS=""
1332	BUILD_DLTEST=""
1333    fi
1334    LDFLAGS="$LDFLAGS $LDFLAGS_ARCH"
1335
1336    # If we're running gcc, then change the C flags for compiling shared
1337    # libraries to the right flags for gcc, instead of those for the
1338    # standard manufacturer compiler.
1339
1340    if test "$DL_OBJS" != "tclLoadNone.o" ; then
1341	if test "$GCC" = "yes" ; then
1342	    case $system in
1343		AIX-*)
1344		    ;;
1345		BSD/OS*)
1346		    ;;
1347		IRIX*)
1348		    ;;
1349		NetBSD-*|FreeBSD-*)
1350		    ;;
1351		Darwin-*)
1352		    ;;
1353		SCO_SV-3.2*)
1354		    ;;
1355		windows)
1356		    ;;
1357		*)
1358		    SHLIB_CFLAGS="-fPIC"
1359		    ;;
1360	    esac
1361	fi
1362    fi
1363
1364    if test "$SHARED_LIB_SUFFIX" = "" ; then
1365	SHARED_LIB_SUFFIX='${PACKAGE_VERSION}${SHLIB_SUFFIX}'
1366    fi
1367    if test "$UNSHARED_LIB_SUFFIX" = "" ; then
1368	UNSHARED_LIB_SUFFIX='${PACKAGE_VERSION}.a'
1369    fi
1370
1371    AC_SUBST(DL_LIBS)
1372
1373    AC_SUBST(CFLAGS_DEBUG)
1374    AC_SUBST(CFLAGS_OPTIMIZE)
1375    AC_SUBST(CFLAGS_WARNING)
1376
1377    AC_SUBST(STLIB_LD)
1378    AC_SUBST(SHLIB_LD)
1379
1380    AC_SUBST(SHLIB_LD_LIBS)
1381    AC_SUBST(SHLIB_CFLAGS)
1382
1383    AC_SUBST(LD_LIBRARY_PATH_VAR)
1384
1385    # These must be called after we do the basic CFLAGS checks and
1386    # verify any possible 64-bit or similar switches are necessary
1387    TEA_TCL_EARLY_FLAGS
1388    TEA_TCL_64BIT_FLAGS
1389])
1390
1391#--------------------------------------------------------------------
1392# TEA_MISSING_POSIX_HEADERS
1393#
1394#	Supply substitutes for missing POSIX header files.  Special
1395#	notes:
1396#	    - stdlib.h doesn't define strtol, strtoul, or
1397#	      strtod insome versions of SunOS
1398#	    - some versions of string.h don't declare procedures such
1399#	      as strstr
1400#
1401# Arguments:
1402#	none
1403#
1404# Results:
1405#
1406#	Defines some of the following vars:
1407#		NO_DIRENT_H
1408#		NO_ERRNO_H
1409#		NO_VALUES_H
1410#		HAVE_LIMITS_H or NO_LIMITS_H
1411#		NO_STDLIB_H
1412#		NO_STRING_H
1413#		NO_SYS_WAIT_H
1414#		NO_DLFCN_H
1415#		HAVE_SYS_PARAM_H
1416#
1417#		HAVE_STRING_H ?
1418#
1419# tkUnixPort.h checks for HAVE_LIMITS_H, so do both HAVE and
1420# CHECK on limits.h
1421#--------------------------------------------------------------------
1422
1423AC_DEFUN([TEA_MISSING_POSIX_HEADERS], [
1424    AC_CACHE_CHECK([dirent.h], tcl_cv_dirent_h,
1425    AC_TRY_LINK([#include <sys/types.h>
1426#include <dirent.h>], [
1427#ifndef _POSIX_SOURCE
1428#   ifdef __Lynx__
1429	/*
1430	 * Generate compilation error to make the test fail:  Lynx headers
1431	 * are only valid if really in the POSIX environment.
1432	 */
1433
1434	missing_procedure();
1435#   endif
1436#endif
1437DIR *d;
1438struct dirent *entryPtr;
1439char *p;
1440d = opendir("foobar");
1441entryPtr = readdir(d);
1442p = entryPtr->d_name;
1443closedir(d);
1444], tcl_cv_dirent_h=yes, tcl_cv_dirent_h=no))
1445
1446    if test $tcl_cv_dirent_h = no; then
1447	AC_DEFINE(NO_DIRENT_H, 1, [Do we have <dirent.h>?])
1448    fi
1449
1450    AC_CHECK_HEADER(errno.h, , [AC_DEFINE(NO_ERRNO_H, 1, [Do we have <errno.h>?])])
1451    AC_CHECK_HEADER(float.h, , [AC_DEFINE(NO_FLOAT_H, 1, [Do we have <float.h>?])])
1452    AC_CHECK_HEADER(values.h, , [AC_DEFINE(NO_VALUES_H, 1, [Do we have <values.h>?])])
1453    AC_CHECK_HEADER(limits.h,
1454	[AC_DEFINE(HAVE_LIMITS_H, 1, [Do we have <limits.h>?])],
1455	[AC_DEFINE(NO_LIMITS_H, 1, [Do we have <limits.h>?])])
1456    AC_CHECK_HEADER(stdlib.h, tcl_ok=1, tcl_ok=0)
1457    AC_EGREP_HEADER(strtol, stdlib.h, , tcl_ok=0)
1458    AC_EGREP_HEADER(strtoul, stdlib.h, , tcl_ok=0)
1459    AC_EGREP_HEADER(strtod, stdlib.h, , tcl_ok=0)
1460    if test $tcl_ok = 0; then
1461	AC_DEFINE(NO_STDLIB_H, 1, [Do we have <stdlib.h>?])
1462    fi
1463    AC_CHECK_HEADER(string.h, tcl_ok=1, tcl_ok=0)
1464    AC_EGREP_HEADER(strstr, string.h, , tcl_ok=0)
1465    AC_EGREP_HEADER(strerror, string.h, , tcl_ok=0)
1466
1467    # See also memmove check below for a place where NO_STRING_H can be
1468    # set and why.
1469
1470    if test $tcl_ok = 0; then
1471	AC_DEFINE(NO_STRING_H, 1, [Do we have <string.h>?])
1472    fi
1473
1474    AC_CHECK_HEADER(sys/wait.h, , [AC_DEFINE(NO_SYS_WAIT_H, 1, [Do we have <sys/wait.h>?])])
1475    AC_CHECK_HEADER(dlfcn.h, , [AC_DEFINE(NO_DLFCN_H, 1, [Do we have <dlfcn.h>?])])
1476
1477    # OS/390 lacks sys/param.h (and doesn't need it, by chance).
1478    AC_HAVE_HEADERS(sys/param.h)
1479])
1480
1481#--------------------------------------------------------------------
1482# TEA_BLOCKING_STYLE
1483#
1484#	The statements below check for systems where POSIX-style
1485#	non-blocking I/O (O_NONBLOCK) doesn't work or is unimplemented.
1486#	On these systems (mostly older ones), use the old BSD-style
1487#	FIONBIO approach instead.
1488#
1489# Arguments:
1490#	none
1491#
1492# Results:
1493#
1494#	Defines some of the following vars:
1495#		HAVE_SYS_IOCTL_H
1496#		HAVE_SYS_FILIO_H
1497#		USE_FIONBIO
1498#		O_NONBLOCK
1499#
1500#--------------------------------------------------------------------
1501
1502AC_DEFUN([TEA_BLOCKING_STYLE], [
1503    AC_CHECK_HEADERS(sys/ioctl.h)
1504    AC_CHECK_HEADERS(sys/filio.h)
1505    TEA_CONFIG_SYSTEM
1506    AC_MSG_CHECKING([FIONBIO vs. O_NONBLOCK for nonblocking I/O])
1507    case $system in
1508	# There used to be code here to use FIONBIO under AIX.  However, it
1509	# was reported that FIONBIO doesn't work under AIX 3.2.5.  Since
1510	# using O_NONBLOCK seems fine under AIX 4.*, I removed the FIONBIO
1511	# code (JO, 5/31/97).
1512
1513	OSF*)
1514	    AC_DEFINE(USE_FIONBIO, 1, [Should we use FIONBIO?])
1515	    AC_MSG_RESULT([FIONBIO])
1516	    ;;
1517	SunOS-4*)
1518	    AC_DEFINE(USE_FIONBIO, 1, [Should we use FIONBIO?])
1519	    AC_MSG_RESULT([FIONBIO])
1520	    ;;
1521	*)
1522	    AC_MSG_RESULT([O_NONBLOCK])
1523	    ;;
1524    esac
1525])
1526
1527#--------------------------------------------------------------------
1528# TEA_TIME_HANLDER
1529#
1530#	Checks how the system deals with time.h, what time structures
1531#	are used on the system, and what fields the structures have.
1532#
1533# Arguments:
1534#	none
1535#
1536# Results:
1537#
1538#	Defines some of the following vars:
1539#		USE_DELTA_FOR_TZ
1540#		HAVE_TM_GMTOFF
1541#		HAVE_TM_TZADJ
1542#		HAVE_TIMEZONE_VAR
1543#
1544#--------------------------------------------------------------------
1545
1546AC_DEFUN([TEA_TIME_HANDLER], [
1547    AC_CHECK_HEADERS(sys/time.h)
1548    AC_HEADER_TIME
1549    AC_STRUCT_TIMEZONE
1550
1551    AC_CHECK_FUNCS(gmtime_r localtime_r)
1552
1553    AC_CACHE_CHECK([tm_tzadj in struct tm], tcl_cv_member_tm_tzadj,
1554	AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_tzadj;],
1555	    tcl_cv_member_tm_tzadj=yes, tcl_cv_member_tm_tzadj=no))
1556    if test $tcl_cv_member_tm_tzadj = yes ; then
1557	AC_DEFINE(HAVE_TM_TZADJ, 1, [Should we use the tm_tzadj field of struct tm?])
1558    fi
1559
1560    AC_CACHE_CHECK([tm_gmtoff in struct tm], tcl_cv_member_tm_gmtoff,
1561	AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_gmtoff;],
1562	    tcl_cv_member_tm_gmtoff=yes, tcl_cv_member_tm_gmtoff=no))
1563    if test $tcl_cv_member_tm_gmtoff = yes ; then
1564	AC_DEFINE(HAVE_TM_GMTOFF, 1, [Should we use the tm_gmtoff field of struct tm?])
1565    fi
1566
1567    #
1568    # Its important to include time.h in this check, as some systems
1569    # (like convex) have timezone functions, etc.
1570    #
1571    AC_CACHE_CHECK([long timezone variable], tcl_cv_timezone_long,
1572	AC_TRY_COMPILE([#include <time.h>],
1573	    [extern long timezone;
1574	    timezone += 1;
1575	    exit (0);],
1576	    tcl_cv_timezone_long=yes, tcl_cv_timezone_long=no))
1577    if test $tcl_cv_timezone_long = yes ; then
1578	AC_DEFINE(HAVE_TIMEZONE_VAR, 1, [Should we use the global timezone variable?])
1579    else
1580	#
1581	# On some systems (eg IRIX 6.2), timezone is a time_t and not a long.
1582	#
1583	AC_CACHE_CHECK([time_t timezone variable], tcl_cv_timezone_time,
1584	    AC_TRY_COMPILE([#include <time.h>],
1585		[extern time_t timezone;
1586		timezone += 1;
1587		exit (0);],
1588		tcl_cv_timezone_time=yes, tcl_cv_timezone_time=no))
1589	if test $tcl_cv_timezone_time = yes ; then
1590	    AC_DEFINE(HAVE_TIMEZONE_VAR, 1, [Should we use the global timezone variable?])
1591	fi
1592    fi
1593])
1594
1595#--------------------------------------------------------------------
1596# TEA_BUGGY_STRTOD
1597#
1598#	Under Solaris 2.4, strtod returns the wrong value for the
1599#	terminating character under some conditions.  Check for this
1600#	and if the problem exists use a substitute procedure
1601#	"fixstrtod" (provided by Tcl) that corrects the error.
1602#	Also, on Compaq's Tru64 Unix 5.0,
1603#	strtod(" ") returns 0.0 instead of a failure to convert.
1604#
1605# Arguments:
1606#	none
1607#
1608# Results:
1609#
1610#	Might defines some of the following vars:
1611#		strtod (=fixstrtod)
1612#
1613#--------------------------------------------------------------------
1614
1615AC_DEFUN([TEA_BUGGY_STRTOD], [
1616    AC_CHECK_FUNC(strtod, tcl_strtod=1, tcl_strtod=0)
1617    if test "$tcl_strtod" = 1; then
1618	AC_CACHE_CHECK([for Solaris2.4/Tru64 strtod bugs], tcl_cv_strtod_buggy,[
1619	    AC_TRY_RUN([
1620		extern double strtod();
1621		int main() {
1622		    char *infString="Inf", *nanString="NaN", *spaceString=" ";
1623		    char *term;
1624		    double value;
1625		    value = strtod(infString, &term);
1626		    if ((term != infString) && (term[-1] == 0)) {
1627			exit(1);
1628		    }
1629		    value = strtod(nanString, &term);
1630		    if ((term != nanString) && (term[-1] == 0)) {
1631			exit(1);
1632		    }
1633		    value = strtod(spaceString, &term);
1634		    if (term == (spaceString+1)) {
1635			exit(1);
1636		    }
1637		    exit(0);
1638		}], tcl_cv_strtod_buggy=ok, tcl_cv_strtod_buggy=buggy,
1639		    tcl_cv_strtod_buggy=buggy)])
1640	if test "$tcl_cv_strtod_buggy" = buggy; then
1641	    AC_LIBOBJ([fixstrtod])
1642	    USE_COMPAT=1
1643	    AC_DEFINE(strtod, fixstrtod, [Do we want to use the strtod() in compat?])
1644	fi
1645    fi
1646])
1647
1648#--------------------------------------------------------------------
1649# TEA_TCL_LINK_LIBS
1650#
1651#	Search for the libraries needed to link the Tcl shell.
1652#	Things like the math library (-lm) and socket stuff (-lsocket vs.
1653#	-lnsl) are dealt with here.
1654#
1655# Arguments:
1656#	Requires the following vars to be set in the Makefile:
1657#		DL_LIBS
1658#		LIBS
1659#		MATH_LIBS
1660#
1661# Results:
1662#
1663#	Subst's the following var:
1664#		TCL_LIBS
1665#		MATH_LIBS
1666#
1667#	Might append to the following vars:
1668#		LIBS
1669#
1670#	Might define the following vars:
1671#		HAVE_NET_ERRNO_H
1672#
1673#--------------------------------------------------------------------
1674
1675AC_DEFUN([TEA_TCL_LINK_LIBS], [
1676    #--------------------------------------------------------------------
1677    # On a few very rare systems, all of the libm.a stuff is
1678    # already in libc.a.  Set compiler flags accordingly.
1679    # Also, Linux requires the "ieee" library for math to work
1680    # right (and it must appear before "-lm").
1681    #--------------------------------------------------------------------
1682
1683    AC_CHECK_FUNC(sin, MATH_LIBS="", MATH_LIBS="-lm")
1684    AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"])
1685
1686    #--------------------------------------------------------------------
1687    # Interactive UNIX requires -linet instead of -lsocket, plus it
1688    # needs net/errno.h to define the socket-related error codes.
1689    #--------------------------------------------------------------------
1690
1691    AC_CHECK_LIB(inet, main, [LIBS="$LIBS -linet"])
1692    AC_CHECK_HEADER(net/errno.h, [
1693	AC_DEFINE(HAVE_NET_ERRNO_H, 1, [Do we have <net/errno.h>?])])
1694
1695    #--------------------------------------------------------------------
1696    #	Check for the existence of the -lsocket and -lnsl libraries.
1697    #	The order here is important, so that they end up in the right
1698    #	order in the command line generated by make.  Here are some
1699    #	special considerations:
1700    #	1. Use "connect" and "accept" to check for -lsocket, and
1701    #	   "gethostbyname" to check for -lnsl.
1702    #	2. Use each function name only once:  can't redo a check because
1703    #	   autoconf caches the results of the last check and won't redo it.
1704    #	3. Use -lnsl and -lsocket only if they supply procedures that
1705    #	   aren't already present in the normal libraries.  This is because
1706    #	   IRIX 5.2 has libraries, but they aren't needed and they're
1707    #	   bogus:  they goof up name resolution if used.
1708    #	4. On some SVR4 systems, can't use -lsocket without -lnsl too.
1709    #	   To get around this problem, check for both libraries together
1710    #	   if -lsocket doesn't work by itself.
1711    #--------------------------------------------------------------------
1712
1713    tcl_checkBoth=0
1714    AC_CHECK_FUNC(connect, tcl_checkSocket=0, tcl_checkSocket=1)
1715    if test "$tcl_checkSocket" = 1; then
1716	AC_CHECK_FUNC(setsockopt, , [AC_CHECK_LIB(socket, setsockopt,
1717	    LIBS="$LIBS -lsocket", tcl_checkBoth=1)])
1718    fi
1719    if test "$tcl_checkBoth" = 1; then
1720	tk_oldLibs=$LIBS
1721	LIBS="$LIBS -lsocket -lnsl"
1722	AC_CHECK_FUNC(accept, tcl_checkNsl=0, [LIBS=$tk_oldLibs])
1723    fi
1724    AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(nsl, gethostbyname,
1725	    [LIBS="$LIBS -lnsl"])])
1726
1727    # Don't perform the eval of the libraries here because DL_LIBS
1728    # won't be set until we call TEA_CONFIG_CFLAGS
1729
1730    TCL_LIBS='${DL_LIBS} ${LIBS} ${MATH_LIBS}'
1731    AC_SUBST(TCL_LIBS)
1732    AC_SUBST(MATH_LIBS)
1733])
1734
1735#--------------------------------------------------------------------
1736# TEA_TCL_EARLY_FLAGS
1737#
1738#	Check for what flags are needed to be passed so the correct OS
1739#	features are available.
1740#
1741# Arguments:
1742#	None
1743#
1744# Results:
1745#
1746#	Might define the following vars:
1747#		_ISOC99_SOURCE
1748#		_LARGEFILE64_SOURCE
1749#		_LARGEFILE_SOURCE64
1750#
1751#--------------------------------------------------------------------
1752
1753AC_DEFUN([TEA_TCL_EARLY_FLAG],[
1754    AC_CACHE_VAL([tcl_cv_flag_]translit($1,[A-Z],[a-z]),
1755	AC_TRY_COMPILE([$2], $3, [tcl_cv_flag_]translit($1,[A-Z],[a-z])=no,
1756	    AC_TRY_COMPILE([[#define ]$1[ 1
1757]$2], $3,
1758		[tcl_cv_flag_]translit($1,[A-Z],[a-z])=yes,
1759		[tcl_cv_flag_]translit($1,[A-Z],[a-z])=no)))
1760    if test ["x${tcl_cv_flag_]translit($1,[A-Z],[a-z])[}" = "xyes"] ; then
1761	AC_DEFINE($1, 1, [Add the ]$1[ flag when building])
1762	tcl_flags="$tcl_flags $1"
1763    fi
1764])
1765
1766AC_DEFUN([TEA_TCL_EARLY_FLAGS],[
1767    AC_MSG_CHECKING([for required early compiler flags])
1768    tcl_flags=""
1769    TEA_TCL_EARLY_FLAG(_ISOC99_SOURCE,[#include <stdlib.h>],
1770	[char *p = (char *)strtoll; char *q = (char *)strtoull;])
1771    TEA_TCL_EARLY_FLAG(_LARGEFILE64_SOURCE,[#include <sys/stat.h>],
1772	[struct stat64 buf; int i = stat64("/", &buf);])
1773    TEA_TCL_EARLY_FLAG(_LARGEFILE_SOURCE64,[#include <sys/stat.h>],
1774	[char *p = (char *)open64;])
1775    if test "x${tcl_flags}" = "x" ; then
1776	AC_MSG_RESULT([none])
1777    else
1778	AC_MSG_RESULT([${tcl_flags}])
1779    fi
1780])
1781
1782#--------------------------------------------------------------------
1783# TEA_TCL_64BIT_FLAGS
1784#
1785#	Check for what is defined in the way of 64-bit features.
1786#
1787# Arguments:
1788#	None
1789#
1790# Results:
1791#
1792#	Might define the following vars:
1793#		TCL_WIDE_INT_IS_LONG
1794#		TCL_WIDE_INT_TYPE
1795#		HAVE_STRUCT_DIRENT64
1796#		HAVE_STRUCT_STAT64
1797#		HAVE_TYPE_OFF64_T
1798#
1799#--------------------------------------------------------------------
1800
1801AC_DEFUN([TEA_TCL_64BIT_FLAGS], [
1802    AC_MSG_CHECKING([for 64-bit integer type])
1803    AC_CACHE_VAL(tcl_cv_type_64bit,[
1804	tcl_cv_type_64bit=none
1805	# See if the compiler knows natively about __int64
1806	AC_TRY_COMPILE(,[__int64 value = (__int64) 0;],
1807	    tcl_type_64bit=__int64, tcl_type_64bit="long long")
1808	# See if we should use long anyway  Note that we substitute in the
1809	# type that is our current guess for a 64-bit type inside this check
1810	# program, so it should be modified only carefully...
1811        AC_TRY_COMPILE(,[switch (0) {
1812            case 1: case (sizeof(]${tcl_type_64bit}[)==sizeof(long)): ;
1813        }],tcl_cv_type_64bit=${tcl_type_64bit})])
1814    if test "${tcl_cv_type_64bit}" = none ; then
1815	AC_DEFINE(TCL_WIDE_INT_IS_LONG, 1, [Are wide integers to be implemented with C 'long's?])
1816	AC_MSG_RESULT([using long])
1817    elif test "${tcl_cv_type_64bit}" = "__int64" \
1818		-a "${TEA_PLATFORM}" = "windows" ; then
1819	# We actually want to use the default tcl.h checks in this
1820	# case to handle both TCL_WIDE_INT_TYPE and TCL_LL_MODIFIER*
1821	AC_MSG_RESULT([using Tcl header defaults])
1822    else
1823	AC_DEFINE_UNQUOTED(TCL_WIDE_INT_TYPE,${tcl_cv_type_64bit},
1824	    [What type should be used to define wide integers?])
1825	AC_MSG_RESULT([${tcl_cv_type_64bit}])
1826
1827	# Now check for auxiliary declarations
1828	AC_CACHE_CHECK([for struct dirent64], tcl_cv_struct_dirent64,[
1829	    AC_TRY_COMPILE([#include <sys/types.h>
1830#include <sys/dirent.h>],[struct dirent64 p;],
1831		tcl_cv_struct_dirent64=yes,tcl_cv_struct_dirent64=no)])
1832	if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then
1833	    AC_DEFINE(HAVE_STRUCT_DIRENT64, 1, [Is 'struct dirent64' in <sys/types.h>?])
1834	fi
1835
1836	AC_CACHE_CHECK([for struct stat64], tcl_cv_struct_stat64,[
1837	    AC_TRY_COMPILE([#include <sys/stat.h>],[struct stat64 p;
1838],
1839		tcl_cv_struct_stat64=yes,tcl_cv_struct_stat64=no)])
1840	if test "x${tcl_cv_struct_stat64}" = "xyes" ; then
1841	    AC_DEFINE(HAVE_STRUCT_STAT64, 1, [Is 'struct stat64' in <sys/stat.h>?])
1842	fi
1843
1844	AC_CHECK_FUNCS(open64 lseek64)
1845	AC_MSG_CHECKING([for off64_t])
1846	AC_CACHE_VAL(tcl_cv_type_off64_t,[
1847	    AC_TRY_COMPILE([#include <sys/types.h>],[off64_t offset;
1848],
1849		tcl_cv_type_off64_t=yes,tcl_cv_type_off64_t=no)])
1850	dnl Define HAVE_TYPE_OFF64_T only when the off64_t type and the
1851	dnl functions lseek64 and open64 are defined.
1852	if test "x${tcl_cv_type_off64_t}" = "xyes" && \
1853	        test "x${ac_cv_func_lseek64}" = "xyes" && \
1854	        test "x${ac_cv_func_open64}" = "xyes" ; then
1855	    AC_DEFINE(HAVE_TYPE_OFF64_T, 1, [Is off64_t in <sys/types.h>?])
1856	    AC_MSG_RESULT([yes])
1857	else
1858	    AC_MSG_RESULT([no])
1859	fi
1860    fi
1861])
1862
1863##
1864## Here ends the standard Tcl configuration bits and starts the
1865## TEA specific functions
1866##
1867
1868#------------------------------------------------------------------------
1869# TEA_INIT --
1870#
1871#	Init various Tcl Extension Architecture (TEA) variables.
1872#	This should be the first called TEA_* macro.
1873#
1874# Arguments:
1875#	none
1876#
1877# Results:
1878#
1879#	Defines and substs the following vars:
1880#		CYGPATH
1881#		EXEEXT
1882#	Defines only:
1883#		TEA_VERSION
1884#		TEA_INITED
1885#		TEA_PLATFORM (windows or unix)
1886#
1887# "cygpath" is used on windows to generate native path names for include
1888# files. These variables should only be used with the compiler and linker
1889# since they generate native path names.
1890#
1891# EXEEXT
1892#	Select the executable extension based on the host type.  This
1893#	is a lightweight replacement for AC_EXEEXT that doesn't require
1894#	a compiler.
1895#------------------------------------------------------------------------
1896
1897AC_DEFUN([TEA_INIT], [
1898    # TEA extensions pass this us the version of TEA they think they
1899    # are compatible with.
1900    TEA_VERSION="3.5"
1901
1902    AC_MSG_CHECKING([for correct TEA configuration])
1903    if test x"${PACKAGE_NAME}" = x ; then
1904	AC_MSG_ERROR([
1905The PACKAGE_NAME variable must be defined by your TEA configure.in])
1906    fi
1907    if test x"$1" = x ; then
1908	AC_MSG_ERROR([
1909TEA version not specified.])
1910    elif test "$1" != "${TEA_VERSION}" ; then
1911	AC_MSG_RESULT([warning: requested TEA version "$1", have "${TEA_VERSION}"])
1912    else
1913	AC_MSG_RESULT([ok (TEA ${TEA_VERSION})])
1914    fi
1915    case "`uname -s`" in
1916	*win32*|*WIN32*|*CYGWIN_NT*|*CYGWIN_9*|*CYGWIN_ME*|*MINGW32_*)
1917	    AC_CHECK_PROG(CYGPATH, cygpath, cygpath -w, echo)
1918	    EXEEXT=".exe"
1919	    TEA_PLATFORM="windows"
1920	    ;;
1921	*)
1922	    CYGPATH=echo
1923	    EXEEXT=""
1924	    TEA_PLATFORM="unix"
1925	    ;;
1926    esac
1927
1928    # Check if exec_prefix is set. If not use fall back to prefix.
1929    # Note when adjusted, so that TEA_PREFIX can correct for this.
1930    # This is needed for recursive configures, since autoconf propagates
1931    # $prefix, but not $exec_prefix (doh!).
1932    if test x$exec_prefix = xNONE ; then
1933	exec_prefix_default=yes
1934	exec_prefix=$prefix
1935    fi
1936
1937    AC_SUBST(EXEEXT)
1938    AC_SUBST(CYGPATH)
1939
1940    # This package name must be replaced statically for AC_SUBST to work
1941    AC_SUBST(PKG_LIB_FILE)
1942    # Substitute STUB_LIB_FILE in case package creates a stub library too.
1943    AC_SUBST(PKG_STUB_LIB_FILE)
1944
1945    # We AC_SUBST these here to ensure they are subst'ed,
1946    # in case the user doesn't call TEA_ADD_...
1947    AC_SUBST(PKG_STUB_SOURCES)
1948    AC_SUBST(PKG_STUB_OBJECTS)
1949    AC_SUBST(PKG_TCL_SOURCES)
1950    AC_SUBST(PKG_HEADERS)
1951    AC_SUBST(PKG_INCLUDES)
1952    AC_SUBST(PKG_LIBS)
1953    AC_SUBST(PKG_CFLAGS)
1954])
1955
1956#------------------------------------------------------------------------
1957# TEA_ADD_SOURCES --
1958#
1959#	Specify one or more source files.  Users should check for
1960#	the right platform before adding to their list.
1961#	It is not important to specify the directory, as long as it is
1962#	in the generic, win or unix subdirectory of $(srcdir).
1963#
1964# Arguments:
1965#	one or more file names
1966#
1967# Results:
1968#
1969#	Defines and substs the following vars:
1970#		PKG_SOURCES
1971#		PKG_OBJECTS
1972#------------------------------------------------------------------------
1973AC_DEFUN([TEA_ADD_SOURCES], [
1974    vars="$@"
1975    for i in $vars; do
1976	case $i in
1977	    [\$]*)
1978		# allow $-var names
1979		PKG_SOURCES="$PKG_SOURCES $i"
1980		PKG_OBJECTS="$PKG_OBJECTS $i"
1981		;;
1982	    *)
1983		# check for existence - allows for generic/win/unix VPATH
1984		if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \
1985		    -a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \
1986		    ; then
1987		    AC_MSG_ERROR([could not find source file '$i'])
1988		fi
1989		PKG_SOURCES="$PKG_SOURCES $i"
1990		# this assumes it is in a VPATH dir
1991		i=`basename $i`
1992		# handle user calling this before or after TEA_SETUP_COMPILER
1993		if test x"${OBJEXT}" != x ; then
1994		    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.${OBJEXT}"
1995		else
1996		    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.\${OBJEXT}"
1997		fi
1998		PKG_OBJECTS="$PKG_OBJECTS $j"
1999		;;
2000	esac
2001    done
2002    AC_SUBST(PKG_SOURCES)
2003    AC_SUBST(PKG_OBJECTS)
2004])
2005
2006#------------------------------------------------------------------------
2007# TEA_ADD_STUB_SOURCES --
2008#
2009#	Specify one or more source files.  Users should check for
2010#	the right platform before adding to their list.
2011#	It is not important to specify the directory, as long as it is
2012#	in the generic, win or unix subdirectory of $(srcdir).
2013#
2014# Arguments:
2015#	one or more file names
2016#
2017# Results:
2018#
2019#	Defines and substs the following vars:
2020#		PKG_STUB_SOURCES
2021#		PKG_STUB_OBJECTS
2022#------------------------------------------------------------------------
2023AC_DEFUN([TEA_ADD_STUB_SOURCES], [
2024    vars="$@"
2025    for i in $vars; do
2026	# check for existence - allows for generic/win/unix VPATH
2027	if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \
2028	    -a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \
2029	    ; then
2030	    AC_MSG_ERROR([could not find stub source file '$i'])
2031	fi
2032	PKG_STUB_SOURCES="$PKG_STUB_SOURCES $i"
2033	# this assumes it is in a VPATH dir
2034	i=`basename $i`
2035	# handle user calling this before or after TEA_SETUP_COMPILER
2036	if test x"${OBJEXT}" != x ; then
2037	    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.${OBJEXT}"
2038	else
2039	    j="`echo $i | sed -e 's/\.[[^.]]*$//'`.\${OBJEXT}"
2040	fi
2041	PKG_STUB_OBJECTS="$PKG_STUB_OBJECTS $j"
2042    done
2043    AC_SUBST(PKG_STUB_SOURCES)
2044    AC_SUBST(PKG_STUB_OBJECTS)
2045])
2046
2047#------------------------------------------------------------------------
2048# TEA_ADD_TCL_SOURCES --
2049#
2050#	Specify one or more Tcl source files.  These should be platform
2051#	independent runtime files.
2052#
2053# Arguments:
2054#	one or more file names
2055#
2056# Results:
2057#
2058#	Defines and substs the following vars:
2059#		PKG_TCL_SOURCES
2060#------------------------------------------------------------------------
2061AC_DEFUN([TEA_ADD_TCL_SOURCES], [
2062    vars="$@"
2063    for i in $vars; do
2064	# check for existence, be strict because it is installed
2065	if test ! -f "${srcdir}/$i" ; then
2066	    AC_MSG_ERROR([could not find tcl source file '${srcdir}/$i'])
2067	fi
2068	PKG_TCL_SOURCES="$PKG_TCL_SOURCES $i"
2069    done
2070    AC_SUBST(PKG_TCL_SOURCES)
2071])
2072
2073#------------------------------------------------------------------------
2074# TEA_ADD_HEADERS --
2075#
2076#	Specify one or more source headers.  Users should check for
2077#	the right platform before adding to their list.
2078#
2079# Arguments:
2080#	one or more file names
2081#
2082# Results:
2083#
2084#	Defines and substs the following vars:
2085#		PKG_HEADERS
2086#------------------------------------------------------------------------
2087AC_DEFUN([TEA_ADD_HEADERS], [
2088    vars="$@"
2089    for i in $vars; do
2090	# check for existence, be strict because it is installed
2091	if test ! -f "${srcdir}/$i" ; then
2092	    AC_MSG_ERROR([could not find header file '${srcdir}/$i'])
2093	fi
2094	PKG_HEADERS="$PKG_HEADERS $i"
2095    done
2096    AC_SUBST(PKG_HEADERS)
2097])
2098
2099#------------------------------------------------------------------------
2100# TEA_ADD_INCLUDES --
2101#
2102#	Specify one or more include dirs.  Users should check for
2103#	the right platform before adding to their list.
2104#
2105# Arguments:
2106#	one or more file names
2107#
2108# Results:
2109#
2110#	Defines and substs the following vars:
2111#		PKG_INCLUDES
2112#------------------------------------------------------------------------
2113AC_DEFUN([TEA_ADD_INCLUDES], [
2114    vars="$@"
2115    for i in $vars; do
2116	PKG_INCLUDES="$PKG_INCLUDES $i"
2117    done
2118    AC_SUBST(PKG_INCLUDES)
2119])
2120
2121#------------------------------------------------------------------------
2122# TEA_ADD_LIBS --
2123#
2124#	Specify one or more libraries.  Users should check for
2125#	the right platform before adding to their list.  For Windows,
2126#	libraries provided in "foo.lib" format will be converted to
2127#	"-lfoo" when using GCC (mingw).
2128#
2129# Arguments:
2130#	one or more file names
2131#
2132# Results:
2133#
2134#	Defines and substs the following vars:
2135#		PKG_LIBS
2136#------------------------------------------------------------------------
2137AC_DEFUN([TEA_ADD_LIBS], [
2138    vars="$@"
2139    for i in $vars; do
2140	if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then
2141	    # Convert foo.lib to -lfoo for GCC.  No-op if not *.lib
2142	    i=`echo "$i" | sed -e 's/^\([[^-]].*\)\.lib[$]/-l\1/i'`
2143	fi
2144	PKG_LIBS="$PKG_LIBS $i"
2145    done
2146    AC_SUBST(PKG_LIBS)
2147])
2148
2149#------------------------------------------------------------------------
2150# TEA_ADD_CFLAGS --
2151#
2152#	Specify one or more CFLAGS.  Users should check for
2153#	the right platform before adding to their list.
2154#
2155# Arguments:
2156#	one or more file names
2157#
2158# Results:
2159#
2160#	Defines and substs the following vars:
2161#		PKG_CFLAGS
2162#------------------------------------------------------------------------
2163AC_DEFUN([TEA_ADD_CFLAGS], [
2164    PKG_CFLAGS="$PKG_CFLAGS $@"
2165    AC_SUBST(PKG_CFLAGS)
2166])
2167
2168#------------------------------------------------------------------------
2169# TEA_PREFIX --
2170#
2171#	Handle the --prefix=... option by defaulting to what Tcl gave
2172#
2173# Arguments:
2174#	none
2175#
2176# Results:
2177#
2178#	If --prefix or --exec-prefix was not specified, $prefix and
2179#	$exec_prefix will be set to the values given to Tcl when it was
2180#	configured.
2181#------------------------------------------------------------------------
2182AC_DEFUN([TEA_PREFIX], [
2183    if test "${prefix}" = "NONE"; then
2184	prefix_default=yes
2185	if test x"${TCL_PREFIX}" != x; then
2186	    AC_MSG_NOTICE([--prefix defaulting to TCL_PREFIX ${TCL_PREFIX}])
2187	    prefix=${TCL_PREFIX}
2188	else
2189	    AC_MSG_NOTICE([--prefix defaulting to /usr/local])
2190	    prefix=/usr/local
2191	fi
2192    fi
2193    if test "${exec_prefix}" = "NONE" -a x"${prefix_default}" = x"yes" \
2194	-o x"${exec_prefix_default}" = x"yes" ; then
2195	if test x"${TCL_EXEC_PREFIX}" != x; then
2196	    AC_MSG_NOTICE([--exec-prefix defaulting to TCL_EXEC_PREFIX ${TCL_EXEC_PREFIX}])
2197	    exec_prefix=${TCL_EXEC_PREFIX}
2198	else
2199	    AC_MSG_NOTICE([--exec-prefix defaulting to ${prefix}])
2200	    exec_prefix=$prefix
2201	fi
2202    fi
2203])
2204
2205#------------------------------------------------------------------------
2206# TEA_SETUP_COMPILER_CC --
2207#
2208#	Do compiler checks the way we want.  This is just a replacement
2209#	for AC_PROG_CC in TEA configure.in files to make them cleaner.
2210#
2211# Arguments:
2212#	none
2213#
2214# Results:
2215#
2216#	Sets up CC var and other standard bits we need to make executables.
2217#------------------------------------------------------------------------
2218AC_DEFUN([TEA_SETUP_COMPILER_CC], [
2219    # Don't put any macros that use the compiler (e.g. AC_TRY_COMPILE)
2220    # in this macro, they need to go into TEA_SETUP_COMPILER instead.
2221
2222    # If the user did not set CFLAGS, set it now to keep
2223    # the AC_PROG_CC macro from adding "-g -O2".
2224    if test "${CFLAGS+set}" != "set" ; then
2225	CFLAGS=""
2226    fi
2227
2228    AC_PROG_CC
2229    AC_PROG_CPP
2230
2231    AC_PROG_INSTALL
2232
2233    #--------------------------------------------------------------------
2234    # Checks to see if the make program sets the $MAKE variable.
2235    #--------------------------------------------------------------------
2236
2237    AC_PROG_MAKE_SET
2238
2239    #--------------------------------------------------------------------
2240    # Find ranlib
2241    #--------------------------------------------------------------------
2242
2243    AC_PROG_RANLIB
2244
2245    #--------------------------------------------------------------------
2246    # Determines the correct binary file extension (.o, .obj, .exe etc.)
2247    #--------------------------------------------------------------------
2248
2249    AC_OBJEXT
2250    AC_EXEEXT
2251])
2252
2253#------------------------------------------------------------------------
2254# TEA_SETUP_COMPILER --
2255#
2256#	Do compiler checks that use the compiler.  This must go after
2257#	TEA_SETUP_COMPILER_CC, which does the actual compiler check.
2258#
2259# Arguments:
2260#	none
2261#
2262# Results:
2263#
2264#	Sets up CC var and other standard bits we need to make executables.
2265#------------------------------------------------------------------------
2266AC_DEFUN([TEA_SETUP_COMPILER], [
2267    # Any macros that use the compiler (e.g. AC_TRY_COMPILE) have to go here.
2268    AC_REQUIRE([TEA_SETUP_COMPILER_CC])
2269
2270    #------------------------------------------------------------------------
2271    # If we're using GCC, see if the compiler understands -pipe. If so, use it.
2272    # It makes compiling go faster.  (This is only a performance feature.)
2273    #------------------------------------------------------------------------
2274
2275    if test -z "$no_pipe" -a -n "$GCC"; then
2276	AC_MSG_CHECKING([if the compiler understands -pipe])
2277	OLDCC="$CC"
2278	CC="$CC -pipe"
2279	AC_TRY_COMPILE(,, AC_MSG_RESULT([yes]), CC="$OLDCC"
2280	    AC_MSG_RESULT([no]))
2281    fi
2282
2283    #--------------------------------------------------------------------
2284    # Common compiler flag setup
2285    #--------------------------------------------------------------------
2286
2287    AC_C_BIGENDIAN
2288    if test "${TEA_PLATFORM}" = "unix" ; then
2289	TEA_TCL_LINK_LIBS
2290	TEA_MISSING_POSIX_HEADERS
2291	# Let the user call this, because if it triggers, they will
2292	# need a compat/strtod.c that is correct.  Users can also
2293	# use Tcl_GetDouble(FromObj) instead.
2294	#TEA_BUGGY_STRTOD
2295    fi
2296])
2297
2298#------------------------------------------------------------------------
2299# TEA_MAKE_LIB --
2300#
2301#	Generate a line that can be used to build a shared/unshared library
2302#	in a platform independent manner.
2303#
2304# Arguments:
2305#	none
2306#
2307#	Requires:
2308#
2309# Results:
2310#
2311#	Defines the following vars:
2312#	CFLAGS -	Done late here to note disturb other AC macros
2313#       MAKE_LIB -      Command to execute to build the Tcl library;
2314#                       differs depending on whether or not Tcl is being
2315#                       compiled as a shared library.
2316#	MAKE_SHARED_LIB	Makefile rule for building a shared library
2317#	MAKE_STATIC_LIB	Makefile rule for building a static library
2318#	MAKE_STUB_LIB	Makefile rule for building a stub library
2319#------------------------------------------------------------------------
2320
2321AC_DEFUN([TEA_MAKE_LIB], [
2322    if test "${TEA_PLATFORM}" = "windows" -a "$GCC" != "yes"; then
2323	MAKE_STATIC_LIB="\${STLIB_LD} -out:\[$]@ \$(PKG_OBJECTS)"
2324	MAKE_SHARED_LIB="\${SHLIB_LD} \${SHLIB_LD_LIBS} \${LDFLAGS_DEFAULT} -out:\[$]@ \$(PKG_OBJECTS)"
2325	MAKE_STUB_LIB="\${STLIB_LD} -out:\[$]@ \$(PKG_STUB_OBJECTS)"
2326    else
2327	MAKE_STATIC_LIB="\${STLIB_LD} \[$]@ \$(PKG_OBJECTS)"
2328	MAKE_SHARED_LIB="\${SHLIB_LD} -o \[$]@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}"
2329	MAKE_STUB_LIB="\${STLIB_LD} \[$]@ \$(PKG_STUB_OBJECTS)"
2330    fi
2331
2332    if test "${SHARED_BUILD}" = "1" ; then
2333	MAKE_LIB="${MAKE_SHARED_LIB} "
2334    else
2335	MAKE_LIB="${MAKE_STATIC_LIB} "
2336    fi
2337
2338    #--------------------------------------------------------------------
2339    # Shared libraries and static libraries have different names.
2340    # Use the double eval to make sure any variables in the suffix is
2341    # substituted. (@@@ Might not be necessary anymore)
2342    #--------------------------------------------------------------------
2343
2344    if test "${TEA_PLATFORM}" = "windows" ; then
2345	if test "${SHARED_BUILD}" = "1" ; then
2346	    # We force the unresolved linking of symbols that are really in
2347	    # the private libraries of Tcl and Tk.
2348	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \"`${CYGPATH} ${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}`\""
2349	    if test x"${TK_BIN_DIR}" != x ; then
2350		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \"`${CYGPATH} ${TK_BIN_DIR}/${TK_STUB_LIB_FILE}`\""
2351	    fi
2352	    eval eval "PKG_LIB_FILE=${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
2353	else
2354	    eval eval "PKG_LIB_FILE=${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
2355	fi
2356	# Some packages build their own stubs libraries
2357	eval eval "PKG_STUB_LIB_FILE=${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}"
2358	if test "$GCC" = "yes"; then
2359	    PKG_STUB_LIB_FILE=lib${PKG_STUB_LIB_FILE}
2360	fi
2361	# These aren't needed on Windows (either MSVC or gcc)
2362	RANLIB=:
2363	RANLIB_STUB=:
2364    else
2365	RANLIB_STUB="${RANLIB}"
2366	if test "${SHARED_BUILD}" = "1" ; then
2367	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} ${TCL_STUB_LIB_SPEC}"
2368	    if test x"${TK_BIN_DIR}" != x ; then
2369		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} ${TK_STUB_LIB_SPEC}"
2370	    fi
2371	    eval eval "PKG_LIB_FILE=lib${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
2372	    RANLIB=:
2373	else
2374	    eval eval "PKG_LIB_FILE=lib${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
2375	fi
2376	# Some packages build their own stubs libraries
2377	eval eval "PKG_STUB_LIB_FILE=lib${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}"
2378    fi
2379
2380    # These are escaped so that only CFLAGS is picked up at configure time.
2381    # The other values will be substituted at make time.
2382    CFLAGS="${CFLAGS} \${CFLAGS_DEFAULT} \${CFLAGS_WARNING}"
2383    if test "${SHARED_BUILD}" = "1" ; then
2384	CFLAGS="${CFLAGS} \${SHLIB_CFLAGS}"
2385    fi
2386
2387    AC_SUBST(MAKE_LIB)
2388    AC_SUBST(MAKE_SHARED_LIB)
2389    AC_SUBST(MAKE_STATIC_LIB)
2390    AC_SUBST(MAKE_STUB_LIB)
2391    AC_SUBST(RANLIB_STUB)
2392])
2393
2394#------------------------------------------------------------------------
2395# TEA_PUBLIC_TCL_HEADERS --
2396#
2397#	Locate the installed public Tcl header files
2398#
2399# Arguments:
2400#	None.
2401#
2402# Requires:
2403#	CYGPATH must be set
2404#
2405# Results:
2406#
2407#	Adds a --with-tclinclude switch to configure.
2408#	Result is cached.
2409#
2410#	Substs the following vars:
2411#		TCL_INCLUDES
2412#------------------------------------------------------------------------
2413
2414AC_DEFUN([TEA_PUBLIC_TCL_HEADERS], [
2415    AC_MSG_CHECKING([for Tcl public headers])
2416
2417    AC_ARG_WITH(tclinclude, [  --with-tclinclude       directory containing the public Tcl header files], with_tclinclude=${withval})
2418
2419    AC_CACHE_VAL(ac_cv_c_tclh, [
2420	# Use the value from --with-tclinclude, if it was given
2421
2422	if test x"${with_tclinclude}" != x ; then
2423	    if test -f "${with_tclinclude}/tcl.h" ; then
2424		ac_cv_c_tclh=${with_tclinclude}
2425	    else
2426		AC_MSG_ERROR([${with_tclinclude} directory does not contain tcl.h])
2427	    fi
2428	else
2429	    if test "`uname -s`" = "Darwin"; then
2430		# If Tcl was built as a framework, attempt to use
2431		# the framework's Headers directory
2432		case ${TCL_DEFS} in
2433		    *TCL_FRAMEWORK*)
2434			list="`ls -d ${TCL_BIN_DIR}/Headers 2>/dev/null`"
2435			;;
2436		esac
2437	    fi
2438
2439	    # Look in the source dir only if Tcl is not installed,
2440	    # and in that situation, look there before installed locations.
2441	    if test -f "${TCL_BIN_DIR}/Makefile" ; then
2442		list="$list `ls -d ${TCL_SRC_DIR}/generic 2>/dev/null`"
2443	    fi
2444
2445	    # Check order: pkg --prefix location, Tcl's --prefix location,
2446	    # relative to directory of tclConfig.sh.
2447
2448	    eval "temp_includedir=${includedir}"
2449	    list="$list \
2450		`ls -d ${temp_includedir}        2>/dev/null` \
2451		`ls -d ${TCL_PREFIX}/include     2>/dev/null` \
2452		`ls -d ${TCL_BIN_DIR}/../include 2>/dev/null`"
2453	    if test "${TEA_PLATFORM}" != "windows" -o "$GCC" = "yes"; then
2454		list="$list /usr/local/include /usr/include"
2455		if test x"${TCL_INCLUDE_SPEC}" != x ; then
2456		    d=`echo "${TCL_INCLUDE_SPEC}" | sed -e 's/^-I//'`
2457		    list="$list `ls -d ${d} 2>/dev/null`"
2458		fi
2459	    fi
2460	    for i in $list ; do
2461		if test -f "$i/tcl.h" ; then
2462		    ac_cv_c_tclh=$i
2463		    break
2464		fi
2465	    done
2466	fi
2467    ])
2468
2469    # Print a message based on how we determined the include path
2470
2471    if test x"${ac_cv_c_tclh}" = x ; then
2472	AC_MSG_ERROR([tcl.h not found.  Please specify its location with --with-tclinclude])
2473    else
2474	AC_MSG_RESULT([${ac_cv_c_tclh}])
2475    fi
2476
2477    # Convert to a native path and substitute into the output files.
2478
2479    INCLUDE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tclh}`
2480
2481    TCL_INCLUDES=-I\"${INCLUDE_DIR_NATIVE}\"
2482
2483    AC_SUBST(TCL_INCLUDES)
2484])
2485
2486
2487#------------------------------------------------------------------------
2488# TEA_PROG_TCLSH
2489#	Determine the fully qualified path name of the tclsh executable
2490#	in the Tcl build directory or the tclsh installed in a bin
2491#	directory. This macro will correctly determine the name
2492#	of the tclsh executable even if tclsh has not yet been
2493#	built in the build directory. The tclsh found is always
2494#	associated with a tclConfig.sh file. This tclsh should be used
2495#	only for running extension test cases. It should never be
2496#	or generation of files (like pkgIndex.tcl) at build time.
2497#
2498# Arguments
2499#	none
2500#
2501# Results
2502#	Subst's the following values:
2503#		TCLSH_PROG
2504#------------------------------------------------------------------------
2505
2506AC_DEFUN([TEA_PROG_TCLSH], [
2507    AC_MSG_CHECKING([for tclsh])
2508    if test -f "${TCL_BIN_DIR}/Makefile" ; then
2509        # tclConfig.sh is in Tcl build directory
2510        if test "${TEA_PLATFORM}" = "windows"; then
2511            TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}"
2512        else
2513            TCLSH_PROG="${TCL_BIN_DIR}/tclsh"
2514        fi
2515    else
2516        # tclConfig.sh is in install location
2517        if test "${TEA_PLATFORM}" = "windows"; then
2518            TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}"
2519        else
2520            TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}${TCL_DBGX}"
2521        fi
2522        list="`ls -d ${TCL_BIN_DIR}/../bin 2>/dev/null` \
2523              `ls -d ${TCL_BIN_DIR}/..     2>/dev/null` \
2524              `ls -d ${TCL_PREFIX}/bin     2>/dev/null`"
2525        for i in $list ; do
2526            if test -f "$i/${TCLSH_PROG}" ; then
2527                REAL_TCL_BIN_DIR="`cd "$i"; pwd`"
2528                break
2529            fi
2530        done
2531        TCLSH_PROG="${REAL_TCL_BIN_DIR}/${TCLSH_PROG}"
2532    fi
2533    AC_MSG_RESULT([${TCLSH_PROG}])
2534    AC_SUBST(TCLSH_PROG)
2535])
2536