automake: Sources

1 
1 9.4 Built Sources
1 =================
1 
1 Because Automake’s automatic dependency tracking works as a side-effect
1 of compilation (⇒Dependencies) there is a bootstrap issue: a
1 target should not be compiled before its dependencies are made, but
1 these dependencies are unknown until the target is first compiled.
1 
1    Ordinarily this is not a problem, because dependencies are
1 distributed sources: they preexist and do not need to be built.  Suppose
1 that ‘foo.c’ includes ‘foo.h’.  When it first compiles ‘foo.o’, ‘make’
1 only knows that ‘foo.o’ depends on ‘foo.c’.  As a side-effect of this
1 compilation ‘depcomp’ records the ‘foo.h’ dependency so that following
1 invocations of ‘make’ will honor it.  In these conditions, it’s clear
1 there is no problem: either ‘foo.o’ doesn’t exist and has to be built
1 (regardless of the dependencies), or accurate dependencies exist and
1 they can be used to decide whether ‘foo.o’ should be rebuilt.
1 
1    It’s a different story if ‘foo.h’ doesn’t exist by the first ‘make’
1 run.  For instance, there might be a rule to build ‘foo.h’.  This time
1 ‘file.o’’s build will fail because the compiler can’t find ‘foo.h’.
1 ‘make’ failed to trigger the rule to build ‘foo.h’ first by lack of
1 dependency information.
1 
1    The ‘BUILT_SOURCES’ variable is a workaround for this problem.  A
1 source file listed in ‘BUILT_SOURCES’ is made on ‘make all’ or ‘make
1 check’ (or even ‘make install’) before other targets are processed.
1 However, such a source file is not _compiled_ unless explicitly
1 requested by mentioning it in some other ‘_SOURCES’ variable.
1 
1    So, to conclude our introductory example, we could use ‘BUILT_SOURCES
1 = foo.h’ to ensure ‘foo.h’ gets built before any other target (including
1 ‘foo.o’) during ‘make all’ or ‘make check’.
1 
1    ‘BUILT_SOURCES’ is actually a bit of a misnomer, as any file which
1 must be created early in the build process can be listed in this
1 variable.  Moreover, all built sources do not necessarily have to be
1 listed in ‘BUILT_SOURCES’.  For instance, a generated ‘.c’ file doesn’t
1 need to appear in ‘BUILT_SOURCES’ (unless it is included by another
1 source), because it’s a known dependency of the associated object.
1 
1    It might be important to emphasize that ‘BUILT_SOURCES’ is honored
1 only by ‘make all’, ‘make check’ and ‘make install’.  This means you
1 cannot build a specific target (e.g., ‘make foo’) in a clean tree if it
1 depends on a built source.  However it will succeed if you have run
1 ‘make all’ earlier, because accurate dependencies are already available.
1 
1    The next section illustrates and discusses the handling of built
1 sources on a toy example.
1 

Menu