Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect use of $ when getting relative directory #4

Closed
m8pple opened this issue Oct 26, 2015 · 3 comments
Closed

Incorrect use of $ when getting relative directory #4

m8pple opened this issue Oct 26, 2015 · 3 comments

Comments

@m8pple
Copy link
Contributor

m8pple commented Oct 26, 2015

Somebody pointed out (sorry, I've forgotten who), that there is a problem in the
instructions for getting the relative directory. What I've suggested is doing this:

./configure --prefix="$(pwd)/../../local"

This works fine in the shell, but what I didn't consider is what happens inside
the makefile.

Inside the makefile, $ means "macro expansion", and $(X) means look
for makefile variable called X. I managed to introduce this bug as a
regression in this commit: d43cbb6. The aim was to make things simpler, but I didn't test properly.

Potential solutions are:

Use back-tick syntax

In the shell, the syntax:

`pwd`

is equivalent to

$(pwd)

so you can use:

./configure --prefix="`pwd`/../../local"

in the makefile or on the command line.

Use shell from within the makefile

There is a function called shell in makefiles which will
call a function in the shell. So this:

$(shell pwd)

will work within the makefile. However, it will not work on
the shell. So in the makefile you can use something like:

./configure --prefix="$(shell pwd)/../../local"

Use the abspath function in the makefile

There is also a function called abspath within make, which uses
an internal function (not the shell) to get an absolute path. You
can used this as something like:

$(abspath ../../local)

to get the path of a file. So the makefile command becomes:

./configure --prefix="$(abspath ../../local)"
@cianyleow
Copy link

@m8pple your help file on the slightly nicer version of the command has an extra ')' at the end before the double quotes.

@SzeKiatTan
Copy link

I used $(CURDIR) and it seems to work in the makefile. Just wondering if it is a legitimate usage?

@m8pple
Copy link
Contributor Author

m8pple commented Oct 29, 2015

Yes, you're right CURDIR works too. In fact it's probably a
better solution than my suggestions when working in the
makefile. I'll note it in the main readme.

@m8pple m8pple closed this as completed in 0c91ddf Oct 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants