Cleanup: bison and flex detection
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 29 Jun 2017 19:59:07 +0000 (15:59 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 17 Jul 2017 21:09:36 +0000 (17:09 -0400)
The previous detection code was quite convoluted and required to have
two variables set to the same value to work. For example, the lexer in
autotools is configured through the LEX variable, even if we require a
specific implementation we have to use it and base our detection code on
it.

The situation is now :

  - the FLEX and BISON variables are ignored.
  - the LEX and YACC variables need to be set if required like before.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
m4/ax_prog_bison_version.m4
m4/ax_prog_flex_version.m4
plugins/ctf/common/metadata/Makefile.am

index c740e986fbadc8a3b418239d1cf7a7b3d337ba8c..369c369c46c03842137f70442f9befdb9f65b382 100644 (file)
@@ -39,8 +39,6 @@ AC_PROG_CC_STDC
 # Checks for programs.
 AC_PROG_MAKE_SET
 LT_INIT(win32-dll)
-AC_PROG_YACC
-AC_PROG_LEX
 AC_PROG_MKDIR_P
 AC_PROG_LN_S
 
@@ -69,27 +67,52 @@ AC_CHECK_HEADERS([ \
        sys/socket.h \
 ])
 
-if test ! -f "$srcdir/plugins/ctf/common/metadata/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]])
-        ])
-fi
+# set $IN_GIT_REPO if we're in the Git repository; the `bootstrap` file
+# is not distributed in tarballs
+AS_IF([test -f "$srcdir/bootstrap"], [in_git_repo=yes], [in_git_repo=no])
+AM_CONDITIONAL([IN_GIT_REPO], [test "x$in_git_repo" = "xyes"])
 
-if test ! -f "$srcdir/plugins/ctf/common/metadata/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]])
-        ])
-fi
+# check for bison
+AC_PROG_YACC
+AX_PROG_BISON_VERSION([2.4], [have_bison=yes])
+
+AS_IF([test "x$have_bison" != "xyes"], [
+  AS_IF([test "x$in_git_repo" = "xyes"], [
+    AC_MSG_FAILURE([
+Bison >= 2.4 is required when building from the Git repository. You can
+set the YACC variable to override automatic detection.
+    ])
+  ], [
+    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. You can set the YACC variable to override automatic
+detection.
+    ])
+  ])
+])
+AM_CONDITIONAL([HAVE_BISON], [test "x$have_bison" = "xyes"])
+
+# check for flex
+AC_PROG_LEX
+AX_PROG_FLEX_VERSION([2.5.35], [have_flex=yes])
+
+AS_IF([test "x$have_flex" != "xyes"], [
+  AS_IF([test "x$in_git_repo" = "xyes"], [
+    AC_MSG_FAILURE([
+Flex >= 2.5.35 is required when building from the Git repository. You can
+set the LEX variable to override automatic detection.
+    ])
+  ], [
+    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. You can set the LEX variable to override automatic
+detection.
+    ])
+  ])
+])
+AM_CONDITIONAL([HAVE_FLEX], [test "x$have_flex" = "xyes"])
 
 
 AM_PATH_GLIB_2_0(2.22.0, ,AC_MSG_ERROR([glib is required in order to compile BabelTrace - download it from ftp://ftp.gtk.org/pub/gtk]) , gmodule-no-export)
index 5da478c18b35d0541a1c192b8e6c032b223fde51..5a8888dea2cc73fcf7cf1c871e448b2d140302d0 100644 (file)
@@ -1,5 +1,5 @@
 # ===========================================================================
-#   http://www.gnu.org/software/autoconf-archive/ax_prog_bison_version.html
+#   https://www.gnu.org/software/autoconf-archive/ax_prog_bison_version.html
 # ===========================================================================
 #
 # SYNOPSIS
 #   Makes sure that bison version is greater or equal to the version
 #   indicated. If true the shell commands in ACTION-IF-TRUE are executed. If
 #   not the shell commands in commands in ACTION-IF-TRUE are executed. If
-#   not the shell commands in ACTION-IF-FALSE are run. Note if $BISON is not
-#   set (for example by running AC_CHECK_PROG or AC_PATH_PROG) the macro
+#   not the shell commands in ACTION-IF-FALSE are run. Note if $YACC is not
+#   set (for example by running AC_PROG_YACC or AC_PATH_PROG) the macro
 #   will fail.
 #
 #   Example:
 #
-#     AC_PATH_PROG([BISON],[bison])
+#     AC_PROG_YACC
 #     AX_PROG_BISON_VERSION([3.0.2],[ ... ],[ ... ])
 #
 #   This will check to make sure that the bison you have is at least version
 #   3.0.2 or greater.
 #
-#   NOTE: This macro uses the $BISON variable to perform the check.
+#   NOTE: This macro uses the $YACC variable to perform the check, if it's
+#   empty it will failover to the $BISON variable for backwards compatibility.
 #
 # LICENSE
 #
 #   Copyright (c) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
+#                 2017 Michael Jeanson <mjeanson@efficios.com>
 #
 #   Copying and distribution of this file, with or without modification, are
 #   permitted in any medium without royalty provided the copyright notice
 #   and this notice are preserved. This file is offered as-is, without any
 #   warranty.
 
-#serial 2
+#serial 4
 
 AC_DEFUN([AX_PROG_BISON_VERSION],[
     AC_REQUIRE([AC_PROG_SED])
     AC_REQUIRE([AC_PROG_GREP])
 
-    AS_IF([test -n "$BISON"],[
+     AS_IF([test -z "$YACC"],[
+         AS_IF([test -n "$BISON"],[
+             YACC=$BISON
+         ])
+     ])
+
+    AS_IF([test -n "$YACC"],[
         ax_bison_version="$1"
 
         AC_MSG_CHECKING([for bison version])
         changequote(<<,>>)
-        bison_version=`$BISON --version 2>&1 \
+        bison_version=`$YACC --version 2>&1 \
           | $SED -n -e '/bison (GNU Bison)/b inspect
 b
 : inspect
index da60e00f52497e08aa2065d152af0e3ead0e0194..6a9bfbe4c86ae9c9f4db157f0afb68ac9bc2d775 100644 (file)
@@ -1,5 +1,5 @@
 # ===========================================================================
-#   http://www.gnu.org/software/autoconf-archive/ax_prog_flex_version.html
+#   https://www.gnu.org/software/autoconf-archive/ax_prog_flex_version.html
 # ===========================================================================
 #
 # SYNOPSIS
 #   Makes sure that flex version is greater or equal to the version
 #   indicated. If true the shell commands in ACTION-IF-TRUE are executed. If
 #   not the shell commands in commands in ACTION-IF-TRUE are executed. If
-#   not the shell commands in ACTION-IF-FALSE are run. Note if $FLEX is not
-#   set (for example by running AC_CHECK_PROG or AC_PATH_PROG) the macro
+#   not the shell commands in ACTION-IF-FALSE are run. Note if $LEX is not
+#   set (for example by running AC_PROG_LEX or AC_PATH_PROG) the macro
 #   will fail.
 #
 #   Example:
 #
-#     AC_PATH_PROG([FLEX],[flex])
+#     AC_PROG_LEX
 #     AX_PROG_FLEX_VERSION([2.5.39],[ ... ],[ ... ])
 #
 #   This will check to make sure that the flex you have is at least version
 #   2.5.39 or greater.
 #
-#   NOTE: This macro uses the $FLEX variable to perform the check.
+#   NOTE: This macro uses the $LEX variable to perform the check, if it's
+#   empty it will failover to the $FLEX variable for backwards compatibility.
 #
 # LICENSE
 #
 #   Copyright (c) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
+#                 2017 Michael Jeanson <mjeanson@efficios.com>
 #
 #   Copying and distribution of this file, with or without modification, are
 #   permitted in any medium without royalty provided the copyright notice
 #   and this notice are preserved. This file is offered as-is, without any
 #   warranty.
 
-#serial 1
+#serial 3
 
 AC_DEFUN([AX_PROG_FLEX_VERSION],[
     AC_REQUIRE([AC_PROG_SED])
     AC_REQUIRE([AC_PROG_GREP])
 
-    AS_IF([test -n "$FLEX"],[
+    AS_IF([test -z "$LEX"],[
+        AS_IF([test -n "$FLEX"],[
+            LEX=$FLEX
+        ])
+    ])
+
+    AS_IF([test -n "$LEX"],[
         ax_flex_version="$1"
 
         AC_MSG_CHECKING([for flex version])
         changequote(<<,>>)
-        flex_version=`$FLEX --version 2>&1 \
+        flex_version=`$LEX --version 2>&1 \
           | $SED -n -e '/flex /b inspect
 b
 : inspect
index 925b31a9493153d3f63dbf341cb8c0fbebbab19c..b6cf623824509cd88aabbded247f1baefc7e3e1f 100644 (file)
@@ -1,11 +1,12 @@
 AM_CPPFLAGS += -I$(builddir) -I$(srcdir)
-BUILT_SOURCES = parser.h parser.c lexer.c
 AM_YFLAGS = -t -d -v
 
 noinst_LTLIBRARIES = libctf-parser.la libctf-ast.la
 
+BUILT_SOURCES = parser.h
+
 libctf_parser_la_SOURCES = lexer.l parser.y objstack.c
-# ctf-scanner-symbols.h is included to prefix generated yy_* symbols
+# scanner-symbols.h is included to prefix generated yy_* symbols
 # with bt_.
 libctf_parser_la_CPPFLAGS = $(AM_CPPFLAGS) \
                -include $(srcdir)/scanner-symbols.h
@@ -31,4 +32,37 @@ if BABELTRACE_BUILD_WITH_MINGW
 libctf_ast_la_LIBADD += -lrpcrt4 -lintl -liconv -lole32 $(POPT_LIBS)
 endif
 
-CLEANFILES = $(BUILT_SOURCES) parser.output
+# start with empty files to clean
+CLEANFILES =
+
+if HAVE_BISON
+# we have bison: we can clean the generated parser files
+CLEANFILES += parser.c parser.h 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."
+
+parser.c parser.h: parser.y
+       @echo $(ERR_MSG)
+       @false
+
+all-local: parser.c parser.h
+endif # HAVE_BISON
+
+if HAVE_FLEX
+# we have flex: we can clean the generated lexer files
+CLEANFILES += 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: lexer.l
+        @echo $(ERR_MSG)
+        @false
+
+all-local: lexer.c
+endif # HAVE_FLEX
This page took 0.029197 seconds and 4 git commands to generate.