Monday, December 6, 2010

Compiling Gnuplot with TTF support on RHEL5.4

I just had to install a recent gnuplot (>4.2) version on RHEL5.4. You need to build libgd and gnuplot yourself in order to get PNG and Truetype font support on that OS.

Before you start compiling libgd you'll need to 'yum-install' devel packages for png, jpeg, freetype and fontconfig. Once you've done this you can download the source package of libgd http://www.libgd.org/releases/gd-2.0.35.tar.gz and do the typical:

$ ./configure --with-jpeg --with-png --with-freetype
$ make
$ sudo make install

You might want to add the library location (default /usr/local/lib) to /etc/ld.so.conf.d and add /usr/local/bin to your PATH variable.

Now  you're almost ready to build gnuplot after you've downloaded the source package http://sourceforge.net/projects/gnuplot/files/gnuplot/4.4.2/gnuplot-4.4.2.tar.gz/download. However, there is a problem with the libgd-config tool that is used by gnuplot's configure. It prints out a bogus library in the libs sections:

$ gdlib-config --all
GD library  2.0.35
includedir: /usr/local/include
cflags:     -I/usr/local/include
ldflags:      -L/usr/lib64  -L/usr/lib64
libs:       -lXpm -lX11 -ljpeg -lfontconfig -lfreetype -lpng12 -lz -lm  @LIBICONV@
libdir:     /usr/local/lib
features:   GD_XPM GD_JPEG GD_FONTCONFIG GD_FREETYPE GD_PNG GD_GIF GD_GIFANIM GD_OPENPOLYGON

In order to dynamically get rid of the @LIBICONV@ entry I renamed gdlib-config and created tiny shell script that removes the bogus library from the output:

$ mv /usr/local/bin/gdlib-config /usr/local/bin/gdlib-config-org
$ cat /usr/loca/bin/gdlib-config
#!/bin/bash
/usr/local/bin/gdlib-config-org $* | sed "s/@LIBICONV@//"

Now glib-config produces the correct output and you can configure and make install gnuplot:

$ ./configure --with-gd=/usr/local/lib
$ make
$ sudo make install

Without patching gdlib-config gnuplot's configure will disable PNG and TTF support by default.


No comments:

Post a Comment