Fix: standardize parser/lexer building
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 2 Apr 2016 20:14:17 +0000 (16:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 15 May 2016 16:54:47 +0000 (12:54 -0400)
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 <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
src/lib/lttng-ctl/filter/Makefile.am

index cfbbe6bba63ca68aaab9f535b2f99a89ee1a32cf..24e74601167efc7c993675c5d22d0cb82bab30b3 100644 (file)
@@ -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"
 
index eb913e924f05f352a0fc7dca5075e8fa47b1c8c9..13a9e195a5f24b11bc85a2862221c76fd9106d07 100644 (file)
@@ -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
This page took 0.027614 seconds and 4 git commands to generate.