2012-11-06 32 views
11

我最近從GNU make文檔中找到了一段代碼,它引用了eval函數。我真的很喜歡它,但是當我試圖在我的機器上測試它(製作3.81/Debian)時,它所做的只是試圖鏈接服務器而不先編譯c文件...爲什麼?是不是兼容?GNU make 3.81:eval函數不工作?

殼牌輸出:

$ make 
cc  -o server 
cc: no input files 

代碼:

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 [email protected] 

clean: 
     rm -f $(ALL_OBJS) $(PROGRAMS) 

回答

18

我想如果你從define線取下=它將工作:

define PROGRAM_template 
    ... 
endef 

我測試過這與GNUMake 3.81。至於爲什麼這個作品和手冊中的版本沒有,我不知道。

+0

謝謝,這工作。奇怪他們爲什麼錯誤地記錄它。 – user1344105

+14

問題在於'='是GNU make 3.82中添加的一個特性,GNU make手冊(包括gnu.org上的副本,Google會向大多數人發送)不會在功能特定時提供絲毫暗示到3.82。使用http://www.gnu.org/software/make/manual/html_node/Reading比較http://developer.apple.com/library/mac/#documentation/developertools/gnumake/make_3.html#SEC22(3.81) -Makefiles.html#Reading-Makefiles(3.82) – reinierpost

+0

非常感謝您的解釋! – user1344105