Makefile and ifeq

I have encountered a strange problem with make and ifeq evaluations and $@.

I want to set specific link libraries based on the target the user supplies when running make.

So I did the following in my makefile:

Foo = bar
ifeq ($@,$(Foo))
Lib = “Equal”
else
Lib = “Not equal”
endif

Later on my compile line I echo’d out the results as:

@ echo “Results of compare” “<”$@">" “<”$(Foo)">" $(Lib)

So I issue ‘make bar’ on the command line and get an output of:

Results of compare Not Equal.

No matter what I do, the ifeq always evaluates to Not Equal.

Even if I do something like:

Input = $@
Blah = $(filter bar, $(Input))
Foo = bar
ifeq ($(Blah),$(Foo))
Lib = “Equal”
else
Lib = “Not Equal”
endif

It still comes out as Not Equal even tho Blah prints out as ‘bar’.

Now I know that ifeq is not broken because if I do:

Blah = bar
Foo = bar
ifeq ($(Blah),$(Foo))
Lib = “Equal”
else
Lib = “Not Equal”
endif

This does evaluate to Equal.

So I’m very very confused about how Make is treating the $@ parameter when converting it to a string. Esp since it can filter out bar part but yet it can’t make the two strings manage to be equal.

Anyone have any idea what’s up with this?

TIA,

Tim

My guess is you cannot use $@ in a ifeq statement.

As a matter of fact if you do

ifeq ($@,)

you will discover that the result is true, meaning $@ resolves to an empty value.

I don’t understand the rational behind this behavior though. I beleive if statement are performed once, the make is first parsed, hence I don’t think it makes sense to use $@.

Mario,

OK, if $@ doesn’t work (even tho you can assign it to a variable as I did with my statement ‘Input = $@’ and Input was set to the value on the command line I expected which doesn’t seem to reconcile with it having a an empty value) then how do you get args passed into a Make command?

I tried $1 which works for scripts and it’s always blank.

Tim

Try $(MAKECMDGOALS)

Xtang,

Works perfectly!

Thanks,

Tim