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