【问题标题】:How to tell AC_SUBST to not substitute variables in arguments?如何告诉 AC_SUBST 不要替换参数中的变量?
【发布时间】:2014-06-10 17:56:55
【问题描述】:

我正在使用自动工具来构建我的项目,并且我想将 AM_CPPFLAGS 全局设置为 -I$(top_srcdir)/include。

https://stackoverflow.com/a/325436/2592351 这个答案对我有帮助,我正在执行“include $(top_srcdir)/include” hack,它可以工作。

但是,我想做那里描述的“AC_SUBST”方式,因为它看起来更干净。问题是当我将它添加到我的 configure.ac 时:

AC_SUBST([AM_CPPFLAGS], [-I$(top_srcdir)/include])

然后 $(top_srcdir) 扩展得太快,我得到 AM_CPPFLAGS = -I/include in subdir/Makefile{,.in}。

而且我不知道如何逃脱它。

-I@top_srcdir@/include
-I\$(top_srcdir)/include
-I$$(top_srcdir)/include

所有这些都因各种原因而失败。

请帮忙。我应该如何编写 AC_SUBST 以便 $(top_srcdir) 在到达 Makefile{,.in} 之前不会被转义?或者我应该使用 AC_SUBST 以外的东西?

【问题讨论】:

标签: c++ autotools autoconf automake m4


【解决方案1】:

不要在configure.ac 中设置AM_CPPFLAGS。如果您发现自己在多个 Makefile.am 中重复相同的序言,您应该使用 non-recursive automake

但在这种特殊情况下,如果你这样做,你应该逃脱它

AM_CPPFLAGS='-I$(top_srcdir)/include'
AC_SUBST([AM_CPPFLAGS])

因为字符串在 bash 变量中被引用,然后扩展为文字。使用AC_SUBST 设置它,它被"" 引用,然后导致$(top_srcdir) 被shell 扩展。

【讨论】:

  • AC_SUBSTing AM_CPPFLAGS 可以。只需在调用 AC_SUBST 时添加单引号也可以:AC_SUBST([AM_CPPFLAGS],['-I$(top_srcdir)/include'])
猜你喜欢
  • 1970-01-01
  • 2013-12-28
  • 2010-12-19
  • 2012-10-11
  • 1970-01-01
  • 2016-12-06
  • 1970-01-01
  • 2015-12-06
相关资源
最近更新 更多