GNU make 3.81:eval函数不起作用?

use*_*105 12 makefile eval

我最近从GNU make文档中找到了这段代码,它引用了eval函数.我真的很喜欢它,但是当我尝试在我的机器上测试它(make 3.81/Debian)时,它所做的只是尝试链接服务器而不首先编译c文件...为什么?make 3.81不兼容吗?

壳牌产量:

$ make
cc     -o server
cc: no input files
Run Code Online (Sandbox Code Playgroud)

码:

 PROGRAMS    = server client

 server_OBJS = server.o server_priv.o server_access.o
 server_LIBS = priv protocol

 client_OBJS = client.o client_api.o client_mem.o
 client_LIBS = protocol

 # Everything after this is generic

 .PHONY: all
 all: $(PROGRAMS)

 define PROGRAM_template =
  $(1): $$($(1)_OBJS) $$($(1)_LIBS:%=-l%)
  ALL_OBJS   += $$($(1)_OBJS)
 endef

 $(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))

 $(PROGRAMS):
         $(LINK.o) $^ $(LDLIBS) -o $@

 clean:
         rm -f $(ALL_OBJS) $(PROGRAMS)
Run Code Online (Sandbox Code Playgroud)

Bet*_*eta 19

我认为如果你=define线上移除它将会起作用:

define PROGRAM_template
  ...
endef
Run Code Online (Sandbox Code Playgroud)

我用GNUMake 3.81进行了测试.至于为什么这个工作而且手册中的版本没有,我不知道.

  • 问题是`=`是GNU make 3.82中添加的一个功能,而GNU make手册(包括gnu.org上的副本,谷歌将向大多数人发送的内容)在某个功能特定的时候没有给出任何细微的暗示3.82.比较http://developer.apple.com/library/mac/#documentation/developertools/gnumake/make_3.html#SEC22(381),http://www.gnu.org/software/make/manual/html_node/Reading -Makefiles.html#Reading-Makefiles(3.82) (14认同)