summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXInit.c
diff options
context:
space:
mode:
authordas <das@noemail.net>2005-05-24 04:21:30 (GMT)
committerdas <das@noemail.net>2005-05-24 04:21:30 (GMT)
commit9aa4e4877c08174ff876b9698175c4685633162f (patch)
treeba20400bcdbf394be0258f6dc603b703b1a34d56 /macosx/tkMacOSXInit.c
parent4f07dcdcb4f2413b7bb024dfbd3a740b166164d6 (diff)
downloadtk-9aa4e4877c08174ff876b9698175c4685633162f.zip
tk-9aa4e4877c08174ff876b9698175c4685633162f.tar.gz
tk-9aa4e4877c08174ff876b9698175c4685633162f.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.13 FossilOrigin-Name: 96e180a1ac990add3a5dd5e44391242c6d60248e
Diffstat (limited to 'macosx/tkMacOSXInit.c')
-rw-r--r--macosx/tkMacOSXInit.c63
1 files changed, 60 insertions, 3 deletions
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c
index f3f785f..7b469a7 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.3.2.5 2005/05/14 20:53:31 das Exp $
+ * RCS: @(#) $Id: tkMacOSXInit.c,v 1.3.2.6 2005/05/24 04:21:32 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
@@ -158,8 +159,64 @@ 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);
+#ifdef TK_FRAMEWORK
+ if (Tcl_MacOSXOpenVersionedBundleResources(interp,
+ "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, tkLibPath) != TCL_OK)
+#endif
+ {
+ /* 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,