Linux内核---8.filechk函数分析

来源:互联网 发布:淘宝店能放音乐吗 编辑:程序博客网 时间:2024/05/30 22:51
filechk是定义在linux-2.6.30.4/scripts/Kbuild.include中

点击(此处)折叠或打开

  1. 49 define filechk
  2.  50 $(Q)set -e; \
  3.  51 $(kecho) ' CHK $@'; \
  4.  52 mkdir -p $(dir $@); \
  5.  53 $(filechk_$(1)) < $< > $@.tmp; \
  6.  54 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
  7.  55 rm -f $@.tmp; \
  8.  56 else \
  9.  57 $(kecho) ' UPD $@'; \
  10.  58 mv -f $@.tmp $@; \
  11.  59 fi
  12.  60 endef
这样调用filechk函数的:

点击(此处)折叠或打开

  1. linux-2.6.30.4/Makefile
  2.    714    include/linux/version.h: $(srctree)/Makefile FORCE
  3.    715        $(call filechk,version.h)
调用时打印如下:

点击(此处)折叠或打开

  1. 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.] && 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中定义的

点击(此处)折叠或打开

  1.    708    define filechk_version.h
  2.    709        (echo \#define LINUX_VERSION_CODE $(shell \
  3.    710        expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \
  4.    711        echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';)
  5.    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

点击(此处)折叠或打开

  1.    699    uts_len := 64
  2.    700    define filechk_utsrelease.h
  3.    701        if [ `echo -"$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
  4.    702         echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
  5.    703         exit 1; \
  6.    704        fi; \
  7.    705        (echo \#define UTS_RELEASE \"$(KERNELRELEASE)\";)
  8.    706    endef

  9.    717 include/linux/utsrelease.h: include/config/kernel.release FORCE
  10.   718$(call filechk,utsrelease.h)
utsrease.h与version.h差不多,utsrease.h中间调用了filechk_utsrelease.h函数,主要是检查KERNELRELEASE这个变量是否超过64字长,如果超过则报错,没有超过就写到include/linux/utsrelease.h.tmp中去,然后更新utsrelease.h。
0 0