博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Makefile 中会在多处地方看到 FORCE
阅读量:7029 次
发布时间:2019-06-28

本文共 2229 字,大约阅读时间需要 7 分钟。

转载:http://blog.csdn.net/wzw88486969/article/details/11739737

 

在内核的 Makefile 中会在多处地方看到 FORCE ,比如:

# vmlinux image - including updated kernel symbolsvmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o $(kallsyms.o) FORCE

实际上它是一个伪目标:

PHONY +=FORCEFORCE:# Declare the contents of the .PHONY variable as phony.  We keep that# information in a variable so we can use it in if_changed and friends..PHONY: $(PHONY)

从上面看到,FORCE 既没有依赖的规则,其底下也没有可执行的命令。

如果一个规则没有命令或者依赖,而且它的目标不是一个存在的文件名,在执行此规则时,目标总会被认为是最新的。也就是说,这个规则一旦被执 行,make 就认为它所表示的目标已经被更新过。当将这样的目标(FORCE)作为一个规则的依赖时(如上的 vmlinux: ),由于依赖总被认为是被更新过的,所以作为依赖所在的规则定义的命令总会被执行。

比如上面的 vmlinux: 在每次 make 时,它下面的这些命令总会被执行:

ifdef CONFIG_HEADERS_CHECK        $(Q)$(MAKE)-f $(srctree)/Makefile headers_checkendififdef CONFIG_SAMPLES        $(Q)$(MAKE) $(build)=samplesendififdef CONFIG_BUILD_DOCSRC        $(Q)$(MAKE) $(build)=Documentationendif        $(call vmlinux-modpost)        $(call if_changed_rule,vmlinux__)        $(Q)rm -f .old_version

用一个直观的例子可以清楚看到这一点,比如有 1 Makefile 文件:

helloworld:file1.o file2.ogcc file1.o file2.o -o helloworldfile1.o:file1.c file2.hgcc -c file1.c -o file1.ofile2.o:file2.c file2.hgcc -c file2.c -o file2.oclean: rm -rf *.o helloworldPHONY   +=FORCEFORCE:.PHONY: $(PHONY)

在执行 make 后,观察文件的生成时间:

[beyes@SLinux Makefile]$ lltotal 32-rw-rw-r--. 1 beyes beyes  129 Apr 16 19:00 file1.c-rw-rw-r--. 1 beyes beyes  924 Apr 16 20:20 file1.o-rw-rw-r--. 1 beyes beyes  108 Apr 16 19:01 file2.c-rw-rw-r--. 1 beyes beyes  139 Apr 16 18:49 file2.h-rw-rw-r--. 1 beyes beyes  880 Apr 16 20:20 file2.o-rwxrwxr-x. 1 beyes beyes 4786 Apr 16 20:20 helloworld-rw-rw-r--. 1 beyes beyes  246 Apr 16 20:20 Makefile

helloworld 文件的生成时间是 20:20

如果将上面的 Makefile 文件的 helloworld:file1.o file2.o 这一句后面加个 FORCE,那么再过几分钟后再 make 时,再观察一下 helloworld 的生成时间,可以看到是重新生成的了,当然在 make 执行时命令的输出也能知道该命令被再次执行:

[beyes@SLinux Makefile]$ lltotal 32-rw-rw-r--. 1 beyes beyes  129 Apr 16 19:00 file1.c-rw-rw-r--. 1 beyes beyes  924 Apr 16 20:20 file1.o-rw-rw-r--. 1 beyes beyes  108 Apr 16 19:01 file2.c-rw-rw-r--. 1 beyes beyes  139 Apr 16 18:49 file2.h-rw-rw-r--. 1 beyes beyes  880 Apr 16 20:20 file2.o-rwxrwxr-x. 1 beyes beyes 4786 Apr 16 20:26 helloworld-rw-rw-r--. 1 beyes beyes  246 Apr 16 20:20 Makefile

 

你可能感兴趣的文章
小技巧积累
查看>>
Java JDBC链接Oracle数据库
查看>>
Moss2010 部署命令
查看>>
Git 操作分支
查看>>
Grid search in the tidyverse
查看>>
hdu 三部曲 Contestants Division
查看>>
day22——创建表、增加数据、查询数据
查看>>
css伪元素实现tootip提示框
查看>>
关于函数指针的总结
查看>>
采用PHP函数uniqid生成一个唯一的ID
查看>>
Centos7安装32位库用来安装32位软件程序
查看>>
【HMOI】小C的填数游戏 DP+线段树维护
查看>>
java中23种设计模式之6-适配器模式(adapter pattern)
查看>>
Easy C 编程 in Linux
查看>>
SQL Server 事务语法
查看>>
poj3761(反序表)
查看>>
x86寄存器总结
查看>>
jquery easyui ajax data属性传值方式
查看>>
封装了些文件相关的操作
查看>>
什么是Solr
查看>>