Commits

Anonymous committed 2137ff8

massive update for osx support

  • Participants
  • Parent commits ec6a8ae

Comments (0)

Files changed (14)

 IMAGE = -lSDL_image
 MIXER = -lSDL_mixer
 SMPEG = -lsmpeg
+EXTRABASE =
 #--EndConfig
 
 
 #these modules are required for pygame to run. they only require
 #SDL as a dependency. these should not be altered
 
-base src/base.c $(SDL)
+base src/base.c $(EXTRABASE) $(SDL)
 cdrom src/cdrom.c $(SDL)
 constants src/constants.c $(SDL)
 display src/display.c $(SDL)
 draw src/draw.c $(SDL)
 image src/image.c $(SDL)
 transform src/transform.c src/SDL_rotozoom/SDL_rotozoom.c $(SDL)
-
+#macosx src/macosx.c src/setproctitle.c -Isrc
 
 
 #the following are placeholders. setup.py can use them to help
 # BREAK = change breaks existing code
 # BUG	= fixed a bug that was (or could have been) crashing
 
+January 6, 2001
+	Merge with bob's inital MacOSX changes
+
 January 5, 2001
         new and upgraded importing [BREAK?]
         fixed numberhandling in set_alpha and set_colorkey
     print 'Using WINDOWS configuration...\n'
     import config_win
     CFG = config_win
+elif sys.platform == 'darwin':
+    print 'Using Darwin configuration...\n'
+    import config_darwin
+    CFG = config_darwin
 else:
     print 'Using UNIX configuration...\n'
     import config_unix
     while line.find('#--EndConfig') == -1:
         line = origsetup.readline()
 
+    if string.find(sys.platform, 'darwin') != -1:
+	newsetup.write('EXTRABASE = src/SDLmain.m\n')
+    else:
+        newsetup.write('EXTRABASE = \n')
     if basepath:
         newsetup.write('BASE = ' + basepath + '\n')
     for d in deps:
 
 
 if __name__ == '__main__': main()
-
-
-

File config_darwin.py

+"""Config on Darwin w/ frameworks"""
+
+import os, sys, shutil, string
+from glob import glob
+
+configcommand = os.environ.get('SDL_CONFIG', 'sdl-config')
+configcommand = configcommand + ' --version --cflags --libs'
+
+class Dependency:
+    libext = '.dylib'
+    def __init__(self, name, checkhead, checklib, lib):
+        self.name = name
+        self.inc_dir = None
+        self.lib_dir = None
+        self.lib = lib
+        self.found = 0
+        self.checklib = checklib+self.libext
+        self.checkhead = checkhead
+        self.cflags = ''
+    
+    def configure(self, incdirs, libdirs):
+        incname = self.checkhead
+        libnames = self.checklib, string.lower(self.name)
+        for dir in incdirs:
+            path = os.path.join(dir, incname)
+            if os.path.isfile(path):
+                self.inc_dir = dir
+                break
+        for dir in libdirs:
+            for name in libnames:
+                path = os.path.join(dir, name)
+                if os.path.isfile(path):
+                    self.lib_dir = dir
+                    break 
+        if self.lib_dir and self.inc_dir:
+            print self.name + '        '[len(self.name):] + ': found'
+            self.found = 1
+        else:
+            print self.name + '        '[len(self.name):] + ': not found'
+
+class FrameworkDependency(Dependency):
+    def configure(self, incdirs, libdirs):
+      for n in '/Library/Frameworks/','~/Library/Frameworks/','/System/Library/Frameworks/':
+        if os.path.isfile(n+self.lib+'.framework/Versions/Current/'+self.lib):
+          print 'Framework '+self.lib+' found'
+          self.found = 1
+          self.inc_dir = n+self.lib+'.framework/Versions/Current/Headers'
+          self.cflags = '-Ddarwin -Xlinker "-F'+n+self.lib+'.framework" -Xlinker "-framework" -Xlinker "'+self.lib+'"'
+          self.origlib = self.lib
+          self.lib = ''
+          return
+      print 'Framework '+self.lib+' not found'
+
+sdl_lib_name = 'SDL'
+if sys.platform.find('bsd') != -1:
+    sdl_lib_name = 'SDL-1.2'
+
+DEPS = [
+    FrameworkDependency('SDL', 'SDL.h', 'lib'+sdl_lib_name, 'SDL'),
+    FrameworkDependency('FONT', 'SDL_ttf.h', 'libSDL_ttf', 'SDL_ttf'),
+    FrameworkDependency('IMAGE', 'SDL_image.h', 'libSDL_image', 'SDL_image'),
+    FrameworkDependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer', 'SDL_mixer'),
+    Dependency('SMPEG', 'smpeg.h', 'libsmpeg', 'smpeg'),
+]
+
+
+from distutils.util import split_quoted
+def main():
+    global DEPS
+    
+    print 'calling "sdl-config"'
+    configinfo = "-I/usr/local/include/SDL -L/usr/local/lib -D_REENTRANT -lSDL"
+    try:
+        configinfo = os.popen(configcommand).readlines()
+        print 'Found SDL version:', configinfo[0]
+        configinfo = ' '.join(configinfo[1:])
+        configinfo = configinfo.split()
+        for w in configinfo[:]:
+            if ',' in w: configinfo.remove(w)
+        configinfo = ' '.join(configinfo)
+        #print 'Flags:', configinfo
+    except:
+        raise SystemExit, """Cannot locate command, "sdl-config". Default SDL compile
+flags have been used, which will likely require a little editing."""
+
+    print 'Hunting dependencies...'
+    incdirs = ['/usr/local/include/smpeg']
+    libdirs = []
+    extralib = []
+    newconfig = []
+    eat_next = None
+    for arg in split_quoted(configinfo):
+      if eat_next:
+        eat_next.append(arg)  
+        eat_next=None
+        continue
+      if arg[:2] == '-I':
+        incdirs.append(arg[2:])
+        newconfig.append(arg)
+      elif arg[:2] == '-L':
+        libdirs.append(arg[2:])
+        newconfig.append(arg)
+      elif arg[:2] == '-F':
+        extralib.append(arg)
+      elif arg == '-framework':
+        extralib.append(arg)
+        eat_next = extralib
+    for d in DEPS:
+      d.configure(incdirs, libdirs)
+
+    newconfig.extend(map(lambda x:'-Xlinker "%s"'%x,extralib))
+    if sys.platform.find('darwin') != -1:
+      newconfig.append('-Ddarwin')
+    configinfo = ' '.join(newconfig)
+    DEPS[0].inc_dirs = []
+    DEPS[0].lib_dirs = []
+    DEPS[0].cflags = configinfo
+    return DEPS
+
+    
+if __name__ == '__main__':
+    print """This is the configuration subscript for Unix.
+             Please run "config.py" for full configuration."""

File lib/__init__.py

 
 # main pygame source
 # lets get things coordinated
+import os,sys
+if sys.platform=='darwin':
+  # this may change someday, but we want to chdir to where our file is if we're in / for no
+  # good reason..
+  if (os.getcwd() == '/') and len(sys.argv):
+    os.chdir(os.path.split(sys.argv[0])[0])
+  else:
+    argv0=''
+    if len(sys.argv): argv0=sys.argv[0]
+    print "WARNING!  Running pygame apps from any method other than through python.app (aka through the finder or launchservices) is UNSUPPORTED!"
+    print "          If you insist on using the terminal, type \"open %s\", and hold down the option key if you need to" % (argv0)
+    print "          specify additional command line arguments.  A dialog box will pop up and make you happy, I promise."
+    print ""
+    print "          I sure hope you ran as \"%s %s\" exactly, otherwise you will really have problems."%(sys.executable,' '.join(sys.argv))
+    print "          WindowServer doesn't like what you're doing as is, and it gets really funky if you run things from the path for whatever reason."
+    print ""
+  # not ready for prime time yet, it just rewrites the commandline so windowserver can pick it up
+  #import pygame.macosx
+
 
 def import_all_pygame():
     def makemodules(**mods): return mods
         base=2, cdrom=0, constants=2, cursors=0, display=0,
         draw=0, event=0, font=0, image=0, joystick=0,
         key=0, mixer=0, mouse=0, movie=0, rect=1, sprite=0,
-        surface=0, time=0, transform=0, surfarray=0
+        surface=0, time=0, transform=0, surfarray=0, version=2
     )
     for mod, required in modules.items():
         try:

File lib/pygame_icon.icns

Binary file added.

File lib/pygame_icon.tiff

Added
New image

File lib/version.py

 releases. (hmm, until we get to versions > 10)
 """
 
-ver = '1.3.3'
+ver = '1.3.4'
 
 def __hiddendummyfunc():
     """pygame.version.ver 
 
 METADATA = {
     "name":             "pygame",
-    "version":          "1.3.3",
+    "version":          "1.3.4",
     "license":          "LGPL",
     "url":              "http://www.pygame.org",
     "author":           "Pete Shinners",
-    "author_email":     "pete@shinners.org",
+    "author_email":     "pygame@seul.org",
     "description":      "Python Game Development",
     "long_description": DESCRIPTION,
 }

File src/SDLmain.m

+/*
+       Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
+       Non-NIB-Code & other changes: Max Horn <max@quendi.de>
+       Hacked for pygame: Bob Ippolito <bob@redivi.com>
+
+       Feel free to customize this file to suit your needs
+*/
+
+#import "SDL.h"
+#import <sys/param.h>
+#import <unistd.h>
+#import <Cocoa/Cocoa.h>
+#import <Carbon/Carbon.h>
+
+extern int NXArgc;
+extern char **NXArgv;
+@interface SDLMain : NSObject
+@end
+
+/* Create a window menu */
+void setupWindowMenu(void)
+{
+    NSMenu		*windowMenu;
+    NSMenuItem	*windowMenuItem;
+    NSMenuItem	*menuItem;
+
+
+    windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
+    
+    /* "Minimize" item */
+    menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
+    [windowMenu addItem:menuItem];
+    [menuItem release];
+    
+    /* Put menu into the menubar */
+    windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
+    [windowMenuItem setSubmenu:windowMenu];
+    [[NSApp mainMenu] addItem:windowMenuItem];
+    
+    /* Tell the application object that this is now the window menu */
+    [NSApp setWindowsMenu:windowMenu];
+
+    /* Finally give up our references to the objects */
+    [windowMenu release];
+    [windowMenuItem release];
+}
+
+/* The main class of the application, the application's delegate */
+@implementation SDLMain
+- (void)quit:(id)sender
+{
+    /* Post a SDL_QUIT event */
+    SDL_Event event;
+    event.type = SDL_QUIT;
+    SDL_PushEvent(&event);
+}
+
+- (void)terminate:(id)sender
+{
+    /* Post a SDL_QUIT event */
+    SDL_Event event;
+    event.type = SDL_QUIT;
+    SDL_PushEvent(&event);
+}
+
+
+NSAutoreleasePool *global_pool;
+SDLMain *sdlMain;
+
+void StartTheDamnApplication (void)
+{
+    NSImage *pygameIcon;
+    global_pool = [[NSAutoreleasePool alloc] init];
+    [NSApplication sharedApplication];
+    [NSApp setMainMenu:[[NSMenu alloc] init]];
+    setupWindowMenu();
+    sdlMain = [[SDLMain alloc] init];
+    [NSApp setDelegate:sdlMain];
+    [NSApp finishLaunching];
+    [NSApp requestUserAttention:NSCriticalRequest];
+    [NSApp updateWindows];
+    pygameIcon = [[NSImage alloc] initWithContentsOfFile: @"/Library/Frameworks/Python.framework/Versions/Current/lib/python2.2/site-packages/pygame/pygame_icon.tiff"];
+    [NSApp setApplicationIconImage:pygameIcon];
+
+}
+
+void WeAreDoneFreeSomeMemory(void)
+{
+    [sdlMain release];
+    [global_pool release];
+}
+
+@end
 #endif
 #endif
 
+#if defined(darwin)
+extern void StartTheDamnApplication(void);
+extern void WeAreDoneFreeSomeMemory(void);
+#endif
 
 
 
 		SDL_InitQuickDraw(&qd);
 #endif
 #endif
+#if defined(darwin)
+                StartTheDamnApplication();
+#endif
 		/*nice to initialize timer, so startup time will be correct before init call*/
 		SDL_Init(SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE);
 		Py_AtExit(atexit_quit);
 	Py_DECREF(privatefuncs);
 	SDL_QuitSubSystem(SDL_INIT_TIMER);
 	SDL_Quit(); /*catch anything left*/
+#if defined(darwin)
+        WeAreDoneFreeSomeMemory();
+#endif
 }
 
 

File src/macosx.c

+#include <Python.h>
+#include <stdio.h>
+#include <string.h>
+#include "setproctitle.h"
+
+static PyMethodDef macosxMethods[]={{NULL,NULL,0,NULL}};
+extern char *Py_GetProgramFullPath(void);
+ 
+/*
+  We do this because dyld does things when modules get linked
+  This gives us a chance to do whateverthehellweneedtodo before
+  AppKit and it's gang gets linked in and starts doing funky shit.
+*/
+
+void initmacosx(void)
+{
+	PyObject *module;
+        char *nullstr = "(null)";
+        /* pornography for the windowserver that doesn't know a damn about paths.. */
+        printf("Py_GetProgramFullPath() = %s\n",Py_GetProgramFullPath());
+        if (strcmp(nullstr,Py_GetProgramFullPath())!=0)
+            setproctitle(Py_GetProgramFullPath());
+        printf("Py_GetProgramFullPath() = %s\n",Py_GetProgramFullPath());
+        module = Py_InitModule("macosx",macosxMethods);
+}

File src/setproctitle.c

+/* 
+   I don't know if it's a good thing to do NXArgc or NXArgv, 
+   but it makes finding the beginning a few steps simpler and
+   resetting their values might be a good thing for WindowServer
+   and the like? 
+
+   bob@redivi.com
+*/
+
+
+#include "setproctitle.h"
+void setproctitle(const char *fmt, ...)
+{
+  int olen,mib[4];
+  struct kinfo_proc kp;
+  size_t bufSize=sizeof(kp);
+  static char newargs[SPT_BUFSIZE];
+  char *p1,*minpos,*endorig;
+  va_list ap;
+
+  /* write out the formatted string, or quit */
+  va_start(ap,fmt);
+  if (fmt) {
+    newargs[sizeof(newargs)-1] = 0;
+    (void)vsnprintf(newargs,sizeof(newargs),fmt,ap);
+  } else {
+    mib[0]=CTL_KERN;
+    mib[1]=KERN_PROC;
+    mib[2]=KERN_PROC_PID;
+    mib[3]=getpid();
+    if (sysctl(mib,4,&kp,&bufSize,NULL,0)) { printf("setproctitle: i dont know my own pid!\n"); return; }
+    strcpy(newargs,kp.kp_proc.p_comm);
+  }  
+  va_end(ap);
+
+  /* find the end of the original string cause we're stackbackwards! */
+  endorig = NXArgv[NXArgc-1]+strlen(NXArgv[NXArgc-1]);
+
+  /* kill the original */
+  bzero(NXArgv[0],(unsigned int)(endorig-NXArgv[0]));
+  for (p1=NXArgv[0]-2;*p1;--p1) *p1=0;
+
+  /* new length (all args) */
+  olen=strlen(newargs);
+
+  /* new NXArgv[0] */
+  minpos = endorig-olen;
+  NXArgv[0] = minpos;
+
+  /* copy the new string to the old place */
+  strcpy(NXArgv[0],newargs);
+
+  /* search for spaces, replace with nulls and increment the argc */
+  NXArgc=1;
+  for (p1=NXArgv[0];*p1;++p1) 
+    if (*p1==' ') { *p1=0; NXArgv[NXArgc++] = p1+1; }
+  NXArgv[NXArgc]=NULL;
+
+  /* why this is here or what for is beyond me.. theres a copy of the executable name before NXArgv[0] */
+  strcpy(NXArgv[0]-strlen(NXArgv[0])-2,NXArgv[0]);
+
+  /* is this even necessary? */
+  p1=endorig;
+  olen=NXArgc;
+  while (++p1<(char *)(USRSTACK-4)) if (!*p1) NXArgv[++olen]=p1+1;  
+/*  while (1) {} */
+}

File src/setproctitle.h

+/* undocumented, may break at any time.. */
+extern char **NXArgv;
+extern int    NXArgc;
+
+/* arbitrary maximum, I got it from the <broken> libutils darwin version */
+#define SPT_BUFSIZE 2048
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/vmparam.h>
+#include <unistd.h>
+void setproctitle(const char *fmt, ...);