Red Hat ENTERPRISE LINUX 3 - DEVELOPER TOOLS GUIDE Manuale Utente Pagina 13

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 24
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 12
Chapter 2. Basic Principles of the Tools 9
makefile. The makefile has rules which explain how and when to remake certain files that are the
targets of a particular rule. A simple makefile rule has the following form:
target... : dependency... command
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. make activates commands on the dependencies to create or to
update the target. A rule can also explain how and when to activate a command. A makefile can
contain other text besides rules; a simple makefile requires only rules. Rules generally follow the
same pattern.
Note that every command line in a makefile must begin with a tab character.
2.10.1. Example Makefile
edit : main.o kbd.o command.o display.o 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
The targets in the example makefile include the executable file, edit, and the main.o and kbd.o
object files. main.c and defs.h are the dependency files. Each .o file is both a target and a depen-
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 Makefile, edit
Vedere la pagina 12
1 2 ... 8 9 10 11 12 13 14 15 16 17 18 ... 23 24

Commenti su questo manuale

Nessun commento