Make
is indispensable for managing large programs,
but is useful for smaller programs as well.
As an example, consider a program consisting of the files
main.f, file1.f,
and file2.f
.
Here is a sample makefile to take these three files and generate an
executable called main
.
OBJ = main.o file1.o file2.o .f.o: f77 -c $< main: $(OBJ) f77 -o main $(OBJ)
.f.o:
and main:
begin with a TAB character.
main:
exist.
If any do not exist, make looks
for a rule to create it. In this case, the lines after .f.o
tell it how to make a .o file from a .f file.
Once all the appropriate .o files exist, make
runs
f77 -o main $(OBJ)
to create the executable.
Make
also compares the modification time of the .f file with
that of the
.o file. If the .f file has been modified since it was last compiled,
make
will recompile the
.f file.
In this example, suppose main.f
had been modified.
Make would recompile main.f
, but not file1.f
or file2.f
.
main.f
and file1.f
include a file
param.h
and that we would like these files recompiled if
it changes.
Add the line
main.o file1.o: param.hto the end of the makefile.
man make
,
or see the online
Make manual