From 540d833dfbe259815a0aec6a231dbe54a74aec4e Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 29 Jun 2017 15:59:07 -0400 Subject: [PATCH] Cleanup: bison and flex detection MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jérémie Galarneau --- configure.ac | 67 +++++++++++++++++-------- m4/ax_prog_bison_version.m4 | 24 ++++++--- m4/ax_prog_flex_version.m4 | 24 ++++++--- plugins/ctf/common/metadata/Makefile.am | 40 +++++++++++++-- 4 files changed, 114 insertions(+), 41 deletions(-) diff --git a/configure.ac b/configure.ac index a3d66c90..25503768 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/m4/ax_prog_bison_version.m4 b/m4/ax_prog_bison_version.m4 index 5da478c1..5a8888de 100644 --- a/m4/ax_prog_bison_version.m4 +++ b/m4/ax_prog_bison_version.m4 @@ -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 @@ -11,41 +11,49 @@ # 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 +# 2017 Michael Jeanson # # 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 diff --git a/m4/ax_prog_flex_version.m4 b/m4/ax_prog_flex_version.m4 index da60e00f..6a9bfbe4 100644 --- a/m4/ax_prog_flex_version.m4 +++ b/m4/ax_prog_flex_version.m4 @@ -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 @@ -11,41 +11,49 @@ # 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 +# 2017 Michael Jeanson # # 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 diff --git a/plugins/ctf/common/metadata/Makefile.am b/plugins/ctf/common/metadata/Makefile.am index 925b31a9..b6cf6238 100644 --- a/plugins/ctf/common/metadata/Makefile.am +++ b/plugins/ctf/common/metadata/Makefile.am @@ -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 -- 2.34.1