[ACCEPTED]-Defining custom GNU make functions-gnu-make

Accepted answer
Score: 11

You forgot the =:
define dep2 =

EDIT:
Put a semicolon at the end of each line. I've 7 tested this and it works (in GNUMake 3.81).

define dep2
$(eval makefile_list_$1 := $(MAKEFILE_LIST));
$(eval -include $1.mk);
$(eval MAKEFILE_LIST := $(makefile_list_$1));
endef

Why these 6 semicolons are necessary I don't know, but 5 in the documentation define seems to be used for 4 multi-line "variables" only when defining 3 sequences of shell commands to be used in 2 recipes, not Make commands, so maybe the 1 rules are a little different.

Score: 3

I would move the $(eval ...) calls outside of dep2. By 9 doing it this way, there's no need for semicolons 8 in dep2. This means doubling the $ signs of some 7 expansions to avoid expansion being done 6 too early. So:

define dep2
makefile_list_$1 := $$(MAKEFILE_LIST)
-include $1.mk
MAKEFILE_LIST := $$(makefile_list_$1)
endef

$(eval $(call dep2,test))

# Quick checks for testing, to be removed from the final code...
$(info $(makefile_list_test))
$(info $(MAKEFILE_LIST))

.DEFAULT_TARGET: all
.PHONY: all
all:
    @echo $@

I've tested the code above 5 and it works with Gnu Make 4.0. I would 4 expect it to work back to Gnu Make 3.8x. The 3 $(eval $(call ...)) pattern is what I always do to execute 2 my custom functions, and I've used it for 1 quite a while now.

Score: 0

You can do as the below line to kill the 4 error:

FOO := $(call dep2, test)

I guess the reason is the early version 3 of gcc (3.8.1/2) can only accept nothing 2 as the return of expression.

eg $(info string) returns 1 nothing, but $(call dep2, test) returns 2 newlines charaters.

More Related questions