summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXInit.c
diff options
context:
space:
mode:
authordas <das@noemail.net>2005-05-23 20:24:55 (GMT)
committerdas <das@noemail.net>2005-05-23 20:24:55 (GMT)
commit42703caca13187bb45b8cdcdac09ec820cbaadb5 (patch)
tree6a75bc6224147be902b9f8707503d0ea3eebc0a9 /macosx/tkMacOSXInit.c
parent6510b57f075f89497c5098d17a159651412b6918 (diff)
downloadtk-42703caca13187bb45b8cdcdac09ec820cbaadb5.zip
tk-42703caca13187bb45b8cdcdac09ec820cbaadb5.tar.gz
tk-42703caca13187bb45b8cdcdac09ec820cbaadb5.tar.bz2
* macosx/Makefile:
* macosx/README: * macosx/Tk-Info.plist.in (new file): * macosx/Wish-Info.plist.in (new file): * unix/Makefile.in: * unix/configure.in: * unix/tcl.m4: * unix/tkUnixInit.c: moved all Darwin framework and TkAqua build support from macosx/Wish.pbproj and macosx/Makefile into the standard unix configure/make buildsystem, the project and macosx/Makefile are no longer required to build Tk.framework and/or TkAqua. TkAqua is now enabled by the --enable-aqua configure option, and static and non-framework builds of TkAqua are now available via the standard configure switches. Tk/X11 can also be built as a framework. The macosx/Makefile now wraps the unix buildsystem and no longer uses the projects, embedded builds are still only available via this Makefile, but for other builds it is not longer required (but its current functionality is still available for backwards compatibility). The projects currently do not call through to the Makefile to build (unlike Tcl.pbproj) so project builds may differ from makefile builds. Due to issues with spaces in pathnames, 'Wish Shell.app' has been renamed to 'Wish.app', the macosx/Makefile installs backwards compatibility symlinks for the old name. * macosx/tkMacOSXInit.c (TkpInit): added support for Tk resource file in non-framework and static builds: the resource file is copied into a __tk_rsrc MachO segment of the library or executable at link time and extracted into a temporary location at initialization. * unix/configure: autoconf-2.59 * unix/tkConfig.h.in (new file): autoheader-2.59 FossilOrigin-Name: a9562fc80cdaf0622e7123d0f42508f705f42a9b
Diffstat (limited to 'macosx/tkMacOSXInit.c')
-rw-r--r--macosx/tkMacOSXInit.c60
1 files changed, 57 insertions, 3 deletions
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c
index b5481ba..14e9cbf 100644
--- a/macosx/tkMacOSXInit.c
+++ b/macosx/tkMacOSXInit.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXInit.c,v 1.9 2005/05/14 20:48:15 das Exp $
+ * RCS: @(#) $Id: tkMacOSXInit.c,v 1.10 2005/05/23 20:24:59 das Exp $
*/
#include "tkInt.h"
@@ -18,6 +18,7 @@
#include "tclInt.h"
#include <sys/stat.h>
#include <mach-o/dyld.h>
+#include <mach-o/getsect.h>
/*
* The Init script (common to Windows and Unix platforms) is
@@ -159,8 +160,61 @@ TkpInit(interp)
* FIXME: Should we come up with a more generic way of doing this?
*/
- Tcl_MacOSXOpenVersionedBundleResources(interp,
- "com.tcltk.tklibrary", TK_VERSION, 1, 1024, tkLibPath);
+ if (Tcl_MacOSXOpenVersionedBundleResources(interp,
+ "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, tkLibPath) != TCL_OK) {
+ /* Tk.framework not found, check if resource file is open */
+ Handle rsrc = Get1NamedResource('CURS', "\phand");
+ if (rsrc) {
+ ReleaseResource(rsrc);
+ } else {
+ struct mach_header *image;
+ char *data = NULL;
+ unsigned long size;
+ int fd = -1;
+ char fileName[L_tmpnam + 15];
+
+ /* Get resource data from __tk_rsrc section of tk library file */
+#ifdef HAVE__DYLD_GET_IMAGE_HEADER_CONTAINING_ADDRESS
+ image = _dyld_get_image_header_containing_address((unsigned long)&TkpInit);
+ if (image) {
+ data = getsectdatafromheader(image, SEG_TEXT, "__tk_rsrc", &size);
+ }
+#else
+ int i, n = _dyld_image_count();
+ for (i = 0; i < n; i++) {
+ image = _dyld_get_image_header(i);
+ if (image) {
+ data = getsectdatafromheader(image, SEG_TEXT, "__tk_rsrc", &size);
+ }
+ if (data) break;
+ }
+#endif
+ while (data) {
+ OSStatus err;
+ FSRef ref;
+ SInt16 refNum;
+
+ /* Write resource data to temporary file and open it */
+ strcpy(fileName, P_tmpdir);
+ if (fileName[strlen(fileName) - 1] != '/') {
+ strcat(fileName, "/");
+ }
+ strcat(fileName, "tkMacOSX_XXXXXX");
+ fd = mkstemp(fileName);
+ if (fd == -1) break;
+ fcntl(fd, F_SETFD, FD_CLOEXEC);
+ if (write(fd, data, size) == -1) break;
+ err = FSPathMakeRef(fileName, &ref, NULL);
+ if (err != noErr) break;
+ err = FSOpenResourceFile(&ref, 0, NULL, fsRdPerm, &refNum);
+ break;
+ }
+ if (fd != -1) {
+ unlink(fileName);
+ close(fd);
+ }
+ }
+ }
/*
* If we don't have a TTY and stdin is a special character file of length 0,