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
set -e; //-e 如果命令带非零值返回,立即退出
$@ // 目标是 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)
utsrease.h与version.h差不多,utsrease.h中间调用了filechk_utsrelease.h函数,主要是检查KERNELRELEASE这个变量是否超过64字长,如果超过则报错,没有超过就写到include/linux/utsrelease.h.tmp中去,然后更新utsrelease.h。
阅读(3895) | 评论(0) | 转发(0) |