如何使用AC_CONFIG_COMMANDS_PRE和AC_CONFIG_COMMANDS_POST?

时间:2017-11-02 08:35:56

标签: autotools autoconf

Autoconf manual讨论了AC_CONFIG_COMMANDS_PREAC_CONFIG_COMMANDS_PRE宏(如下所示)。

当我按以下相对顺序使用宏时,它们不会被应用:

## configure.ac
...

AC_OUTPUT(Makefile)
AC_CONFIG_COMMANDS_POST(cmd)
AC_CONFIG_COMMANDS_POST(cmd)
AC_CONFIG_COMMANDS_POST(cmd)

当我更改相对顺序时:

AC_CONFIG_COMMANDS_POST([sed -e '|S["CC"]|d' config.status > config.status.xxx; mv config.status.xxx config.status])
AC_CONFIG_COMMANDS_POST([sed -e '|S["FLAGS"]|d' config.status > config.status.xxx; mv config.status.xxx config.status])
AC_CONFIG_COMMANDS_POST([sed -e '|S["ac_ct_CC"]|d' config.status > config.status.xxx; mv config.status.xxx config.status])
AC_OUTPUT(Makefile)

然后导致:

configure: creating ./config.status
sed: -e expression #1, char 1: unknown command: `|'
sed: -e expression #1, char 1: unknown command: `|'
sed: -e expression #1, char 1: unknown command: `|'

我的第一个问题是,cmd的格式是什么?是否应该用括号([])包裹AC_CONFIG_COMMANDS?还是需要其他东西?

我的第二个问题是,宏AC_OUTPUTAC_CONFIG_COMMANDS_PREAC_CONFIG_COMMANDS_POST的相对顺序是什么?

我的第三个问题是,config.statusMakefile写在哪个位置,以便我可以修复它?

手册3.1.3 Standard configure.ac Layout中还有一节,但未讨论AC_OUTPUTAC_CONFIG_COMMANDS_PREAC_CONFIG_COMMANDS_POST的相对顺序。

我更喜欢修复Makefile,但我对手册的阅读似乎表明我们在config.status准备就绪时被调用,而不是在Makefile准备就绪时。

提前致谢。

— Macro: AC_CONFIG_COMMANDS (tag..., [cmds], [init-cmds])

    Specify additional shell commands to run at the end of config.status, and 
    shell commands to initialize any variables from configure. Associate the 
    commands with tag. Since typically the cmds create a file, tag should 
    naturally be the name of that file. If needed, the directory hosting tag is 
    created. This macro is one of the instantiating macros; see Configuration 
    Actions.

    Here is an unrealistic example:

              fubar=42
              AC_CONFIG_COMMANDS([fubar],
                                 [echo this is extra $fubar, and so on.],
                                 [fubar=$fubar])

 — Macro: AC_CONFIG_COMMANDS_PRE (cmds)

    Execute the cmds right before creating config.status.

    This macro presents the last opportunity to call AC_SUBST, AC_DEFINE, or
    AC_CONFIG_FOOS macros. 

— Macro: AC_CONFIG_COMMANDS_POST (cmds)

    Execute the cmds right after creating config.status.

1 个答案:

答案 0 :(得分:2)

  

我的第三个问题是,在什么时候编写了config.status或Makefile,以便我可以修复它?

AC_OUTPUTconfig.status实际上应该instantiate您的模板文件。例如:

AC_CONFIG_FILES([Makefile])
AC_CONFIG_COMMANDS_PRE([echo ---- pre config.status])
AC_CONFIG_COMMANDS([tag], [echo ---- at end of config.status])
AC_CONFIG_COMMANDS_POST([echo ---- post config.status])
AC_OUTPUT

我得到了

---- pre config.status
configure: creating ./config.status
---- post config.status
config.status: creating Makefile
config.status: executing depfiles commands
config.status: executing tag commands
---- at end of config.status

因此看起来AC_CONFIG_COMMANDS是您要执行Makefile修正的地方,而AC_CONFIG_COMMANDS_POST是您要执行config.status修正的地方。鉴于文档,这是我所期待的。这也应该回答你的第二个问题。

  

然后导致:[ sed errors ]

尝试:

AC_CONFIG_COMMANDS_POST([sed -e '/S\[["CC"\]]/d' config.status > config.status.xxx; mv config.status.xxx config.status])
AC_CONFIG_COMMANDS_POST([sed -e '/S\[["FLAGS"\]]/d' config.status > config.status.xxx; mv config.status.xxx config.status])
AC_CONFIG_COMMANDS_POST([sed -e '/S\[["ac_ct_CC"\]]/d' config.status > config.status.xxx; mv config.status.xxx config.status])

您可以将GNU shtool视为可移植的sed包装器,因为它可以替换(以及一些您可能觉得有用(或过度杀伤)的其他内容。)