CIS 22 - Data Structures: Unix makefile utility
In order to
use make, the users must specify dependencies in a description file. The
default description filenames are
makefile
or Makefile.
When the user types make, the make utility looks for
makefile
or
Makefile
in the current directory and checks this description file if anything needs
updating.
The description file describes the dependency relationships that exist between various program modules. The dependencies in the description file have the form
The first line is called a dependency and the second line is called a rule. The first character on a rule line must be the TAB character. One or more rule lines may follow a dependency.
Example 1:
The executable mine depends on the object files mine.o and
minelib.o. The following segment describes that dependency relationship.
Example 2:
In more complicated situations, a given target can depend on components
that are themselves targets. The following makefile description file has
three targets.
Here is illustration of a session involving the make utility:
$ atrium7:/users4/st/mgorenbu/cis60.1> ls -l
-rw------- 1 mgorenbu cis 121 Feb 18 00:06 Makefile
-rwx--x--x 1 mgorenbu cis 7084 Feb 18 00:07 my
-rw-r--r-- 1 mgorenbu cis 411 Feb 18 00:04 my.c
-rw------- 1 mgorenbu cis 1976 Feb 18 00:05 my.o
-rw-r--r-- 1 mgorenbu cis 102 Feb 17 23:46 myinc.h
-rw-r--r-- 1 mgorenbu cis 269 Feb 18 00:05 mylib.c
-rw------- 1 mgorenbu cis 1276 Feb 18 00:05 mylib.o
$ atrium7:/users4/st/mgorenbu/cis60.1> pico my.c // I change my.c$ atrium7:/users4/st/mgorenbu/cis60.1> ls -l
-rw------- 1 mgorenbu cis 121 Feb 18 00:06 Makefile
-rwx--x--x 1 mgorenbu cis 7084 Feb 18 00:07 my
-rw-r--r-- 1 mgorenbu cis 452 Feb 23 13:44 my.c
-rw------- 1 mgorenbu cis 1976 Feb 18 00:05 my.o
-rw-r--r-- 1 mgorenbu cis 102 Feb 17 23:46 myinc.h
-rw-r--r-- 1 mgorenbu cis 269 Feb 18 00:05 mylib.c
-rw------- 1 mgorenbu cis 1276 Feb 18 00:05 mylib.o$ atrium7:/users4/st/mgorenbu/cis60.1> make
acc -c my.c
acc -o my my.o mylib.o$ atrium7:/users4/st/mgorenbu/cis60.1> ls -l
-rw------- 1 mgorenbu cis 121 Feb 18 00:06 Makefile
-rwx--x--x 1 mgorenbu cis 7128 Feb 23 13:45 my // my - new executable
-rw-r--r-- 1 mgorenbu cis 452 Feb 23 13:44 my.c // my.c was recompiled
-rw------- 1 mgorenbu cis 2056 Feb 23 13:45 my.o // my.o was recompiled
-rw-r--r-- 1 mgorenbu cis 102 Feb 17 23:46 myinc.h // myinc.h was not recompiled
-rw-r--r-- 1 mgorenbu cis 269 Feb 18 00:05 mylib.c // myinc.c was not recompiled
-rw------- 1 mgorenbu cis 1276 Feb 18 00:05 mylib.o // myinc.o was not recompiled
The following materials were used in creating the page:
Michael Gorenburg