-1

Could anyone please explain why following:

export PATH:=$(PATH):~/bin2
B:=$(shell PATH=$(PATH) testXq.sh)
$(warning $(B))

Is working properly showing results of run of the ~/bin2/testXq.sh, while following:

export PATH:=$(PATH):~/bin2
B:=$(shell testXq.sh)
$(warning $(B))

Returns an error:

make: testXq.sh: Command not found

I am on gmake v4.0

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
gena2x
  • 2,397

2 Answers2

1

I realized that this is duplicate to https://stackoverflow.com/questions/2838715/makefile-variable-initialization-and-export

Which seems a bug in make https://savannah.gnu.org/bugs/?10593 .

gena2x
  • 2,397
  • It does not look like a bug in gmake. Note that this is completely non-portable stuff that regires gmake. – schily May 10 '16 at 09:41
  • It is: 1. Bug report exist. 2. Behaviour is not documented. 3. This question about gmake, and that is clear from the title. Why you talking about portability? – gena2x May 10 '16 at 12:48
-1

It is most unlikely that gmake expands the tilde character, so the tilde remains in the PATH.

The shell however later expands the tilde when the PATH string is passed to the shell again.

Besides the fact that gmake does not expand the tilde character, there is another problem:

  • gmake seems to implement the export keyword only for "normal" shell commands that are run from rules (shell commands after a TAB inserted text).

This is not the first time when gmake causes problems with it's non-orthogonal implementation. Gmake e.g. claims to run on OpenVMS but the $(shell cmd) method does not work on OpenVMS.

schily
  • 19,173
  • No that's entirely not the case, entire PATH seems not propagated. – gena2x May 10 '16 at 09:03
  • But with a tilde inside and that tilde gets expanded to $HOME later in the shell in case you add PATH=$(PATH). – schily May 10 '16 at 11:23
  • Yes, so there is totally no problem with expansion. – gena2x May 10 '16 at 12:10
  • So you now understand my answer that explains why you need to pass the PATH= assignment to the shell? – schily May 10 '16 at 12:17
  • And you seem missed, totally, that is the problem here. Observed behavior is because any variable is not propagated to shell's environment automatically. If you do $(shell var=$(var) command) you just execute string in shell 'var=value_of_gmake_var command' which is interpreted by shell as 'set var to value_of_gmake and execute command', so that effectively propagation of single variable. Hope now it is clear? – gena2x May 10 '16 at 12:53
  • Really, I naturally hate saying 'you wrong' especially to the person who trying to help you. Sorry. – gena2x May 10 '16 at 12:55
  • OK, so you do not grok anything here :-( The shell in your first case sees something like: PATH=abc:~/bin2 and the shell of course expands a tilde in a variable assignment when it appears after a colon – schily May 10 '16 at 13:24
  • I tested, you right, it does expand, but that still has no relation to the question, because if I do makefile with
    export PATH=~/bin \n
    A=$(shell env | grep PATH) \n
    $(warning $(A)) \n
    
    

    It would not print path with ~. Test it, and you understand why your answer is, while holding truth about expansions, is wrong explanation of the problem. I also removed my comment that shell don't expand tilde, because it was wrong statement.

    – gena2x May 10 '16 at 13:42
  • OK, it may be that gmake does not correctly "export" variables. Besides the fact that gmake does not expand the tilde character, it does not export "exported" variables to the shell. – schily May 10 '16 at 14:13