help-make
[Top][All Lists]
Advanced

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

Re: Is there a way to use include directives in macros?


From: David Boyce
Subject: Re: Is there a way to use include directives in macros?
Date: Tue, 21 Mar 2017 07:14:14 -0700

Let me just throw in a couple of tangential points:

1. I see no reason to specify or derive the current directory; make
provides it as $(CURDIR) and this is guaranteed to be a correct absolute
path (unless you deliberately assign to it) since make has no way of
changing its own current directory.

2. Rather than design around the current working dir, I prefer to define
the concept of the mwd or "make working directory" which is the directory
containing the controlling makefile. Generally the same as the cwd though
not necessarily. Something like:

mwd := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

David

On Tue, Mar 21, 2017 at 5:50 AM, Sébastien Hinderer <
address@hidden> wrote:

> Dear Paul,
>
> Many thanks for your so prompt and helpful response!
>
> Paul Smith (2017/03/21 08:31 -0400):
> > On Tue, 2017-03-21 at 13:18 +0100, Sébastien Hinderer wrote:
> > > define INCLUDE
> > >   curdir := $(1)
> > >   include $(1)/Makefile
> > >   unset curdir
>
> (That should have been undefine, by the way)
>
> > > endef
> > >
> > > # List of subdirectories containing a Makefile that should be included
> > >
> > > subdirectories := foo bar baz
> > >
> > > # Include all the specified sub-makefiles
> > > $(foreach subdirectory, $(subdirectories), $(call INCLUDE,
> $(subdirectory)))
> >
> > The expansion of the foreach loop has to be a valid single line of
> > makefile syntax; it will be considered a logical line.  You can't use
> > call to invoke a multiline function containing make syntax like this.
>
> Okay.
>
> > You need eval for that:
> >
> >   $(foreach d,$(subdirectories),$(eval $(call INCLUDE,$(d))))
>
> Ah, thanks! Actually I was aware of eeval but did not realise its link
> with what I was trying to do. Reading its documentation with this new
> light makes everything much clearer. Thaks again!
>
> Sébastien.
>
> _______________________________________________
> Help-make mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-make
>


reply via email to

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