GNU make manual 翻译( 一百零二)

继续翻译

   A phony target should not be a prerequisite of a real target file;if it is, its recipe will be run every time `make' goes to update that file.  As long as a phony target is never a prerequisite of a real target, the phony target recipe will be executed only when the phony target is a specified goal (*note Arguments to Specify the Goals:

Goals.).



   Phony targets can have prerequisites.  When one directory contains multiple programs, it is most convenient to describe all of the programs in one makefile `./Makefile'.  Since the target remade bydefault will be the first one in the makefile, it is common to make this a phony target named `all' and give it, as prerequisites, all the individual programs.  For example:



     all : prog1 prog2 prog3

     .PHONY : all



     prog1 : prog1.o utils.o

             cc -o prog1 prog1.o utils.o



     prog2 : prog2.o

             cc -o prog2 prog2.o



     prog3 : prog3.o sort.o utils.o

             cc -o prog3 prog3.o sort.o utils.o

一个伪目的不应当是一个真的目的的前提条件;如果是,它的片段将会在每次运行make 时被执行。正因为伪目的永远不会是一个真正的目的,所以伪目的的片段才能在仅当其为特殊终点时才获得运行。(*note Arguments to Specify the Goals:Goals)

伪目的自身可以有前提条件。当一个目录包含多个程序,把所有的程序均包含到一个 ./Makefile中是最为方便的。因为缺省的目的重建会针对第一个目的,把此目的命名为伪目的 all ,让它拥有所有其他单独的程序作为前提条件。例如:

all : prog1 prog2 prog3
.PHONY : all

prog1 : prog1.o utils.o
cc -o prog1 prog1.o utils.o

prog2 : prog2.o
cc -o prog2 prog2.o

prog3 : prog3.o sort.o utils.o
cc -o prog3 prog3.o sort.o utils.o

 后文待续

你可能感兴趣的:(Make)