Skip to main content

15.5) Managing The Process With Makefiles


Remembering all of the various compiler commands needed to build an executable program from multiple source files can be tricky, and typing them in is tedious. Also, there can be complex chains of dependencies – e.g., command B should run only if command A ran, and command A should run only if file A has changed; keeping track of all these dependencies can be difficult.

The make build tool solves these problems by allowing us to specify dependencies and the commands that need to be executed in a makefile.

Building the software can be as simple as entering make at the command line – which has the effect of building the first target in the makefile; alternatively, a target can be named explicitly on the command line – e.g., make prog1.

Makefiles should ideally be called makefile or Makefile; other names can be used but will then require the name to be specified when running the make command.

Note: makefiles are normal in the world of UNIX-based operating systems but less commonly used in Windows environments (make is available for Cygwin, though).