make: make Deduces

1 
1 2.5 Letting 'make' Deduce the Recipes
1 =====================================
1 
1 It is not necessary to spell out the recipes for compiling the
1 individual C source files, because 'make' can figure them out: it has an
1 "implicit rule" for updating a '.o' file from a correspondingly named
1 '.c' file using a 'cc -c' command.  For example, it will use the recipe
1 'cc -c main.c -o main.o' to compile 'main.c' into 'main.o'.  We can
11 therefore omit the recipes from the rules for the object files.  ⇒
 Using Implicit Rules Implicit Rules.
1 
1    When a '.c' file is used automatically in this way, it is also
1 automatically added to the list of prerequisites.  We can therefore omit
1 the '.c' files from the prerequisites, provided we omit the recipe.
1 
1    Here is the entire example, with both of these changes, and a
1 variable 'objects' as suggested above:
1 
1      objects = main.o kbd.o command.o display.o \
1                insert.o search.o files.o utils.o
1 
1      edit : $(objects)
1              cc -o edit $(objects)
1 
1      main.o : defs.h
1      kbd.o : defs.h command.h
1      command.o : defs.h command.h
1      display.o : defs.h buffer.h
1      insert.o : defs.h buffer.h
1      search.o : defs.h buffer.h
1      files.o : defs.h buffer.h command.h
1      utils.o : defs.h
1 
1      .PHONY : clean
1      clean :
1              rm edit $(objects)
1 
1 This is how we would write the makefile in actual practice.  (The
1 complications associated with 'clean' are described elsewhere.  See
1 ⇒Phony Targets, and ⇒Errors in Recipes Errors.)
1 
1    Because implicit rules are so convenient, they are important.  You
1 will see them used frequently.
1