Friday 7 March 2008

Gnuplot

Gnuplot is a very popular plotting utility. In order to have full support under Mac OSX, I encourage you to compile it from source. The thing is a bit tricky, as Leopard do not include a decent GNU readline for history support. I will report on how to configure Gnuplot to have the aquaterm, X11, png, jpeg, pdf terminals available, and to have GNU readline support (you need it to have tab completion and history facilities).
  • Install Aquaterm (a few mouse clicks)
  • From fink install the packages pdflib and gd2. This is done from a terminal with the commands fink install pdflib and fink install gd2. These packages contain png, jpeg and pdf libraries.
  • Install GNU readline. Some people adviced to delete Leopard's default readline and to substitute with GNU readline. I have rather installed GNU readline in /usr/local and instructed Gnuplot to link against it. Download readline from here and unpack it somewhere: before running configure, make and make install, you will have to patch one of the configure scripts. In the gnuplot folder search for the file support/shobj-conf and patch it following this. Patching is not hard, you can open support/shobj-conf and see that it looks similar to the patch file. Do you see those lines in the patch file that begin by "+" and "-"? Lines with "-" represent lines already existing in support/shobj-conf: you are going to go in support/shobj-conf and replace them with the corresponding "+" lines of the patch. Alternatively, you can use the unix patch command. At this point you can run configure, make and make install. Default installation is in /usr/local/lib.
  • Download Gnuplot source code and unpack it somewhere. In the Gnuplot directory run configure with ./configure CC=/usr/bin/gcc CFLAGS=-O3 CXX=/usr/bin/g++ --with-readline=/usr/local/lib LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/incl. The compilers flag are to make sure you are using Leopard's default compilers (I have installed this ones which create a conflict with Gnuplot in that they do not enable -ObjC flag by default). The LDFLAGS link to the readline directory, already pointed by the --with-readline flag. When the configuration script has run, make sure that aquaterm, png, jpg, pdf and GNU readline are all compiled correctly. Then you can run make and make install.
Update. Gnuplot can be easily installed, with all dependencies, using MacPorts. I strongly recommend to do this.

No comments: