🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
9.7 KiB

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