README-macosx.txt 9.6 KB

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