bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `cd foo && make` != `make -C foo`


From: Paul Smith
Subject: Re: `cd foo && make` != `make -C foo`
Date: Fri, 10 Nov 2017 11:50:52 -0500

On Fri, 2017-11-10 at 17:36 +0100, Akim Demaille wrote:
> in other words, cd respects my symlinks, but make -C resolves them.

These statements don't make sense to me: what does "respecting a
symlink" mean, and how is it different from "resolving a symlink"?

What I'm assuming you mean is that the pwd command is printing the
fully-resolved path in one case and not in the other case.

In both cases, the symlink is followed and you end up at the same
place.  There's no way to determine, after you've changed directories,
which one of all the possible ways you might have arrived there so
clearly the choices are to either print the one canonical path from the
root to the current directory, or else get "outside help" to let you
know which path you took.

So, this is a feature of pwd, it's not related to make.  From the pwd
man page:

> pwd: pwd [-LP]
>     Print the name of the current working directory.
> 
>     Options:
>       -L        print the value of $PWD if it names the current working
>                 directory
>       -P        print the physical directory, without any symbolic links
> 
>     By default, `pwd' behaves as if `-L' were specified.

Note the final sentence.  Basically, by default `pwd` prints the value
of the shell $PWD variable (if it's not wrong).  If you change your pwd
invocations in your test to "pwd -P" you'll see you always get the same
results no matter how you invoke make.  So, in this case:

  cd bar && make

the shell is changing directories and the shell maintains the PWD
environment variable, so $PWD is set and pwd will print that value.  In
this case:

  make -C bar

make is changing directories, and make doesn't do anything special with
the PWD environment variable which means pwd runs as "pwd -P" in this
case.

> It turns out that on the project I work on, due to specific layout
> constraints (golang trees…) resolving the symlink breaks everything.

This is bad behavior on the part of your build system, but if you want
to avoid fixing it and instead work around it, and you want to use
"make -C", you can set PWD yourself:

    PWD="$PWD/bar" make -C bar



reply via email to

[Prev in Thread] Current Thread [Next in Thread]