Thursday, June 11, 2009


Just after one week I released version 3.0 of source-highlight with the C++ library, I got an email from Pascal Bleser, telling me that he created a php extension using the library, for highlighting code from php without relying on CGI scripts! You can find its plugin extension here: I took a quick look at his code and it's really simple and clean, hopefully this also means that the library of source-highlight can be smooth to use :-).

You can also might want to take a look at his blog post!

Saturday, June 06, 2009

Tutorial: using Autotools with Eclipse (and Linux Tools Project)

As a GNU maintainer, I've always been using autotools (i.e., automake, autoconf, etc.), and I must admit I still haven't found anything such powerful. Now, I started using the plugins of the Linux Tool Project which seem to have improved a lot! They provide plugins for ChangeLog, Valgrind, and in particular for autotools based projects. Since I haven't seen any tutorial for using the autotools plugin, I thought I could write one; well, it's not that difficult to use the autotools plugin, but I hope it can help :-)

Of course, first of all, you need to install the autotools plugin, and I personally prefer the update site method, using Remember that the linux tools are based on CDT plugin.

For this tutorial, we will use an already autotools based project (for the moment, the autotools plugin can create an autotools based project, but without any templates). We will use the GNU Hello program, so you can download the last version from the web site. Then you can untar the contents in a directory (say tmp).

Now, it's time to create a new project in eclipse, in particular, a GNU C Autotools Project (or a C++ project if you're project uses C++):

Let's call it "hello" (and then you can select your location and accept the other defaults). You will now have an empty autotools based C project.

Now, let's import the hello package from the directory where we had untarred it, by using "import file system":

Now, the hello project is populated with the package of GNU Hello; notice that, and .m4 files are handled by the autotools plugins with syntax highlighting, outline, mouse over functionalities, etc.:

Now, BEFORE building the project for the first time, let's take a look at the properties of the project, where you can see we now have an autotools part, where you can customize the autotools versions you might want to use (I take the defaults):

In particular, from "C/C++ Build - Settings" you can configure the arguments passed to the tools, and the build directory (it is often advised to build a package in a different directory, so that you can configure different builds; by default, the build directory is "build", and I'd leave this that way):

Now, let's change some options! For instance, the configure's --prefix option:

The suffix of the installed program

Since we build the program for development and for debugging, let's make sure to turn off C compiler optimizations (which make debugging a pain):

You can then check that debugging is already turned on, as also '-Wall' option (to report all warnings).

Since we downloaded the source package of hello, produced by 'make dist', this provides all the scripts generated by the autotools in order to run 'configure && make'. However, if you get a program from the CVS, it is likely that you need to bootstrap autotools. Now, the autotools plugin relies on an '' script which calls all the autotools in the right order, which must be provided by the package itself; however, this is kind of an old method, since now, to bootstrap autotools, you can rely on the program 'autoreconf' which is part of autotools; so, in case you need to bootstrap the autotools, you can simply call 'autoreconf -i' (this will install required files from autotools) from a shell, in the directory of the project.

Now, you can build the project, by right clicking on the project and by choosing "Build Project"! Since this is the first time we build it, the build directory will be created, the configure script will be called with all the features we selected, and the files are compiled!

Hey, but wait a minute! We could have used ccache to compile the sources! And we should have also enable maintainer mode specific configuration settings! Well, we can still do that by going back to the settings of the project, enable the maintainer setting check box, and specify the gcc command as 'ccache gcc':

Now, let's clean the project (this will issue a 'make distclean', but you can customize this from the setting), and build it again, so that it will be reconfigured with the new settings.

Now, let's create another build configuration (e.g., for the release version of the package, with optimized compiler options, with a different prefix, removing the suffix '-debug' and without the maintainer-mode option enabled). We just need to go to "Manage Configurations...", create a new one, starting from the previous default one:

and now we can set the optimization level for the compiler, disable maintainer mode and use another --prefix option (e.g., '/usr/local/'). It is also important to specify another build directory, say 'build_release' (but when creating a new configuration, the build directory has already been changed to something different from the previous one, i.e., 'build1'):

Now, we can switch between the two different build configurations:

Well, that's all for now; I hope you find this tutorial useful :-)