Makefile macros - dependency to shell

Paweł Sakowski pawel at sakowski.eu.org
Tue Sep 21 16:15:15 CEST 2004


On Tue, 2004-09-21 at 15:01 +0200, maHo wrote:
> [root at tereska /tmp]# make
> echo ""
> 

man sh says:

>        The following parameters are set and/or used by the shell:
> [...]
>        PWD    The  current  working  directory.   Maybe unset or null if shell
>               doesn't know where it is.
> [...]
>        Parameters  with  the export attribute (set using the export or typeset
>        -x commands, or by parameter assignments followed by  simple  commands)
>        are  put  in  the  environment  (see environ(5))

Which doesn't imply that $PWD gets exported. Indeed,

$ su -s/bin/ksh - saq
Password:
$ cat printpwd.c
#include <stdlib.h>
#include <stdio.h>
int main(){printf("%s\n",getenv("PWD"));return 0;}
$ ./a.out
(null)

proves that ksh only sets it as an internal variable. 

Make's $(PWD) construct depends on environment variables, not shell
expansion. If you want to use sh's understanding of $PWD, use:

$ cat Makefile
dupa:
        echo "$$PWD"
$ make
echo "$PWD"
/tmp

Ergo: both make and ksh work properly. It's your Makefile that sucks.

P.S.: in all cases except `su -` the env var PWD got inherited from the
bash process

P.P.S.: it has nothing to do with being root, `su - saq` gives the same
behavior as `su - root`.

-- 
+----------------------------------------------------------------------+
| Paweł Sakowski <pawel at sakowski.eu.org>            Never trust a man  |
|                            who can count up to 1023 on his fingers.  |
+----------------------------------------------------------------------+






More information about the pld-devel-en mailing list