J2ME with Kaffe on OpenBSD

This document is about doing opensource j2me development on OpenBSD.

Currently this is limited to architectures that kaffe has been ported to.

  1. Install Kaffe from ports. (this takes about 2-3 hours on my Mac Mini)
  2. Install Apache Ant from ports.
  3. Download the CLDC Reference Implementation. You can get it here:

    http://www.sun.com/software/communitysource/j2me/cldc/download.xml

    The file will look something like: j2me_cldc-1_0_4-src-winunix.zip. CLDC 1.1 is out now, but I havn't tested it. Most cell phones only support CLDC 1.0 at this time. As a side note, CLDC 1.0 is sometimes referred to as JSR 30.

    We need this tool because it contains the source to a preverifier program that is needed for J2ME developement. There are probably other useful tools that come in this zip file, but this is the only one that is absolutely required.

  4. Extract the j2me_cldc zip file. Then apply the following patch:
    diff -urNp j2me_cldc/tools/preverifier/src/Makefile src/Makefile
    --- j2me_cldc/tools/preverifier/src/Makefile	Wed Dec 31 16:00:00 1969
    +++ src/Makefile	Tue Aug  7 14:25:40 2007
    @@ -0,0 +1,62 @@
    +#
    +# Copyright 1995-2002 by Sun Microsystems, Inc.,
    +# 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
    +# All rights reserved.
    +#
    +# This software is the confidential and proprietary information
    +# of Sun Microsystems, Inc. ("Confidential Information").  You
    +# shall not disclose such Confidential Information and shall use
    +# it only in accordance with the terms of the license agreement
    +# you entered into with Sun.
    +# Use is subject to license terms.
    +#
    +
    +TOP=../../../..
    +include Makefile.inc
    +
    +SRC_DIR = .
    +
    +OBJS = \
    +	check_class.o \
    +	main.o \
    +	utf.o \
    +	check_code.o \
    +        convert_md.o \
    +	util.o \
    +	jar.o \
    +	jar_support.o \
    +	classloader.o \
    +	file.o \
    +	classresolver.o \
    +	stubs.o \
    +	inlinejsr.o \
    +	sys_support.o
    +
    +CFLAGS = \
    +	-I$(SRC_DIR) \
    +	-I /usr/local/include/ \
    +	-DUNIX -DLINUX \
    +	-DJAVAVERIFY \
    +	-DTRIMMED \
    +	-D$(ARCH) $(EXTRACFLAGS)
    +
    +CC = gcc
    +LD = gcc
    +
    +DEBUG_FLAG =  
    +LDFLAGS = -L /usr/local/lib/
    +
    +ifeq ($(DEBUG), true)
    +   DEBUG_FLAG = -g 
    +endif
    +
    +all: preverify
    +
    +preverify: $(OBJS)
    +	$(LD) $(LDFLAGS) -o $@ $(OBJS) -liconv
    +
    +%.o: $(SRC_DIR)/%.c
    +	$(CC) -c $(CFLAGS) $(DEBUG_FLAG) $<
    +
    +clean: 
    +	rm -f core *.o preverify
    diff -urNp j2me_cldc/tools/preverifier/src/Makefile.inc src/Makefile.inc
    --- j2me_cldc/tools/preverifier/src/Makefile.inc	Wed Dec 31 16:00:00 1969
    +++ src/Makefile.inc	Tue Aug  7 14:16:15 2007
    @@ -0,0 +1,23 @@
    +#
    +# Copyright 1995-2002 by Sun Microsystems, Inc.,
    +# 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
    +# All rights reserved.
    +#
    +# This software is the confidential and proprietary information
    +# of Sun Microsystems, Inc. ("Confidential Information").  You
    +# shall not disclose such Confidential Information and shall use
    +# it only in accordance with the terms of the license agreement
    +# you entered into with Sun.
    +# Use is subject to license terms.
    +#
    +
    +# The PLATFORM defined in build/platform-name
    +
    +UNAME=$(shell uname -a)
    +
    +ARCH=i386
    +ifneq (,$(findstring sparc,$(UNAME)))
    +  export ARCH=sparc
    +endif
    +
    +OTHER_FLAGS += -DBUILD_VERSION='"$(VERSION)"'
    diff -urNp j2me_cldc/tools/preverifier/src/convert_md.c src/convert_md.c
    --- j2me_cldc/tools/preverifier/src/convert_md.c	Wed Nov 13 15:07:08 2002
    +++ src/convert_md.c	Tue Aug  7 15:07:00 2007
    @@ -56,12 +56,16 @@ get_langinfo_codeset()
     {
         static char *name = NULL;
     
    +    if (name == NULL || strlen(name) == 0) { 
    +         name = "ISO8859-1";
    +    }
    +/*
         if (name == NULL) { 
             name = nl_langinfo(CODESET);
             if (name == NULL || strlen(name) == 0) { 
                 name = "ISO8859-1";
             }
    -    }
    +    } */
         return name;
     }
     
    diff -urNp j2me_cldc/tools/preverifier/src/typedefs_md.h src/typedefs_md.h
    --- j2me_cldc/tools/preverifier/src/typedefs_md.h	Wed Nov 13 15:07:08 2002
    +++ src/typedefs_md.h	Tue Aug  7 14:23:12 2007
    @@ -41,15 +41,6 @@ typedef long int32_t;
     #endif	/* !defined(_ILP32) && !defined(_LP64) */
     #endif /* SOLARIS2 */
     
    -#ifdef LINUX
    -#ifndef       _UINT64_T
    -#define       _UINT64_T
    -typedef unsigned long long uint64_t;
    -#define _UINT32_T
    -typedef unsigned long uint32_t;
    -#endif
    -#endif /* LINUX */
    -
     #ifdef WIN32
     typedef __int64 int64_t;
     typedef unsigned __int64 uint64_t;
    @@ -132,7 +123,7 @@ extern void ll2str(int64_t a, char *s, char *limit);
     #endif
     
     #ifdef LINUX
    -#include 
    +/*#include  */
     #endif
     
     #ifdef WIN32
    
  5. Type gmake in the j2me_cldc/tools/preverifier/src directory.
  6. Download the latest WTK. It doesn't matter what architecture this is for. We built the important preverify tool, we just need the jars that come with the WTK.

    Download it here: http://java.sun.com/products/sjwtoolkit/download.html

  7. Copy the preverify binary you made in step 5 to $(WTK_DIR)/bin/preverify
Should be all set.