每个编译器选项组合的目标文件目录 [英] Object file directory per compiler option combinations

查看:53
本文介绍了每个编译器选项组合的目标文件目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读gnu make第10.5.4节模式如何匹配",听起来好像我无法做我想做的事.

I was reading gnu make section 10.5.4 "How patterns match" and it does not sound like I can do what I want.

我想设置一个目录结构,其中我的源代码位于一个目录中,并且有一些子目录来保存目标文件. 每个构建配置都有一个子目录. 所以我可能有这些文件

I want to setup a directory structure where my source code is in one directory, and there are sub-directories to hold object files. One sub-directory for each build configuration. So I might have these files

a.c
debug/a.o # compiled with -g
release/a.o # compiled with -O

所以我想制定这样的规则

So I would like to make rules like this

debug/%.o : %.c
    gcc -c -g %.c -o $@

release/%.o : %.c
    gcc -c -O %.c -o $@

但是10.5.4节告诉我,在"debug/a.o"上的匹配将使词干为"debug/a",因此gnu make 会在"debug/a.c"中查找源文件,这不是我想要的.

But section 10.5.4 tells me a match on "debug/a.o" will make the stem be "debug/a" so gnu make will look for the source file at "debug/a.c" which is not what I want.

有没有办法让GNU帮助我?

Is there a way to get GNU make to help me ?

推荐答案

您的makefile将按编写的方式工作.

Your makefile will work as written.

手册的该部分:

当目标模式不包含斜杠时(通常 否),则从文件名中删除文件名中的目录名 与目标前缀和后缀进行比较之前.之后 文件名与目标模式,目录的比较 名称以及以它们结尾的斜杠被添加到 根据模式规则的前提条件生成的前提条件文件名 模式... [加粗]

When the target pattern does not contain a slash (and it usually does not), directory names in the file names are removed from the file name before it is compared with the target prefix and suffix. After the comparison of the file name to the target pattern, the directory names, along with the slash that ends them, are added on to the prerequisite file names generated from the pattern rule's prerequisite patterns... [bold added]

您的目标模式要做包含斜杠.

Your target patterns do contain slashes.

如果您不相信我,请尝试一下.

Try it if you don't believe me.

更正:在命令中,应使用$<而不是%.c.

Correction: in the commands you should use $< rather than %.c.

这篇关于每个编译器选项组合的目标文件目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆