View Full Version : Using ClanLib with autotools (autoconf, automake, pkg-config ...)

05-14-2007, 04:24 PM

I'm using autotools to generate the configure script that will generate the Makefile of the game I'm working on. I managed to get someting that works, but I'm not entirely satisfied.

First, concerning the check of the library presence :

Usually, with autoconf, I do it this way :

To test if foo function of bar library is present, I use this line in configure.in

AC_CHECK_LIB(bar, foo, ,echo "MyApp requires bar library to run."; exit 1)

Unfortunately, this doesn't seem to work with ClanLib, as I would have to write something like this :

AC_CHECK_LIB(clanCore, function, ,echo "MyApp requires ClanLib to run."; exit 1)

The problem is it won't work as all functions are members, so they would need to define the class name, but there is no inclusion made in the test code produced.

<edit reason="forgot this part">
So I did it this way, but I'm not sure if it's clever, and I think it's not really clean :

AC_CHECK_LIB(clanSignals, main, ,echo "MyApp requires ClanLib to run."; exit 1)


Secondly concerning pkg-config :
For now, I'm using a Makefile.in that looks like this :

EXTERN_LIBS = -lclanSignals -lclanGL -lclanCore -lclanSound -lclanDisplay -lclanApp
HEADERS = `pkg-config --cflags clanApp-0.8`

It works, but I'm sure it's not a clean way to do it. What I'd like to have is something :
- that will use only pkg-config to find headers and library (seems easy)
- that will not require to be modified to work with another version of clanlib

Of course, maybe the API will break my app with future version of clanlib, but isn't it one of the objectives to have a backward compatibility at some points ? Then, it would be nice to be able to compile and install an application, no matter which version of ClanLib is installed.

So I'm wondering why pkg-config use the library version number. Isn't it a problem ?

05-15-2007, 02:04 PM
First Question:
Using AC_CHECK_LIB(clanSignals...) would only check for the existence of clanSignals. It would not check for (for example) clanMikmod.

Maybe you can use AC_CHECK_HEADER, i have not tried it with clanlib, but it "should" work:

[AC_MSG_ERROR([Sorry, can't do anything for you])])

ClanLib uses AC_TRY_COMPILE or AC_RUN_IFELSE to create a test program for existence of other libraries.

For example using - AC_TRY_COMPILE - see ClanLib configure.ac
For example using AC_RUN_IFELSE See ClanLib acinclude.m4 CLANLIB_CHECK_LIB macro

Second Question:
The next version of ClanLib 0.9 (which is under development) API is not compatible with ClanLib 0.8 API.

The API is undergoing vast improvements (for example; allowing multiple windows), which will unfortunately break compatibility.

05-15-2007, 03:37 PM
The API is undergoing vast improvements (for example; allowing multiple windows), which will unfortunately break compatibility.

OK, I understand that sometimes, modifying the API is necessary. Of course, adding functions, objects, features ... is nice, and I have no problem with it. But it's another problem when some are suppressed, renamed or modified. I just ported a game from ClanLib-0.6 to ClanLib-0.8, I know what I'm talking about.

These kinds of changes not only break compatibility and give to all developers of application relying on the library a lot of work, it can also introduce new bugs in application. During the upgrade, maybe I won't choose the good replacement for the function/object/variable which name was changed. Or worse, maybe after its name was changed, another function/object/variable took this name that was much more logic for it. But my app is using the old one. Now, it compiles but it doesn't do what I want it to.

I know there are some changes that need to be done, and we all want ClanLib to progress as quick as possible, and to be as good as possible. But as more and more games use it, it should converge to a stable API, and give to its users the assurance of backward compatibility.

05-16-2007, 07:26 AM
(Note: I am not a core developer)

How i understand it, you can still use ClanLib 0.8 for as long as you want, you are not forced to upgrade. Hence, you can specify the library version number when using pkg-config.

The API of 0.9, has changed, as far as i can see, the changes are "sensible". For example, when i converted the ClanLib 0.9 Basic2D example a couple of days ago, these changes were required:

CL_DisplayWindow window("ClanLib Basic2D Example", 640, 480);

Add - CL_GraphicContext gc = window.get_gc();

Replace - CL_Display::draw_line(0, (int)(ypos+198), CL_Display::get_width(), (int)(ypos+198), CL_Color( 127, 0, 0));

With - CL_Draw::line(0, (int)(ypos+198), window.get_width(), (int)(ypos+198),CL_Color(127, 0, 0), gc);

Hopefully, the required changes will be documented somewhere.

I was quite fortunate when i converted my game http://methane.sourceforge.net/ ( from ClanLib-0.6 to ClanLib-0.8, it only require a single change, the removal of a "&" character. !!! Although i did only use ClanLib to open a screen and use a pixel buffer to manually write to.

05-16-2007, 08:37 AM
Hey your game looks cool. I'll try it as soon as I'm back home !