[Gllug] automake: $(srcdir)

Stig Brautaset stigbrau at start.no
Fri Jul 5 10:35:28 UTC 2002


I'm having questions about $(srcdir) this time. 

My project tree has the subdirectories `gga' (which contains source- and
header files for libgga) and `gaqueens', which contains a program that
is to be linked with libgga. Additionally, I've got the subdirectory
`config' which contains various files created by
autoconf/automake/libtool.

Now, in my subdirectory	`gaqueens', I am writing a Makefile.am for a
binary that is to be linked with libgga. What I've found is that I need
to add `AM_CPPFLAGS = -I../gga' (or, -I$(top_builddir)/gga) to
Makefile.am to enable me to use `#include <gga.h>' rather than `#include
"../gga/gga.h"'. 

This is where I start to wonder though; I would expect $(srcdir)  to
yield `../gga', but it persist giving me just `.' [2].  I find this
particularly strange since I listed gga to be my srcdir in configure.ac
by using AC_CONFIG_SRCDIR([gga/gga.c]) (I know this macro does something
else, but shouldn't it set the $(srcdir) variable too?)

Anyway, the generated gaqueens/Makefile has this line:

	DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)/config

This, I believe, suggests that my above assumption about $(srcdir) is
correct, and that $(srcdir) yielding `.' is a bug. I cannot make sense
of the above line otherwise; why would you *ever* want to do `-I. -I.' [2]? 

Now, if my assumptions _were_ indeed correct and this is a bug, I could
write my gaqueens/Makefile.am thus once it was fixed:

	AM_CPPFLAGS = -I$(srcdir)
	bin_PROGRAMS = gaqueens
	gaqueens_SOURCES = gaqueens.c
	gaqueens_LDADD =  $(srcdir)/libgga.la -lm 

However, at the moment I have to write the considerably more kludgey:
(Unless, off course, I take shortcuts such as using `..' in place of
$(top_builddir) since I know that's what it expands to.)

	AM_CPPFLAGS = -I$(top_builddir)/gga
	bin_PROGRAMS = gaqueens
	gaqueens_SOURCES = gaqueens.c
	gaqueens_LDADD =  $(top_builddir)/gga/libgga.la -lm 

Do I make sense at all here? Or am I completely making a fool out of
myself (again)? It's not that big a deal, since it probably takes me
less than a second to key in the extra characters I have to type, but
I'm a sad bastard and want to get to the bottom of this "mystery". 

By the way, gga is a generic genetic algorithm library. It requires
yalla (yet another linked list api) to build. The gaqueens program is a
genetic algorithm solver for the n-queens problem, and comes as a sample
application with gga. LGPL'd sources available, if anybody's interested:

	http://brautaset.org/projects/gga
	http://brautaset.org/projects/yalla

Stig

[1] No wonder, since gaqueens/Makefile has the line `srcdir = .' near the top.
[2] This is the effect, since $(srcdir) is set to `.' above. See [1].

PS: Who can tell I'm on summer break and haven't found a job yet? :-D
PPS: Congratulations to anyone who bothered reading this far...


-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list