automake 1.12更改了bison / yacc输出名称,向后不兼容的更改?

问题描述 投票:4回答:3

我已在https://github.com/Habbie/autoyacc-problem处发布了一个存储库以演示我的问题。

使用automake 1.11及以下版本,在configure.ac中使用AC_PROG_YACC,在Makefile.am中使用AM_YFLAGS=-d,parser.yy变成parser.cc和parser.h。使用automake 1.12,我得到parser.cc和parser.hh。因为mybin.cc具有include "parser.h",这意味着1.12破坏了我的构建。

我感觉这是一个向后不兼容的更改,但是我认为应该有一个理智的方法来处理此问题。

演示:

git clone https://github.com/Habbie/autoyacc-problem.git
cd autoyacc-problem/
autoreconf -i
./configure
make

automake 1.11的结果:构建了mybin。自动制作1.12的结果:

mybin.cc:1:20: error: parser.h: No such file or directory

帮助!

注意:此示例中没有实际的C ++代码,但对于我的实际问题,我确实需要g ++。

c++ yacc autoconf automake
3个回答
2
投票

我不是专家;但是鉴于您如何依赖较旧版本的automake(请参阅zhenech)中未记录的行为,您可以要求使用较新版本的automake(因此您可以依赖定义的行为);或确保所需的文件是由自动制作生成的。

给出的默认输出扩展名是“ .hh”,您可以使用简单的make指令从.h文件(对于旧版本的automake)中生成.hh文件的内容:

.h.hh:
    cp $< $@

如果您希望从.hh文件中生成.h文件,则可能需要更改定义,并且根据我不熟悉的自动工具的lex / yacc处理的具体情况,您可能希望将生成的文件添加到BUILT_SOURCES


0
投票

我在涉及使用bison进行解析的项目中使用以下方法:

我有一个文件m4/AC_PROG_BISON.m4,该文件要么将以下行附加到([automake版本1.11或更低版本],要么不附加(版本1.12+)到config.h文件:

/* Use *.h extension for parser header file */
#define BISON_USE_PARSER_H_EXTENSION 1

比在其中需要包含解析器生成的标头的文件中,添加以下#ifdef语句:

#include "config.h"
#if defined(BISON_USE_PARSER_H_EXTENSION)
#   include "my_parser.h"
#else
#   include "my_parser.hh"
#endif

另外,我开始将以下行添加到configure.ac]:>

AC_PROG_BISON

现在取决于自动制作版本,将包含相关的标题。

文件内容:m4/AC_PROG_BISON.m4

dnl
dnl Check for bison 
dnl AC_PROG_BISON([MIN_VERSION=2.0])
dnl
AC_DEFUN([AC_PROG_BISON], [
if test "x$1" = "x" ; then
    bison_required_version="2.6"
else 
    bison_required_version="$1"
fi

AC_CHECK_PROG(have_prog_bison, [bison], [yes],[no])

AC_DEFINE_UNQUOTED([BISON_VERSION], [0.0],
                   [Defines bison version if bison is not present])

#Do not use *.h extension for parser header file but *.hh
bison_use_parser_h_extension=false

if test "$have_prog_bison" = "yes" ; then
    AC_MSG_CHECKING([for bison version >= $bison_required_version])
    bison_version=`bison --version | head -n 1 | cut '-d ' -f 4`
    AC_DEFINE_UNQUOTED([BISON_VERSION], [$bison_version],
                       [Defines bison version])
    if test "$bison_version" \< "$bison_required_version" ; then
        BISON=:
        AC_MSG_RESULT([no])
        AC_MSG_ERROR([Bison version 2.6 or higher must be installed on the system!])
    else
        AC_MSG_RESULT([yes])
        BISON=bison
        AC_SUBST(BISON)

#Verify automake version
#Upto version 1.11 parser headers for yy files are with h extension, from 1.12 it is hh
        automake_version=`automake --version | head -n 1 | cut '-d ' -f 4`
        AC_DEFINE_UNQUOTED([AUTOMAKE_VERSION], [$automake_version],
                           [Defines automake version])

        if test "$automake_version" \< "1.12" ; then
            #Use *.h extension for parser header file
            bison_use_parser_h_extension=true
            echo "Automake version < 1.12"
            AC_DEFINE([BISON_USE_PARSER_H_EXTENSION], [1],
                      [Use *.h extension for parser header file])
        fi
    fi
else
    BISON=:
    AC_MSG_RESULT([NO])
fi

AM_CONDITIONAL([BISON_USE_PARSER_H_EXTENSION], [test x$bison_use_parser_h_extension = xtrue])
AC_SUBST(BISON)
])

0
投票

您可以使用包括为标头强制使用特定的文件名

© www.soinside.com 2019 - 2024. All rights reserved.