1

I have the following (very simplified) Makefile:

# Makefile MAKESH=shell USER=$($MAKESH logname) 

which aims to store my login name in the USER variable as if the $(shell logname) command was invoked. However this doesn't happen. I suspect that it's due to the way make evaluates variables.

Does anyone have some more insight to this or a possible workaround i.e. explicitly tell make that $MAKESH is actually the shell command?

Thanks.

Edit

Consider the following example:

#parent.mk ... include child.mk ... ------------------- #child.mk export $(shell logname)/path1 export $(shell logname)/path2 ------------------- #bash_script.sh ... source child.mk ... 

(in this example, sourcing child.mk fails)

Essentially, what I wanted to do is to create a file that exports pathnames depending on the current user. The syntax should be valid both for makefiles and bash scripts, since it can be included/sourced from both places.

I also wanted to do subtle changes to these files, since they are part of a larger project and the interconnections are a bit confusing.

I have finally decided to go with this:

#parent.mk ... export logname=$(shell logname) include child.mk ... ------------------- #child.mk export $(logname)/path1 export $(logname)/path2 ------------------- #bash_script.sh ... source child.mk ... 

which is quite hacky, a tiny bit dangerous, but works. If you know a more elegant way/aprroach, let me know.

Finally, thank you for your solutions (and your warnings), which are valid for the pre-editted question.

2
  • Why would you want this? BTW it is not the shell command, but the shell function. Commented Jan 28, 2013 at 16:48
  • the variable USER will not be evaluated until it is used. If you want to get it evaluated immediately use the form := for the assignment Commented Jan 28, 2013 at 17:04

2 Answers 2

5

The syntax should be

USER = $(shell logname) 

I don't know why you want to put "shell" in a variable and screw up the function syntax, but if you really insist, try this:

$(eval USER=$$($MAKESH logname)) 

The $(eval ...) function will just turn it into the first form above, though, so it's wasted effort. (Unless your really trying to do something trickier than your example suggests.)

Sign up to request clarification or add additional context in comments.

Comments

2
MAKESH=shell $(eval USER=$$($(MAKESH) logname)) $(info USER is $(USER)) 

Avoid if possible.

1 Comment

Both answers are the same, but this one also includes the very useful $(info) function.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.