How Do I Avoid Tiger's readline When Compiling PostgreSQL?

I was delighted to find that Mac OS X 10.4 Tiger includes the readline library. So I was able to just compile PostgreSQL and have psql just work. Only it kinda doesn't. For reasons that Tom Lane has explained, Tiger's readline implementation is somewhat buggy. I've reported the issue to Apple (Radar # 4356545), but in the meantime, I've compiled and installed GNU readline 5.0 and wan to use it, instead.

The only problem is that there is no easy way to do it with environment variables or options when configuring PostgreSQL. I've tried:

./configure --includes=/usr/local/include -with-libs=/usr/local/lib

And:

CFLAGS=-L/usr/local/lib LDFLAGS=-I/usr/local/include; ./configure

Neither approach worked. In both cases, it still compiled in Apple's buggy readline library. The only approach I've found to work is the brute force approach:

mv /usr/lib/libreadline.* /tmp
mv /usr/include/readline /tmp
./configure
make
make install
mv /tmp/libreadline.* /usr/lib
mv /tmp/readline /usr/include

But surely I'm missing something! Is there no better way to do it?

Backtalk

rc wrote:

try prefixing the dir where you installed your readline lib like this:

export DYLD_LIBRARY_PATH="/Users/[foo]/custom-readline/lib"

then build postgresql.

Theory wrote:

rc,

I installed GNU readline in /usr/local. And unfortunately, this didn't work:

export DYLD_LIBRARY_PATH=/usr/local/lib
./configure
make
make install

With that, I still get the errors from Apple's readline, so that's obviously what it found. :-(

Tim wrote:

Perhaps ./configure --with-readline=/usr/local ?

Theory wrote:

Tim:

Unfortunately not:

 ./configure --with-readline=/usr/local
...
configure: error: no argument expected for --with-readline option

—Theory

Chris Dolan wrote:

Install Fink from fink.sf.net, then type "fink install postgresql" If nothing else, look at the following file that gets installed with Fink: /sw/fink/10.4-transitional/stable/main/finkinfo/database/postgresql80-unified.info

Theory wrote:

Chris:

You couldn't pay me to use Fink. See Jarkko has to say on the matter. But I'd be happy to see what's in that info file online somewhere…

—Theory

Tim wrote:

I just checked psql on my machine and readline seems to be functioning properly. I install a bunch of libraries using darwinports (including the most recent readline), then I usually manually compile the bigger programs like postgresql from source so I can get exactly the features I want.

I'm not sure that it would make a difference, but is /usr/local before /usr in your path?

What were your options for ./configure for readline?

Theory wrote:

Tim:

Yeah, you probably got GNU readline from darwinports, so it just worked. No, /usr/local is not before /usr in my path. I'll have to try that. I used no options to ./configure when building readline.

—Theory

Tim wrote:

I take it all back. It looks like I am experiencing the bug you Tom Lane mentions. Nevertheless, I do have a .psql_history in my home directory and history in psql does work; the bug on exit of psql is just a minor annoyance as far as I can tell.

Normally the way you configure a program to override the default location for a particular library is to pass it to ./configure the way I mentioned ealier (./configure --desired-option=/path/to/libs). Maybe that's something the postgres devs should look into allowing in the future. At this point ./configure --help only indicates the ability to disable readline with --without-readline.

There also seems to be a --with-headers=DIRS and --with-libraries=DIRS. Maybe something like ./configure --with-headers=/usr/local --with-libraries=/usr/local to make it look in /usr/local in addition to the default location. And if that doesn't work, specify /usr/local:/usr to hopefully force it to look in /usr/local first.

Theory wrote:

Tim,

Yeah, it's just a nuisance, I agree. I'd just rather do without it. As I said, I reported the bug to Apple.

Unfortunately, changing the path so that /usr/local/bin comes before /usr/bin doesn't work—not too surprising since there's no binary with readline. And as I said in my original post, specifying --with-libraries and --with-includes doesn't work, either. :-(

—Theory

dcreemer wrote:

No problems here using DarwinPorts -- http://darwinports.opendarwin.org/

Martin wrote:

You might check config.log, maybe there are some hints on what is going wrong. One think to look for is that libreadline might depend on other libs (termcap, curses).

mattm wrote:

This seems to work for me (I have GNU readline in $HOME/dev-local/readline)
./configure --prefix=$HOME/dev-local/postgresql-8.1.0 CPPFLAGS=-I$HOME/dev-local/readline/include LDFLAGS=-L$HOME/dev-local/readline/lib
(CPPFLAGS is for pre-processor flags)
iBook:~/dev-local/postgresql-8.1.0/bin mattm$ otool -L ./psql 
./psql:
        /Users/mattm/dev-local/postgresql-8.1.0/lib/libpq.4.dylib (compatibility version 4.0.0, current version 4.1.0)
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
        /Users/mattm/dev-local/readline/lib/libreadline.5.1.dylib (compatibility version 5.0.0, current version 5.1.0)
        /usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 369.1.5)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.1.2)

Theory wrote:

mattm

Bah! That doesn't work for me, either. I tried both:

./configure CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib

And:

./configure CPPFLAGS=-I/usr/local/include/realine LDFLAGS=-L/usr/local/lib

Neither worked. :-(

—Theory

Theory wrote:

Here's the output from otool:

% otool -L src/bin/psql/psql
src/bin/psql/psql:
        /usr/local/pgsql/lib/libpq.4.dylib (compatibility version 4.0.0, current version 4.1.0)
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
        /usr/lib/libedit.2.dylib (compatibility version 2.0.0, current version 2.0.0)
        /usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 369.1.5)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.1.2)
        /usr/lib/libmx.A.dylib (compatibility version 1.0.0, current version 92.0.0)

realine isn't even listed there, which makes me think that it's embedded in libSystem. This version was compiled with CPPFLAGS=-I/usr/local/include/realine LDFLAGS=-L/usr/local/lib

—Theory

mattm wrote:

I think Apple's readline implementation is in libedit (read Tom Lane's email).

It might be best to start from scratch, and try doing a 'make distclean' before running configure again. CPPFLAGS=-I/usr/local/include should do it - no need to put 'readline' or 'realine' (I take it 'realine' is a typo? :))

Maybe you could post the output of 'find /usr/local' ?

Theory wrote:

mattm

I have been deleting the sources every time and unpacking the tarball afresh, so no problems there. And yes, realine was a typo. :-)

I have a lot of stuff in /usr/local, so I won't post it all. But readline is there—that's how I got it to work by moving Apple's readline out of the way in the original blog post above.

But this should show you what I have:

% find /usr/local/include/readline 
/usr/local/include/readline
/usr/local/include/readline/chardefs.h
/usr/local/include/readline/history.h
/usr/local/include/readline/keymaps.h
/usr/local/include/readline/readline.h
/usr/local/include/readline/rlconf.h
/usr/local/include/readline/rlstdc.h
/usr/local/include/readline/rltypedefs.h
/usr/local/include/readline/tilde.h
% find /usr/local/lib/libreadline* 
/usr/local/lib/libreadline.
/usr/local/lib/libreadline.a

—Theory

mattm wrote:

I'd perhaps try a fresh compile of GNU readline version 5.1, I have:

./lib/libhistory.5.1.dylib
./lib/libhistory.5.dylib
./lib/libhistory.a
./lib/libhistory.dylib
./lib/libreadline.5.1.dylib
./lib/libreadline.5.dylib
./lib/libreadline.a
./lib/libreadline.dylib

Theory wrote:

mattm

Hrm. It isn't building the shared libraries for me. I used this incantation:

perl -i.bak -p -e \
    "s/SHLIB_LIBS=.*/SHLIB_LIBS='-lSystem -lncurses -lcc_dynamic'/g" \
    support/shobj-conf
./configure --enable-shared
make
make install

How did you build readline?

—Theory

mattm wrote:

Just a simple './configure --prefix=$HOME/dev-local/readline' Version 5.0 didn't work for me, but 5.1 did.

Theory wrote:

mattm,

Hrm. Then I don't know what the deal is. You're building on Tiger, of course...I don't understand at all why it isn't creating dylibs. :-(

—Theory

mattm wrote:

Yeah, building on Tiger. With Xcode 2.2