GNU make 3.81: eval function not working?

eval, makefile

Solution

I think it will work if you remove the `=` from the `define` line:

define PROGRAM_template
  ...
endef

I've tested this with GNUMake 3.81. As for why this works and the version in the manual doesn't, I have no idea.

Problem

I recently found this piece of example code from the GNU make documentation that refers to the eval function. I really like it, but when I tried to test it on my machine (make 3.81/Debian), all it does is trying to link the server without compiling the c files first ... why? Is make 3.81 not compatible? Shell output: ``` $ make cc -o server cc: no input files ``` Code: ``` 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) ```

Original source