GNU make manual 翻译(六十六)

继续翻译

 .SECONDEXPANSION:                        
     main_OBJS := main.o try.o test.o                        
     lib_OBJS := lib.o api.o                        
                        
     main lib: $$($$@_OBJS)                        
                        
   Here, after the initial expansion the prerequisites of both the `main' and `lib' targets will be `$($@_OBJS)'.  During the secondary expansion, the `$@' variable is set to the name of the target and so  the expansion for the `main' target will yield `$(main_OBJS)', or  `main.o try.o test.o', while the secondary expansion for the `lib' target will yield `$(lib_OBJS)', or `lib.o api.o'.                        

.SECONDEXPANSION:

main_OBJS :=main.o try.o test.o

lib_OBJS:= lib.o api.o

main lib: $$ ($$@_OBJS)

这里,在对main 和 lib 的目的的前提条件进行了初始的扩展后,得到了 $($@_OBJS)。

在第二次扩展的时候,$@变量指向 目的的名字,于是对目的main的扩展导致了 $(main_OBJS),进而变成了  main.o try.o test.o, 对 目的lib 的扩展,导致了 $(lib_OBJS), 进而变成了 lib.o api.o。

(下面一小段是我自己加的标注)

$$($$@_OBJS) 在第一次扩展后,变化为:

$($@_OBJS)
对照 main lib  $ ($@_OBJS)
其实是:
main : $($@_OBJS) 和 lib: $($@_OBJS)

由于 $@代表了冒号左边,所以演化为:
main: $(main_OBJS) 和 lib: $(lib_OBJS)

由于前面定义了 $(main_OBJS)和 $(lib_OBJS)

所以进一步地,转化为:

main: main.o try.o test.o
lib:   lib.o api.o

后文待续

原文地址:https://www.cnblogs.com/gaojian/p/2688572.html