author Sam Lantinga
Sat, 21 Jun 2014 11:16:26 -0700
changeset 8882 4fc9e98413c3
parent 8289 d2acd700f8f7
permissions -rw-r--r--
Removed references to Raspberry Pi
     1 ==============================================================================
     2 Using the Simple DirectMedia Layer with Mac OS X
     3 ==============================================================================
     5 These instructions are for people using Apple's Mac OS X (pronounced
     6 "ten").
     8 From the developer's point of view, OS X is a sort of hybrid Mac and
     9 Unix system, and you have the option of using either traditional
    10 command line tools or Apple's IDE Xcode.
    12 To build SDL using the command line, use the standard configure and make
    13 process:
    15 	./configure
    16 	make
    17 	sudo make install
    19 You can also build SDL as a Universal library (a single binary for both
    20 32-bit and 64-bit Intel architectures), on Mac OS X 10.7 and newer, by using
    21 the script in build-scripts:
    22 	sh build-scripts/
    23 	sudo build-scripts/ install
    24 This script builds SDL with 10.5 ABI compatibility on i386 and 10.6
    25 ABI compatibility on x86_64 architectures.  For best compatibility you
    26 should compile your application the same way.  A script which wraps
    27 gcc to make this easy is provided in test/
    29 Please note that building SDL requires at least Xcode 4.6 and the 10.7 SDK
    30 (even if you target back to 10.5 systems). PowerPC support for Mac OS X has
    31 been officially dropped as of SDL 2.0.2.
    33 To use the library once it's built, you essential have two possibilities:
    34 use the traditional autoconf/automake/make method, or use Xcode.
    36 ==============================================================================
    37 Caveats for using SDL with Mac OS X
    38 ==============================================================================
    40 Some things you have to be aware of when using SDL on Mac OS X:
    42 - If you register your own NSApplicationDelegate (using [NSApp setDelegate:]),
    43   SDL will not register its own. This means that SDL will not terminate using
    44   SDL_Quit if it receives a termination request, it will terminate like a 
    45   normal app, and it will not send a SDL_DROPFILE when you request to open a
    46   file with the app. To solve these issues, put the following code in your 
    47   NSApplicationDelegate implementation:
    49   - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
    50   {
    51       if (SDL_GetEventState(SDL_QUIT) == SDL_ENABLE) {
    52           SDL_Event event;
    53           event.type = SDL_QUIT;
    54           SDL_PushEvent(&event);
    55       }
    57       return NSTerminateCancel;
    58   }
    60   - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
    61   {
    62       if (SDL_GetEventState(SDL_DROPFILE) == SDL_ENABLE) {
    63           SDL_Event event;
    64           event.type = SDL_DROPFILE;
    65           event.drop.file = SDL_strdup([filename UTF8String]);
    66           return (SDL_PushEvent(&event) > 0);
    67       }
    69       return NO;
    70   }
    72 ==============================================================================
    73 Using the Simple DirectMedia Layer with a traditional Makefile
    74 ==============================================================================
    76 An existing autoconf/automake build system for your SDL app has good chances
    77 to work almost unchanged on OS X. However, to produce a "real" Mac OS X binary
    78 that you can distribute to users, you need to put the generated binary into a
    79 so called "bundle", which basically is a fancy folder with a name like
    80 "".
    82 To get this build automatically, add something like the following rule to
    83 your
    85 bundle_contents =
    86 APP_NAME_bundle: EXE_NAME
    87 	mkdir -p $(bundle_contents)/MacOS
    88 	mkdir -p $(bundle_contents)/Resources
    89 	echo "APPL????" > $(bundle_contents)/PkgInfo
    90 	$(INSTALL_PROGRAM) $< $(bundle_contents)/MacOS/
    92 You should replace EXE_NAME with the name of the executable. APP_NAME is what
    93 will be visible to the user in the Finder. Usually it will be the same
    94 as EXE_NAME but capitalized. E.g. if EXE_NAME is "testgame" then APP_NAME 
    95 usually is "TestGame". You might also want to use @PACKAGE@ to use the package
    96 name as specified in your file.
    98 If your project builds more than one application, you will have to do a bit
    99 more. For each of your target applications, you need a separate rule.
   101 If you want the created bundles to be installed, you may want to add this
   102 rule to your
   104 install-exec-hook: APP_NAME_bundle
   105 	rm -rf $(DESTDIR)$(prefix)/Applications/
   106 	mkdir -p $(DESTDIR)$(prefix)/Applications/
   107 	cp -r $< /$(DESTDIR)$(prefix)Applications/
   109 This rule takes the Bundle created by the rule from step 3 and installs them
   110 into $(DESTDIR)$(prefix)/Applications/.
   112 Again, if you want to install multiple applications, you will have to augment
   113 the make rule accordingly.
   116 But beware! That is only part of the story! With the above, you end up with
   117 a bare bone .app bundle, which is double clickable from the Finder. But
   118 there are some more things you should do before shipping your product...
   120 1) The bundle right now probably is dynamically linked against SDL. That 
   121    means that when you copy it to another computer, *it will not run*,
   122    unless you also install SDL on that other computer. A good solution
   123    for this dilemma is to static link against SDL. On OS X, you can
   124    achieve that by linking against the libraries listed by
   125      sdl-config --static-libs
   126    instead of those listed by
   127      sdl-config --libs
   128    Depending on how exactly SDL is integrated into your build systems, the
   129    way to achieve that varies, so I won't describe it here in detail
   130 2) Add an 'Info.plist' to your application. That is a special XML file which
   131    contains some meta-information about your application (like some copyright
   132    information, the version of your app, the name of an optional icon file,
   133    and other things). Part of that information is displayed by the Finder
   134    when you click on the .app, or if you look at the "Get Info" window.
   135    More information about Info.plist files can be found on Apple's homepage.
   138 As a final remark, let me add that I use some of the techniques (and some
   139 variations of them) in Exult and ScummVM; both are available in source on
   140 the net, so feel free to take a peek at them for inspiration!
   143 ==============================================================================
   144 Using the Simple DirectMedia Layer with Xcode
   145 ==============================================================================
   147 These instructions are for using Apple's Xcode IDE to build SDL applications.
   149 - First steps
   151 The first thing to do is to unpack the Xcode.tar.gz archive in the
   152 top level SDL directory (where the Xcode.tar.gz archive resides).
   153 Because Stuffit Expander will unpack the archive into a subdirectory,
   154 you should unpack the archive manually from the command line:
   155 	cd [path_to_SDL_source]
   156 	tar zxf Xcode.tar.gz
   157 This will create a new folder called Xcode, which you can browse
   158 normally from the Finder.
   160 - Building the Framework
   162 The SDL Library is packaged as a framework bundle, an organized
   163 relocatable folder hierarchy of executable code, interface headers,
   164 and additional resources. For practical purposes, you can think of a 
   165 framework as a more user and system-friendly shared library, whose library
   166 file behaves more or less like a standard UNIX shared library.
   168 To build the framework, simply open the framework project and build it. 
   169 By default, the framework bundle "SDL.framework" is installed in 
   170 /Library/Frameworks. Therefore, the testers and project stationary expect
   171 it to be located there. However, it will function the same in any of the
   172 following locations:
   174     ~/Library/Frameworks
   175     /Local/Library/Frameworks
   176     /System/Library/Frameworks
   178 - Build Options
   179     There are two "Build Styles" (See the "Targets" tab) for SDL.
   180     "Deployment" should be used if you aren't tweaking the SDL library.
   181     "Development" should be used to debug SDL apps or the library itself.
   183 - Building the Testers
   184     Open the SDLTest project and build away!
   186 - Using the Project Stationary
   187     Copy the stationary to the indicated folders to access it from
   188     the "New Project" and "Add target" menus. What could be easier?
   190 - Setting up a new project by hand
   191     Some of you won't want to use the Stationary so I'll give some tips:
   192     * Create a new "Cocoa Application"
   193     * Add src/main/macosx/SDLMain.m , .h and .nib to your project
   194     * Remove "main.c" from your project
   195     * Remove "MainMenu.nib" from your project
   196     * Add "$(HOME)/Library/Frameworks/SDL.framework/Headers" to include path
   197     * Add "$(HOME)/Library/Frameworks" to the frameworks search path
   198     * Add "-framework SDL -framework Foundation -framework AppKit" to "OTHER_LDFLAGS"
   199     * Set the "Main Nib File" under "Application Settings" to "SDLMain.nib"
   200     * Add your files
   201     * Clean and build
   203 - Building from command line
   204     Use pbxbuild in the same directory as your .pbproj file
   206 - Running your app
   207     You can send command line args to your app by either invoking it from
   208     the command line (in *.app/Contents/MacOS) or by entering them in the
   209     "Executables" panel of the target settings.
   211 - Implementation Notes
   212     Some things that may be of interest about how it all works...
   213     * Working directory
   214         As defined in the SDL_main.m file, the working directory of your SDL app
   215         is by default set to its parent. You may wish to change this to better
   216         suit your needs.
   217     * You have a Cocoa App!
   218         Your SDL app is essentially a Cocoa application. When your app
   219         starts up and the libraries finish loading, a Cocoa procedure is called,
   220         which sets up the working directory and calls your main() method.
   221         You are free to modify your Cocoa app with generally no consequence 
   222         to SDL. You cannot, however, easily change the SDL window itself.
   223         Functionality may be added in the future to help this.
   226 Known bugs are listed in the file "BUGS"