Defining custom GNU make functions

Viewed 23444

What is the problem with the dep2 function in the sample code below?

dep1 = $(eval makefile_list_$1 := $(MAKEFILE_LIST))$(eval -include $1.mk)$(eval MAKEFILE_LIST := $(makefile_list_$1))

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

$(call dep1,test)
$(call dep2,test)

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

GNU make 3.81 and 3.82 produce Makefile:10: *** missing separator. Stop. which points to the dep2 call, dep1 is run without errors. The only difference between the two variants is the newlines in dep2 (and the whole point why I'd like to use define).

4 Answers

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

FOO := $(call dep2, test)

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

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

Related