In a GNU Makefile, I am defining the contents of a temporary file using multi-line variable syntax as follows:
define __FOO__
file
with
many
lines
endef
This file happens to be a GDB script, which supports function definitions with the following syntax:
define my-func
foo
end
I suppose you see the problem already:
define __FOO__
define my-func
foo
end
endef
make
pukes with the following error:
Makefile:218: *** missing 'endef', unterminated 'define'. Stop.
In the link I posted above, GNU confidently explains the feature:
You may nest define directives: make will keep track of nested directives and report an error if they are not all properly closed with endef. Note that lines beginning with the recipe prefix character are considered part of a recipe, so any define or endef strings appearing on such a line will not be considered make directives.
So if I heed that advice and insert the recipe prefix character (\t
) at the beginning of each line:
define __FOO__
define my-func
foo
end
endef
It happily parses this, but now __FOO__
has a leading \t
at the front of every line when I write it to file in a recipe:
foo:
@echo $$__FOO__ > my-file
$ cat my-file
define my-func
foo
end
This may be OK in many cases, but I can imagine it leads to some potentially ambiguous content, which I would rather not enjoy debugging next year.
How should I be handling this — including a string with a leading define
, and not have leading tabs in the output?