Ancurio
Ancurio

Reputation: 1728

Makefile variable assignment: 'include' not allowed as variable?

On my Fedora15 box, I can write Makefiles like this:

app  = MyApplication
deps = `pkg-config ...`

which works perfectly fine. However, whenever I tried executing such Makefiles on Debian machines, I got errors apparently because of the whitespace around '='. So rewriting them like this:

app=MyApplication
deps=`pkg-config ...`

fixes it. Now my question is, how is this incompatibility caused? My Fedora make is version 3.82, whereas my Debian one is 3.81. Searching the Changelog of make didn't reveal any changed which would make this possible either..

EDIT:

I seem to have found the cause for this weird behavior: In most of my makefiles, I usually use the variable "include" to hold all the pkg-config outputs. Now apparently 'include' is some sort of keyword, which, when not used like this on Debian

include="stuff"

triggers a macro, looking for a path or something. If I use it as shown above, I can use it as a normal variable. But now the interesting part is: I can always use 'include' as a variable name on Fedora! Therefore lines like this:

include = `pkg-config --blah`

worked perfectly under Fedora, but always failed under Debian spitting out lines of "Makefile:2: =: No such file or directory" (it was expetcing the '=' and everything else to be paths apparently)

Now my question still stands however why I can do such things on Fedora (why the 'include macro doesn't seem defined there) but not on Debian?

Upvotes: 0

Views: 375

Answers (1)

Reinier Torenbeek
Reinier Torenbeek

Reputation: 17383

Now my question still stands however why I can do such things on Fedora (why the 'include macro doesn't seem defined there) but not on Debian?

The different behavior is not caused by the difference in distributions of Linux, but by the difference in the make versions in those distribution. If you have whitespace(s) after include, before = (or any other assignment flavor), 3.81 will incorrectly parse it as an include directive.

The same holds for other directives, like for example vpath. In 3.81, assigning a value to a variable named vpath does not work if you have a space before the =, the variable vpath will not be defined. In 3.82, that was fixed -- if you want to call it that way :-) I would prefer make to complain about these variable names in any case.

Upvotes: 1

Related Questions