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: Sébastien Hinderer
Subject: Re: Is there a way to use include directives in macros?
Date: Tue, 21 Mar 2017 16:24:32 +0100

Dear David,

Many thanks for your comments. Being a beginner in designing good build
systems I am very interested in every answer, especially the answers to
the questions I don't even think to ask because I don't realise
there is something to learn there.

David Boyce (2017/03/21 07: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.

So in the way I imagined things until now, there is a main Makefile at
the toplevel directory of the project and it includes sub-makefiles
located in each sub-directory where there is something to build. The
current directory never changes and the paths to the files are expressed
relatively to the top-level source directory.

That's why I wanted to use curdir, to write rules like:

$(curdir)program: $(program_objects)

where program_objects contains a list of curdir-prefixed names.

Is that wrong? What is the recommended way?

About absolute paths, I see two problems:

1. The project needs to work on Windows where I believe it is common to
have spaces in directory names and I have heard that make is not that
good at dealing with this. Is that correct?

2. Wouldn't that mean that the paths shown in error messages would
become absolute, too? Is it common to show absolute paths in error
messages?

> 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)))))

Okay, thanks. I don't know yet what to do about this. With your
solution, it seems to me that each sub-makefile would have to include
this line, whereas with mine all the makefiles can just use the curdir
variable which gives the relative path to the top source directory.

But please let me know if I am wrong, I'm happy to learn.


Sébastien.
> 
> 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
> >
> _______________________________________________
> 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]