[Spice-devel] [PATCH] Fix build when builddir != srcdir

Jonathon Jongsma jjongsma at redhat.com
Wed Nov 16 16:26:35 UTC 2016


On Wed, 2016-11-16 at 11:18 -0500, Frediano Ziglio wrote:
>>> > On Wed, 2016-11-16 at 06:20 -0500, Frediano Ziglio wrote:
> > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > Acked-by: Christophe Fergeau <cfergeau at redhat.com>
> > > > 
> > > > On Tue, Nov 15, 2016 at 12:13:21PM -0600, Jonathon Jongsma
> > > > wrote:
> > > > > 
> > > > > 
> > > > > The following build error occurs when building outside of the
> > > > > source
> > > > > directory:
> > > > > 
> > > > > glib-mkenums --template spice-server-enums.tmpl.c
> > > > > ../../server/spice-server.h > spice-server-enums.c
> > > > > Can't open spice-server-enums.tmpl.c: No such file or
> > > > > directory
> > > > > Makefile:1111: recipe for target 'spice-server-enums.c'
> > > > > failed
> > > > > 
> > > > > GNU Make does some magic to know that the spice-server-
> > > > > enums.tmpl.c file
> > > 
> > > It's a combination of automake and VPATH (which is currently
> > > quite
> > > standard
> > > so it's more a automake setting).
> > > 
> > > > 
> > > > 
> > > > > 
> > > > > 
> > > > > listed in the prerequisites for the rule is located in the
> > > > > srcdir. But
> > > > > when we use the bare filename in the rule definition, it
> > > > > assumes
> > > > > that it is
> > > > > in the builddir. If there was an automatic variable that we
> > > > > could
> > > > > use
> > > > > (like $< that we already use for the first prerequisite), the
> > > > > srdir
> > > 
> > > From this part of the comment seems there is no way to extract
> > > the
> > > second prerequisite. In GNU make you can use $(word 2,$^) if you
> > > want to do this without using some hacks.
> > > Also is not that make assumes that is in builddir is that make
> > > does not parse much the rules definitions as doing so would cause
> > > problems. Is not defined for instance that you want to use
> > > spice-server-enums.tmpl.c as a filename so should try to find
> > > the file. As far as make is concern it's just a string. The
> > > parsing
> > > of rule body is limited to $ (which can be quoted) and line
> > > joiningm
> > > beside that lines are passed verbatim to the shell (which can be
> > > changed).
>> > True, we could use a make function, but I'd still prefer to just
> > prepend
> > $(srcdir) explicitly. I think it's more straightforward.
>> > > 
> > > 
> > > > 
> > > > 
> > > > > 
> > > > > 
> > > > > would be automatically prepended to the filename, but there's
> > > > > nothing we
> > > > > can use for the second prerequisite. So we need to explicitly
> > > > > specify
> > > > > the location of the input template file.
> > > 
> > > I would remove this part.
>>> > How about this?
>> >     Make/Automake uses VPATH to determine that the spice-server-
> > enums.tmpl.c
> >     file listed in the prerequisites for the rule is located in the
> > srcdir.
> >     When we use an automatic variable (e.g. $<), the srcdir path
> > gets
> >     automatically prepended to the filename. But when we use the
> > filename
> >     directly within the rule definition, this won't happen. So we
> > need to
> >     explicitly specify that the input template file is located in
> > srcdir.
>> > Jonathon
>> 
> Not exactly. Specifically
> 
> "When we use an automatic variable (e.g. $<), the srcdir path gets
>  automatically prepended to the filename."
> 
> It's not that $< is expanded is that when the prerequisite
> are evaluated (which is distinct from where are parsed) make try to
> resolve
> the files and potentially expand them if needed (or create them, but
> this is OT). So when the rule is called the prerequisites are already
> resolved
> with proper paths. When $< is used in this case the first
> prerequisite is
> picked up (kind of $(word 1,$^)) which is already resolved.
> 
> Frediano


I thought that's basically what I said, although perhaps I didn't use
precise language. How about:

Make/Automake uses VPATH to determine that the spice-server-
enums.tmpl.c file listed in the prerequisites for the rule is located
in the srcdir. When we use an automatic variable (e.g. $<), the full
path to the resolved file is used. But when we use the literal filename
directly within the rule definition, this won't happen. So we need to
explicitly specify that the input template file is located in srcdir.


More information about the Spice-devel mailing list