Discussion:
Extraneous text after `else' directive
Michael Morrell
2010-06-12 02:14:39 UTC
Permalink
Given the following Makefile:

--------------------------
ifdef FOO
XYZ = 1
else ifeq ("$(BAR)", "abc")
XYZ = 2
else
XYZ = 3
endif

all:
@echo $(XYZ)
--------------------------

It works as expected:

% FOO=a make
1
% BAR=abc make
2
% make
3

If, however, I "break" it by deleting the space after "ifeq":

--------------------------
ifdef FOO
XYZ = 1
else ifeq("$(BAR)", "abc")
XYZ = 2
else
XYZ = 3
endif

all:
@echo $(XYZ)
--------------------------

I get:

% FOO=a make
Makefile:3: Extraneous text after `else' directive
1
% BAR=abc make
Makefile:3: Extraneous text after `else' directive
2
% make
Makefile:3: Extraneous text after `else' directive
2

Two questions.

1) Is it just me, or is the manual not that clear that a space after
"ifeq" is required?

2) Is there a way to have this case cause make to fail (return an exit
status of 1)? The note about "Extraneous text" is easy to miss in a
large Makefile output file.

Thanks,

Michael
Paul Smith
2010-06-12 03:29:56 UTC
Permalink
Post by Michael Morrell
--------------------------
ifdef FOO
XYZ = 1
else ifeq("$(BAR)", "abc")
XYZ = 2
else
XYZ = 3
endif
% FOO=a make
Makefile:3: Extraneous text after `else' directive
1
1) Is it just me, or is the manual not that clear that a space after
"ifeq" is required?
Well, it doesn't say so explicitly however all the examples and the
section that defines the syntax ("Syntax of Conditionals") use
whitespace.
Post by Michael Morrell
2) Is there a way to have this case cause make to fail (return an exit
status of 1)? The note about "Extraneous text" is easy to miss in a
large Makefile output file.
There is no way to do that currently (except changing the source of
course). However, maybe it's not a bad idea to make this a fatal syntax
error rather than a warning / informational note.
--
-------------------------------------------------------------------------------
Paul D. Smith <***@gnu.org> Find some GNU make tips at:
http://www.gnu.org http://make.mad-scientist.net
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
Loading...