filechk是定义在linux-2.6.30.4/scripts/Kbuild.include中
点击(此处)折叠或打开
- 49 define filechk
- 50 $(Q)set -e; \
- 51 $(kecho) ' CHK $@'; \
- 52 mkdir -p $(dir $@); \
- 53 $(filechk_$(1)) < $< > $@.tmp; \
- 54 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
- 55 rm -f $@.tmp; \
- 56 else \
- 57 $(kecho) ' UPD $@'; \
- 58 mv -f $@.tmp $@; \
- 59 fi
- 60 endef
这样调用filechk函数的:
点击(此处)折叠或打开
- linux-2.6.30.4/Makefile
- 714 include/linux/version.h: $(srctree)/Makefile FORCE
- 715 $(call filechk,version.h)
调用时打印如下:
点击(此处)折叠或打开
- set -e; : ' CHK include/linux/version.h'; mkdir -p include/linux/; (echo \#define LINUX_VERSION_CODE 132638; echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';) < /root/kernel/linux-2.6.30.4/Makefile > include/linux/version.h.tmp; if [ -r include/linux/version.h ] && cmp -s include/linux/version.h include/linux/version.h.tmp; then rm -f include/linux/version.h.tmp; else : ' UPD include/linux/version.h'; mv -f include/linux/version.h.tmp include/linux/version.h; fi
$@ // 目标是 include/linux/version.h
$< // 依赖是 $(srctree)/Makefile
L53 $(filechk_$(1)) < $< > $@.tmp; //$(1)是Makefile中函数的第一个参数的写法,此处是version.h
//$(file_chk_version.h) < /root/kernel/linux-2.6.30.4/Makefile > include/linux/versin.h.tmp
//这个地方不是很明白为什么要把 /root/kernel/linux-2.6.30.4/Makefile重定向为输入,去掉之后是没有问题的。
//$(file_chk_version.h)是在linux-2.6.30.4/Makefile中定义的
点击(此处)折叠或打开
- 708 define filechk_version.h
- 709 (echo \#define LINUX_VERSION_CODE $(shell \
- 710 expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \
- 711 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';)
- 712 endef
将下面这两句写入到include/linux/version.h.tmp中
#define LINUX_VERSION_CODE 132638
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
L55
if [ -r $@ ] && cmp -s $@ $@.tmp; //如果 include/linux/version.h存在并且与version.h.tmp按字节比较不一样,就用version.h.tmp覆盖version.h。
//假设Makefile中定义的版本号与version.h不一致,则以Makefile中的版本号为准。
还有一处调用filechk
点击(此处)折叠或打开
- 699 uts_len := 64
- 700 define filechk_utsrelease.h
- 701 if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
- 702 echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
- 703 exit 1; \
- 704 fi; \
- 705 (echo \#define UTS_RELEASE \"$(KERNELRELEASE)\";)
- 706 endef
-
- 717 include/linux/utsrelease.h: include/config/kernel.release FORCE
- 718$(call filechk,utsrelease.h)