Writing portable code
GNUstep opens up some fairly interesting opportunities to target a number of platforms with the same source code, for example porting MacOS X Cocoa applications to Linux, the BSDs, other Unices and (ultimately) Windows without significant re-engineering effort or degraded end-user functionality.
Some portability gotchas are listed below (please update when you run into a new one!):
MacOS X to GNUstep
OS-X developers should try and avoid CoreFoundation as this will complicate your dependency situation on non-Mac hosts, even if that part of CoreFoundation has actually been ported.
GNUstep Base and the FoundationKit offer many parts of the CoreFoundation functionality in a natural Objective-C manner.
Use following to distinguish between Cocoa and GNUstep
#ifdef GNUSTEP /* GNUstep code goes here ... */ #else /* OS-X Cocoa native code goes here ... */ #endif
FIXME: add following:
- how to port interface (.nib) files
- how to convert xCode project to GNUstep project (makefile or ProjectCenter)
Notes
Do not rely on tools available in development environment
All the world is not Linux or FreeBSD or Windows. System constants may be different on different platforms. Paths to command-line tools, the parameters they accept and locations of temporary directories may be different to what you are used to on your platform.
- GNUstep Base and the FoundationKit offer some of this functionality "for free".
- Try not to hard code paths and so on into your code, use macros (not recommended), or even better an abstraction mechanism.
- Avoid hard-coding system constants, or platform-specific ones where Posix or commonly-accepted ones exist (and we're not talking about glibc here :-)