“make”的其他用途是什么? 命令?
有一天,一位系统管理员老师告诉我,我应该学习使用“make”,因为我可以将它用于许多其他只会触发编译的事情。
我从来没有机会更长时间地谈论它。 你有什么好的例子吗?
作为奖励,这个工具是否已被弃用,现代替代品是什么(用于编译目的和其他目的)?
A sysadmin teacher told me one day that I should learn to use "make" because I could use it for a lot of other things that just triggering complilations.
I never got the chance to talk longer about it. Do you have any good example ?
As a bonus, isn't it this tool deprecated, and what are modern alternatives (for the compilation purpose and others) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我记得几年前在 Slashdot 上看到过一篇文章,描述了一种使用 make 优化 Linux 启动顺序的技术。
编辑:
这是 IBM 的一篇文章 解释了原理。
I remember seeing an article on Slashdot a few years ago describing a technique for optimising Linux boot sequence by using make.
edit:
Here's an article from IBM explaining the principle.
Make可以用来执行任何你想执行的命令。 它最适合用于需要依赖性检查的活动,但是您没有理由不能使用 make 来检查电子邮件、重新启动服务器、进行备份或执行其他操作。
Ant、NAnt 和 msbuild 被认为是现代的替代方案,但 plain-old-make 仍然在不使用 Java 或 .NET 的环境中广泛使用。
Make can be used to execute any commands you want to execute. It is best used for activities that require dependency checking, but there is no reason you couldn't use make to check your e-mail, reboot your servers, make backups, or anything else.
Ant, NAnt, and msbuild are supposedly the modern alternatives, but plain-old-make is still used extensively in environments that don't use Java or .NET.
吗?! 不,一点也不。 我使用 Linux,所以我意识到我不是一个普通人,但我几乎每天都使用它。 我确信有成千上万的 Linux 开发者每天都在使用它。
What?! No, not even slightly. I'm on Linux so I realise I'm not an average person, but I use it almost daily. I'm sure there are thousands of Linux devs who do use it daily.
除了编译之外,make 的另一项出色用途是 LaTeX。 如果您正在使用 LaTeX 进行任何严肃的工作,您会发现 make 非常方便,因为在使用 BibTex 或目录时需要多次重新解释 .tex 文件。
Make 绝对不会被弃用。 尽管做同样的事情有不同的方法(Windows 上的批处理文件,Linux 上的 shell 脚本),但恕我直言,make 效果最好。
One excellent thing make can be used for besides compilation is LaTeX. If you're doing any serious work with LaTeX, you'll find make very handy because of the need to re-interpret .tex files several times when using BibTex or tables of contents.
Make is definitely not deprecated. Although there are different ways of doing the same thing (batch files on Windows, shell scripts on Linux) make works the best, IMHO.
Make 执行拓扑排序,也就是说给定一堆东西和一组当一件事在另一件事之前的要求中,它找到了一种对所有事物进行排序的方法,以便满足所有要求。 构建事物(程序、文档、分发 tarball 等)是拓扑排序的一种常见用途,但还有其他用途。 您可以为数据中心中的每台服务器创建一个包含一个条目的 Makefile,包括服务器之间的依赖关系(NFS、NIS、DNS 等),并且 make 可以告诉您断电后打开计算机的顺序,或者停电前按什么顺序关闭它们。 您可以使用它来确定在单个服务器上启动服务的顺序。 您可以用它来确定早上穿衣服的顺序。 任何需要找到满足 A 形式的一系列特定要求的一堆事物或任务的顺序的问题都在 B 之前,这是一个可以用 make 解决的潜在候选者。
Make performs a topological sort, which is to say that given a bunch of things, and a set of requirements that one thing be before another thing, it finds a way to order all of the things so that all of the requirements are met. Building things (programs, documents, distribution tarballs, etc.) is one common use for topological sorting, but there are others. You can create a Makefile with one entry for every server in your data center, including dependencies between servers (NFS, NIS, DNS, etc.) and make can tell you what order in which to turn on your computers after a power outage, or what order to turn them off in before a power outage. You can use it to figure out what order in which to start services on a single server. You can use it to figure out what order to put your clothes on in the morning. Any problem where you need to find an order of a bunch of things or tasks that satisfies a bunch of specific requirements of the form A goes before B is a potential candidate for being solved with make.
我见过的最随意的使用是在 BCCD。 它实际上工作得很好,一旦你克服了 wtf 时刻......
将 make 视为具有附加功能的 shell 脚本。
The most random use I've ever seen is make being used in place of bash for init scripts on BCCD. It actually worked decently, once you got over the wtf moment....
Think of make as shell scripts with added oomph.
好吧,我确信 UNIX 工具“make”仍然被大量使用,即使它在 .Net 世界中日渐式微。 虽然现在越来越多的人可能使用 MSBUILD、Ant、nAnt 和其他工具,但它们本质上只是使用不同的文件语法“make”。 基本概念是相同的。
对于任何将输入文件处理为输出文件的情况,Make 工具都很方便。 使用 MSWord 编写报告,但以 PDF 形式分发? -- 使用 make 生成 PDF。
Well, I sure that the UNIX tool "make" is still being used a lot, even if it's waning in the .Net world. And while more people may be using MSBUILD, Ant, nAnt, and others tools these days, they are essentially just "make" with a different file syntax. The basic concept is the same.
Make tools are handy for anything where there's an input file which is processed into an output file. Write your reports in MSWord, but distribute them as PDFs? -- use make to generate the PDFs.
如果需要的话,配置文件可以通过 crontab 进行更改。
我有
postfix
映射和squid
外部表的示例。/etc/postfix/Makefile 的示例:
etc
Configuration file changes through crontab, if needed.
I have examples for
postfix
maps, and forsquid
external tables.Example for /etc/postfix/Makefile:
etc