Discussion:
Finding #includes from a yacc .y.
Ralph Corderoy
2017-11-20 18:38:59 UTC
Permalink
Hi,

In a subdirectory, a foo.y gets turned into a foo.c. Both thus
`#include "bar.h"' that sits alongside them. This all works fine. But
use a build directory, i.e. run configure from somewhere other than `.',
and foo.c fails to build because bar.h isn't found. (A similar problem
happens with lex's C output.)

It seems wrong for foo.y to have to `#include "path/from/root/to/bar.h"
since that means it has to alter if they move around the hierarchy. Is
there another way?
--
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy
Ralph Corderoy
2017-11-20 18:51:22 UTC
Permalink
Hi again,
Post by Ralph Corderoy
It seems wrong for foo.y to have to `#include
"path/from/root/to/bar.h" since that means it has to alter if they
move around the hierarchy. Is there another way?
I can be more precise having dug into this project a bit.
Currently, it has

sbr_libmh_a_CPPFLAGS = ${AM_CPPFLAGS} -I./sbr

Would it be wrong or a misuse of top_srcdir to change that to

sbr_libmh_a_CPPFLAGS = ${AM_CPPFLAGS} -I$(top_srcdir)/sbr

so bar.h is found whether building locally or in another directory?

It works in this one case, but I know that doesn't necessarily mean it's
right. :-)
--
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy
Ralph Corderoy
2017-11-20 19:24:28 UTC
Permalink
More noise...
Post by Ralph Corderoy
It works in this one case, but I know that doesn't necessarily mean
it's right. :-)
I've found AM_CPPFLAGS in `info automake | less' and I think that's
answering it.
--
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy
Nick Bowler
2017-11-20 19:24:47 UTC
Permalink
Hi Ralph,
Post by Ralph Corderoy
Post by Ralph Corderoy
It seems wrong for foo.y to have to `#include
"path/from/root/to/bar.h" since that means it has to alter if they
move around the hierarchy. Is there another way?
I can be more precise having dug into this project a bit.
Currently, it has
sbr_libmh_a_CPPFLAGS = ${AM_CPPFLAGS} -I./sbr
This relative include path refers to the current working directory
of the compiler, which is normally the build directory and is thus
essentially equivalent to -I$(builddir)/sbr ...
Post by Ralph Corderoy
Would it be wrong or a misuse of top_srcdir to change that to
sbr_libmh_a_CPPFLAGS = ${AM_CPPFLAGS} -I$(top_srcdir)/sbr
... so if your headers are in the source directory, as is typical,
then something like this is perfectly sensible.

Cheers,
Nick

Loading...