我最近从GNU make文档中发现了这个引用eval函数的示例代码.我真的很喜欢它,但是当我试图在我的机器上测试(make 3.81 / Debian)时,它所做的只是尝试链接服务器,而不是首先编译c文件?为什么?使3.81不兼容吗?
外壳输出:
$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 $@ clean: rm -f $(ALL_OBJS) $(PROGRAMS)