Make is spawning a _new_ shell to source the commands and make the
environment changes. Make itself is not a shell, and cannot source.
See comments inline:

gk wrote:
> 
> I have sourced a function 'xmsubdirs' into my current shell and was
> expecting it to be available from a makefile rule but it is not.
> The Gnu make manual doesn't seem to address this issue; it simply addresses
> the use of shell environmental variables.
> Functions are exported to subshells in bash; why isn't make able to access
> them?
> 
> --- Makefile:
> 
> .PHONY: foo goo boo moo
> 
> boo :
>         @xmsubdirs
> 
> # i tried treating xmsubdirs like a variable
> moo :
>         @$(xmsubdirs)
> 
> foo :
>         @echo $(shell $(xmsubdirs))
> 
> goo :
>         @echo $$(xmsubdirs)
> 
> --- output
> 
> [greg@p3 test]$ xmsubdirs
> foo.html.xm goo junkme moo.xm project

This is what it should do, OK.

> [greg@p3 test]$ make boo
> make: xmsubdirs: Command not found
> make: *** [boo] Error 127

Here, make searches the path for an executable, and cannot find it. If
possible, make can spawn many commands directly, without the overhead of an
intermediate shell, but of course not bash-shell-functions...

> [greg@p3 test]$ make moo
> make: Nothing to be done for `moo'.

The make variable $(xmsubdirs) has never been defined, is therefore empty,
so the reaction is correct.

> [greg@p3 test]$ make foo
> 

Here you're calling the shell without anything (Mind: $(xmsubdirs) is
empty!!), so it produces an empty line, and exits.

> [greg@p3 test]$ make goo
> /bin/sh: xmsubdirs: command not found

Now, here's something. Can you please be more specific on your environment?
I'm especially interested in the shell called here, since such functions as
you have defined are bash-specific, and you seem to be using the normal sh
here, which doesn't support functions, but I do not like shooting from the
hip too much...

> 
> --- function source
> 
> function xmsubdirs(){
>         [ -z "$1" ] && set .
>      XMLMAKE_BUILD_EXCLUDE_DIRS_RE='(^CVS$)|(^trash$)'
>      if [[ ! -z "$XMLMAKE_BUILD_EXCLUDE_DIRS_RE" ]]
>      then
>          export CURRENT_SUBDIRS=$(find "$1" -name '*' -type d -maxdepth 1|
> xargs --replace=d basename d | grep -v  -E $XMLMAKE_BUILD_EXCLUDE_DIRS_RE)
>      else
>          export CURRENT_SUBDIRS=$(find "$1" -name '*' -type d -maxdepth 1|
> xargs --replace=d basename d )
>      fi
>      echo ${CURRENT_SUBDIRS}
> }
> 
> Thanks,
> Greg Keraunen
> 
> _______________________________________________
> Help-make mailing list
> [EMAIL PROTECTED]
> http://mail.gnu.org/mailman/listinfo/help-make

Ciao,

Johan Bezem
CSK Software AG


_______________________________________________
Help-make mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/help-make

Reply via email to