f78
A Simple Makefile
To use the previous sample makefile to create the executable file called ‘
To use this makefile to delete the executable file and all the object files
from the directory, type:
In the sample makefile shown in
When a target is a file, it needs to be recompiled or relinked if any of its
dependencies change. In addition, any dependencies that are themselves
automatically generated should first be updated. In the previous example,
A shell command follows each line that contains a target and dependencies.
These shell commands say how to update the target file. A tab character must come
at the beginning of every command line to distinguish commands lines from other
lines in the makefile. (Bear in mind that
The target
insert.o search.o files.o utils.o
cc -o edit main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
main.o : main.c defs.h
cc -c main.c
kbd.o : kbd.c defs.h command.h
cc -c kbd.c
command.o : command.c defs.h command.h
cc -c command.c
display.o : display.c defs.h buffer.h
cc -c display.c
insert.o : insert.c defs.h buffer.h
cc -c insert.c
search.o : search.c defs.h buffer.h
cc -c search.c
files.o : files.c defs.h buffer.h command.h
cc -c files.c
utils.o : utils.c defs.h
cc -c utils.c
clean :
rm edit main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
We split each long line into two lines using backslash-newline (\); this is like using one long line, but is easier to read.