hepsut
hepsut

Reputation: 13

Make extra newline in prerequisite in define recipe

I am trying to create a Makefile which uses a recipe created using the define syntax. However, I have run into a problem where Make believes that the last prerequisite has a newline appended to it, resulting in a "no rule found" error. A minimal working example is given below, the problem is triggered by trying to make the foo/bar target.

foo:
    mkdir foo

define FIZZ
foo/bar: foo
    touch foo/bar
endef

$(call FIZZ)

The exact error message is

make: *** No rule to make target 'foo
', needed by 'foo/bar'. Stop.

I have tried versions 4.1 and 4.2.1 of GNU Make. Can anyone tell me what I am doing wrong (or is this a bug)?

Upvotes: 1

Views: 135

Answers (1)

Mike Kinghan
Mike Kinghan

Reputation: 61550

What you are trying to do here is expand the variable FIZZ to inject the definition of the target foo/bar (its prerequisites and recipe) into the expanded makefile. $(call FIZZ) is not the tool for that:

$(call variable,param,param,...)

may behave surprisingly if the arguments contain embedded whitespace. You want 8.9 The eval Function, as in:

Makefile

foo:
    mkdir foo

define FIZZ
foo/bar: foo
    touch foo/bar
endef

$(eval $(FIZZ))

Then you'll get:

$ make foo/bar
mkdir foo
touch foo/bar

Upvotes: 0

Related Questions