Noeud:Using Flex with the GNU Build System, Noeud « Next »:Exercises on Flex, Noeud « Previous »:Advanced Use of Flex, Noeud « Up »:Scanning with Flex
Autoconf and Automake provide some generic Lex support, but no Flex
dedicated support. In particular Automake expects lex.yy.c
as
output file, which makes it go through various hoops to prevent several
concurrent invocations of lex
to overwrite each others'
output.
As Gperf, Lex and Flex are maintainer requirements: someone changing the
package needs them, but their result is shipped so that a regular user
does not need them. I have already emphasized that you should not
bother with vendor Lexes, Flex alone will fulfill all your needs, and
keep you away from troubles. If you use Automake's AM_PROG_LEX
,
then if flex
or else lex
is found, it is used as is,
otherwise missing
is used to invoke flex
.
Unfortunately, if lex
is available, but not good enough to
handle your files, then the output scanner will be destroyed.
Therefore, to avoid this, we really want to wrap the lex
invocations with missing
. I suggest:
# Sometimes Flex is installed as Lex, e.g., NetBSD. AC_CHECK_PROG([FLEX], [flex lex], [flex]) # Force the use of `missing' to wrap Flex invocations. AM_MISSING_PROG([LEX], [$FLEX]) # Perform all the tests Automake and Autoconf need. AM_PROG_LEX
Then, in your Makefile.am
, forget your Flex sources need a
special handling, Automake takes care of it all. Merely list them as
ordinary source files:
LDFLAGS = -no-undefined pkglibexec_LTLIBRARIES = yleval.la yleval_la_SOURCES = ylparse.y ylscan.l yleval.c yleval.h ylparse.h yleval_la_LDFLAGS = -module
and that's all. In particular, do not bother with LEXLIB
at all:
configure
defines it to -ll
or -lfl
, but we
already emphasized that Flex' output is self-contained and portable, see
Using Flex.