From: Philippe Proulx Date: Sat, 2 Apr 2016 20:14:17 +0000 (-0400) Subject: Fix: standardize parser/lexer building X-Git-Tag: v2.9.0-rc1~265 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=1113825053b8f8ff141ffdc375bab04f9e78932b;p=lttng-tools.git Fix: standardize parser/lexer building This patch makes the build system act as follows: if in Git repo: require bison/flex (configure) build parser/lexer (make, make clean) else: if bison exists: build parser (make, make clean) else: warn that bison is missing (configure) create "error" parser target in Makefile (make) do not clean parser (make clean not available) if flex exists: build lexer (make, make clean) else: warn that flex is missing (configure) create "error" lexer target in Makefile (make) do not clean lexer (make clean not available) Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/configure.ac b/configure.ac index cfbbe6bba..24e746011 100644 --- a/configure.ac +++ b/configure.ac @@ -795,27 +795,49 @@ AM_CONDITIONAL([BUILD_LIB_UST_CONSUMER], [test x$build_lib_ust_consumer = xyes]) AC_PATH_PROG([PGREP], [pgrep], [no]) AM_CONDITIONAL([HAS_PGREP], [test "x$PGREP" != "xno"]) -if test ! -f "$srcdir/src/lib/lttng-ctl/filter/filter-parser.h"; then - if test x"$(basename "$YACC")" != "xbison -y"; then - AC_MSG_ERROR([[bison not found and is required when building from git. - Please install bison]]) - fi - AC_PATH_PROG([BISON],[bison]) - AX_PROG_BISON_VERSION([2.4], [],[ - AC_MSG_ERROR([[Bison >= 2.4 is required when building from git]]) +# check for bison +have_bison=yes + +AS_IF([test "x$(basename "$YACC")" != "xbison -y"], [have_bison=no]) +AC_PATH_PROG([BISON], [bison]) +AX_PROG_BISON_VERSION([2.4], [], [have_bison=no]) + +AS_IF([test "x$have_bison" = "xno"], [ + AS_IF([test "x$in_git_repo" = "xyes"], [ + AC_MSG_ERROR([Bison >= 2.4 is required when building from the Git repository.]) + ], [ + AC_MSG_WARN([ +Missing Bison >= 2.4. Note that the parser files are already built in +this distribution tarball, so Bison is only needed if you intend to +modify their sources. + ]) ]) -fi +]) -if test ! -f "$srcdir/src/lib/lttng-ctl/filter/filter-lexer.c"; then - if test x"$LEX" != "xflex"; then - AC_MSG_ERROR([[flex not found and is required when building from git. - Please install flex]]) - fi - AC_PATH_PROG([FLEX],[flex]) - AX_PROG_FLEX_VERSION([2.5.35], [],[ - AC_MSG_ERROR([[Flex >= 2.5.35 is required when building from git]]) +# export bison condition +AM_CONDITIONAL([HAVE_BISON], [test "x$have_bison" = "xyes"]) + +# check for flex +have_flex=yes + +AS_IF([test "x$LEX" != "xflex"], [have_flex=no]) +AC_PATH_PROG([FLEX], [flex]) +AX_PROG_FLEX_VERSION([2.5.35], [], [have_flex=no]) + +AS_IF([test "x$have_flex" = "xno"], [ + AS_IF([test "x$in_git_repo" = "xyes"], [ + AC_MSG_ERROR([Flex >= 2.5.35 is required when building from the Git repository.]) + ], [ + AC_MSG_WARN([ +Missing Flex >= 2.5.35. Note that the lexer files are already built in +this distribution tarball, so Flex is only needed if you intend to +modify their sources. + ]) ]) -fi +]) + +# export flex condition +AM_CONDITIONAL([HAVE_FLEX], [test "x$have_flex" = "xyes"]) CFLAGS="-Wall $CFLAGS -g -fno-strict-aliasing" diff --git a/src/lib/lttng-ctl/filter/Makefile.am b/src/lib/lttng-ctl/filter/Makefile.am index eb913e924..13a9e195a 100644 --- a/src/lib/lttng-ctl/filter/Makefile.am +++ b/src/lib/lttng-ctl/filter/Makefile.am @@ -7,9 +7,9 @@ noinst_HEADERS = filter-ast.h \ filter-symbols.h BUILT_SOURCES = filter-parser.h -AM_YFLAGS = -t -d -v -libfilter_la_SOURCES = filter-lexer.l filter-parser.y \ +libfilter_la_SOURCES = \ + filter-parser.y filter-lexer.l \ filter-visitor-set-parent.c \ filter-visitor-xml.c \ filter-visitor-generate-ir.c \ @@ -22,7 +22,42 @@ libfilter_la_SOURCES = filter-lexer.l filter-parser.y \ memstream.h libfilter_la_CFLAGS = -include filter-symbols.h +AM_YFLAGS = -t -d -v + +# start with empty files to clean +CLEANFILES = + +if HAVE_BISON +# we have bison: we can clean the generated parser files +CLEANFILES += filter-parser.c filter-parser.h filter-parser.output +else # HAVE_BISON +# create target used to stop the build if we want to build the parser, +# but we don't have the necessary tool to do so +ERR_MSG = "Error: Cannot build target because bison is missing." +ERR_MSG += "Make sure bison is installed and run the configure script again." + +filter-parser.c filter-parser.h: filter-parser.y + @echo $(ERR_MSG) + @false + +all-local: filter-parser.c filter-parser.h +endif # HAVE_BISON + +if HAVE_FLEX +# we have flex: we can clean the generated lexer files +CLEANFILES += filter-lexer.c +else # HAVE_FLEX +# create target used to stop the build if we want to build the lexer, +# but we don't have the necessary tool to do so +ERR_MSG = "Error: Cannot build target because flex is missing." +ERR_MSG += "Make sure flex is installed and run the configure script again." + +filter-lexer.c: filter-lexer.l + @echo $(ERR_MSG) + @false + +all-local: filter-lexer.c +endif # HAVE_FLEX + filter_grammar_test_SOURCES = filter-grammar-test.c filter_grammar_test_LDADD = libfilter.la - -CLEANFILES = filter-lexer.c filter-parser.c filter-parser.h filter-parser.output