automake:修改隐式 make 规则以包含额外的标志

发布于 2024-09-26 16:05:16 字数 282 浏览 5 评论 0原文

如何添加适用于所有 makefile 的额外标志变量(如 CPPFLAGS)?目前,我们正在使用 CPPFLAGS,但它应该保留为用户变量,我想保留它。我不想使用 AM_CPPFLAGS,因为我想为特定的 Makefile.amS 保留它。我想要的是像 GLOBAL_CPPFLAGS 这样的东西,我可以在configure.ac中设置它并将其应用于所有内容。如果有一种方法可以显式忽略该标志,那就太好了。

我认为我需要做的是编写自己的 make 规则,但是如何使其在所有子文件夹中可用而不将其复制到每个 Makefile.am 中?

How can I add extra flag variables (like CPPFLAGS) that will apply to all makefiles? Currently, we're using CPPFLAGS, but that is supposed to be reserved as a user variable and I would like to reserve it. I'd prefer not to use AM_CPPFLAGS because I would like to reserve that for specific Makefile.amS. What I want is something like GLOBAL_CPPFLAGS that I could set in configure.ac and have it applied to everything. It would also be nice if there were a way to explicitly ignore the flag.

I think what I need to do is to write my own make rule, but how would I make that available in all subfolders without copying it into every Makefile.am?

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

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

发布评论

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

评论(3

老旧海报 2024-10-03 16:05:16

您不使用 CPPFLAGS 是正确的。这是一个用户变量。我要做的是这样的:

在源目录的根目录中,创建一个名为 common.am 的文件,并在其中定义您需要的任何内容:

## common.am
AM_CPPFLAGS = -DFOO

我知道您说过您不想使用 AM_CPPFLAGS,但请听我说完。在您的各个子目录中, include $(top_srcdir)/common .am 并根据需要扩展或覆盖 AM_CPPFLAGS

## bar/Makefile.am
include $(top_srcdir)/common.am
AM_CPPFLAGS += -DBAR

如果要覆盖,请使用 = 而不是 += >:

## baz/Makefile.am
include $(top_srcdir)/common.am
AM_CPPFLAGS = -DBAZ

You're correct in not using CPPFLAGS. That's a user variable. What I'd do is something like this:

In the root of your source dir, create a file called common.am and define whatever you need in there:

## common.am
AM_CPPFLAGS = -DFOO

I know you said you didn't want to use AM_CPPFLAGS, but hear me out. In your individual subdirectories, include $(top_srcdir)/common.am and extend or override AM_CPPFLAGS as needed:

## bar/Makefile.am
include $(top_srcdir)/common.am
AM_CPPFLAGS += -DBAR

If you want to override, use = instead of +=:

## baz/Makefile.am
include $(top_srcdir)/common.am
AM_CPPFLAGS = -DBAZ
画骨成沙 2024-10-03 16:05:16

我想你回答了你自己的问题:你必须将新规则复制到每个 makefile 中。

I think you answered your own question: you will have to copy the new rule into every makefile.

伊面 2024-10-03 16:05:16

CPPFLAGS 是您可能应该使用的机制。只需在 configure.ac 中的某个位置连接您想要的标志:

GLOBAL_CPPFLAGS="-DSOMETHING"

...

CPPFLAGS="$CPPFLAGS $GLOBAL_CPPFLAGS"

就可以设置了。

CPPFLAGS is the mechanism you probably should be using. Just concatenate the flags you want somewhere in configure.ac:

GLOBAL_CPPFLAGS="-DSOMETHING"

...

CPPFLAGS="$CPPFLAGS $GLOBAL_CPPFLAGS"

and you should be set.

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