Permalink
Browse files

New Mac Launcher

  • Loading branch information...
1 parent ae72b2f commit b5d1817504415d951a7465e0b65bc36f35f41835 @kthakore kthakore committed Jun 26, 2010
Showing with 75 additions and 249 deletions.
  1. +1 −1 MacOSX/Info.plist
  2. +37 −0 MacOSX/Makefile.test
  3. +0 −12 MacOSX/launcher.h
  4. +0 −204 MacOSX/launcher.m
  5. +30 −0 MacOSX/main.c
  6. +7 −32 inc/My/Builder/Darwin.pm
View
2 MacOSX/Info.plist
@@ -44,7 +44,7 @@
<key>NSAppleScriptEnabled</key>
<false/>
<key>NSHumanReadableCopyright</key>
- <string>Copyright © 2000-2006, David J. Goehrig, All Rights Reserved.</string>
+ <string>Copyright © 2009-2010, Kartik Thakore.</string>
<key>NSMainNibFile</key>
<string></string>
</dict>
View
37 MacOSX/Makefile.test
@@ -0,0 +1,37 @@
+#!/bin/make -f
+
+BUILD=build
+APP_PARTS=\
+ $(BUILD)/SDLPerl.app/Contents/Info.plist \
+ $(BUILD)/SDLPerl.app/Contents/MacOS/SDLPerl \
+ $(BUILD)/SDLPerl.app/Contents/Resources/SDLPerl.rsrc \
+ $(BUILD)/SDLPerl.app/Contents/PkgInfo
+
+all: $(BUILD)/SDLPerl.app
+
+clean:
+ rm -rf $(BUILD)
+
+$(BUILD)/SDLPerl.app: $(APP_PARTS)
+
+$(BUILD)/SDLPerl.app/Contents:
+ mkdir -p $@
+
+$(BUILD)/SDLPerl.app/Contents/MacOS:
+ mkdir -p $@
+
+$(BUILD)/SDLPerl.app/Contents/Resources:
+ mkdir -p $@
+
+$(BUILD)/SDLPerl.app/Contents/PkgInfo: $(BUILD)/SDLPerl.app/Contents
+ echo -n "BNDL????" > $@
+
+$(BUILD)/SDLPerl.app/Contents/Info.plist: $(BUILD)/SDLPerl.app/Contents
+ cp Info.plist $@
+
+$(BUILD)/SDLPerl.app/Contents/MacOS/SDLPerl: $(BUILD)/SDLPerl.app/Contents/MacOS
+ gcc -o $@ $(ARCH_FLAGS) main.c
+
+$(BUILD)/SDLPerl.app/Contents/Resources/SDLPerl.rsrc: $(BUILD)/SDLPerl.app/Contents/Resources
+ /Developer/Tools/Rez -d __DARWIN__ -useDF -o $(BUILD)/SDLPerl.rsrc $(ARCH_FLAGS) SDLPerl.r
+ /Developer/Tools/ResMerger -dstIs DF $(BUILD)/SDLPerl.rsrc -o $@
View
12 MacOSX/launcher.h
@@ -1,12 +0,0 @@
-/* launcher.h */
-
-@interface SDLPerlMain : NSObject
-- (void) launchPerl: (NSString*) script;
-- (void) applicationWillFinishLaunching: (NSNotification*) note;
-- (void) applicationDidFinishLaunching: (NSNotification*) note;
-- (void) setupWorkingDirectory: (BOOL) changep;
-@end
-
-@interface SDLPerlApplication : NSApplication
-- (void) terminate: (id) sender;
-@end
View
204 MacOSX/launcher.m
@@ -1,204 +0,0 @@
-// lancher.m
-//
-// Copyright (C) 2006 David J. Goehrig <dgoehrig@cpan.org>
-//
-//
-
-
-// Define _SDL_main_h to avoid using SDLMain.m
-
-#define _SDL_main_h
-#include <Foundation/Foundation.h>
-#include <AppKit/AppKit.h>
-#include <EXTERN.h>
-#include <perl.h>
-#include <SDL/SDL.h>
-#include "launcher.h"
-
-static SDLPerlMain* sdlplmain;
-static PerlInterpreter *my_perl = NULL;
-char path[MAXPATHLEN];
-char libpath[MAXPATHLEN];
-char scriptfile[MAXPATHLEN];
-int argc_perl;
-char** argv_perl;
-char** env_perl;
-
-BOOL init_path;
-
-void xs_init (pTHX);
-EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
-EXTERN_C void
-xs_init(pTHX)
-{
- char *file = __FILE__;
-
- sprintf(libpath,"%s/Contents/Resources/lib/%s",path,ARCHNAME);
- //fprintf(stderr,"LIBPATH: %s\n",libpath);
-
- dXSUB_SYS;
-
- /* DynaLoader is a special case */
- newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
- SV* svpth = newSVpv(libpath,strlen(libpath));
- AV* inc = get_av("INC",0);
- if (inc && svpth) {
- av_unshift(inc,1);
- av_store(inc,0,svpth);
- }
-}
-
-
-@implementation SDLPerlApplication
-- (void) terminate:(id)sender
-{
- //fprintf(stderr,"Quitting Event\n");
- SDL_Event event;
- event.type = SDL_QUIT;
- SDL_PushEvent(&event);
- [NSApp stop: nil];
-}
-@end
-
-@implementation SDLPerlMain
-- (void) setupWorkingDirectory:(BOOL)changep
-{
- CFURLRef bpath;
- //fprintf(stderr,"Setup working directory ? %s", (changep ? "True" : "False"));
- if (! changep) return;
- bpath = CFBundleCopyBundleURL(CFBundleGetMainBundle());
- if (CFURLGetFileSystemRepresentation(bpath,true,(UInt8*)path,MAXPATHLEN)) {
- //fprintf(stderr,"PATH: %s\n",path);
- chdir((char*)path);
- }
-}
-
-- (void) applicationWillFinishLaunching: (NSNotification *) note
-{
- NSMenu* appleMenu;
- NSMenuItem* item;
- NSDictionary* dict;
- NSString* appName;
- NSString* title;
-
- //fprintf(stderr, "Application will finish launching\n");
-
- dict = (NSDictionary*)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
- appName = (dict ? [dict objectForKey: @"CFBundleName"] : [[NSProcessInfo processInfo] processName]);
-
- appleMenu = [[NSMenu alloc] initWithTitle: @""];
-
- title = [@"About " stringByAppendingString: appName ];
- [appleMenu addItemWithTitle: title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
-
- [appleMenu addItem: [NSMenuItem separatorItem]];
-
- title = [@"Hide " stringByAppendingString: appName ];
- [appleMenu addItemWithTitle: title action:@selector(hide:) keyEquivalent:@"h"];
-
- title = @"Hide Others";
- [appleMenu addItemWithTitle: title action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
-
- title = @"Show All";
- [appleMenu addItemWithTitle: title action:@selector(unhideAllApplications:) keyEquivalent:@""];
-
- [appleMenu addItem: [NSMenuItem separatorItem]];
-
- title = @"Quit";
- [appleMenu addItemWithTitle: title action:@selector(terminate:) keyEquivalent:@"q"];
-
- item = [[NSMenuItem alloc] initWithTitle:@"" action: nil keyEquivalent:@""];
- [item setSubmenu: appleMenu];
-
- [[NSApp mainMenu] addItem: item];
-
- [NSApp setMainMenu: appleMenu];
-
- //fprintf(stderr,"Done with menu\n");
-}
-
-- (void) applicationDidFinishLaunching: (NSNotification *) note
-{
- //fprintf(stderr, "Application did finish launching\n");
-
- //fprintf(stderr, "SCRIPT: %s\n",scriptfile);
- NSString* scr = [[NSString alloc] initWithUTF8String: scriptfile];
- //fprintf(stderr, "Setting directory: %s\n",init_path ? "true" : "false");
- [self setupWorkingDirectory: init_path];
- //fprintf(stderr,"Launching perl script %s\n", scriptfile);
- [self launchPerl: scr ];
- [NSApp terminate: self];
-}
-
-- (void) launchPerl: (NSString*) script
-{
-// int count = 3;
-// char* embedding[] = { path, scriptfile, "0"};
- unsigned buflen = [ script lengthOfBytesUsingEncoding: NSUTF8StringEncoding] + 1;
- [script getCString:scriptfile maxLength: buflen encoding:NSUTF8StringEncoding];
- //fprintf(stderr,"Launching script: %s\n",scriptfile);
- PERL_SYS_INIT3(&argc_perl, &argv_perl, &env_perl);
- my_perl = perl_alloc();
- perl_construct(my_perl);
- perl_parse(my_perl,xs_init,argc_perl,argv_perl,(char **)NULL);
- PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
-
- //fprintf(stderr,"Running perl\n");
- perl_run(my_perl);
- //fprintf(stderr,"Destructing perl\n");
- perl_destruct(my_perl);
- //fprintf(stderr,"Freeing perl\n");
- perl_free(my_perl);
- //fprintf(stderr,"Quiting perl script: %s\n",scriptfile);
- PERL_SYS_TERM();
-}
-
-- (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename
-{
- //fprintf(stderr,"openFile %s\n", [filename UTF8String]);
- //fprintf(stderr, "Setting directory: %s\n",init_path ? "true" : "false");
- [self setupWorkingDirectory: init_path];
- //fprintf(stderr,"launching perl\n");
- [self launchPerl: filename];
-}
-
-@end
-
-int
-main( int argc, char** argv, char** env)
-{
- NSAutoreleasePool* pool;
-
- argc_perl = argc;
- argv_perl = argv;
- env_perl = env;
-
- init_path = YES;
- memset(scriptfile,0,MAXPATHLEN);
- if( argc >= 2 ) {
- if ( argc == 2 ) {
- strncpy(scriptfile,argv[1],strlen(argv[1]));
- } else {
- strncpy(scriptfile,argv[1],strlen(argv[2]));
- }
- }
- //fprintf(stderr, "[main] SCRIPT: %s\n",scriptfile);
-
-
- pool = [[NSAutoreleasePool alloc] init];
-
- [SDLPerlApplication sharedApplication];
- [NSApp setMainMenu: [[NSMenu alloc] init]];
-
- sdlplmain = [[SDLPerlMain alloc] init];
- [sdlplmain retain];
- [NSApp setDelegate: sdlplmain];
-
- [NSApp run];
-
- //fprintf(stderr,"Terminating NSApp\n");
- [sdlplmain release];
- [pool release];
-
- return 0;
-}
View
30 MacOSX/main.c
@@ -0,0 +1,30 @@
+#include <EXTERN.h> /* from the Perl distribution */
+#include <perl.h> /* from the Perl distribution */
+
+static PerlInterpreter *my_perl; /* ** The Perl interpreter ***/
+static void xs_init (pTHX);
+
+EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
+
+EXTERN_C void
+xs_init(pTHX)
+{
+ char *file = __FILE__;
+ /* DynaLoader is a special case */
+ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
+}
+
+
+
+int main(int argc, char **argv, char **env)
+{
+ PERL_SYS_INIT3(&argc,&argv,&env);
+ my_perl = perl_alloc();
+ perl_construct(my_perl);
+ PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
+ perl_parse(my_perl, xs_init, argc, argv, (char **)NULL);
+ perl_run(my_perl);
+ perl_destruct(my_perl);
+ perl_free(my_perl);
+ PERL_SYS_TERM();
+}
View
39 inc/My/Builder/Darwin.pm
@@ -1,33 +1,4 @@
#!/usr/bin/env perl
-#
-# Darwin.pm
-#
-# Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
-#
-# ------------------------------------------------------------------------------
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-# ------------------------------------------------------------------------------
-#
-# Please feel free to send questions, suggestions or improvements to:
-#
-# David J. Goehrig
-# dgoehrig@cpan.org
-#
-
package My::Builder::Darwin;
use strict;
@@ -39,7 +10,7 @@ use base 'My::Builder';
sub special_build_settings
{
my $self = shift;
- $self->{c_source} = ['launcher.m'];
+ $self->{c_source} = ['src','main.c'];
$self->{c_sources} = 'MacOSX';
$self->{install_base} = "SDLPerl.app/Contents/Resources";
}
@@ -58,9 +29,13 @@ sub build_bundle
$libs .= ' ' . `$^X -MExtUtils::Embed -e ldopts`;
chomp($libs);
$libs =~ s/-lSDLmain//g;
- print STDERR "gcc $cflags MacOSX/launcher.m $libs -framework Cocoa -o \"$bundle_contents/MacOS/SDLPerl\"";
- print STDERR `gcc $cflags MacOSX/launcher.m $libs -framework Cocoa -o \"$bundle_contents/MacOS/SDLPerl\"`;
+ my $cmd = "gcc $cflags $libs MacOSX/main.c -o \"$bundle_contents/MacOS/SDLPerl\"";
+ print STDERR $cmd;
+ system ($cmd);
+# my $rez = "/Developer/Tools/Rez -d __DARWIN__ -useDF -o $bundle_content/Resources/SDLPerl.rsrc $(ARCH_FLAGS) SDLPerl.r
+# /Developer/Tools/ResMerger -dstIs DF $bundle_content/Resources/SDLPerl.rsrc -o $@"
mkdir "$bundle_contents/Resources",0755;
+ print
system "echo \"APPL????\" > \"$bundle_contents/PkgInfo\"";
system "cp MacOSX/Info.plist \"$bundle_contents/\"";
system "cp \"MacOSX/SDLPerl.icns\" \"$bundle_contents/Resources\"";

0 comments on commit b5d1817

Please sign in to comment.