Question

I have a makefile that used to work with make 3.80. Now I updated to 3.81 and I obtain the following error:

Makefile:185: *** invalid syntax in conditional.  Stop.

Line 185 corresponds to:

ifdef $(FDEP_FILES)

A few lines above I define FDEP_FILES

FDEP_FILES   += $(addsuffix .df, $(TEST_BASENAMES_FC))

and

TEST_BASENAMES_FC      += $(basename  $(shell ls *.fc  2> /dev/null ))

The makefile works when there is only one .fc file in the folder, while it fails in case of multiple makefile.

Was it helpful?

Solution

If what you want to is determine whether FDEP_FILES is defined then the test should be:

ifdef FDEP_FILES

The reason it fails when you have more than one file is that $(FDEP_FILES) will be expanded to its value and then ifdef will test whether the variable named with this value is defined. Since the value is not a valid variable name, you get an error.

But note that ifdef will consider a variable with an empty string as a value as being defined. With the code you've shown us, I'm not convinced that you won't end up with an empty string under some circumstances. You should consider testing with ifneq ($(strip $(FDEP_FILES)),). With this test, the branch will be taken only if FDEP_FILES has a non-empty string as value.

OTHER TIPS

I don't know what you thought the old version of make was doing, but it was not doing that.

The ifdef construct takes a variable name as an argument. You are passing it a variable value. If you have this:

FOO = bar

ifdef $(FOO)

then you're actually testing whether the make variable bar is defined or not. If you want to know whether the make variable FOO is defined, you don't want to expand it:

ifdef FOO

In your situation you have a variable whose value has multiple words separated by spaces:

FOO = bar baz

In this case, in previous versions of make ifdef $(FOO) would not throw an error because make used to allow spaces in variable names, so make would check if the variable bar baz was defined or not--not what you wanted, but not a syntax error.

In the newer versions of GNU make, variable names cannot contain whitespace, so this:

ifdef bar baz

is now a syntax error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top