#1224 Port to Mac OS X (with patch)

final: 8.1.1
closed-out-of-date
5
2015-02-03
2000-10-26
Anonymous
No

OriginalBugID: 2527 RFE
Version: 8.1.1
SubmitDate: '1999-08-12'
LastModified: '2000-04-18'
Severity: MED
Status: Assigned
Submitter: techsupp
ChangedBy: hobbs
OS: Macintosh
OSVersion: Mac OS 10.0
Machine: Power PC
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'

Name:
Wilfredo Sanchez

DesiredBehavior:
This patch ports Tcl to Mac OS X and Mac OS X Server. It may be of
benefit to OpenStep (though not NeXTStep) also, though I haven't tried
it.

Patch:
Index: CoreOS/Scripting/tcl/tcl/generic/tclEnv.c
diff -u CoreOS/Scripting/tcl/tcl/generic/tclEnv.c:1.1.1.3 CoreOS/Scripting/tcl/tcl/generic/tclEnv.c:1.3
--- CoreOS/Scripting/tcl/tcl/generic/tclEnv.c:1.1.1.3 Tue Jul 27 13:35:50 1999
+++ CoreOS/Scripting/tcl/tcl/generic/tclEnv.c Wed Aug 4 13:33:44 1999
@@ -70,6 +70,11 @@
*----------------------------------------------------------------------
*/

+#if defined(__APPLE__) && defined(__DYNAMIC__)
+#include <crt_externs.h>
+char **environ = NULL;
+#endif
+
void
TclSetupEnv(interp)
Tcl_Interp *interp; /* Interpreter whose "env" array is to be
@@ -78,6 +83,10 @@
Tcl_DString envString;
char *p1, *p2;
int i;
+
+#if defined(__APPLE__) && defined(__DYNAMIC__)
+ environ = *_NSGetEnviron();
+#endif

/*
* Synchronize the values in the environ array with the contents
Index: CoreOS/Scripting/tcl/tcl/unix/Makefile.in
diff -u CoreOS/Scripting/tcl/tcl/unix/Makefile.in:1.1.1.3 CoreOS/Scripting/tcl/tcl/unix/Makefile.in:1.6
--- CoreOS/Scripting/tcl/tcl/unix/Makefile.in:1.1.1.3 Tue Jul 27 13:35:32 1999
+++ CoreOS/Scripting/tcl/tcl/unix/Makefile.in Wed Aug 4 13:33:46 1999
@@ -26,6 +26,10 @@

prefix = @prefix@
exec_prefix = @exec_prefix@
+bindir = @bindir@
+libdir = @libdir@
+includedir = @includedir@
+mandir = @mandir@

# The following definition can be set to non-null for special systems
# like AFS with replication. It allows the pathnames used for installation
@@ -37,7 +41,7 @@
# Directory from which applications will reference the library of Tcl
# scripts (note: you can set the TCL_LIBRARY environment variable at
# run-time to override this value):
-TCL_LIBRARY = $(prefix)/lib/tcl$(VERSION)
+TCL_LIBRARY = @TCL_LIBRARY@

# Package search path.
TCL_PACKAGE_PATH = @TCL_PACKAGE_PATH@
@@ -46,19 +50,22 @@
SCRIPT_INSTALL_DIR = $(INSTALL_ROOT)$(TCL_LIBRARY)

# Directory in which to install libtcl.so or libtcl.a:
-LIB_INSTALL_DIR = $(INSTALL_ROOT)$(exec_prefix)/lib
+LIB_INSTALL_DIR = $(INSTALL_ROOT)$(libdir)

# Path to use at runtime to refer to LIB_INSTALL_DIR:
-LIB_RUNTIME_DIR = $(exec_prefix)/lib
+LIB_RUNTIME_DIR = $(libdir)

# Directory in which to install the program tclsh:
-BIN_INSTALL_DIR = $(INSTALL_ROOT)$(exec_prefix)/bin
+BIN_INSTALL_DIR = $(INSTALL_ROOT)$(bindir)

# Directory in which to install the include file tcl.h:
-INCLUDE_INSTALL_DIR = $(INSTALL_ROOT)$(prefix)/include
+INCLUDE_INSTALL_DIR = $(INSTALL_ROOT)$(includedir)

+# Directory in which to install the (NeXT/Apple) framework:
+FRAMEWORK = @FRAMEWORK@
+
# Top-level directory in which to install manual entries:
-MAN_INSTALL_DIR = $(INSTALL_ROOT)$(prefix)/man
+MAN_INSTALL_DIR = $(INSTALL_ROOT)$(mandir)

# Directory in which to install manual entry for tclsh:
MAN1_INSTALL_DIR = $(MAN_INSTALL_DIR)/man1
@@ -87,7 +94,7 @@
#CFLAGS = $(CFLAGS_OPTIMIZE)
#CFLAGS = $(CFLAGS_DEBUG) $(CFLAGS_OPTIMIZE)
CFLAGS = @CFLAGS@
-
+LDFLAGS = @LD_FLAGS@

# To disable ANSI-C procedure prototypes reverse the comment characters
# on the following lines:
@@ -179,6 +186,7 @@
# these definitions by hand.

SHLIB_LD = @SHLIB_LD@
+SHLIB_LD_CORE = @SHLIB_LD_CORE@
SHLIB_CFLAGS = @SHLIB_CFLAGS@

SHLIB_SUFFIX = @SHLIB_SUFFIX@
@@ -244,7 +252,7 @@
${AC_FLAGS} ${MATH_FLAGS} ${GENERIC_FLAGS} ${PROTO_FLAGS} ${MEM_DEBUG_FLAGS} ${COMPILE_DEBUG_FLAGS} ${ENV_FLAGS} -DTCL_SHLIB_EXT=\"${SHLIB_SUFFIX}\"

-LIBS = @DL_LIBS@ @LIBS@ $(MATH_LIBS) -lc
+LIBS = @DL_LIBS@ @LIBS@ $(MATH_LIBS)

DEPEND_SWITCHES = ${CFLAGS} -I${GENERIC_DIR} -I${SRC_DIR} ${AC_FLAGS} ${MATH_FLAGS} @@ -383,6 +391,7 @@
$(UNIX_DIR)/tclLoadDld.c $(GENERIC_DIR)/tclLoadNone.c $(UNIX_DIR)/tclLoadOSF.c + $(UNIX_DIR)/tclLoadDyld.c $(UNIX_DIR)/tclLoadShl.c

# Note: don't include DL_SRCS in SRCS: most of those files won't
@@ -418,11 +427,11 @@

tclsh: ${TCLSH_OBJS} ${TCL_LIB_FILE}
- ${CC} @LD_FLAGS@ ${TCLSH_OBJS} @TCL_BUILD_LIB_SPEC@ ${LIBS} + ${CC} $(LDFLAGS) ${TCLSH_OBJS} @TCL_BUILD_LIB_SPEC@ ${LIBS} @TCL_LD_SEARCH_FLAGS@ -o tclsh

tcltest: ${TCLTEST_OBJS} ${TCL_LIB_FILE} ${BUILD_DLTEST}
- ${CC} @LD_FLAGS@ ${TCLTEST_OBJS} @TCL_BUILD_LIB_SPEC@ ${LIBS} + ${CC} $(LDFLAGS) ${TCLTEST_OBJS} @TCL_BUILD_LIB_SPEC@ ${LIBS} @TCL_LD_SEARCH_FLAGS@ -o tcltest

xttest: ${XTTEST_OBJS} ${GENERIC_OBJS} ${UNIX_OBJS} ${COMPAT_OBJS} @@ -494,6 +503,9 @@

install: install-binaries install-libraries install-man

+install-strip:
+ $(MAKE) install INSTALL_PROGRAM="$(INSTALL_PROGRAM) -s"
+
# Note: before running ranlib below, must cd to target directory because
# some ranlibs write to current directory, and this might not always be
# possible (e.g. if installing as root).
@@ -520,8 +532,21 @@
fi
@echo "Installing tclsh"
@$(INSTALL_PROGRAM) tclsh $(BIN_INSTALL_DIR)/tclsh$(VERSION)
- @echo "Installing tclConfig.sh"
- @$(INSTALL_DATA) tclConfig.sh $(LIB_INSTALL_DIR)/tclConfig.sh
+ @if [ "x$(FRAMEWORK)" = "x" ]; then + echo "Installing tclConfig.sh"; + $(INSTALL_DATA) tclConfig.sh $(LIB_INSTALL_DIR)/tclConfig.sh; + else + echo "Installing framework"; + chmod u+w $(LIB_INSTALL_DIR)/$(TCL_LIB_FILE); + strip -S $(LIB_INSTALL_DIR)/$(TCL_LIB_FILE); + chmod 555 $(LIB_INSTALL_DIR)/$(TCL_LIB_FILE); + ( cd $(INSTALL_ROOT)$(FRAMEWORK); + mkdir -p -m 755 Versions/$(VERSION)/Resources; + rm -f Headers; ln -s Versions/$(VERSION)/Headers; + rm -f Tcl; ln -s Versions/$(VERSION)/Tcl; + rm -f Resources; ln -s Versions/$(VERSION)/Resources; ); + $(INSTALL_DATA) tclConfig.sh $(INSTALL_ROOT)$(FRAMEWORK)/Versions/$(VERSION)/Resources/tclConfig.sh; + fi
@if test "$(TCL_STUB_LIB_FILE)" != "" ; then echo "Installing $(TCL_STUB_LIB_FILE)"; $(INSTALL_DATA) $(STUB_LIB_FILE) @@ -529,7 +554,7 @@
fi

install-libraries:
- @for i in $(INSTALL_ROOT)$(prefix)/lib $(INCLUDE_INSTALL_DIR) + @for i in $(INSTALL_ROOT)$(libdir) $(INCLUDE_INSTALL_DIR) $(SCRIPT_INSTALL_DIR); do if [ ! -d $$i ] ; then @@ -803,6 +828,9 @@

tclLoadOSF.o: $(UNIX_DIR)/tclLoadOSF.c
$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tclLoadOSF.c
+
+tclLoadDyld.o: $(UNIX_DIR)/tclLoadDyld.c
+ $(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tclLoadDyld.c

tclLoadShl.o: $(UNIX_DIR)/tclLoadShl.c
$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tclLoadShl.c
Index: CoreOS/Scripting/tcl/tcl/unix/configure.in
diff -u CoreOS/Scripting/tcl/tcl/unix/configure.in:1.1.1.3 CoreOS/Scripting/tcl/tcl/unix/configure.in:1.4
--- CoreOS/Scripting/tcl/tcl/unix/configure.in:1.1.1.3 Tue Jul 27 13:35:33 1999
+++ CoreOS/Scripting/tcl/tcl/unix/configure.in Wed Aug 4 13:33:47 1999
@@ -2,7 +2,7 @@
dnl generate the file "configure", which is run during Tcl installation
dnl to configure the system for the local environment.
AC_INIT(../generic/tcl.h)
-# RCS: @(#) $Id: configure.in,v 1.1.1.3 1999/07/27 20:35:33 wsanchez Exp $
+# RCS: @(#) $Id: configure.in,v 1.4 1999/08/04 20:33:47 wsanchez Exp $

TCL_VERSION=8.1
TCL_MAJOR_VERSION=8
@@ -746,6 +746,8 @@
fullSrcDir=`cd $srcdir; pwd`
EXTRA_CFLAGS=""
TCL_EXPORT_FILE_SUFFIX=""
+LIBTCL="libtcl"
+LIBTCLSTUB="libtclstub"
TCL_UNSHARED_LIB_SUFFIX=""
TCL_TRIM_DOTS='`echo ${VERSION} | tr -d .`'
ECHO_VERSION='`echo ${VERSION}`'
@@ -947,6 +949,51 @@
LD_FLAGS=""
LD_SEARCH_FLAGS=""
;;
+ Rhapsody-* | "Mac OS"-*)
+ # If --libdir and --includedir weren't specified make the default
+ # behaviour to enable shared code and create a Tcl framework.
+ # If --prefix=/usr, then we're replacing the system's tcl; otherwise,
+ # create the framework in /Local.
+ if test "${libdir}" = '${exec_prefix}/lib' + -a "${includedir}" = '${prefix}/include'; then
+ if test "$exec_prefix" = "/usr"; then
+ domain="/System"
+ else
+ domain="/Local"
+ fi
+ FRAMEWORK="${domain}/Library/Frameworks/Tcl.framework"
+ frameworkVersioned="${FRAMEWORK}/Versions/${TCL_VERSION}"
+ libdir="${frameworkVersioned}"
+ TCL_LIBRARY='/System/Library/Tcl/$(VERSION)'
+ LIBTCL="Tcl"
+ TCL_SHARED_LIB_SUFFIX="-NONE-"
+ TCL_UNSHARED_LIB_SUFFIX=".a"
+ TCL_LIB_FLAG="Tcl"
+ TCL_LIB_SPEC="-framework Tcl"
+ TCL_STUB_LIB_FLAG="-ltclstub"
+ TCL_STUB_LIB_SPEC="-L${frameworkVersioned} ${TCL_STUB_LIB_FLAG}"
+ TCL_STUB_LIB_PATH="${frameworkVersioned}${LIBTCLSTUB}${TCL_UNSHARED_LIB_SUFFIX}"
+ TCL_PACKAGE_PATH="/Local/Library/Tcl /Network/Library/Tcl /System/Library/Tcl"
+ TCL_LIB_VERSIONS_OK="no"
+ fi
+ if test -n $FRAMEWORK -a "${includedir}" = '${prefix}/include'; then
+ includedir="${frameworkVersioned}/Headers"
+ fi
+ patchLevel=`echo ${TCL_PATCH_LEVEL} | sed 's/^\.//'`
+ SHLIB_CFLAGS="-fno-common"
+ SHLIB_LD="cc -bundle -undefined suppress"
+ SHLIB_LD_CORE="cc -dynamiclib"
+ SHLIB_LD_CORE="${SHLIB_LD_CORE} -compatibility_version 1 -current_version ${patchLevel}"
+ SHLIB_LD_CORE="${SHLIB_LD_CORE} -install_name ${libdir}/\${TCL_LIB_FILE}"
+ SHLIB_LD_CORE="${SHLIB_LD_CORE} -seg1addr 0x6a800000"
+ SHLIB_LD_LIBS=""
+ SHLIB_SUFFIX=".bundle"
+ DL_OBJS="tclLoadDyld.o"
+ DL_LIBS=""
+ LD_FLAGS=""
+ LD_SEARCH_FLAGS=""
+ CFLAGS_OPTIMIZE="-O3"
+ ;;
NEXTSTEP-*)
SHLIB_CFLAGS=""
SHLIB_LD="cc -nostdlib -r"
@@ -1234,6 +1281,14 @@
BUILD_DLTEST=""
fi

+# SHLIB_LD_CORE holds the flags for linking a dynamic libtcl;
+# usually these are the same as SHLIB_LD, but on some systems,
+# the linker distinguishes loadbles which are loaded automatically
+# by the linker (libraries) from those loaded by code in the
+# program (modules).
+
+if test "$SHLIB_LD_CORE" = ""; then SHLIB_LD_CORE="$SHLIB_LD"; fi
+
# If we're running gcc, then change the C flags for compiling shared
# libraries to the right flags for gcc, instead of those for the
# standard manufacturer compiler.
@@ -1249,6 +1304,10 @@
;;
NetBSD-*|FreeBSD-*|OpenBSD-*)
;;
+ Rhapsody-*)
+ ;;
+ "Mac OS"-*)
+ ;;
RISCos-*)
;;
ULTRIX-4.*)
@@ -1332,6 +1391,7 @@
if test "$TCL_SHARED_LIB_SUFFIX" = "" ; then
TCL_SHARED_LIB_SUFFIX='${VERSION}\$\{DBGX\}${SHLIB_SUFFIX}'
fi
+if test "$TCL_SHARED_LIB_SUFFIX" = "-NONE-" ; then TCL_SHARED_LIB_SUFFIX=""; fi
if test "$TCL_UNSHARED_LIB_SUFFIX" = "" ; then
TCL_UNSHARED_LIB_SUFFIX='${VERSION}\$\{DBGX\}.a'
fi
@@ -1342,11 +1402,11 @@
TCL_SHARED_BUILD=1
TCL_SHLIB_CFLAGS="${SHLIB_CFLAGS}"
TCL_LD_SEARCH_FLAGS="${LD_SEARCH_FLAGS}"
- eval "TCL_LIB_FILE=libtcl${TCL_SHARED_LIB_SUFFIX}"
+ eval "TCL_LIB_FILE=${LIBTCL}${TCL_SHARED_LIB_SUFFIX}"
if test "x$DL_OBJS" = "xtclLoadAout.o"; then
MAKE_LIB="ar cr \${TCL_LIB_FILE} \${OBJS}"
else
- MAKE_LIB="\${SHLIB_LD} -o \${TCL_LIB_FILE} \${OBJS} ${SHLIB_LD_LIBS}"
+ MAKE_LIB="\${SHLIB_LD_CORE} -o \${TCL_LIB_FILE} \${OBJS} ${SHLIB_LD_LIBS}"
RANLIB=":"
fi
else
@@ -1364,7 +1424,7 @@
esac
TCL_SHLIB_CFLAGS=""
TCL_LD_SEARCH_FLAGS="${LD_SEARCH_FLAGS}"
- eval "TCL_LIB_FILE=libtcl${TCL_UNSHARED_LIB_SUFFIX}"
+ eval "TCL_LIB_FILE=${LIBTCL}${TCL_UNSHARED_LIB_SUFFIX}"
MAKE_LIB="ar cr \${TCL_LIB_FILE} \${OBJS}"
fi

@@ -1381,22 +1441,24 @@
# up the Tcl library.

if test $TCL_SHARED_BUILD = 0 -o $TCL_NEEDS_EXP_FILE = 0; then
- if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
- TCL_LIB_FLAG="-ltcl${TCL_VERSION}\${TCL_DBGX}"
- else
- TCL_LIB_FLAG="-ltcl`echo ${TCL_VERSION} | tr -d .`\${TCL_DBGX}"
+ if test "${TCL_LIB_FLAG}" = ""; then
+ if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
+ TCL_LIB_FLAG="-ltcl${TCL_VERSION}\${TCL_DBGX}"
+ else
+ TCL_LIB_FLAG="-ltcl`echo ${TCL_VERSION} | tr -d .`\${TCL_DBGX}"
+ fi
fi
TCL_BUILD_LIB_SPEC="-L`pwd` ${TCL_LIB_FLAG}"
- TCL_LIB_SPEC="-L${exec_prefix}/lib ${TCL_LIB_FLAG}"
+ if test "${TCL_LIB_SPEC}" = ""; then TCL_LIB_SPEC="-L${exec_prefix}/lib ${TCL_LIB_FLAG}"; fi
else
TCL_BUILD_EXP_FILE="lib.exp"
- eval "TCL_EXP_FILE=libtcl${TCL_EXPORT_FILE_SUFFIX}"
+ eval "TCL_EXP_FILE=${LIBTCL}${TCL_EXPORT_FILE_SUFFIX}"

# Replace DBGX with TCL_DBGX
eval "TCL_EXP_FILE=\"${TCL_EXP_FILE}\""

TCL_BUILD_LIB_SPEC="-bI:`pwd`/${TCL_BUILD_EXP_FILE}"
- TCL_LIB_SPEC="-bI:${exec_prefix}/lib/${TCL_EXP_FILE}"
+ if test "${TCL_LIB_SPEC}" = ""; then TCL_LIB_SPEC="-bI:${exec_prefix}/lib/${TCL_EXP_FILE}"; fi
fi
VERSION='${VERSION}'
eval "CFG_TCL_SHARED_LIB_SUFFIX=${TCL_SHARED_LIB_SUFFIX}"
@@ -1404,6 +1466,10 @@
eval "CFG_TCL_EXPORT_FILE_SUFFIX=${TCL_EXPORT_FILE_SUFFIX}"
VERSION=${TCL_VERSION}

+if test "$TCL_LIBRARY" = ""; then
+ TCL_LIBRARY = '$(libdir)/tcl$(VERSION)'
+fi
+
#--------------------------------------------------------------------
# The statements below define the symbol TCL_PACKAGE_PATH, which
# gives a list of directories that may contain packages. The list
@@ -1411,10 +1477,12 @@
# another for platform-independent scripts.
#--------------------------------------------------------------------

-if test "$prefix" != "$exec_prefix"; then
- TCL_PACKAGE_PATH="${exec_prefix}/lib ${prefix}/lib"
-else
- TCL_PACKAGE_PATH="${prefix}/lib"
+if test "x$TCL_PACKAGE_PATH" = "x"; then
+ if test "$prefix" != "$exec_prefix"; then
+ TCL_PACKAGE_PATH="${exec_prefix}/lib ${prefix}/lib"
+ else
+ TCL_PACKAGE_PATH="${prefix}/lib"
+ fi
fi

#--------------------------------------------------------------------
@@ -1422,7 +1490,7 @@
# stub support.
#--------------------------------------------------------------------
# Replace ${VERSION} with contents of ${TCL_VERSION}
-eval "STUB_LIB_FILE=libtclstub${TCL_UNSHARED_LIB_SUFFIX}"
+eval "STUB_LIB_FILE=${LIBTCLSTUB}${TCL_UNSHARED_LIB_SUFFIX}"
# Replace DBGX with TCL_DBGX
eval "STUB_LIB_FILE=\"${STUB_LIB_FILE}\""

@@ -1430,16 +1498,18 @@

TCL_STUB_LIB_FILE=${STUB_LIB_FILE}

-if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
- TCL_STUB_LIB_FLAG="-ltclstub${TCL_VERSION}\${TCL_DBGX}"
-else
- TCL_STUB_LIB_FLAG="-ltclstub`echo ${TCL_VERSION} | tr -d .`\${TCL_DBGX}"
+if test "${TCL_STUB_LIB_FLAG}" = ""; then
+ if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
+ TCL_STUB_LIB_FLAG="-ltclstub${TCL_VERSION}\${TCL_DBGX}"
+ else
+ TCL_STUB_LIB_FLAG="-ltclstub`echo ${TCL_VERSION} | tr -d .`\${TCL_DBGX}"
+ fi
fi

TCL_BUILD_STUB_LIB_SPEC="-L`pwd` ${TCL_STUB_LIB_FLAG}"
-TCL_STUB_LIB_SPEC="-L${exec_prefix}/lib ${TCL_STUB_LIB_FLAG}"
+if test "${TCL_STUB_LIB_SPEC}" = ""; then TCL_STUB_LIB_SPEC="-L${exec_prefix}/lib ${TCL_STUB_LIB_FLAG}"; fi
TCL_BUILD_STUB_LIB_PATH="`pwd`/${TCL_STUB_LIB_FILE}"
-TCL_STUB_LIB_PATH="${exec_prefix}/lib/${TCL_STUB_LIB_FILE}"
+if test "${TCL_STUB_LIB_PATH}" = ""; then TCL_STUB_LIB_PATH="${exec_prefix}/lib/${TCL_STUB_LIB_FILE}"; fi

AC_SUBST(STUB_LIB_FILE)

@@ -1463,11 +1533,13 @@
AC_SUBST(DL_LIBS)
AC_SUBST(DL_OBJS)
AC_SUBST(EXTRA_CFLAGS)
+AC_SUBST(FRAMEWORK)
AC_SUBST(LD_FLAGS)
AC_SUBST(MAKE_LIB)
AC_SUBST(MATH_LIBS)
AC_SUBST(SHLIB_CFLAGS)
AC_SUBST(SHLIB_LD)
+AC_SUBST(SHLIB_LD_CORE)
AC_SUBST(SHLIB_LD_LIBS)
AC_SUBST(SHLIB_SUFFIX)
AC_SUBST(TCL_BUILD_LIB_SPEC)
@@ -1479,6 +1551,7 @@
AC_SUBST(TCL_EXP_FILE)
AC_SUBST(TCL_LIB_SPEC)
AC_SUBST(TCL_LIB_VERSIONS_OK)
+AC_SUBST(TCL_LIBRARY)
AC_SUBST(TCL_MAJOR_VERSION)
AC_SUBST(TCL_MINOR_VERSION)
AC_SUBST(TCL_PACKAGE_PATH)
Index: CoreOS/Scripting/tcl/tcl/unix/tclLoadDyld.c
diff -u /dev/null CoreOS/Scripting/tcl/tcl/unix/tclLoadDyld.c:1.1
--- /dev/null Thu Aug 5 19:09:18 1999
+++ CoreOS/Scripting/tcl/tcl/unix/tclLoadDyld.c Wed Aug 4 13:33:47 1999
@@ -0,0 +1,161 @@
+/*
+ * tclLoadDyld.c --
+ *
+ * This procedure provides a version of the TclLoadFile that
+ * works with NeXT/Apple's dyld dynamic loading. This file
+ * provided by Wilfredo Sanchez (wsanchez@apple.com).
+ * The works on Mac OS X and Mac OS X Server.
+ * It should work with OpenStep, but it's not been tried.
+ *
+ * Copyright (c) 1995 Apple Computer, Inc.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ * RCS: @(#) $Id: tclLoadDyld.c,v 1.1 1999/08/04 20:33:47 wsanchez Exp $
+ */
+
+#include "tclInt.h"
+#include <mach-o/dyld.h>
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclpLoadFile --
+ *
+ * Dynamically loads a binary code file into memory and returns
+ * the addresses of two procedures within that file, if they
+ * are defined.
+ *
+ * Results:
+ * A standard Tcl completion code. If an error occurs, an error
+ * message is left in interp->result. *proc1Ptr and *proc2Ptr
+ * are filled in with the addresses of the symbols given by
+ * *sym1 and *sym2, or NULL if those symbols can't be found.
+ *
+ * Side effects:
+ * New code suddenly appears in memory.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclpLoadFile(interp, fileName, sym1, sym2, proc1Ptr, proc2Ptr, clientDataPtr)
+ Tcl_Interp *interp; /* Used for error reporting. */
+ char *fileName; /* Name of the file containing the desired
+ * code. */
+ char *sym1, *sym2; /* Names of two procedures to look up in
+ * the file's symbol table. */
+ Tcl_PackageInitProc **proc1Ptr, **proc2Ptr;
+ /* Where to return the addresses corresponding
+ * to sym1 and sym2. */
+ ClientData *clientDataPtr; /* Filled with token for dynamically loaded
+ * file which will be passed back to
+ * TclpUnloadFile() to unload the file. */
+{
+ NSObjectFileImageReturnCode err;
+ NSObjectFileImage image;
+ NSModule module;
+ NSSymbol symbol;
+ char *name;
+
+ if ((err=NSCreateObjectFileImageFromFile(fileName, &image)) != NSObjectFileImageSuccess) {
+ switch (err) {
+ case NSObjectFileImageFailure:
+ interp->result = "dyld: general failure"; break;
+ case NSObjectFileImageInappropriateFile:
+ interp->result = "dyld: inappropriate Mach-O file"; break;
+ case NSObjectFileImageArch:
+ interp->result = "dyld: inappropriate Mach-O architecture"; break;
+ case NSObjectFileImageFormat:
+ interp->result = "dyld: invalid Mach-O file format"; break;
+ case NSObjectFileImageAccess:
+ interp->result = "dyld: permission denied"; break;
+ default:
+ interp->result = "dyld: unknown failure"; break;
+ }
+ return TCL_ERROR;
+ }
+
+ module = NSLinkModule(image, fileName, TRUE);
+
+ if (module == NULL) {
+ interp->result = "dyld: falied to link module";
+ return TCL_ERROR;
+ }
+
+ name = (char*)malloc(sizeof(char)*(strlen(sym1)+2));
+ sprintf(name, "_%s", sym1);
+ symbol = NSLookupAndBindSymbol(name);
+ free(name);
+ *proc1Ptr = NSAddressOfSymbol(symbol);
+
+ name = (char*)malloc(sizeof(char)*(strlen(sym2)+2));
+ sprintf(name, "_%s", sym2);
+ symbol = NSLookupAndBindSymbol(name);
+ free(name);
+ *proc2Ptr = NSAddressOfSymbol(symbol);
+
+ *clientDataPtr = module;
+
+ return TCL_OK;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclpUnloadFile --
+ *
+ * Unloads a dynamically loaded binary code file from memory.
+ * Code pointers in the formerly loaded file are no longer valid
+ * after calling this function.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Code dissapears from memory.
+ * Note that this is a no-op on older (OpenStep) versions of dyld.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+TclpUnloadFile(clientData)
+ ClientData clientData; /* ClientData returned by a previous call
+ * to TclpLoadFile(). The clientData is
+ * a token that represents the loaded
+ * file. */
+{
+ NSUnLinkModule(clientData, FALSE);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclGuessPackageName --
+ *
+ * If the "load" command is invoked without providing a package
+ * name, this procedure is invoked to try to figure it out.
+ *
+ * Results:
+ * Always returns 0 to indicate that we couldn't figure out a
+ * package name; generic code will then try to guess the package
+ * from the file name. A return value of 1 would have meant that
+ * we figured out the package name and put it in bufPtr.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclGuessPackageName(fileName, bufPtr)
+ char *fileName; /* Name of file containing package (already
+ * translated to local form if needed). */
+ Tcl_DString *bufPtr; /* Initialized empty dstring. Append
+ * package name to this if possible. */
+{
+ return 0;
+}
Index: CoreOS/Scripting/tcl/tcl/unix/tclUnixPort.h
diff -u CoreOS/Scripting/tcl/tcl/unix/tclUnixPort.h:1.1.1.3 CoreOS/Scripting/tcl/tcl/unix/tclUnixPort.h:1.2
--- CoreOS/Scripting/tcl/tcl/unix/tclUnixPort.h:1.1.1.3 Tue Jul 27 13:35:32 1999
+++ CoreOS/Scripting/tcl/tcl/unix/tclUnixPort.h Wed Aug 4 13:33:48 1999
@@ -422,7 +422,7 @@
* Variables provided by the C library:
*/

-#if defined(_sgi) || defined(__sgi)
+#if defined(_sgi) || defined(__sgi) || (defined(__APPLE__) && defined(__DYNAMIC__))
# define environ _environ
#endif
extern char **environ;

PatchFiles:
generic/tclEnv.c:
- Initialize environ for dyld-dynamic Tcl library.

unix/Makefile.in:
- Let configure set bindir and friends.
- Add support for installing a NeXT/Apple-style Tcl framework.
- Add install-strip target, as per gnu makefile conventions.
- Add tclLoadDyld.c target.
- Remove -lc from LIBS; we don't have a -lc. It should be added
to @LIBS@ by configure for the odd platforms that need it; I
don't know which they are.

unix/configure.in:
- Make libtcl and libtclstub strings into varioables.
- Add Rhapsody (Mac OS X Server) and Mac OS (10.0 and greater)
as platforms.
- Build Tcl library as a NeXT/Apple-style framework unless
configured otherwise.
- Make some more variables overrideable by platform to allow
framework install locations, different compile flags.
- Allow for different linker flags for building libtcl, as
opposed to loadables. (SHLIB_LD_CORE)

unix/tclLoadDyld.c:
- New file. Supports dyld dynamic loading.

unix/tclUnixPort.h:
- Rename environ on Mac OS X and Rhapsody, like SGI to avoid
conflict with the runtime environ symbol in crt1.

We'd need to get a copy of the most recent Mac OS X to verify
this, along with testing against the Unix envs that it touches
into with the config changes.
-- 12/04/1999 hobbs
Made core coding changes in generic/tclEnv.c and unix/tclUnixPort.h
as well as new unix/tclLoadDyld.c for 8.3.1. Also made changes to
unix/Makefile.in for:
- Let configure set bindir and friends.
- Add install-strip target, as per gnu makefile conventions.
- Add tclLoadDyld.c target.

I didn't remove -lc (I was recently on a system that needed this...
was it AIX or perhaps Tru64??). This needs to be further examined.
I didn't make the rest of the configure.in or Makefile.in changes
because it touched quite a bit of stuff, and some of it wasn't
correct (ie TCL_LIBRARY was made to use $exec_prefix when it
really was supposed to use $prefix - it's for the platform
independent scripts).

The 8.3.1 changes need to be reconciled against what wasn't done,
to see what needs to be added for full MacOS/X configurability.
Hopefully getting all the core code in is a good step in the
right direction.
-- 04/18/2000 hobbs

Discussion

  • Don Porter

    Don Porter - 2001-04-04
    • labels: 104235 --> 53. Configuration and Build Tools
     
  • Daniel A. Steffen

    Logged In: YES
    user_id=90580

    8.3.3 has fred's latest changes from Apple's darwin cvs
    repository checked in (except some Makefile mods). This is
    the version distributed with OSX 10.0

    attached the full diff against 8.3.2 that I sent to jeff for
    8.3.3, should probably be incorporated into 8.4 in some form.

     
  • Daniel A. Steffen

    diff of Apple tcl 8.3.2 from darwin cvs against 8.3.2

     
  • Andreas Kupries

    Andreas Kupries - 2001-08-23
    • assigned_to: nobody --> hobbs
     
  • Daniel A. Steffen

    • assigned_to: hobbs --> das
    • status: open --> closed-out-of-date
     
  • Daniel A. Steffen

    Logged In: YES
    user_id=90580

    This patch has been superseded by 'tcl-darwin-8-3-1-
    branch.patch' in patch #435258 against 8.3.3