makefile 中的变量目标

发布于 2024-11-18 06:05:12 字数 562 浏览 3 评论 0原文

我正在尝试编译一组目标。然而它似乎只做了第一个。下面是显示错误的我的 makefile 的删减。

  OBJECTS = abc def ghi
  SOURCES = abc.c def.c ghi.c

  $(OBJECTS):     $(SOURCES)
          @echo target is $@, source is $<

在 shell 中,

  $ touch abc.c def.c ghi.c
  $ make

当我运行 make 时,我得到以下输出:

  target is abc, source is abc.c

所以它似乎只运行第一个目标。

如果我替换 $<使用 $^,输出为:

  target is abc, source is abc.c def.c ghi.c

我的问题,是否可以像 (%: %) 模式那样对变量执行扩展?

I am trying to compile set of targets. However it only seems to do the first one. Below is a cut down of the my makefile that shows the error.

  OBJECTS = abc def ghi
  SOURCES = abc.c def.c ghi.c

  $(OBJECTS):     $(SOURCES)
          @echo target is $@, source is 
lt;

In shell,

  $ touch abc.c def.c ghi.c
  $ make

When I run make I get the following output:

  target is abc, source is abc.c

So it only seems to be running the first target.

If I replace $< with $^, the output is:

  target is abc, source is abc.c def.c ghi.c

My question, is it possible to perform expansions on variables like with the (%: %) pattern?

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

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

发布评论

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

评论(1

一杯敬自由 2024-11-25 06:05:12

试试这个:

  OBJECTS = abc def ghi

  all: $(OBJECTS)

  $(OBJECTS):%:%.c
          @echo target is $@, source is 
lt;

问题是

  1. 默认目标(如果您只输入“make”,Make 会选择该目标)是 makefile 中的第一个目标,即“abc”。
  2. 您为每个对象设置了所有源先决条件。也就是说,所有三个来源都是“abc”的先决条件。它们也是“def”和“ghi”的先决条件。

Try this:

  OBJECTS = abc def ghi

  all: $(OBJECTS)

  $(OBJECTS):%:%.c
          @echo target is $@, source is 
lt;

The trouble was

  1. The default target (which is what Make chooses if you just type `make`) is the first target in the makefile, which was `abc`.
  2. You made all sources prerequisites of every object. That is, all three sources were prerequisites of `abc`. They were also prerequisites of `def` and of `ghi`.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文