Explicit dependencies on searched-for sources
Learn how to declare the searched-for source object as an explicit dependency in the makefile.
There are situations in which the configuration lookup algorithm that clearmake uses qualifies a derived object, even though rebuilding the target would produce a different result. Configuration lookup requires that for each object listed in an existing CR, the current view must select the same version of that object. However, when search paths must be used to find an object, a target rebuild might use a different object than the one listed in the CR. Configuration lookup does not take this possibility into account.
When files are accessed by explicit path names, configuration lookup qualify derived objects
correctly. Configuration lookup might qualify a derived object incorrectly if files are
accessed at build time by a search through multiple directories, for example, when the
-I option to a C or C++ compiler specifies a header file or when the
-L option to a linker specifies a library file. The following build script
uses a search to locate a library file, libprojutil.a
:
hello:
cc -o hello -L /usr/project/lib -L /usr/local/lib \
main.o util.o -lprojutil
The command clearmake
hello might qualify an existing derived object built with
/usr/local/lib/libprojutil.a
, even though rebuilding the target would now use
/usr/project/lib/libprojutil.a
instead.
clearmake addresses this problem in the same way as some standard make implementations:
- You must declare the searched-for source object as an explicit dependency in the makefile:
hello: libprojutil.a ...
- You must use the
VPATH
macro to specify the set of directories to be searched:VPATH = /usr/project/lib:/usr/local/lib
Given this makefile, clearmake uses the VPATH
(if any) when
it performs configuration lookup on libprojutil.a
. If a candidate derived
object was built with /usr/local/lib/projutil.a
, but would be built with
/usr/project/lib/projutil.a
in the current view, the candidate is
rejected.
VPATH
macro is not used for all source dependencies listed in the config
record. It is used only for explicitly declared dependencies of the target. Also,
clearmake searches only in the current view. Build Tool Dependencies: You can use this mechanism to implement dependencies on build tools. For example, you can track the version of the C compiler used in a build as follows:
msg.o: msg.c $(CC)
$(CC) -c msg.c
With this makefile, either your VPATH
must include the directories on your
search path (if the $(CC)
value is cc
), or you must use a
full path name as the $(CC)
value.