README-macosx.txt 9.8 KB

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