Archive for February, 2012

Compiling Java-Readline with GNU readline for OSX

February 8, 2012 4 comments

I had previously wrote some instructions for compiling the libreadline-java on OSX with the built-in readline libary on OS X (for use with Henplus). Its time to revisit that, cause it had some issues.

  • OS X Lion, and maybe other versions, doesn’t ship with GNU readline at all. Instead, it ships with a BSD-licensed alternative called libedit, which has a compatibility layer to emulate GNU readline, but has some weird quirks that for those used to GNU readline get annoyed with.
  • libeadline-java I have since found already supports libedit. I didn’t realize that at the time, and so the patches I made do essentially the same thing as if libreadline-java were configured to compile against libedit in the first place.
  • And also, this guy Andre keeps bugging me, I don’t know him, but don’t want to let him down none the less.

The new strategy is this, compile your own GNU readline, then point libreadline-java at it and compile against your new GNU readline library. There’s still some tweaks that need to be done, but there are less and they are more straight forward.

Compiling GNU readline

There’s only one small tweak you have to make to the build scripts to get it to compile correctly, at least for Lion. The latest version of GNU readline, version 6.2, doesn’t have support for compiling against Lion, but thanks to some other sleuthing, the tweak is pretty simple:

In the file support/shobj-conf,

  • Find the line darwin[89]*|darwin10*) and change it to darwin[89]*|darwin10*|darwin11*)

Now, configure, build and install as usual, we’ll target /usr/local as the destination

configure --prefix=/usr/local
make intall

Ok, done with that. I’ve made a readline-6.2-osx-lion.patch for those of you interested.

Tweaking Java-Readline

Ok, now on to compiling libreadline-java with the freshly build libreadline. First off, the list of tweaks you need to make

In the source root, edit Makefile and make the following changes:

  • Below the line # Operating system dependent
    Add JAVA_HOME = `/usr/libexec/java_home`
  • Change the JAVAINCLUDE variable
    to /System/Library/Frameworks/JavaVM.framework/Headers
    (This is needed to find jni.h)
  • Change the JAVANATINC variable to /usr/local/include

Next, edit src/native/Makefile and change the following:

  • Change the  LIBPATH variable to -L/usr/local/lib
  • Change the CFLAGS to -fno-common
  • Change $(CC) -shared (OBJECTS) $(LIBPATH) $($(TG)_LIBS) -o $@ to
    $(CC) -bundle -flat_namespace $(OBJECTS) $(LIBPATH) $($(TG)_LIBS) -o $@

Now, you can run make, and you will end up with and libreadline-java.jar.

Rename to libJavaReadline.dylib, and you are set. You can now go on to use libreadline-java in your target application, like Henplus, as you expect.

I’ve made a libreadline-java-0.8.0-osx-lion.patch script for those who would rather use the patch command rather than doing it by hand.

Categories: Computing Tags: , , ,