This is the documentation of version 1.18. You may want the documentation of the stable version (2.0) or of the well tested 2.1 development snapshot or our homepage.

Automaticaly Inferring Object Files

If you use standard conventions regarding header file names, makepp is capable of guessing which .o or .lo files need to be linked with your program. I use this to pick out files from a library directory which contains modules used in many different programs. Instead of making a library .a file and having the linker pick out the relevant modules, makepp can pick out the relevant modules for you. This way, only the relevant modules get compiled.

Makepp's algorithm for inferring object dependencies depends on the convention that the implementation of all classes or functions defined in a header file xyz.h are compiled into an object file called xyz.o (or xyz.lo). So makepp's algorithm for inferring object dependencies starts with one or a few objects that we know have to be linked into the program. It looks at which files were included with #include in those sources, and tries to find corresponding object files for each of the include files.

To use this, apply the $(infer_objects ) function to the dependency list, like this:

myprog: $(infer_objects main.o another_object.o, \
		**/*.o /other/library/dirs/**/*.o)
	$(CXX) $(inputs) -o $(output) $(LIBS)

The infer_objects function takes two arguments (separated by a comma, as shown). The first is one or a few object files that are known to be required (wildcards are permissible here). The second is a list of possible objects (normally you would use a wildcard here) that could be linked in if necessary. The return value from this function is a list that contains first all of the objects in the first argument, and then after those, all additional objects that were contained in the second argument that are required by the objects in the first argument.

For example, suppose main.o comes from main.cpp, which includes my_class.h. infer_objects looks for files with the name my_class.o. If exactly one such file is found, it is added to the list. (If two object files my_class.o are found in different directories, a warning message is printed.) infer_objects also examines my_class.cpp to see what it includes, and what additional object files are implied.

Since you can write your own functions in perl, you can encode your own algorithms to infer additional objects; other more sophisticated algorithms are possible for C++, and different algorithms will be needed for other languages.

Table of contents | Next (build algorithm) | Previous (scanning for inculdes)
Last modified: Tue Dec 26 19:06:30 PST 2000