Previous: Configure script, Up: Project building system

2.3.3 Makefiles

VRR uses GNU Make and sophisticated Makefile files structure for building process. In the root directory, there is the main Makefile containing the bulk of building rules and in almost every subdirectory there is a local Makefile.

The main difference between VRR and other projects using many Makefiles is that make doesn't get called recursively for every subdirectory. Instead, every local Makefile is included into the main Makefile (and Makefile from subsubdirectory gets included into subdirectory Makefile, and so on). Thus it is possible to use all rules and variables from the root Makefile, speeding and simplifying the compilation process reasonably.

Another significant difference is that all binaries and object files are not created among the sources, but rather in the directory obj in a directory structure resembling the original source tree. Also, all binaries and other data is then installed in the run directory.

In the root Makefile, there are many automating rules like handling C sources, linking of binaries and copying data files. Thus only little work is needed to compile program, link library, etc.

The typical local Makefile looks as follows:

     ifndef POTEMKIN
     EXPORT_MODS = \
          pdf \
          ps \
     obj/export/svg.o: CFLAGS+=$(XML_CFLAGS)
     obj/export/zpipe: $(Z_LIBS)
     $(LIBEXPORT):$(addsuffix .o,$(addprefix obj/export/,$(EXPORT_MODS)))

In every subdirectory Makefile, you should add the directory into the DIRS variable. If there are executable programs, add them into the PROGS variable, with the full path inside the obj directory. There are also three destination variables BINDIR, LIBDIR and DATADIR. Modifying them causes different destination directory.

The source files dependencies are handled automatically by the compiler. During compilation, the compiler dependency output is saved, processed with the build/mergedeps script and included into the main Makefile.

Here are the Makefile targets the programmer is encouraged to use.