makefile:可以忽略目录的模式规则
我正在尝试拥有一个MakeFile规则,该规则可以从目录中的源文件中生成一个对象文件,该文件明确指定。
exe: foo.o bar.o
foo.o: path/to/foo.c
%.o: %.c
echo Making $@ from $<
此示例将发现需要制作“ EXE”,然后搜索以制作“ foo.o”。 “ foo.o”搜索将尝试使用STEM“ FOO”的模式规则,并且无法使用该规则,因为“ foo.c”不存在。我想找到一种方法,可以看到可以使用模式规则从“路径/到/foo.c”编译“ foo.o”。
就我而言,对我来说,将规则为“%.o:path/to/%。C”是没有意义的,因为应该为需要源位于另一个目录中的每个目标指定路径。
模式规则适用于同一目录中由“ bar.c”制成的“ bar.o”,我想保持该工作。
I am trying to have a Makefile rule that can generate an object file from a source file in a directory that is specified explicitly.
exe: foo.o bar.o
foo.o: path/to/foo.c
%.o: %.c
echo Making $@ from lt;
This example will find it needs to make "exe", then search to make "foo.o". The "foo.o" search will try pattern rules with stem "foo" and fail to use the rule because "foo.c" doesn't exist. I want to find a way to have it see that "foo.o" can be compiled from "path/to/foo.c" using the pattern rule.
In my case it doesn't make sense for me to have the rule be "%.o: path/to/%.c" because the path should be specified for each target that needs the source to be located in another directory.
The pattern rule works for "bar.o" being made from "bar.c" within the same directory and I want to keep that working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在要使用的解决方案是:
这有一个缺点,即在同一位置的makefile中不可见模式规则的命令。它还需要扩展到可能需要具有这种“脱离路径”依赖性的其他模式规则。
The solution I am going with for now is:
This has a drawback that the command for the pattern rule is not visible in the Makefile at the same place. It also will need to be expanded for other pattern rules that may need to have this "out of path" dependency.