Blackberry compilator preprocessor. Prepare builds for multiple OS versions from single sources

For blackberry there is always a need to prepare builds for different BlackBerry OS versions.
Here is the instructions how to do this without having different branches of sources for each OS verion:

  • Use a //#preprocess tag at the begin of the file, this will tell a compilator to use a preprocessor
  • Use //#ifdef SOMETHING //#else //#endif, or //#ifndef SOMETHING //#else //#endif – to include or not include some lines of code (for instance imports of some packages) in a particular JDE, or project for particular OS
  • Create different projects for different OS with defined compilator options.
  • In JDE 4.7 and upper you can add definitions directly in JDE in project properties, Compiler tab. In version above 4.7, do this manually inside .jdp file: Edit the .jdp file manuall:Find the Options line, Add ‘–define ;;…;, e.g.: Options=-quiet -define= VER_4_2_0_AND_ABOVE;PREPROCESSOR .Note: The –define statement is an argument passed to rapc

Sample of usage:

//#ifdef API47
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.TouchGesture;

//#ifdef API47
//Override touchEvent to provide image scrolling for touch screen devices.
protected boolean touchEvent(TouchEvent touchEvent)

Refer to this link for documents of preprocessor commands: