Makedepend
Encyclopedia
makedepend is a Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 tool used to generate dependencies
Coupling (computer science)
In computer science, coupling or dependency is the degree to which each program module relies on each one of the other modules.Coupling is usually contrasted with cohesion. Low coupling often correlates with high cohesion, and vice versa...

 of C source files.

History

makedepend was developed as part of MIT's Project Athena
Project Athena
Project Athena was a joint project of MIT, Digital Equipment Corporation, and IBM to produce a campus-wide distributed computing environment for educational use. It was launched in 1983, and research and development ran until June 30, 1991, eight years after it began...

. It was used extensively in building X11 and ancillary packages, but has since become superseded by the dependency generation facilities of various compilers, and is now used primarily as a worst-case fallback, e.g. by depcomp and GNU Automake.

Usage

makedepend is invoked with a list of sourcefiles:
makedepend [options] foo.c bar.c ...
However, it is more often invoked as a target from a makefile, typically under the depend target, such that make depend will invoke makedepend on all source files in the project. One such example target would be as follows:
SRCS = file1.c file2.c ...
CFLAGS = -O -DHACK -I../foobar -xyz
depend:
makedepend -- $(CFLAGS) -- $(SRCS)

Purpose

When building C language projects, it is imperative for incremental compilation (and useful for clean compilation) to be able to track dependencies
Coupling (computer science)
In computer science, coupling or dependency is the degree to which each program module relies on each one of the other modules.Coupling is usually contrasted with cohesion. Low coupling often correlates with high cohesion, and vice versa...

 between compilation units. C expresses interfaces between compilation units via header file
Header file
Some programming languages use header files. These files allow programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers...

s; as such, it is often necessary to rebuild a compilation unit when a header it includes is changed. make needs to be informed of these dependencies.

makedepend solves this problem by parsing the code of C source files to generate a list of dependencies (those header files included directly and indirectly). It is able to understand conditional compilation
Conditional compilation
In computer programming, conditional compilation is compilation implementing methods which allow the compiler to produce differences in the executable produced controlled by parameters that are provided during compilation...

 constructs so as to not generate excessive dependencies. It then appends rules expressing the dependencies to the Makefile.

Alternatives

Most modern compilers provide a flag (often -M) that uses the compiler's own source parser to generate a list of dependencies. This may be preferred to makedepend because it reduces the likelihood of the dependencies generated being at odds with the compiler's own behaviour.

Since compilers accept different flags for dependency generation, and may behave differently in outputting dependency information, it is desirable to use a wrapper script that can invoke the compiler appropriately (and fall back to makedepend if necessary). One popular such wrapper script is depcomp, which is distributed with and used by GNU Automake.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK