Contents Previous Next Index

Chapter   12

Building Your Port


The MIDP build environment is a set of makefiles, the Java™ platform tools, and the free tools from the CygWin project such as gcc and make. For more information on CygWin tools, see:

http://sources.redhat.com/cygwin

The tools and makefiles work together to create a specific target. A target is a name in a makefile that is associated with a file or set of related files on which a set of commands will be run. The commands will typically act on the target’s files to create, update, or delete them.

The build environment provides configuration options to enable you to customize the target. For example, configuration options control whether to include debugging symbols. These configuration options are macros in the makefiles.

Gnumake accepts targets and configuration options on the command line using the general syntax:

make [target ...] [config_option=value ...] 

The make command has more options, however. See your make documentation for more information. Instead of being a make tutorial, this section shows you how to use the tool in the context of the MIDP build environment.

This chapter contains advice to help you build different versions of the midp executable command. It contains the sections:

12.1 The Build Process

This section covers the makefiles that the make command uses, how to run a build, and how the full build works. It contains the sections:

12.1.1 Makefiles

The Release Contents contains a list of all files in the build. The table in this section shows only the makefiles, along with a brief description of their purposes, in roughly the order that they are used in the build. In the table, midpInstallDir is the directory that holds your MIDP installation. In addition, when a file is in a shared directory, the table shows the directory with Windows-style separators (\).

TABLE 7  –  Makefiles  
Makefile
Directory or directories
Description
GNUmakefile 
This file is in multiple, device-specific directories:
  • midpInstallDir\build\win32\kvm\
  • midpInstallDir/build/linux/kvm/
  • midpInstallDir/build/solaris/
Top-level makefile; the build starts here
Platform.gmk 
This file is in multiple, device-specific directories:
  • midpInstallDir\build\win32\kvm
  • midpInstallDir/build/linux/kvm
  • midpInstallDir/build/solaris
Definitions of the target platform and CPU
Defs.gmk 
midpInstallDir\build\share\makefiles\ 
Global definitions (such as common Java programming language and native source files); no targets
Defs.gmk 
midpInstallDir\build\share\makefiles\kvm\ 
Global virtual machine (VM) specific definitions (such as Java programming language and native VM source files); no targets
Defs-pre.gmk 
This file is in multiple, device-specific directories:
  • midpInstallDir\build\win32\kvm\makefiles\
  • midpInstallDir/build/linux/kvm/makefiles/
  • midpInstallDir/build/solaris/makefiles/
Platform-specific definitions (such as the suffix for executable files); no targets
Defs-post.gmk 
This file is in multiple, device-specific directories:
  • midpInstallDir\build\win32\kvm\makefiles\
  • midpInstallDir/build/linux/kvm/makefiles/
  • midpInstallDir/build/solaris/makefiles/
Platform-specific definitions (such as include files); no targets
MIDP.gmk 
midpInstallDir\build\share\makefiles\ 
MIDP directives and build targets
CancelImplicits.gmk 
midpInstallDir\build\share\makefiles\ 
Directives that cancel the GNUmake implicit rules that MIDP doesn’t use; this is for faster builds
Tools.gmk 
midpInstallDir\build\share\makefiles\ 
Definitions and targets for building MIDP tools, such as MEKeyTool
VM.gmk 
midpInstallDir\build\share\makefiles\kvm\ 
Definitions and targets for building the VM and its tools (such as the preverifier)
Example.gmk 
midpInstallDir\build\share\makefiles\ 
Definitions and targets for building the samples
Docs.gmk 
Files with this name are in multiple directories:
  • midpInstallDir\build\share\makefiles\
  • midpInstallDir\build\share\makefiles\kvm\
Definitions, directives, and targets for using the Javadoc™ tool to build the reference documentation
Release.gmk 
midpInstallDir\build\share\makefiles\ 
Definitions and targets for building release bundles
Testbeans.gmk 
midpInstallDir\build\share\makefiles\ 
Definitions and rules for compiling and installing TestBeans unit test programs into an existing MIDP TestBeans runtime workspace

For more information on the targets in these makefiles, see Appendix A, "Build Targets.” For more information on the definitions, see Appendix B, "Configuration Options.”

12.1.2 Build Instructions

To build the MIDP executable or documentation bundle:

  1. Change directories to the location of the platform-dependent makefiles.
  2. On a Microsoft Windows platform this is the directory midpInstallDir\build\win32\kvm. For example:

    c:\> cd midp2.0fcs\build\win32\kvm 
    

    On a UNIX® platform, the directory is midpInstallDir/build/linux/kvm or midpInstallDir/build/solaris.

  3. Choose one or more targets and configuration options.
  4. You can choose to use the default target and configuration options, or choose other targets and options.

    The default build target, all, creates a MIDP executable and builds the examples. The default configuration options direct the build environment to create an executable that supports the full CLDC reference implementation, supports internationalization, and does not include debugging symbols.

    See Appendix A, "Build Targets” for a list of targets and common build options.

  5. Run the make tool with any targets and configuration options.
  6. Providing no arguments uses the default build target and configuration-options.

    For example, to clean up from any previous builds, then build a MIDP executable you would run the command:

    c:\midp2.0fcs\build\win32\kvm> make clean all 
    

 

If the target that you use creates a MIDP executable, it will be placed in the following directory:

12.1.3 Example Commands

The following list describes common functionality requirements and the combinations of targets and configuration-options that provide them.

12.1.4 Build Steps for the Target all

When you build the MIDP Reference Implementation with the target all, GNUmake performs the following steps:

  1. Builds the preverifier
  2. Creates the ROMizer
  3. Compiles and preverifies Java code
  4. Creates the classes.zip file
  5. Reads classes.zip and generates ROMjavaplatform.c
  6. Builds the extractOffsets tool
  7. Uses the extractOffsets tool to generate header files with offsets into the classes of the Java programming language
  8. Compiles CLDC and MIDP C files
  9. Links the CLDC and MIDP C file
  10. Creates the MEKeyTool and JadTool utilities
  11. Creates the MidpInstallDir/build/appdb directory
  12. Compiles, preverifies, and packages the examples (except the HelloMIDlet, which is left for the reader of Creating MIDlet Suites to do).

12.2 Adding Files to the Build

The MIDP build environment allows you to add new class files and object files to the build that are not part of the source distribution. To add the files, you must update the contents of the Defs-pre.gmk file. (See TABLE 7 for more information on this file.)

This section shows you how to update the file in the topics:

12.2.1 Adding Java Programming Language Files

You can add two types of classes written in the Java programming language to the build: platform-specific and platform-generic.

If you add platform-specific classes, they must be in PLATFORM_CLASS_DIR, which has the default value midpInstallDir/src/platform/classes. There is no required location for platform-generic classes.

The two types of classes are held in different variables in the Defs-pre.gmk file:

To add a file to one of these variables, add a line that has the following syntax to the Defs-pre.gmk file:

VARIABLE_NAME += fileName 

For example, to add the platform-specific class com.MyCompany.productY.Foo, you would update the PLATFORM_INCLUDE_CLASSES variable like this:

PLATFORM_INCLUDE_CLASSES += classes/com/MyCompany/productY/foo.java  

Similarly, to add the platform-generic class com.MyCompany.midp.bar, you would update the MIDP_INCLUDE_CLASSES variable like this:

MIDP_INCLUDE_CLASSES += classes/com/MyCompany/midp/bar.java 

The classes will be included in the build the next time you use the default target, all.

12.2.2 Adding C Files

You can add two types of C language files to the build: platform-specific and platform-generic. Different variables in Defs-pre.gmk hold these two kinds of files:

To add a file to one of these variables, add a line that has the following syntax to the Defs-pre.gmk file:

VARIABLE_NAME += fileName 

For example, to add the platform-specific file, productY_natives.c, you would update the PLATFORM_INCLUDE_SRC variable like this:

PLATFORM_INCLUDE_SRC += productY_natives.c 

Similarly, to add the platform-generic file, common_natives.c, you would update the MIDP_INCLUDE_SRC variable like this:

MIDP_INCLUDE_SRC += common_natives.c 

This is the normal way to add native method implementations to MIDP. The files will be included in the build the next time you use the default target, all.

12.3 Removing Unused Code

Removing unused code can improve the footprint of your port. This section covers two areas where you might find code to remove: configuration code and code made obsolete by your customization.

The MIDP Reference Implementation uses a configuration mechanism to select among alternate behaviors at runtime. In commercial ports of the RI, many of these design choices will have been made. (For example, whether the device has a color or grey scale screen.) You can eliminate the branches created by the configuration options that your device does not use. To locate these branches, look for calls to the Configuration.getProperty method. The list of classes that include optional behavior based on calls to access configuration parameters is:

In addition, if you have customized the MIDP Reference Implementation (for example, by re-implementing one or more components in native code), there could be Java programming language or C code that is no longer used. Some examples have already appeared in the text, such as in Section 6.3 "Using Native Widgets for MIDP Screens" . You can use the examples in this guide as a starting point for a more thorough search.

 


Contents Previous Next Index Porting MIDP
MIDP Reference Implementation, Version 2.0 FCS