Roland Ver. 4.5 Technické informace Strana 16

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 212
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 15
6 GNU make
Thus, if we change the file insert.c and run make, make will compile that file to update
insert.o, and then link edit. If we change the file command.h and run make, make will
recompile the object files kbd.o, command.o and files.o and then link the file edit.
2.4 Variables Make Makefiles Simpler
In our example, we had to list all the object files twice in the rule for edit (repeated here):
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
Such duplication is error-prone; if a new object file is added to the system, we might
add it to one list and forget the other. We can eliminate the risk and simplify the makefile
by using a variable. Variables allow a text string to be defined once and substituted in
multiple places later (see Chapter 6 [How to Use Variables], page 59).
It is standard practice for every makefile to have a variable named objects, OBJECTS,
objs, OBJS, obj, or OBJ which is a list of all object file names. We would define such a
variable objects with a line like this in the makefile:
objects = main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
Then, each place we want to put a list of the object file names, we can substitute the
variable’s value by writing $(objects) (see Chapter 6 [How to Use Variables], page 59).
Here is how the complete simple makefile looks when you use a variable for the object
files:
Zobrazit stránku 15
1 2 ... 11 12 13 14 15 16 17 18 19 20 21 ... 211 212

Komentáře k této Příručce

Žádné komentáře