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