C H A P T E R  3

Quick Start: Building on Linux for Linux

This chapter describes a self-hosted Linux build, which means that you build and run the Java Wireless Client software on the same Linux machine. The goal of this chapter is to get you from zero to a functional MIDP software stack as fast as possible. Later chapters describe all the options for each part of the build.

Linux builds come in two flavors:

This chapter describes how to perform the linux_fb_gcc build.

This chapter is based on example scripts that help you run the different parts of the build. The scripts are available in docs/build-scripts/linux-x86. Once you have everything set up, run the scripts to perform the build. Work along as you read through the chapter to understand how it all fits together.

 


Setting Up Your Environment

Most of the time, Linux already has most of the tools you need. These examples show how to find out if you have these tools available. If you do not, you will need to install the appropriate tools and adjust your PATH to include them.

   $ make --version
   GNU Make 3.80
   Copyright (C) 2002  Free Software Foundation, Inc.
   This is free software; see the source for copying conditions.
   There is NO warranty; not even for MERCHANTABILITY or FITNESS
   FOR A PARTICULAR PURPOSE.
   $

On your computer, GNU Make might be gmake instead of make.

   $ gcc --version
   3.3.4
   $
   $ java -version
   java version "1.4.2_08"
   Java(TM) 2 Runtime Environment, Standard Edition
      (build 1.4.2_08-b03)
   Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)
   $ javac
   Usage: javac <options> <source files>
   where possible options include:
   ...
   $

Each of the build scripts in the rest of this chapter operate by setting up, doing some work, and cleaning up.

The setting up script is setup.sh and the cleaning up script is teardown.sh.

setup.sh looks like this:


export Acme=/home/jonathan/jwc
export JDK_DIR=/usr/java/j2sdk1.4.2_08
export Scripts=`pwd`
export Output=$Acme/output
export Log=$Acme/log.txt
rm -f $Log

This script is available as docs/build-scripts/linux-x86/setup.sh.

The Acme variable is the top level of the Java Wireless Client software. Adjust the value to point to the top level of your own installation. Also, make sure JDK_DIR points to the top directory of your JDK.

Don't run setup.sh yet. It is used by the build scripts in the rest of this chapter.

teardown.sh looks like this:


cat $Log
cd $Scripts

You do not need to modify this script.


Building PCSL

The first step is to build PCSL. Tell PCSL the target platform and where to put output files. Set PCSL_PLATFORM to linux_i386_gcc. Tell PCSL where to put its output files with the PCSL_OUTPUT_DIR variable.

In addition, tell PCSL what kind of networking implementation to use. Do this by setting NETWORK_MODULE to bsd/generic.

Here is a script, build-pcsl.sh, that performs the build:


. setup.sh
 
cd $Acme/pcsl
make \
  PCSL_PLATFORM=linux_i386_gcc \
  PCSL_OUTPUT_DIR=$Output/pcsl \
  NETWORK_MODULE=bsd/generic \
  $1
 
if [ $? -ne 0 ]; then
  echo "build-pcsl=failed" >> $Log
else
  echo "build-pcsl=OK" >> $Log
fi
 
. $Scripts/teardown.sh

This script uses the setup.sh and teardown.sh script from before.

Run build-pcsl.sh as follows:


build-scripts/linux-x86> sh build-pcsl.sh
.
.
.
building memory port module...
make[4]: Entering directory `/home/jonathan/jwc/pcsl/memory/memory_port'
make[4]: Leaving directory `/home/jonathan/jwc/pcsl/memory/memory_port'
building memory module...
make[4]: Entering directory `/home/jonathan/jwc/pcsl/memory/malloc'
make[4]: Leaving directory `/home/jonathan/jwc/pcsl/memory/malloc'
make[3]: Leaving directory `/home/jonathan/jwc/pcsl/memory'
make[2]: Leaving directory `/home/jonathan/jwc/pcsl/string/utf16'
make[1]: Leaving directory `/home/jonathan/jwc/pcsl/string'
build-pcsl=OK
build-scripts/linux-x86>

A series of build messages will be displayed, with a message at the end about the success of the PCSL build.

The output goes in $Acme/output/pcsl. Take a look:


/home/jonathan> ls jwc/output/pcsl
linux_i386
/home/jonathan> ls jwc/output/pcsl/linux_i386
inc  lib  obj
/home/jonathan>


Building CLDC

CLDC is built on top of PCSL. Tell CLDC to use PCSL by setting ENABLE_PCSL to true, and specify where to find PCSL with PCSL_OUTPUT_DIR.

In addition, the CLDC build system expects you to define various environment variables, as follows:

The following script, build-cldc.sh, runs the CLDC build.


. setup.sh
 
cd $Acme/cldc/build/linux_i386
make \
  JDK_DIR=$JDK_DIR \
  ENABLE_PCSL=true \
  PCSL_OUTPUT_DIR=$Output/pcsl \
  JVMWorkSpace=$Acme/cldc \
  JVMBuildSpace=$Output/cldc \
  $1
 
if [ $? -ne 0 ]; then
  echo "cldc_status=failed" >> $Log
else
  echo "cldc_status=OK" >> $Log
fi
 
. $Scripts/teardown.sh

Go ahead and give it a try with sh build-cldc.sh. Wait for a success message at the end of the build, and take a look at the generated files in output/cldc.


Building Java Wireless Client Software

The last step in creating a Java Wireless Client software stack is building MIDP and optional APIs. This chapter describes how to build MIDP only. Later chapters describe how to include optional APIs in this part of the build and the many variables you can use to change how Java Wireless Client software is built.

For now, build MIDP using the CLDC and PCSL output you already generated.

You need JDK_DIR defined, just as it was for the CLDC build. In addition, you must tell the MIDP build where to find PCSL and CLDC:

The first thing that happens with the MIDP build is that tools are created for use later in the build. Use TOOLS_DIR to point to the tools directory.

Finally, set MIDP_OUTPUT_DIR to the location that contains the output of the build when it is complete.

Run the build from the midp/build/linux_fb_gcc directory. Here is a script, build-sjwc.sh, that sets the necessary variables and runs the MIDP build:


. setup.sh
 
cd $Acme/midp/build/linux_fb_gcc
make \
  JDK_DIR=$JDK_DIR \
  PCSL_OUTPUT_DIR=$Output/pcsl \
  CLDC_DIST_DIR=$Output/cldc/linux_i386/dist \
  TOOLS_DIR=$Acme/tools
  MIDP_OUTPUT_DIR=$Output/midp \
  $1
 
if [ $? -ne 0 ]; then
  echo "sjwc_status=failed" >> $Log
else
  echo "sjwc_status=OK" >> $Log
fi
 
. $Scripts/teardown.sh

Run sh build-sjwc.sh without modifying the script. Wait until you see the message sjwc_status=OK at the end of the build. Congratulations! You've just built a complete MIDP stack.


Running Java Wireless Client Software

Now what do you do with it?

The fb build of the Java Wireless Client software uses a framebuffer for display and user input. Use the Qt tool qvfb to see the simulated screen of the device and provide keyboard input. qvfb supports up to ten independent displays, numbered from :0 through :9.

Pick an available display and set QWS_DISPLAY to its number. Next, run qvfb with a bit depth of 16. Adjust the size of the framebuffer to match the expectations of the Java Wireless Client software.


export QTDIR=/opt/Qtopia
export QWS_DISPLAY=:4
$QTDIR/bin/qvfb -depth 16 -width 176 -height 210 &

Run docs/build-scripts/linux-x86/run-qvfb.sh if you wish. The qvfb window appears, but it is empty.

Now run the Java Wireless Client software. Set QTDIR and QWS_DISPLAY the same as before. Then run the usertest command.


export QTDIR=/opt/Qtopia
export QWS_DISPLAY=:4
output/midp/bin/i386/usertest

See docs/build-scripts/linux-x86/run-usertest.sh for an example.

The Java Wireless Client software runs in the qvfb window. Use your keyboard for input, if necessary. You might have to click in the qvfb window before using the keyboard. Use F1 and F2 for the soft buttons.

FIGURE 3-1 MIDlet Running in the qvfb Window.


You can install and test MIDlets on this simulated device. See the Tools Guide for complete details.