Example Makefile - Red Hat ENTERPRISE LINUX 3 - DEVELOPER TOOLS GUIDE Manual

Developer tools guide
Hide thumbs Also See for ENTERPRISE LINUX 3 - DEVELOPER TOOLS GUIDE:
Table of Contents

Advertisement

Chapter 2. Basic Principles of the Tools
target is usually the name of a file that a program generates; examples of targets are executable or
object files. A target can also be the name of an action to carry out, such as with the clean command (a
command that, deletes all files from a build directory before building). A dependency is a file that
is used as input to create the target. A target often depends on several files. command is activated by
make wnen dependancy has changed. A rule may have more than one command, with each command
on its own line. Usually a command is in a rule with dependencies and serves to create a target file if
any dependencies change. However, the rule that specifies commands for the target does not require
dependencies; for instance, the rule containing the delete command that associates with the target,
clean, does not have dependencies.
update the target. A rule can also explain how and when to activate a command. A
contain other text besides rules; a simple
same pattern.
Note that every command line in a
2.10.1. Example
edit : main.o kbd.o command.o display.o insert.o search.o \
cc -o edit main.o kbd.o command.o display.o insert.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 \
The targets in the example
object files.
main.c
dency. When a target is a file, it needs to be recompiled or relinked if any of its dependencies change.
You must first update any dependencies that automatically generate. In the example
depends on eight object files; the object file,
the
header file. A shell command follows each line that contains a target and dependencies,
defs.h
saying how to update the target file; a tab character must come at the beginning of every command line
to distinguish command lines from other lines in the
make
makefile
Makefile
files.o utils.o
search.o files.o utils.o
search.o files.o utils.o
include the executable file,
makefile
and
are the dependency files. Each
defs.h
activates commands on the dependencies to create or to
requires only rules. Rules generally follow the
makefile
must begin with a tab character.
, depends on the source file,
main.o
makefile
, and the
edit
main.o
file is both a target and a depen-
.o
Makefile
.
does not know anything about
make
9
can
makefile
and
kbd.o
,
edit
, and on
main.c

Advertisement

Table of Contents
loading

Table of Contents