In this whitepaper, John Graham-Cumming, Founder and Chief Scientist at Electric Cloud, Inc.
will provide time-saving tips for automating and optimizing dependencies between files in a
software build. Three main types of dependencies will be discussed: those that exist between
source and object files (that are used to regenerate objects when source changes), those that
exist between objects (for example, used to drive a linker), and dependencies at the module
or project level.
Solving the Dependency Problem in
Software Builds Time-Saving Tips for Handling Dependencies in Make
John Graham-Cumming Chief Scientist Electric Cloud, Inc. September, 2005
Executive Summary
Make is a tool that controls the generation of executables and other non-source files of a program from the program's source files. Dependencies between files in a build are a critical part of Make; without them Make doesn't know what to build or when to rebuild items. Accurate dependencies are the cornerstone of a successful build, and yet are all too often missing or broken, which results in wasted time or, worse, in corrupt or incorrect object code.
In this whitepaper, John Graham-Cumming, Founder and Chief Scientist at Electric Cloud, Inc. will provide time-saving tips for automating and optimizing dependencies between files in a software build. Three main types of dependencies will be discussed: those that exist between source and object files (that are used to regenerate objects when source changes), those that exist between objects (for example, used to drive a linker), and dependencies at the module or project level.
For source/object dependencies in particular, instead of generating dependencies manually, there are simple techniques for generating dependencies automatically, saving time and reducing errors and rework. This paper provides specific guidance, complete with examples, for automating dependency generation, and describes some of the challenges left unsolved by traditional freeware/open source dependency management techniques.
The paper is technical and aimed at someone with familiarity with a flavor of Make. Experienced users of GNU Make should find the worked examples of interest.
Introduction
It's ironic that Make, which was designed to solve the "I've changed something; now what do I rebuild?" problem, introduces a nightmare of updating the dependencies between files in a build. In fact, Make has transformed the original problem such that it requires giving Make exact information about the dependencies - something the build manager didn't have in the first place!
This whitepaper looks at solutions to the dependency problem in Make (focusing on GNU Make because of its wide platform coverage and popularity) and identifies outstanding problems in dependency management.
The paper is technical and aimed at someone with familiarity with a flavor of Make. Experienced users of GNU Make should find the examples of interest.
Why do Dependencies Matter?
Dependencies are Make's bread and butter; without them Make doesn't know what to build or when to rebuild items. In its simplest form, a dependency is a relationship between an object file and a source file (e.g. foo.o: foo.c means foo.o is built from foo.c). Accurate dependencies are the cornerstone of a successful build. If a Makefile contains incomplete dependencies, then objects that need updating may be left untouched, and if it contains over-specified dependencies, too much work may be performed which will produce slow builds.
Additionally, if the build manager wants to speed up the build process by using parallel Make to run jobs on a multi-processor machine, accurate dependencies are vital. Without them, a parallel build may appear to terminate correctly while producing corrupt or incorrect object code. That can happen if build steps occur in the wrong order; without good dependencies a library file might get created before one of the objects it contains is remade.
Finally, every developer needs good dependencies to get fast, accurate incremental builds. The last thing a developer wants is to touch a single source code file and find that many other unrelated files are being built, wasting time, because of bad dependency information.
Types of Dependencies
This whitepaper discusses three main types of dependencies: those that exist between source and object files (that are used to regenerate objects when source changes), those that exist between objects (for example, used to drive a lin... [download for more]