Tools and Development Environment (make & cvs)

From Wiki**3

Revision as of 00:57, 9 March 2008 by Root (talk | contribs) (Make)

The following examples describe how to use the make and cvs tools. This very short guide is not intended as a replacement for the corresponding manuals.

Make

Make is a utility for building and maintaining programs. In a more general definition, it can be described as a dependency management tool (in the sense that is controls how targets are updated when dependencies change).

Make is especially useful for managing large programs, in which multiple, often not obvious, dependencies occur.

Below, the most usual features are covered (other features, such as conditionals and cycles are not, since they are not of special interest in most cases).

Rules

The general syntax of a rule is as follows (target is supposed to be "built" by the commands 1 though N):

 target: dependency1 dependency2 ... dependencyN
         command1
         command2
         ...
         commandN

There are two types of rules: implicit, which make uses for derived building targets from derived (calculated) dependencies; and explicit, in which both targets and dependencies are specified.

The following is an example of an implicit rule for obtaining a compiled (.o) file from a C++ (.cpp) source, by simple compilation. Variable CXXFLAGS is used to specify compilation flags.

 CXXFLAGS=-ggdb -O3

 %.o: %.cpp
         $(CXX) $(CXXFLAGS) -c $*.c -o $*.o

In this rule, % represents a pattern (the same pattern appears in commands section represented by the $* pseudo-variable).

The same rule could be written thus (here $< represents the first dependency, and $@ the target to be built by the rule):

 %.o: %.cpp
         $(CXX) $(CXXFLAGS) -c $< -o $@

CVS

Examples