matth1j
matth1j

Reputation: 31

autotools with bison and flex sources

I have a C project which includes a flex and a bison source file; the flex file #includes the bison-generated tab.h file.

So I've added AC_PROG_LEX and AC_PROG_YACC to my configure.ac file. But after I've run the autotools and I attempt to make the project, the flex-generated .c file is compiled before bison has been run to generate the tab.h file #included by the flex .c file. Hence the compilation fails.

I'm very much an autotools (and stackoverflow!) newbie - do I need to make autotools aware of the flex .o dependency on the bison .tab.h? If so, where would that dependency go - in the Makefile.am containing the project SOURCES list?

TIA John

Upvotes: 2

Views: 1754

Answers (2)

Johann Oskarsson
Johann Oskarsson

Reputation: 816

In my experience, you can't have the parser and the scanner use the same prefix.

That is,

bin_PROGRAM = baz
AM_YFLAGS = -d
BUILT_SOURCES = foo.h
baz_SOURCES = main.c foo.l foo.y

will not work, but

bin_PROGRAM = baz
AM_YFLAGS = -d
BUILT_SOURCES = bar.h
baz_SOURCES = main.c foo.l bar.y

will insure automake builds bar.y before foo.l.

So make sure your scanner and parser use different filenames, and you're good to go.

Upvotes: 0

Borbus
Borbus

Reputation: 593

You need to tell automake that the header file is to be built rather than already provided by you. Put this in the Makefile.am:

BUILT_SOURCES = tab.h

Upvotes: 2

Related Questions