0

I am trying to create a Makefile with target file name = folder name. Instead of hard coding it I used the function

FILE=$(PWD##*/)

I also tried FILE=$(echo PWD##*/) and FILE=$(echo $(PWD##*/)). But I am getting an error: un-terminated variable reference. I know it's difficult to do such variable manipulations in Makefile. Is there a work around?

Thanks

1
  • To clarify Andrew Gillis's answer below, makefiles are not shell scripts, and you can't use shell script syntax directly when assigning makefile variables. The ##*/ syntax works with shell variables, inside shell scripts. It won't work with make variables, within makefiles. Commented Oct 13, 2017 at 17:40

1 Answer 1

1

Setting FILE like this should work:

FILE = $(notdir $(PWD))

An alternative is to call out to shell to do the same:

FILE = $(shell basename $${PWD})
Sign up to request clarification or add additional context in comments.

4 Comments

It worked the first time but when I tried re running it : it says Circular reference , dependency dropped.
generally that means a target has a dependency, and that dependency has a dependency on the target
Put another way, that error has nothing to do with this issue and you haven't shown any part of your makefile that would help diagnose it. You should try to figure it out yourself and if you can't, open a new question with more details of your makefile related to the lines referenced in the error message from make.
Also, the quoting above is wrong: you should be using $${PWD} not \${PWD}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.