更改configure.ac中的* FLAGS与子项目缓存 [英] Changing *FLAGS in configure.ac vs. caching with subprojects

查看:492
本文介绍了更改configure.ac中的* FLAGS与子项目缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我想在我的configure脚本中向CFLAGS添加一个特定的标志,该标志应传播到所有子项目的configure脚本:

Say I wish to add a specific flag to CFLAGS within my configure script, that should propagate to all subprojects' configure scripts:

CFLAGS+=" -Dfoobar"
export CFLAGS
AC_CONFIG_SUBDIRS([sub])

当琐碎地调用configure时,此方法有效.一旦发生以下情况之一:

This works when configure is invoked trivially. As soon as one of the following happens:

    调用configure时,会在环境中导出
  1. CFLAGS
  2. CFLAGS是在configure命令行上设置的
  3. 使用了缓存(configure -C)
  1. CFLAGS is exported in the environment when configure is invoked
  2. CFLAGS is set on configure command-line
  3. caching is used (configure -C)

此方法不再有效.在前两种情况下,导出的CFLAGS会被简单地忽略;而在最后一个中,configure失败

This approach no longer works. In the first two cases, the exported CFLAGS is simply ignored; and in the last one, configure fails with

配置:错误:在上一次运行中未设置"CFLAGS"

configure: error: `CFLAGS' was not set in the previous run


我设法通过以下方式使它可靠地工作:


I have managed to get this working reliably by:

AM_CFLAGS+=" -Dfoobar"
export AM_CFLAGS
AC_SUBST([AM_CFLAGS]) # repeat this line in every configure.ac for each *FLAGS
AC_CONFIG_SUBDIRS([sub])

考虑到有多个子项目,并且可能需要像这样设置多个*FLAGS变量,这是中途的,但仍然不是最优的.有没有办法仅通过破解顶级configure.ac来实现此目的?

Considering there are multiple subprojects, and multiple *FLAGS variables that may need to be set like this, this is half-way okay but still suboptimal. Is there a way to make this work by only hacking the top-level configure.ac?

推荐答案

最终的解决方案是

The ultimate solution was to un-precious the affected variables:

顶级configure.ac:

Top-level configure.ac:

AC_INIT([test], [0.1])
AC_CONFIG_MACRO_DIR([m4]) # for ax_append_flag.m4
AM_INIT_AUTOMAKE([-Wall -Werror foreign])

AC_PROG_CC
AC_PROG_SED

# Modify the CFLAGS. AX_APPEND_FLAG makes sure not to add the flag if it's already there
AX_APPEND_FLAG([-Dtop-configure], [CFLAGS])

AC_DEFUN([AX_UNPRECIOUS], [
    m4_define([_AC_PRECIOUS_VARS], m4_bpatsubst(_AC_PRECIOUS_VARS, [$1
], []))
])
AX_UNPRECIOUS([CFLAGS])
export CFLAGS

AC_CONFIG_SUBDIRS([sub])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

在幕后,永远不会将CFLAGS视为珍贵,因此也不会将其缓存或传递给子包configure s—他们将其视为环境变量专有,然后对其进行缓存自己在常见的顶级config.cache中.

Behind the curtains, CFLAGS is never seen as precious and thus never cached or passed to sub-package configures—they see it as an environment variable exclusively, and then cache it themselves in the common top-level config.cache.

这非常可靠,并且在我之前的解决方案中进行了改进,即使在顶级配置运行中也允许缓存值(并且更加简单).

This works very reliably, and improves upon my previous solution by allowing cached values even across top-level configure runs (and by being simpler).

这篇关于更改configure.ac中的* FLAGS与子项目缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆