Simon Klaver
Simon Klaver

Reputation: 528

Makefile says target is empty but it shouldn't be

I am trying to have a Makefile which is able to use different instances of g++ based on whether I give along a certain target or not. So: If I run make home I want CC to be the g++ executable in /usr/bin, and otherwise in some long path <longpath>/bin.
So I tried checking for my target:

ifeq ("$(TARGET)", "home")
    GCCPATH = /usr
    HSPARG = home
endif

$(info "$(TARGET)")
$(info "$@")

GCCPATH ?= <longpath>
CC = $(GCCPATH)/bin/g++
GCCLIBPATH = $(GCCPATH)/lib64

However, the outcome of this is:

$ make home
""
""
<further build information>

and GCCPATH is in all occasions equal to <longpath>.

Now my questions are:
1. What do I do wrong?
2. How to fix it?

Upvotes: 1

Views: 60

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 80921

First of all, make home doesn't set TARGET to home. So you have to execute make TARGET='home' to set it.

Secondly, make cares about spaces, including spaces after commas. So when you wrote ifeq ("$(TARGET)", "home"), make didn't toss away the space after the comma like you might have expected. So what make ended up comparing was "home" and " home".
You can see this by running make TARGET=' home' and seeing what you get. Remove that space and you'll fix the problem.

That said all your quoting isn't doing anything for make either. It doesn't generally care. Quotes are just literal characters to make in almost all places (except in ifeq "arg1" "arg2" cases, etc. and maybe one or two other places but I can't think of any offhand), so you don't need them in the calls to $(info) or even in your ifeq test since you are using the ifeq (arg1,arg2) version.

Upvotes: 2

Related Questions