makefile 的其他用途
makefile 通常用于源代码编译;然而,作为一种依赖机制,make
可以有更多用途。
举一个小例子,我有一个每天运行的脚本,它可能会根据一些网络抓取在目录中更新或创建一些“*.csv.gz”文件;所有 gzip 压缩的文件需要合并为一个文件,如果有新文件,显然需要运行合并过程。
在我的例子中,以下 makefile 完成了这项工作:
consolidation: datasummary.pcl
datasummary.pcl: *.csv.gz
consolidate.py
cron 作业运行更新过程,然后 make 合并
;如果 datasummary.pcl
文件早于任何 *.csv.gz
文件,则 consolidate.py
运行。
我对 makefile 的不寻常使用(即与源编译无关)的想法非常感兴趣。您还可以提供哪些其他有趣的 makefile 使用示例?
假设我们谈论的是 GNU make;如果不是,请指定版本。
A makefile is typically used for source compilation; however, as a dependency mechanism, make
can have many more uses.
For a minor example, I have a script that runs daily, and it might update or create some '*.csv.gz' files in a directory based on some web-scraping; all the gzipped files need to be consolidated into one file, and if there are new files, obviously the consolidation process needs to be run.
In my case, the following makefile does the job:
consolidation: datasummary.pcl
datasummary.pcl: *.csv.gz
consolidate.py
The cron job runs the update process, and then make consolidation
; if the datasummary.pcl
file is older than any *.csv.gz
file, consolidate.py
runs.
I'm very interested in ideas about unusual (i.e. not about source compiling) uses of a makefile. What other interesting examples of makefile usage can you give?
Let's assume we talk about GNU make; if otherwise, please specify version.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我记得几年前看到过一些关于使用 Makefile 引导 Linux 系统的内容。各个系统组件被设置为目标,并且 make 将首先加载依赖项,就像 make 所做的那样。我相信他们从中获得了令人印象深刻的启动速度。这就是导致 基于依赖项的启动的原因 在 Debian/Ubuntu 中。
I remember seeing something several years ago about booting Linux systems using Makefiles. Individual system components were set as targets and make would load up the dependencies first, like make does. I believe they got impressive boot speeds out of it. That's what led to the dependency-based boot in Debian/Ubuntu.
在我工作时管理的系统上,我们使用 makefile 和一些脚本来生成命名、dhcpd 和 pxe 引导的配置文件。输入文件的内容如下:
例如:
然后我们有一个 makefile,它通过各种脚本运行该输入文件以生成适当的配置。然后它将重新启动配置已更改的所有守护程序。
On a system I administer at work we use a makefile and some scripts to generate config files for named, dhcpd and pxe booting. The input file is along the lines of:
for example:
We then have a makefile which runs that input file though various scripts to generate the appropriate configurations. It will then restart any daemons whose configs have changed.