Difference between revisions of "Writing portable code"

From GNUstepWiki
Jump to navigation Jump to search
(structured)
m (formatting)
Line 4: Line 4:
  
 
== Porting Applications ==
 
== Porting Applications ==
 +
  
 
=== Porting from GNUstep to Cocoa ===
 
=== Porting from GNUstep to Cocoa ===
  
 
tbd.
 
tbd.
 +
 +
  
 
=== Porting from Cocoa to GNUstep ===
 
=== Porting from Cocoa to GNUstep ===
Line 20: Line 23:
  
 
GNUstep Base and the FoundationKit offer many parts of the CoreFoundation functionality in a natural Objective-C manner.
 
GNUstep Base and the FoundationKit offer many parts of the CoreFoundation functionality in a natural Objective-C manner.
 
 
  
 
==== The porting itself ====
 
==== The porting itself ====
Line 47: Line 48:
  
 
* don't use WebKit (currently)
 
* don't use WebKit (currently)
 +
 +
  
 
== Stumbling Blocks ==
 
== Stumbling Blocks ==
Line 72: Line 75:
 
* how to port interface (.nib) files using [http://freshmeat.net/projects/nib2gmodel/ nib2gmodel]
 
* how to port interface (.nib) files using [http://freshmeat.net/projects/nib2gmodel/ nib2gmodel]
 
* how to convert xCode project to GNUstep project (creating a GNUstep [http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/index.html Makefile] or [[ProjectCenter]])
 
* how to convert xCode project to GNUstep project (creating a GNUstep [http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/index.html Makefile] or [[ProjectCenter]])
 +
 +
  
 
== Notes ==
 
== Notes ==

Revision as of 23:41, 3 March 2005

GNUstep opens up some fairly interesting opportunities to target a number of platforms with the same source code, for example porting Mac OS 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!):

Porting Applications

Porting from GNUstep to Cocoa

tbd.


Porting from Cocoa to GNUstep

Porting from Cocoa to GNUstep has different aspects.

First there is the compatibility of the basic Foundation Kit and Application Kit. We support a lot of classes, but not all of them and the same is true for specific methods, Specifically newly introduced classes and methods may still be missing as GNUstep started out aiming at OpenStep compatibility.

Second you have all the additional frameworks and libraries programmers on Mac OS X take for granted, for some of them free replacements exists, for most they are still missing.

Mac 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.

The porting itself

short overview:

  • write a makefile
  • convert your NIB files to gmodel
  • provide an Info.plist.

detailed instructions:

  1. you need to write a new GNUstep make file for the project (very easy, still there is currently no automatic way to do so)
  2. you need to convert the NIB files to GNUstep format. At some point in time GORM will be able to read NIB files, but currently you need to use the gmodel intermediate format for this and for this the above mentioned tools are used.

Don'ts

Don't use anything we do not provide:

  • don't use CoreFoundation
  • don't use KeyChain
  • don't use Carbon
  • don't use Quartz
  • don't use QuickTime

gcc mainline currently doesn't support ObjC++ although it is already in the works somewhat (expected for gcc 4.1). that means:

  • don't use WebKit (currently)


Stumbling Blocks

  • Apple's Cocoa.h

it is there to enable pre-compiled headers and speed up compile time thusly. Anyway, it contains just two lines:

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

So you can easily work around this by providing your own or replace your include of <Cocoa/Cocoa.h> with just the above, which will also work on OS-X.

  • When you need to distinguish between Cocoa and GNUstep, you may use the following
#ifdef GNUSTEP
    /* GNUstep code goes here ... */
#else
    /* OS-X Cocoa native code goes here ... */
#endif


FIXME: add following:


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 :-)