README-macosx.txt 8.3 KB

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