有没有办法告诉 automake 不要解释 automakefile 的一部分?

发布于 2024-12-04 17:10:49 字数 413 浏览 1 评论 0原文

有没有办法告诉 automake 不要解释 Makefile.am 的一部分?

具体来说,我正在尝试在 Makefile.am 中编码 Makefile 条件。 其他人已经注意到,这不起作用,因为 automake 解释了 endif 结构。

有没有办法转义或引用 Makefile.am 文件中的字符串,以便 automake 将它们逐字复制到目标 Makefile 中?具体来说,我不希望它以如下方式解释 endif:

ifeq "$(SOMEVAR)" ""
SOMEVAR="default_value"
endif

Is there a way to tell automake not to interpret part of the Makefile.am?

Specifically, I am trying to encode a Makefile conditional in a Makefile.am. As other people have noticed, this doesn't work because automake interprets the endif construct.

Is there any way to escape or quote strings in Makefile.am files so that automake copies them verbatim into the destination Makefile? Specifically I don't want it to interpret the endif in something like:

ifeq "$(SOMEVAR)" ""
SOMEVAR="default_value"
endif

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

栩栩如生 2024-12-11 17:10:50

automake 执行条件语句的原因是因为有些恐龙 make 不执行条件语句。也就是说,如果您确实必须这样做,您可以将代码片段定义为 configure.ac 中的变量,并将 AC_SUBST 定义到您的 Makefile 中。这样,automake就没有机会看到它。请记住使用 AM_SUBST_NOTMAKE 来避免创建像 FOO = @FOO@ 这样的行。)

dnl In configure.ac:
snippet='
ifeq ($(somevar),Y)
foo
endif
'
AC_SUBST([snippet])
AM_SUBST_NOTMAKE([snippet])

并且:

## In Makefile.am:
@snippet@

我真诚地希望有比这更好的方法。

The reason automake does conditionals is because some dinosaur makes don't. That said, if you really must do this, you could define your snippet as a variable in configure.ac and AC_SUBST it into your Makefile. That way, automake won't get a chance to see it. Remember to use AM_SUBST_NOTMAKE to avoid creating a line like FOO = @FOO@.)

dnl In configure.ac:
snippet='
ifeq ($(somevar),Y)
foo
endif
'
AC_SUBST([snippet])
AM_SUBST_NOTMAKE([snippet])

and:

## In Makefile.am:
@snippet@

I sincerely hope there's a better way than this.

尬尬 2024-12-11 17:10:50

最简单的方法是在 ifdefifeqifneqelse 和 < 之前插入一个空格代码>endif。这样,这些关键字就不会被 automake 解析器识别。一定要插入一个空格,它不能与制表符一起使用。

来源:https://patchwork.kernel.org/patch/6709921/

The simplest way to do so is to insert a space before the ifdef, ifeq, ifneq, else and endif. That way, these keywords are not recognized by the automake parser. Be sure to insert a space, it won't work with a tab.

source: https://patchwork.kernel.org/patch/6709921/

一身软味 2024-12-11 17:10:50

我设法找到了不同的解决方案。您可以将要转义的位放在单独的文件中,然后执行以下操作:

$(eval include $(srcdir)/Include.Makefile)

由于 automake 不理解 $(eval 它只会保持整行完整。因此您可以将任何您想要的内容放入另一个文件和 GNU make 会很高兴地读取它,注意你不能直接使用 include 因为 Automake 确实理解这一点并且会进入另一个文件。

I managed to find a different solution. You can put your to-be-escaped bits in a separate file and then do:

$(eval include $(srcdir)/Include.Makefile)

Since automake doesn't understand $(eval it just leaves the entire line intact. Thus you can put whatever you want into the other file and GNU make will happily read it. Note you can't just use include directly since Automake does understand that and will go into the other file.

一杆小烟枪 2024-12-11 17:10:50

怎么样:

SOMEVAR=$(if $(SOMEVAR),$(SOMEVAR),"default_value")

How about:

SOMEVAR=$(if $(SOMEVAR),$(SOMEVAR),"default_value")
姜生凉生 2024-12-11 17:10:50

在 automake (GNU automake) 1.16.5 中,当我用换行符和空格隔离关键字时,简单条件 ifeq ... endif 会通过 automake 传递到 Makefile 中,如下所示:

if %?INSTALL%
# 1 preceding newline
  ifeq (true,$(call direction,uninstall %DIR% PROGRAMS %BASE%))  # 2 preceding spaces
## -------------- ##
## Uninstalling.  ##
## -------------- ##

.PHONY uninstall-am: uninstall-%DIR%PROGRAMS-$(%NDIR%_STATUS)
uninstall-%DIR%PROGRAMS: uninstall-%DIR%PROGRAMS-$(%NDIR%_STATUS)
uninstall-%DIR%PROGRAMS-supported: uninstall-%DIR%PROGRAMS
uninstall-%DIR%PROGRAMS-unsupported:
    @echo "%NDIR% (PROGRAMS) not installed" >&2

uninstall-%DIR%PROGRAMS: $(install_%DIR%_PROGRAMS)
    @test 
lt; \
    && $(NORMAL_UNINSTALL) \
    && $(autotoolsdir)/uninstall -P PROGRAMS -LT ?LIBTOOL? -I $? >&2 

  endif # 2 preceding spaces
# 1 subsequent newline
endif %?INSTALL%
  

如果我混合,情况尤其如此 : automake 条件语句与 make 条件语句,如上所示。

In automake (GNU automake) 1.16.5 simple conditionals ifeq ... endif do pass through automake into Makefile when I isolate the keywords with newline and spaces, like so:

if %?INSTALL%
# 1 preceding newline
  ifeq (true,$(call direction,uninstall %DIR% PROGRAMS %BASE%))  # 2 preceding spaces
## -------------- ##
## Uninstalling.  ##
## -------------- ##

.PHONY uninstall-am: uninstall-%DIR%PROGRAMS-$(%NDIR%_STATUS)
uninstall-%DIR%PROGRAMS: uninstall-%DIR%PROGRAMS-$(%NDIR%_STATUS)
uninstall-%DIR%PROGRAMS-supported: uninstall-%DIR%PROGRAMS
uninstall-%DIR%PROGRAMS-unsupported:
    @echo "%NDIR% (PROGRAMS) not installed" >&2

uninstall-%DIR%PROGRAMS: $(install_%DIR%_PROGRAMS)
    @test 
lt; \
    && $(NORMAL_UNINSTALL) \
    && $(autotoolsdir)/uninstall -P PROGRAMS -LT ?LIBTOOL? -I $? >&2 

  endif # 2 preceding spaces
# 1 subsequent newline
endif %?INSTALL%
  

That is especially the case if I mix automake conditionals with make conditionals, like shown above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文