Next: Creating a makefile Up: Writing Larger Programs Previous: The Make Utility

Make Programming

Make programming is fairly straightforward. Basically, we write a sequence of commands which describes how our program (or system of programs) can be constructed from source files.

The construction sequence is described in makefiles which contain dependency rules and construction rules.

A dependency rule has two parts - a left and right side separated by a :

left side : right side

The left side gives the names of a target(s) (the names of the program or system files) to be built, whilst the right side gives names of files on which the target depends (eg. source files, header files, data files)

If the target is out of date with respect to the constituent parts, construction rules following the dependency rules are obeyed.

So for a typical C program, when a make file is run the following tasks are performed:

  1. The makefile is read. Makefile says which object and library files need to be linked and which header files and sources have to be compiled to create each object file.

  2. Time and date of each object file are checked against source and header files it depends on. If any source, header file later than object file then files have been altered since last compilation THEREFORE recompile object file(s).

  3. Once all object files have been checked the time and date of all object files are checked against executable files. If any later object files will be recompiled.

NOTE: Make files can obey any commands we type from command line. Therefore we can use makefiles to do more than just compile a system source module. For example, we could make backups of files, run programs if data files have been changed or clean up directories.


Dave.Marshall@cm.cf.ac.uk
Wed Sep 14 10:06:31 BST 1994