构建时自动创建目录
我有一个用 C
编写的项目,我使用 mercurial
(我也可以使用 git
)进行版本控制和 GNU
make
用于构建。该项目包括几个用于构建时生成的文件的空目录,例如依赖项 makefile 和目标文件。
然而,当我检查该项目时,不会创建空目录(它们被版本控制系统忽略)并且构建失败。
我想到的唯一补救措施是在项目的 58 个 makefile 中的每个配方中添加一个 mkdir -p
指令(它相当大)。除了大量编辑之外,GNU
make
手册中不鼓励使用 mkdir -p
,因为它与其他版本的 make< /代码>。
有没有更聪明的方法来解决这个问题?
I have a project written in C
and I am using mercurial
(I can use git
too) for version control and GNU
make
for building. The project includes several empty directories used for build-time generated files, such as dependency makefiles and object files.
When I check out the project, however, empty directories are not created (they are ignored by the version control system) and the build fails.
The only remedy I have in mind is to add a mkdir -p
directive in every single recipe in the 58 makefiles of the project (it is quite big). Apart from a lot of editing, mkdir -p
is discouraged in the GNU
make
manual for being incompatible with other versions of make
.
Is there any smarter way to overcome the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
git 和 Mercurial 都跟踪文件,而不是目录,因此不会存储空目录。
常见的技巧是仅将一个空文件添加到您需要的目录中,例如:
然后将其添加到存储库中。
Both git and Mercurial track files, not directories, so empty directories will not be stored.
The common trick is to just add an empty file to the directories you need, like:
And then add that to the repository.
包含:
你可以在 makefile 中
output
中的所有文件都将依赖于创建目录,而无需单独修改每个规则。$(MKDIR_P)
定义(mkdir -p
对于大多数系统或不起作用的特殊脚本)可以由配置脚本提供(例如 autoconf 使用AC_PROG_MKDIR_P
)或 makefile 中的条件设置。You can have:
in the makefile. Than all files in
output
will depend on creating the directory without modifying each rule separately.The
$(MKDIR_P)
definition (mkdir -p
for most systems or a special script where that does not work) can be provided by configuration script (e.g. autoconf usingAC_PROG_MKDIR_P
) or conditional setting in the makefile.正如您提到的,您也可以使用 git,也许您会对 bazaar 可以跟踪这一事实感兴趣目录的处理方式与文件的处理方式相同。我不知道这是否适合你,只是说一下。
As you mention that you could use git as well, maybe that you would be interested by the fact that bazaar can track directories the same way it does for files. I don't know if it is an option for you, just saying.