学习 GNUMake 的资源?
我正在尝试为我正在进行的一个小项目学习 GNUMake。 到目前为止,即使是“基本”教程也显得相当粗糙,而且我还没有理解 makefile 语法。
有没有人有一些好的资源可以帮助绝对的初学者熟悉 GNUMake?
I'm trying to learn GNUMake for a small project I'm working on. So far, even the "basic" tutorials seem pretty rough and I've yet to make sense of the makefile syntax.
Does anyone have some good resources for an absolute beginner to get familiar with GNUMake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
权威指南是 http://www.gnu.org/software/make/manual /make.html
有一本 o'reilly 的书《Managing Projects with GNU Make》有更多解释。
您也可以使用早期版本,它们不专门涵盖 GnuMake,但要薄得多。
Make 在开发人员中是一个肮脏的秘密——我们没有人理解它,我们只是从别人那里借用了一个 make 脚本并改变了它。 我想只有一个脚本是从头开始编写的(可能是由该工具的创建者编写的)。
当您需要做的不仅仅是简单的示例时,大多数人要么切换到更现代的构建系统(如 Ant),要么使用 Perl/Python/等构建自己的系统。
The definitive guide is http://www.gnu.org/software/make/manual/make.html
There is an o'reilly book "Managing Projects with GNU Make" which has more explanation.
You can also uses the earlier editions, they don't cover GnuMake specifically but are a lot thinner.
Make is a dirty secret among developers - none of us understand it, we just borrow a make script from somebody else and change it. I imagine only one script was ever written from scratch (probably by the creator of the tool).
When you need to do more than the simple example most people either switch to a more modern build system like Ant or roll their own in Perl/Python/etc.
make 最常用的功能可以分为几个简单的概念、目标、依赖项和变量。
目标是您想要构建的东西,但目标下的命令可以是编译器命令或脚本。 一般来说,每个目标都指代代码中的一个模块,但您可以根据您的项目需要进行细化。
依赖项是项目中的文件或其他目标。 最好的例子是 C 项目,您正在其中从一堆目标文件构建二进制文件。 在构建二进制文件之前,每个目标文件都需要存在,因此 make 将遍历您的目标,直到完成所有依赖项,然后运行整个目标的命令。
变量并不总是必需的,但对于处理诸如编译器标志之类的事情非常方便。 典型的示例是 CC 和 CCFLAG,它们将引用您使用的编译器(即 gcc)和 -ansi -Wall -o2 等标志。
一些更一般的提示和技巧:
The most commonly used features of make can be broken down into a couple simple concepts, targets, dependencies and variables.
Targets are the things you want to build, but the command(s) beneath a target can be compiler commands or scripts. Generally each target refers to a module in your code, but you can make these as granular as you want to suit your project.
Dependencies are files or other targets in your project. The best example of this is for a C project where you're building a binary from a bunch of object files. Each object file will need to exist before you can build the binary, so make will traverse your targets until all of the dependencies have been completed, and then run the command for the overall target.
Variables aren't always necessary, but are pretty handy for handling things like compiler flags. The canonical examples are CC and CCFLAGs which will refer to the compiler your using i.e. gcc and the flags like -ansi -Wall -o2.
A couple more general tips and tricks:
《使用 GNU Make 管理项目,第 3 版》被置于“GNU 自由文档许可证”之下,可以合法地免费在线阅读:链接。
"Managing Projects with GNU Make, 3rd edition" is put under "GNU Free Documentation License" and can be legally read online for free: link.
我同意奥莱利的书建议。
有关 Make 的一些有用的提示、技巧和见解,请查看 Mr. 制作文章
I concur with the O'Reilly book suggestion.
For some helpful tips, tricks and insights into Make look at the Mr. Make articles
mgb:更糟糕的是。 我曾经从头开始编写过一个复杂的 make 系统(几千个文件、五十或一百个目录、四五个编译器和交叉编译目标、2 个操作系统等)。 我坐下来,首先从里到外学习了 gnu make,设计了系统,首先尝试了一个原型。 我们对结果都非常满意。
但那是几年前的事了。 你知道我今天怎么写吗? 和你描述的一样。 它实在是太繁琐了,语法细节也太晦涩难懂了,除非你经常这样做,否则你就记不住细节。 我想,就像任何其他具有非直观语法和一些奇怪规则的语言一样。
mgb: It's even worse that that. I once did write a complicated make system from scratch (a few thousand files, fifty or a hundred directories, four or five compilers and cross-compilation targets, 2 OS's, etc.). I sat down and learned gnu make inside and out first off, designed the system, played around with a prototype first. We were all very happy with the result.
But that was years ago. You know how I write them today? Same way you describe. It's just fiddly enough and the syntax details are obscure enough than unless you do it fairly regularly you can't remember the details. Just like any other language with non-intuitive syntax and some quirky rules, I guess.
我不太喜欢 GNU 信息系统,但我发现 GNU make 信息页面非常有用。 一旦您了解了非常基本的概念以及大致可用的内容,我发现信息页面是引用信息(例如预构建函数)的最快方式。
(忘记 GNU
info
程序,并使用例如pinfo
相反。)I am not great fan of GNU info system, but I have found the GNU make info pages to be very useful. Once you know the very basic concepts and roughly what kind of things are available, I have found that info pages are the quickest way to refer information like prebuilt functions, for example.
(Forget the GNU
info
program, and use e.g.pinfo
instead.)