自动创建.OBJDIR子目录 [英] Automatically create .OBJDIR subdirectories

查看:52
本文介绍了自动创建.OBJDIR子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统:FreeBSD 11.0-释放

OS: FreeBSD 11.0-RELEASE

我有以下目录结构:

/xxx/obj/
/xxx/src/deep.cpp
/xxx/flat.cpp
/xxx/makefile

makefile的内容如下:

The content of makefile is as follows:

flat.out: flat.o

deep.out: src/deep.o

我建公寓没问题:

/xxx $ make flat.out
c++ -O2 -pipe -c /xxx/flat.cpp -o flat.o
cc -O2 -pipe  flat.o  -o flat.out
/xxx $ ls obj
flat.o          flat.out

但是当我尝试深入学习时,它会失败:

But when I try to build deep it fails:

/xxx $ make deep.out
c++ -O2 -pipe -c /xxx/src/deep.cpp -o src/deep.o
error: unable to open output file 'src/deep.o': 'No such file or directory'
1 error generated.
*** Error code 1

Stop.
make: stopped in /xxx

如果我随后手动创建/xxx/obj/src ,则会成功:

If I then create /xxx/obj/src manually it succeeds:

/xxx $ mkdir obj/src
/xxx $ make deep.out
c++ -O2 -pipe -c /xxx/src/deep.cpp -o src/deep.o
cc -O2 -pipe  src/deep.o  -o deep.out
/xxx $ ls obj
deep.out        flat.o          flat.out        src
/xxx $ ls obj/src
deep.o

根据此来源 bmake(又名bsdmake?)支持自动创建资源外的OBJDIR,但我不知道具体如何.

According to this source bmake (aka bsdmake?) supports automatic creation of out-of-source OBJDIRs, but I cannot figure out how exactly.

在通常情况下,如何配置bmake自动创建相关目录?

How do I configure bmake to create the relevant directories automatically, in the general case?

推荐答案

支持源外OBJDIR的自动创建,但您似乎并不希望这样做.可以使用 bmake(1)指令实现源外OBJDIR 的创建,但 bmake(1)程序本身不支持.就是这样,

Automatic creation of out-of-source OBJDIRs is supported but not in the sense you seem to expect it. Creation of out-of-source OBJDIRs can be implemented with bmake(1) directives but is not supported by the bmake(1) program itself. That said,

  • 如果您使用FreeBSD附带的 bmake(1)指令来构建您的项目,那么 obj 目标将支持并实现OBJDIR的创建,这样,命令 make obj 将创建OBJDIR.参见文件 <代码> bsd.obj.mk 获取更多文档和实施细节.FreeBSD源代码包含许多使用这些指令进行构建的程序示例.

  • If you use bmake(1) directives shipped with FreeBSD to build your project, then the creation of OBJDIRs is supported and implemented by the obj target, so that the command make obj will create the OBJDIRs. See the file bsd.obj.mk for further documentation and implementation details. FreeBSD sources contain a lot of examples of programs using these directives to build.

如果您使用(便携式)bmake(1)指令> bsdowl包 ,那么目标 obj 支持并实现OBJDIR的创建,因此命令 make obj 或使用更通用的目标命令 make preparatives 将创建OBJDIR.示例目录 包含几个基于 C 的示例,展示了如何准备您的使用 bsdowl包

If you use bmake(1) directives shipped as the (portable) bsdowl package, then the creation of OBJDIRs is supported and implemented by the target obj so that the command make obj or the command make preparatives using a more general target will create the OBJDIRs. The example directory contains several C-based examples showing how to prepare your Makefiles to build your project with the bsdowl package.

如果您使用自定义的 bmake(1)指令,那么您将必须自己实现一个实现此目标的目标.文件 bsd.obj.mk 绝对是上手的好资源.

If you use custom bmake(1) directives, then you will have to implement a target taking care of this creation yourself. The file bsd.obj.mk is definitely a good source to get started with this.

需要注意的重要一点是, bmake(1)在处理任何目标之前确定其实际工作目录,这意味着执行请求目标的目标几乎总是正确的做法.自行创建OBJDIR.因此,示例中的命令 bmake obj all 将失败,并返回与您上面报告的相同的错误消息.正确的调用应该是 bmake obj&&bmake all ,因为第二个 bmake(1)进程现在有机会更改为上一次运行创建的OBJDIR.

An important point to note, is that bmake(1) determines its actual working directory before processing any targets, which means that it is almost always the right thing to do to execute the target requesting the creation of OBJDIRs on its own. Because of this, the command bmake obj all from your example would fail with the same error message you reported above. The correct invocation would instead be bmake obj && bmake all, since the second bmake(1) process has now the chance to change to the OBJDIR created by the previous run.

这篇关于自动创建.OBJDIR子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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