Home > Computing > Compiling Java-Readline with GNU readline for OSX

Compiling Java-Readline with GNU readline for OSX

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 libJavaReadline.so and libreadline-java.jar.

Rename libJavaReadline.so 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: , , ,
  1. André
    February 8, 2012 at 11:25 am

    Nice one!
    *thumbs up* from the guy, who was bugging you 🙂
    lets try it right now

    • André
      February 8, 2012 at 12:42 pm

      you made my day!
      and sorry for bugging you 🙂
      the proper TAB completion and history search are finally back
      now i have my henplus in the way i love it

  2. L. Fraga
    March 21, 2012 at 3:51 am

    Thank you. It’s great to have henplus working properly. To save work, I created a shell script (https://gist.github.com/2146054) that downloads the tarballs and the patches using wget, and follows the steps you provided. Use, modify and share at will.

  1. February 8, 2012 at 9:42 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: