1#------------------------------------------------------------------------
2# SC_PATH_TCLCONFIG --
3#
4#	Locate the tclConfig.sh file and perform a sanity check on
5#	the Tcl compile flags
6#	Currently a no-op for Windows
7#
8# Arguments:
9#	PATCH_LEVEL	The patch level for Tcl if any.
10#
11# Results:
12#
13#	Adds the following arguments to configure:
14#		--with-tcl=...
15#
16#	Sets the following vars:
17#		TCL_BIN_DIR	Full path to the tclConfig.sh file
18#------------------------------------------------------------------------
19
20AC_DEFUN([SC_PATH_TCLCONFIG], [
21    AC_MSG_CHECKING([the location of tclConfig.sh])
22
23    if test -d ../../tcl8.5$1/win;  then
24	TCL_BIN_DIR_DEFAULT=../../tcl8.5$1/win
25    elif test -d ../../tcl8.5/win;  then
26	TCL_BIN_DIR_DEFAULT=../../tcl8.5/win
27    else
28	TCL_BIN_DIR_DEFAULT=../../tcl/win
29    fi
30    
31    AC_ARG_WITH(tcl, [  --with-tcl=DIR          use Tcl 8.5 binaries from DIR],
32	    TCL_BIN_DIR=$withval, TCL_BIN_DIR=`cd $TCL_BIN_DIR_DEFAULT; pwd`)
33    if test ! -d $TCL_BIN_DIR; then
34	AC_MSG_ERROR(Tcl directory $TCL_BIN_DIR does not exist)
35    fi
36    if test ! -f $TCL_BIN_DIR/tclConfig.sh; then
37	AC_MSG_ERROR(There is no tclConfig.sh in $TCL_BIN_DIR:  perhaps you did not specify the Tcl *build* directory (not the toplevel Tcl directory) or you forgot to configure Tcl?)
38    fi
39    AC_MSG_RESULT($TCL_BIN_DIR/tclConfig.sh)
40])
41
42#------------------------------------------------------------------------
43# SC_PATH_TKCONFIG --
44#
45#	Locate the tkConfig.sh file
46#	Currently a no-op for Windows
47#
48# Arguments:
49#	none
50#
51# Results:
52#
53#	Adds the following arguments to configure:
54#		--with-tk=...
55#
56#	Sets the following vars:
57#		TK_BIN_DIR	Full path to the tkConfig.sh file
58#------------------------------------------------------------------------
59
60AC_DEFUN([SC_PATH_TKCONFIG], [
61    AC_MSG_CHECKING([the location of tkConfig.sh])
62
63    if test -d ../../tk8.5$1/win;  then
64	TK_BIN_DIR_DEFAULT=../../tk8.5$1/win
65    elif test -d ../../tk8.5/win;  then
66	TK_BIN_DIR_DEFAULT=../../tk8.5/win
67    else
68	TK_BIN_DIR_DEFAULT=../../tk/win
69    fi
70    
71    AC_ARG_WITH(tk, [  --with-tk=DIR          use Tk 8.5 binaries from DIR],
72	    TK_BIN_DIR=$withval, TK_BIN_DIR=`cd $TK_BIN_DIR_DEFAULT; pwd`)
73    if test ! -d $TK_BIN_DIR; then
74	AC_MSG_ERROR(Tk directory $TK_BIN_DIR does not exist)
75    fi
76    if test ! -f $TK_BIN_DIR/tkConfig.sh; then
77	AC_MSG_ERROR(There is no tkConfig.sh in $TK_BIN_DIR:  perhaps you did not specify the Tk *build* directory (not the toplevel Tk directory) or you forgot to configure Tk?)
78    fi
79
80    AC_MSG_RESULT([$TK_BIN_DIR/tkConfig.sh])
81])
82
83#------------------------------------------------------------------------
84# SC_LOAD_TCLCONFIG --
85#
86#	Load the tclConfig.sh file.
87#
88# Arguments:
89#	
90#	Requires the following vars to be set:
91#		TCL_BIN_DIR
92#
93# Results:
94#
95#	Subst the following vars:
96#		TCL_BIN_DIR
97#		TCL_SRC_DIR
98#		TCL_LIB_FILE
99#
100#------------------------------------------------------------------------
101
102AC_DEFUN([SC_LOAD_TCLCONFIG], [
103    AC_MSG_CHECKING([for existence of $TCL_BIN_DIR/tclConfig.sh])
104
105    if test -f "$TCL_BIN_DIR/tclConfig.sh" ; then
106        AC_MSG_RESULT([loading])
107	. $TCL_BIN_DIR/tclConfig.sh
108    else
109        AC_MSG_RESULT([file not found])
110    fi
111
112    #
113    # If the TCL_BIN_DIR is the build directory (not the install directory),
114    # then set the common variable name to the value of the build variables.
115    # For example, the variable TCL_LIB_SPEC will be set to the value
116    # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC
117    # instead of TCL_BUILD_LIB_SPEC since it will work with both an
118    # installed and uninstalled version of Tcl.
119    #
120
121    if test -f $TCL_BIN_DIR/Makefile ; then
122        TCL_LIB_SPEC=${TCL_BUILD_LIB_SPEC}
123        TCL_STUB_LIB_SPEC=${TCL_BUILD_STUB_LIB_SPEC}
124        TCL_STUB_LIB_PATH=${TCL_BUILD_STUB_LIB_PATH}
125    fi
126
127    #
128    # eval is required to do the TCL_DBGX substitution
129    #
130
131    eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
132    eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
133    eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""
134
135    eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""
136    eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
137    eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""
138
139    AC_SUBST(TCL_VERSION)
140    AC_SUBST(TCL_BIN_DIR)
141    AC_SUBST(TCL_SRC_DIR)
142
143    AC_SUBST(TCL_LIB_FILE)
144    AC_SUBST(TCL_LIB_FLAG)
145    AC_SUBST(TCL_LIB_SPEC)
146
147    AC_SUBST(TCL_STUB_LIB_FILE)
148    AC_SUBST(TCL_STUB_LIB_FLAG)
149    AC_SUBST(TCL_STUB_LIB_SPEC)
150
151    AC_SUBST(TCL_DEFS)
152])
153
154#------------------------------------------------------------------------
155# SC_LOAD_TKCONFIG --
156#
157#	Load the tkConfig.sh file
158#	Currently a no-op for Windows
159#
160# Arguments:
161#	
162#	Requires the following vars to be set:
163#		TK_BIN_DIR
164#
165# Results:
166#
167#	Sets the following vars that should be in tkConfig.sh:
168#		TK_BIN_DIR
169#------------------------------------------------------------------------
170
171AC_DEFUN([SC_LOAD_TKCONFIG], [
172    AC_MSG_CHECKING([for existence of $TK_BIN_DIR/tkConfig.sh])
173
174    if test -f "$TK_BIN_DIR/tkConfig.sh" ; then
175        AC_MSG_RESULT([loading])
176	. $TK_BIN_DIR/tkConfig.sh
177    else
178        AC_MSG_RESULT([could not find $TK_BIN_DIR/tkConfig.sh])
179    fi
180
181
182    AC_SUBST(TK_BIN_DIR)
183    AC_SUBST(TK_SRC_DIR)
184    AC_SUBST(TK_LIB_FILE)
185])
186
187#------------------------------------------------------------------------
188# SC_ENABLE_SHARED --
189#
190#	Allows the building of shared libraries
191#
192# Arguments:
193#	none
194#	
195# Results:
196#
197#	Adds the following arguments to configure:
198#		--enable-shared=yes|no
199#
200#	Defines the following vars:
201#		STATIC_BUILD	Used for building import/export libraries
202#				on Windows.
203#
204#	Sets the following vars:
205#		SHARED_BUILD	Value of 1 or 0
206#------------------------------------------------------------------------
207
208AC_DEFUN([SC_ENABLE_SHARED], [
209    AC_MSG_CHECKING([how to build libraries])
210    AC_ARG_ENABLE(shared,
211	[  --enable-shared         build and link with shared libraries [--enable-shared]],
212    [tcl_ok=$enableval], [tcl_ok=yes])
213
214    if test "${enable_shared+set}" = set; then
215	enableval="$enable_shared"
216	tcl_ok=$enableval
217    else
218	tcl_ok=yes
219    fi
220
221    if test "$tcl_ok" = "yes" ; then
222	AC_MSG_RESULT([shared])
223	SHARED_BUILD=1
224    else
225	AC_MSG_RESULT([static])
226	SHARED_BUILD=0
227	AC_DEFINE(STATIC_BUILD)
228    fi
229])
230
231#------------------------------------------------------------------------
232# SC_ENABLE_THREADS --
233#
234#	Specify if thread support should be enabled
235#
236# Arguments:
237#	none
238#	
239# Results:
240#
241#	Adds the following arguments to configure:
242#		--enable-threads=yes|no
243#
244#	Defines the following vars:
245#		TCL_THREADS
246#------------------------------------------------------------------------
247
248AC_DEFUN([SC_ENABLE_THREADS], [
249    AC_MSG_CHECKING(for building with threads)
250    AC_ARG_ENABLE(threads, [  --enable-threads        build with threads],
251	[tcl_ok=$enableval], [tcl_ok=no])
252
253    if test "$tcl_ok" = "yes"; then
254	AC_MSG_RESULT(yes)
255	TCL_THREADS=1
256	AC_DEFINE(TCL_THREADS)
257	# USE_THREAD_ALLOC tells us to try the special thread-based
258	# allocator that significantly reduces lock contention
259	AC_DEFINE(USE_THREAD_ALLOC)
260    else
261	TCL_THREADS=0
262	AC_MSG_RESULT([no (default)])
263    fi
264    AC_SUBST(TCL_THREADS)
265])
266
267#------------------------------------------------------------------------
268# SC_ENABLE_SYMBOLS --
269#
270#	Specify if debugging symbols should be used
271#	Memory (TCL_MEM_DEBUG) and compile (TCL_COMPILE_DEBUG) debugging
272#	can also be enabled.
273#
274# Arguments:
275#	none
276#	
277#	Requires the following vars to be set in the Makefile:
278#		CFLAGS_DEBUG
279#		CFLAGS_OPTIMIZE
280#	
281# Results:
282#
283#	Adds the following arguments to configure:
284#		--enable-symbols
285#
286#	Defines the following vars:
287#		CFLAGS_DEFAULT	Sets to $(CFLAGS_DEBUG) if true
288#				Sets to $(CFLAGS_OPTIMIZE) if false
289#		LDFLAGS_DEFAULT	Sets to $(LDFLAGS_DEBUG) if true
290#				Sets to $(LDFLAGS_OPTIMIZE) if false
291#		DBGX		Debug library extension
292#
293#------------------------------------------------------------------------
294
295AC_DEFUN([SC_ENABLE_SYMBOLS], [
296    AC_MSG_CHECKING([for build with symbols])
297    AC_ARG_ENABLE(symbols, [  --enable-symbols        build with debugging symbols [--disable-symbols]],    [tcl_ok=$enableval], [tcl_ok=no])
298# FIXME: Currently, LDFLAGS_DEFAULT is not used, it should work like CFLAGS_DEFAULT.
299    if test "$tcl_ok" = "no"; then
300	CFLAGS_DEFAULT='$(CFLAGS_OPTIMIZE)'
301	LDFLAGS_DEFAULT='$(LDFLAGS_OPTIMIZE)'
302	DBGX=""
303	AC_MSG_RESULT([no])
304
305	AC_DEFINE(TCL_CFG_OPTIMIZED)
306    else
307	CFLAGS_DEFAULT='$(CFLAGS_DEBUG)'
308	LDFLAGS_DEFAULT='$(LDFLAGS_DEBUG)'
309	DBGX=g
310	if test "$tcl_ok" = "yes"; then
311	    AC_MSG_RESULT([yes (standard debugging)])
312	fi
313    fi
314    AC_SUBST(CFLAGS_DEFAULT)
315    AC_SUBST(LDFLAGS_DEFAULT)
316    AC_DEFINE(TCL_CFG_DEBUG)
317
318    if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then
319	AC_DEFINE(TCL_MEM_DEBUG)
320    fi
321
322    if test "$tcl_ok" = "compile" -o "$tcl_ok" = "all"; then
323	AC_DEFINE(TCL_COMPILE_DEBUG)
324	AC_DEFINE(TCL_COMPILE_STATS)
325    fi
326
327    if test "$tcl_ok" != "yes" -a "$tcl_ok" != "no"; then
328	if test "$tcl_ok" = "all"; then
329	    AC_MSG_RESULT([enabled symbols mem compile debugging])
330	else
331	    AC_MSG_RESULT([enabled $tcl_ok debugging])
332	fi
333    fi
334])
335
336#--------------------------------------------------------------------
337# SC_CONFIG_CFLAGS
338#
339#	Try to determine the proper flags to pass to the compiler
340#	for building shared libraries and other such nonsense.
341#
342#	NOTE: The backslashes in quotes below are substituted twice
343#	due to the fact that they are in a macro and then inlined
344#	in the final configure script.
345#
346# Arguments:
347#	none
348#
349# Results:
350#
351#	Can the following vars:
352#		EXTRA_CFLAGS
353#		CFLAGS_DEBUG
354#		CFLAGS_OPTIMIZE
355#		CFLAGS_WARNING
356#		LDFLAGS_DEBUG
357#		LDFLAGS_OPTIMIZE
358#		LDFLAGS_CONSOLE
359#		LDFLAGS_WINDOW
360#		CC_OBJNAME
361#		CC_EXENAME
362#		CYGPATH
363#		STLIB_LD
364#		SHLIB_LD
365#		SHLIB_LD_LIBS
366#		LIBS
367#		AR
368#		RC
369#		RES
370#
371#		MAKE_LIB
372#		MAKE_EXE
373#		MAKE_DLL
374#
375#		LIBSUFFIX
376#		LIBPREFIX
377#		LIBRARIES
378#		EXESUFFIX
379#		DLLSUFFIX
380#
381#--------------------------------------------------------------------
382
383AC_DEFUN([SC_CONFIG_CFLAGS], [
384
385    # Step 0: Enable 64 bit support?
386
387    AC_MSG_CHECKING([if 64bit support is requested])
388    AC_ARG_ENABLE(64bit,[  --enable-64bit          enable 64bit support (where applicable)], [do64bit=$enableval], [do64bit=no])
389    AC_MSG_RESULT($do64bit)
390
391    # Cross-compiling options for Windows/CE builds
392
393    AC_MSG_CHECKING([if Windows/CE build is requested])
394    AC_ARG_ENABLE(wince,[  --enable-wince          enable Win/CE support (where applicable)], [doWince=$enableval], [doWince=no])
395    AC_MSG_RESULT($doWince)
396
397    AC_MSG_CHECKING([for Windows/CE celib directory])
398    AC_ARG_WITH(celib,[  --with-celib=DIR        use Windows/CE support library from DIR],
399	    CELIB_DIR=$withval, CELIB_DIR=NO_CELIB)
400    AC_MSG_RESULT([$CELIB_DIR])
401
402    # Set some defaults (may get changed below)
403    EXTRA_CFLAGS=""
404
405    AC_CHECK_PROG(CYGPATH, cygpath, cygpath -w, echo)
406
407    SHLIB_SUFFIX=".dll"
408
409    # Check for a bug in gcc's windres that causes the
410    # compile to fail when a Windows native path is
411    # passed into windres. The mingw toolchain requires
412    # Windows native paths while Cygwin should work
413    # with both. Avoid the bug by passing a POSIX
414    # path when using the Cygwin toolchain.
415
416    if test "$GCC" = "yes" && test "$CYGPATH" != "echo" ; then
417	conftest=/tmp/conftest.rc
418	echo "STRINGTABLE BEGIN" > $conftest
419	echo "101 \"name\"" >> $conftest
420	echo "END" >> $conftest
421
422	AC_MSG_CHECKING([for Windows native path bug in windres])
423	cyg_conftest=`$CYGPATH $conftest`
424	if AC_TRY_COMMAND($RC -o conftest.res.o $cyg_conftest) ; then
425	    AC_MSG_RESULT([no])
426	else
427	    AC_MSG_RESULT([yes])
428	    CYGPATH=echo
429	fi
430	conftest=
431	cyg_conftest=
432    fi
433
434    if test "$CYGPATH" = "echo" || test "$ac_cv_cygwin" = "yes"; then
435        DEPARG='"$<"'
436    else
437        DEPARG='"$(shell $(CYGPATH) $<)"'
438    fi
439
440    # set various compiler flags depending on whether we are using gcc or cl
441
442    AC_MSG_CHECKING([compiler flags])
443    if test "${GCC}" = "yes" ; then
444	if test "$do64bit" != "no" ; then
445	    AC_MSG_WARN([64bit mode not supported with GCC on Windows])
446	fi
447	SHLIB_LD=""
448	SHLIB_LD_LIBS=""
449	LIBS="-lws2_32"
450	# mingw needs to link ole32 and oleaut32 for [send], but MSVC doesn't
451	LIBS_GUI="-lgdi32 -lcomdlg32 -limm32 -lcomctl32 -lshell32 -luuid -lole32 -loleaut32"
452	STLIB_LD='${AR} cr'
453	RC_OUT=-o
454	RC_TYPE=
455	RC_INCLUDE=--include
456	RC_DEFINE=--define
457	RES=res.o
458	MAKE_LIB="\${STLIB_LD} \[$]@"
459	POST_MAKE_LIB="\${RANLIB} \[$]@"
460	MAKE_EXE="\${CC} -o \[$]@"
461	LIBPREFIX="lib"
462
463	#if test "$ac_cv_cygwin" = "yes"; then
464	#    extra_cflags="-mno-cygwin"
465	#    extra_ldflags="-mno-cygwin"
466	#else
467	#    extra_cflags=""
468	#    extra_ldflags=""
469	#fi
470
471	if test "$ac_cv_cygwin" = "yes"; then
472	  touch ac$$.c
473	  if ${CC} -c -mwin32 ac$$.c >/dev/null 2>&1; then
474	    case "$extra_cflags" in
475	      *-mwin32*) ;;
476	      *) extra_cflags="-mwin32 $extra_cflags" ;;
477	    esac
478	    case "$extra_ldflags" in
479	      *-mwin32*) ;;
480	      *) extra_ldflags="-mwin32 $extra_ldflags" ;;
481	    esac
482	  fi
483	  rm -f ac$$.o ac$$.c
484	else
485	  extra_cflags=''
486	  extra_ldflags=''
487	fi
488
489	if test "${SHARED_BUILD}" = "0" ; then
490	    # static
491            AC_MSG_RESULT([using static flags])
492	    runtime=
493	    MAKE_DLL="echo "
494	    LIBSUFFIX="s\${DBGX}.a"
495	    LIBFLAGSUFFIX="s\${DBGX}"
496	    LIBRARIES="\${STATIC_LIBRARIES}"
497	    EXESUFFIX="s\${DBGX}.exe"
498	else
499	    # dynamic
500            AC_MSG_RESULT([using shared flags])
501
502	    # ad-hoc check to see if CC supports -shared.
503	    if "${CC}" -shared 2>&1 | egrep ': -shared not supported' >/dev/null; then
504		AC_MSG_ERROR([${CC} does not support the -shared option.
505                You will need to upgrade to a newer version of the toolchain.])
506	    fi
507
508	    runtime=
509	    # Link with gcc since ld does not link to default libs like
510	    # -luser32 and -lmsvcrt by default. Make sure CFLAGS is
511	    # included so -mno-cygwin passed the correct libs to the linker.
512	    SHLIB_LD='${CC} -shared ${CFLAGS}'
513	    SHLIB_LD_LIBS='${LIBS}'
514	    # Add SHLIB_LD_LIBS to the Make rule, not here.
515	    MAKE_DLL="\${SHLIB_LD} \$(LDFLAGS) -o \[$]@ ${extra_ldflags} \
516	        -Wl,--out-implib,\$(patsubst %.dll,lib%.a,\[$]@)"
517
518	    LIBSUFFIX="\${DBGX}.a"
519	    LIBFLAGSUFFIX="\${DBGX}"
520	    EXESUFFIX="\${DBGX}.exe"
521	    LIBRARIES="\${SHARED_LIBRARIES}"
522	fi
523	# DLLSUFFIX is separate because it is the building block for
524	# users of tclConfig.sh that may build shared or static.
525	DLLSUFFIX="\${DBGX}.dll"
526	SHLIB_SUFFIX=.dll
527
528	EXTRA_CFLAGS="${extra_cflags}"
529
530	CFLAGS_DEBUG=-g
531	CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer"
532	CFLAGS_WARNING="-Wall"
533	LDFLAGS_DEBUG=
534	LDFLAGS_OPTIMIZE=
535
536	# Specify the CC output file names based on the target name
537	CC_OBJNAME="-o \[$]@"
538	CC_EXENAME="-o \[$]@"
539
540	# Specify linker flags depending on the type of app being 
541	# built -- Console vs. Window.
542	#
543	# ORIGINAL COMMENT:
544	# We need to pass -e _WinMain@16 so that ld will use
545	# WinMain() instead of main() as the entry point. We can't
546	# use autoconf to check for this case since it would need
547	# to run an executable and that does not work when
548	# cross compiling. Remove this -e workaround once we
549	# require a gcc that does not have this bug.
550	#
551	# MK NOTE: Tk should use a different mechanism. This causes 
552	# interesting problems, such as wish dying at startup.
553	#LDFLAGS_WINDOW="-mwindows -e _WinMain@16 ${extra_ldflags}"
554	LDFLAGS_CONSOLE="-mconsole ${extra_ldflags}"
555	LDFLAGS_WINDOW="-mwindows ${extra_ldflags}"
556
557	# gcc under Windows supports only 32bit builds
558	MACHINE="X86"
559    else
560	if test "${SHARED_BUILD}" = "0" ; then
561	    # static
562            AC_MSG_RESULT([using static flags])
563	    runtime=-MT
564	    MAKE_DLL="echo "
565	    LIBSUFFIX="s\${DBGX}.lib"
566	    LIBFLAGSUFFIX="s\${DBGX}"
567	    LIBRARIES="\${STATIC_LIBRARIES}"
568	    EXESUFFIX="s\${DBGX}.exe"
569	    SHLIB_LD_LIBS=""
570	else
571	    # dynamic
572            AC_MSG_RESULT([using shared flags])
573	    runtime=-MD
574	    # Add SHLIB_LD_LIBS to the Make rule, not here.
575	    MAKE_DLL="\${SHLIB_LD} \$(LDFLAGS) -out:\[$]@"
576	    LIBSUFFIX="\${DBGX}.lib"
577	    LIBFLAGSUFFIX="\${DBGX}"
578	    EXESUFFIX="\${DBGX}.exe"
579	    LIBRARIES="\${SHARED_LIBRARIES}"
580	    SHLIB_LD_LIBS='${LIBS}'
581	fi
582	# DLLSUFFIX is separate because it is the building block for
583	# users of tclConfig.sh that may build shared or static.
584	DLLSUFFIX="\${DBGX}.dll"
585
586 	# This is a 2-stage check to make sure we have the 64-bit SDK
587 	# We have to know where the SDK is installed.
588	# This magic is based on MS Platform SDK for Win2003 SP1 - hobbs
589	# MACHINE is IX86 for LINK, but this is used by the manifest,
590	# which requires x86|amd64|ia64.
591	MACHINE="X86"
592	if test "$do64bit" != "no" ; then
593	    if test "x${MSSDK}x" = "xx" ; then
594		MSSDK="C:/Progra~1/Microsoft Platform SDK"
595	    fi
596	    MSSDK=`echo "$MSSDK" | sed -e 's!\\\!/!g'`
597	    PATH64=""
598	    case "$do64bit" in
599	      amd64|x64|yes)
600		MACHINE="AMD64" ; # assume AMD64 as default 64-bit build
601		PATH64="${MSSDK}/Bin/Win64/x86/AMD64"
602		;;
603	      ia64)
604		MACHINE="IA64"
605		PATH64="${MSSDK}/Bin/Win64"
606		;;
607	    esac
608	    if test ! -d "${PATH64}" ; then
609		AC_MSG_WARN([Could not find 64-bit $MACHINE SDK to enable 64bit mode])
610		AC_MSG_WARN([Ensure latest Platform SDK is installed])
611		do64bit="no"
612	    else
613		AC_MSG_RESULT([   Using 64-bit $MACHINE mode])
614	    fi
615	fi
616
617	LIBS="user32.lib advapi32.lib ws2_32.lib"
618	if test "$do64bit" != "no" ; then
619	    # The space-based-path will work for the Makefile, but will
620	    # not work if AC_TRY_COMPILE is called.  TEA has the
621	    # TEA_PATH_NOSPACE to avoid this issue.
622	    # Check if _WIN64 is already recognized, and if so we don't
623	    # need to modify CC.
624	    AC_CHECK_DECL([_WIN64], [],
625			  [CC="\"${PATH64}/cl.exe\" -I\"${MSSDK}/Include\" \
626			 -I\"${MSSDK}/Include/crt\" \
627			 -I\"${MSSDK}/Include/crt/sys\""])
628	    RC="\"${MSSDK}/bin/rc.exe\""
629	    CFLAGS_DEBUG="-nologo -Zi -Od ${runtime}d"
630	    # Do not use -O2 for Win64 - this has proved buggy in code gen.
631	    CFLAGS_OPTIMIZE="-nologo -O1 ${runtime}"
632	    lflags="-nologo -MACHINE:${MACHINE} -LIBPATH:\"${MSSDK}/Lib/${MACHINE}\""
633	    LINKBIN="\"${PATH64}/link.exe\""
634	    # Avoid 'unresolved external symbol __security_cookie' errors.
635	    # c.f. http://support.microsoft.com/?id=894573
636	    LIBS="$LIBS bufferoverflowU.lib"
637	else
638	    RC="rc"
639	    # -Od - no optimization
640	    # -WX - warnings as errors
641	    CFLAGS_DEBUG="-nologo -Z7 -Od -WX ${runtime}d"
642	    # -O2 - create fast code (/Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy)
643	    CFLAGS_OPTIMIZE="-nologo -O2 ${runtime}"
644	    lflags="-nologo"
645	    LINKBIN="link"
646	fi
647
648	if test "$doWince" != "no" ; then
649	    # Set defaults for common evc4/PPC2003 setup
650	    # Currently Tcl requires 300+, possibly 420+ for sockets
651	    CEVERSION=420; 		# could be 211 300 301 400 420 ...
652	    TARGETCPU=ARMV4;	# could be ARMV4 ARM MIPS SH3 X86 ...
653	    ARCH=ARM;		# could be ARM MIPS X86EM ...
654	    PLATFORM="Pocket PC 2003"; # or "Pocket PC 2002"
655	    if test "$doWince" != "yes"; then
656		# If !yes then the user specified something
657		# Reset ARCH to allow user to skip specifying it
658		ARCH=
659		eval `echo $doWince | awk -F "," '{ \
660	if (length([$]1)) { printf "CEVERSION=\"%s\"\n", [$]1; \
661	if ([$]1 < 400)	  { printf "PLATFORM=\"Pocket PC 2002\"\n" } }; \
662	if (length([$]2)) { printf "TARGETCPU=\"%s\"\n", toupper([$]2) }; \
663	if (length([$]3)) { printf "ARCH=\"%s\"\n", toupper([$]3) }; \
664	if (length([$]4)) { printf "PLATFORM=\"%s\"\n", [$]4 }; \
665		}'`
666		if test "x${ARCH}" = "x" ; then
667		    ARCH=$TARGETCPU;
668		fi
669	    fi
670	    OSVERSION=WCE$CEVERSION;
671	    if test "x${WCEROOT}" = "x" ; then
672		WCEROOT="C:/Program Files/Microsoft eMbedded C++ 4.0"
673		if test ! -d "${WCEROOT}" ; then
674		    WCEROOT="C:/Program Files/Microsoft eMbedded Tools"
675		fi
676	    fi
677	    if test "x${SDKROOT}" = "x" ; then
678		SDKROOT="C:/Program Files/Windows CE Tools"
679		if test ! -d "${SDKROOT}" ; then
680		    SDKROOT="C:/Windows CE Tools"
681		fi
682	    fi
683	    # The space-based-path will work for the Makefile, but will
684	    # not work if AC_TRY_COMPILE is called.
685	    WCEROOT=`echo "$WCEROOT" | sed -e 's!\\\!/!g'`
686	    SDKROOT=`echo "$SDKROOT" | sed -e 's!\\\!/!g'`
687	    CELIB_DIR=`echo "$CELIB_DIR" | sed -e 's!\\\!/!g'`
688	    if test ! -d "${CELIB_DIR}/inc"; then
689		AC_MSG_ERROR([Invalid celib directory "${CELIB_DIR}"])
690	    fi
691	    if test ! -d "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}"\
692		-o ! -d "${WCEROOT}/EVC/${OSVERSION}/bin"; then
693		AC_MSG_ERROR([could not find PocketPC SDK or target compiler to enable WinCE mode [$CEVERSION,$TARGETCPU,$ARCH,$PLATFORM]])
694	    else
695		CEINCLUDE="${SDKROOT}/${OSVERSION}/${PLATFORM}/include"
696		if test -d "${CEINCLUDE}/${TARGETCPU}" ; then
697		    CEINCLUDE="${CEINCLUDE}/${TARGETCPU}"
698		fi
699		CELIBPATH="${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}"
700	    fi
701	fi
702
703	if test "$doWince" != "no" ; then
704	    CEBINROOT="${WCEROOT}/EVC/${OSVERSION}/bin"
705	    if test "${TARGETCPU}" = "X86"; then
706		CC="${CEBINROOT}/cl.exe"
707	    else
708		CC="${CEBINROOT}/cl${ARCH}.exe"
709	    fi
710	    CC="\"${CC}\" -I\"${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\""
711	    RC="\"${WCEROOT}/Common/EVC/bin/rc.exe\""
712	    arch=`echo ${ARCH} | awk '{print tolower([$]0)}'`
713	    defs="${ARCH} _${ARCH}_ ${arch} PALM_SIZE _MT _DLL _WINDOWS"
714	    for i in $defs ; do
715		AC_DEFINE_UNQUOTED($i)
716	    done
717#	    if test "${ARCH}" = "X86EM"; then
718#		AC_DEFINE_UNQUOTED(_WIN32_WCE_EMULATION)
719#	    fi
720	    AC_DEFINE_UNQUOTED(_WIN32_WCE, $CEVERSION)
721	    AC_DEFINE_UNQUOTED(UNDER_CE, $CEVERSION)
722	    CFLAGS_DEBUG="-nologo -Zi -Od"
723	    CFLAGS_OPTIMIZE="-nologo -O2"
724	    lversion=`echo ${CEVERSION} | sed -e 's/\(.\)\(..\)/\1\.\2/'`
725	    lflags="-nodefaultlib -MACHINE:${ARCH} -LIBPATH:\"${CELIBPATH}\" -subsystem:windowsce,${lversion} -nologo"
726	    LINKBIN="\"${CEBINROOT}/link.exe\""
727	    AC_SUBST(CELIB_DIR)
728	    if test "${CEVERSION}" -lt 400 ; then
729		LIBS="coredll.lib corelibc.lib winsock.lib"
730	    else
731		LIBS="coredll.lib corelibc.lib ws2.lib"
732	    fi
733	    # celib currently stuck at wce300 status
734	    #LIBS="$LIBS \${CELIB_DIR}/wince-${ARCH}-pocket-${OSVERSION}-release/celib.lib"
735	    LIBS="$LIBS \"\${CELIB_DIR}/wince-${ARCH}-pocket-wce300-release/celib.lib\""
736	    LIBS_GUI="commctrl.lib commdlg.lib"
737	else
738	    LIBS_GUI="gdi32.lib comdlg32.lib imm32.lib comctl32.lib shell32.lib uuid.lib"
739	fi
740
741	SHLIB_LD="${LINKBIN} -dll -incremental:no ${lflags}"
742	# link -lib only works when -lib is the first arg
743	STLIB_LD="${LINKBIN} -lib ${lflags}"
744	RC_OUT=-fo
745	RC_TYPE=-r
746	RC_INCLUDE=-i
747	RC_DEFINE=-d
748	RES=res
749	MAKE_LIB="\${STLIB_LD} -out:\[$]@"
750	POST_MAKE_LIB=
751	MAKE_EXE="\${CC} -Fe\[$]@"
752	LIBPREFIX=""
753
754	CFLAGS_DEBUG="${CFLAGS_DEBUG} -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE"
755	CFLAGS_OPTIMIZE="${CFLAGS_OPTIMIZE} -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE"
756
757	EXTRA_CFLAGS=""
758	CFLAGS_WARNING="-W3"
759	LDFLAGS_DEBUG="-debug:full"
760	LDFLAGS_OPTIMIZE="-release"
761	
762	# Specify the CC output file names based on the target name
763	CC_OBJNAME="-Fo\[$]@"
764	CC_EXENAME="-Fe\"\$(shell \$(CYGPATH) '\[$]@')\""
765
766	# Specify linker flags depending on the type of app being 
767	# built -- Console vs. Window.
768	if test "$doWince" != "no" -a "${TARGETCPU}" != "X86"; then
769	    LDFLAGS_CONSOLE="-link ${lflags}"
770	    LDFLAGS_WINDOW=${LDFLAGS_CONSOLE}
771	else
772	    LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}"
773	    LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}"
774	fi
775    fi
776
777    if test "$do64bit" != "no" ; then
778	AC_DEFINE(TCL_CFG_DO64BIT)
779    fi
780
781    # DL_LIBS is empty, but then we match the Unix version
782    AC_SUBST(DL_LIBS)
783    AC_SUBST(CFLAGS_DEBUG)
784    AC_SUBST(CFLAGS_OPTIMIZE)
785    AC_SUBST(CFLAGS_WARNING)
786])
787
788#------------------------------------------------------------------------
789# SC_WITH_TCL --
790#
791#	Location of the Tcl build directory.
792#
793# Arguments:
794#	none
795#
796# Results:
797#
798#	Adds the following arguments to configure:
799#		--with-tcl=...
800#
801#	Defines the following vars:
802#		TCL_BIN_DIR	Full path to the tcl build dir.
803#------------------------------------------------------------------------
804
805AC_DEFUN([SC_WITH_TCL], [
806    if test -d ../../tcl8.5$1/win;  then
807	TCL_BIN_DEFAULT=../../tcl8.5$1/win
808    else
809	TCL_BIN_DEFAULT=../../tcl8.5/win
810    fi
811    
812    AC_ARG_WITH(tcl, [  --with-tcl=DIR          use Tcl 8.5 binaries from DIR],
813	    TCL_BIN_DIR=$withval, TCL_BIN_DIR=`cd $TCL_BIN_DEFAULT; pwd`)
814    if test ! -d $TCL_BIN_DIR; then
815	AC_MSG_ERROR(Tcl directory $TCL_BIN_DIR does not exist)
816    fi
817    if test ! -f $TCL_BIN_DIR/Makefile; then
818	AC_MSG_ERROR(There is no Makefile in $TCL_BIN_DIR:  perhaps you did not specify the Tcl *build* directory (not the toplevel Tcl directory) or you forgot to configure Tcl?)
819    else
820	echo "building against Tcl binaries in: $TCL_BIN_DIR"
821    fi
822    AC_SUBST(TCL_BIN_DIR)
823])
824
825#------------------------------------------------------------------------
826# SC_PROG_TCLSH
827#	Locate a tclsh shell installed on the system path. This macro
828#	will only find a Tcl shell that already exists on the system.
829#	It will not find a Tcl shell in the Tcl build directory or
830#	a Tcl shell that has been installed from the Tcl build directory.
831#	If a Tcl shell can't be located on the PATH, then TCLSH_PROG will
832#	be set to "". Extensions should take care not to create Makefile
833#	rules that are run by default and depend on TCLSH_PROG. An
834#	extension can't assume that an executable Tcl shell exists at
835#	build time.
836#
837# Arguments
838#	none
839#
840# Results
841#	Subst's the following values:
842#		TCLSH_PROG
843#------------------------------------------------------------------------
844
845AC_DEFUN([SC_PROG_TCLSH], [
846    AC_MSG_CHECKING([for tclsh])
847
848    AC_CACHE_VAL(ac_cv_path_tclsh, [
849	search_path=`echo ${PATH} | sed -e 's/:/ /g'`
850	for dir in $search_path ; do
851	    for j in `ls -r $dir/tclsh[[8-9]]*.exe 2> /dev/null` \
852		    `ls -r $dir/tclsh* 2> /dev/null` ; do
853		if test x"$ac_cv_path_tclsh" = x ; then
854		    if test -f "$j" ; then
855			ac_cv_path_tclsh=$j
856			break
857		    fi
858		fi
859	    done
860	done
861    ])
862
863    if test -f "$ac_cv_path_tclsh" ; then
864	TCLSH_PROG="$ac_cv_path_tclsh"
865	AC_MSG_RESULT($TCLSH_PROG)
866    else
867	# It is not an error if an installed version of Tcl can't be located.
868	TCLSH_PROG=""
869	AC_MSG_RESULT([No tclsh found on PATH])
870    fi
871    AC_SUBST(TCLSH_PROG)
872])
873
874#------------------------------------------------------------------------
875# SC_BUILD_TCLSH
876#	Determine the fully qualified path name of the tclsh executable
877#	in the Tcl build directory. This macro will correctly determine
878#	the name of the tclsh executable even if tclsh has not yet
879#	been built in the build directory. The build tclsh must be used
880#	when running tests from an extension build directory. It is not
881#	correct to use the TCLSH_PROG in cases like this.
882#
883# Arguments
884#	none
885#
886# Results
887#	Subst's the following values:
888#		BUILD_TCLSH
889#------------------------------------------------------------------------
890
891AC_DEFUN([SC_BUILD_TCLSH], [
892    AC_MSG_CHECKING([for tclsh in Tcl build directory])
893    BUILD_TCLSH=${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}
894    AC_MSG_RESULT($BUILD_TCLSH)
895    AC_SUBST(BUILD_TCLSH)
896])
897
898#--------------------------------------------------------------------
899# SC_TCL_CFG_ENCODING	TIP #59
900#
901#	Declare the encoding to use for embedded configuration information.
902#
903# Arguments:
904#	None.
905#
906# Results:
907#	Might append to the following vars:
908#		DEFS	(implicit)
909#
910#	Will define the following vars:
911#		TCL_CFGVAL_ENCODING
912#
913#--------------------------------------------------------------------
914
915AC_DEFUN([SC_TCL_CFG_ENCODING], [
916    AC_ARG_WITH(encoding, [  --with-encoding              encoding for configuration values], with_tcencoding=${withval})
917
918    if test x"${with_tcencoding}" != x ; then
919	AC_DEFINE_UNQUOTED(TCL_CFGVAL_ENCODING,"${with_tcencoding}")
920    else
921	# Default encoding on windows is not "iso8859-1"
922	AC_DEFINE(TCL_CFGVAL_ENCODING,"cp1252")
923    fi
924])
925
926#--------------------------------------------------------------------
927# SC_EMBED_MANIFEST
928#
929#	Figure out if we can embed the manifest where necessary
930#
931# Arguments:
932#	An optional manifest to merge into DLL/EXE.
933#
934# Results:
935#	Will define the following vars:
936#		VC_MANIFEST_EMBED_DLL
937#		VC_MANIFEST_EMBED_EXE
938#
939#--------------------------------------------------------------------
940
941AC_DEFUN([SC_EMBED_MANIFEST], [
942    AC_MSG_CHECKING(whether to embed manifest)
943    AC_ARG_ENABLE(embedded-manifest,
944	AC_HELP_STRING([--enable-embedded-manifest],
945		[embed manifest if possible (default: yes)]),
946	[embed_ok=$enableval], [embed_ok=yes])
947
948    VC_MANIFEST_EMBED_DLL=
949    VC_MANIFEST_EMBED_EXE=
950    result=no
951    if test "$embed_ok" = "yes" -a "${SHARED_BUILD}" = "1" \
952       -a "$GCC" != "yes" ; then
953	# Add the magic to embed the manifest into the dll/exe
954	AC_EGREP_CPP([manifest needed], [
955#if defined(_MSC_VER) && _MSC_VER >= 1400
956print("manifest needed")
957#endif
958	], [
959	# Could do a CHECK_PROG for mt, but should always be with MSVC8+
960	# Could add 'if test -f' check, but manifest should be created
961	# in this compiler case
962	# Add in a manifest argument that may be specified
963	# XXX Needs improvement so that the test for existence accounts
964	# XXX for a provided (known) manifest
965	VC_MANIFEST_EMBED_DLL="if test -f \[$]@.manifest ; then mt.exe -nologo -manifest \[$]@.manifest $1 -outputresource:\[$]@\;2 ; fi"
966	VC_MANIFEST_EMBED_EXE="if test -f \[$]@.manifest ; then mt.exe -nologo -manifest \[$]@.manifest $1 -outputresource:\[$]@\;1 ; fi"
967	result=yes
968	if test "x$1" != x ; then
969	    result="yes ($1)"
970	fi
971	])
972    fi
973    AC_MSG_RESULT([$result])
974    AC_SUBST(VC_MANIFEST_EMBED_DLL)
975    AC_SUBST(VC_MANIFEST_EMBED_EXE)
976])
977