Kbuild 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #
  2. # Kbuild for top-level directory of the kernel
  3. # This file takes care of the following:
  4. # 1) Generate bounds.h
  5. # 2) Generate timeconst.h
  6. # 3) Generate asm-offsets.h (may need bounds.h and timeconst.h)
  7. # 4) Check for missing system calls
  8. # 5) Generate constants.py (may need bounds.h)
  9. # Default sed regexp - multiline due to syntax constraints
  10. define sed-y
  11. "/^->/{s:->#\(.*\):/* \1 */:; \
  12. s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
  13. s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
  14. s:->::; p;}"
  15. endef
  16. # Use filechk to avoid rebuilds when a header changes, but the resulting file
  17. # does not
  18. define filechk_offsets
  19. (set -e; \
  20. echo "#ifndef $2"; \
  21. echo "#define $2"; \
  22. echo "/*"; \
  23. echo " * DO NOT MODIFY."; \
  24. echo " *"; \
  25. echo " * This file was generated by Kbuild"; \
  26. echo " */"; \
  27. echo ""; \
  28. sed -ne $(sed-y); \
  29. echo ""; \
  30. echo "#endif" )
  31. endef
  32. #####
  33. # 1) Generate bounds.h
  34. bounds-file := include/generated/bounds.h
  35. always := $(bounds-file)
  36. targets := kernel/bounds.s
  37. # We use internal kbuild rules to avoid the "is up to date" message from make
  38. kernel/bounds.s: kernel/bounds.c FORCE
  39. $(Q)mkdir -p $(dir $@)
  40. $(call if_changed_dep,cc_s_c)
  41. $(obj)/$(bounds-file): kernel/bounds.s FORCE
  42. $(call filechk,offsets,__LINUX_BOUNDS_H__)
  43. #####
  44. # 2) Generate timeconst.h
  45. timeconst-file := include/generated/timeconst.h
  46. targets += $(timeconst-file)
  47. quiet_cmd_gentimeconst = GEN $@
  48. define cmd_gentimeconst
  49. (echo $(CONFIG_HZ) | bc -q $< ) > $@
  50. endef
  51. define filechk_gentimeconst
  52. (echo $(CONFIG_HZ) | bc -q $< )
  53. endef
  54. $(obj)/$(timeconst-file): kernel/time/timeconst.bc FORCE
  55. $(call filechk,gentimeconst)
  56. #####
  57. # 3) Generate asm-offsets.h
  58. #
  59. offsets-file := include/generated/asm-offsets.h
  60. always += $(offsets-file)
  61. targets += arch/$(SRCARCH)/kernel/asm-offsets.s
  62. # We use internal kbuild rules to avoid the "is up to date" message from make
  63. arch/$(SRCARCH)/kernel/asm-offsets.s: arch/$(SRCARCH)/kernel/asm-offsets.c \
  64. $(obj)/$(timeconst-file) $(obj)/$(bounds-file) FORCE
  65. $(Q)mkdir -p $(dir $@)
  66. $(call if_changed_dep,cc_s_c)
  67. $(obj)/$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
  68. $(call filechk,offsets,__ASM_OFFSETS_H__)
  69. #####
  70. # 4) Check for missing system calls
  71. #
  72. always += missing-syscalls
  73. targets += missing-syscalls
  74. quiet_cmd_syscalls = CALL $<
  75. cmd_syscalls = $(CONFIG_SHELL) $< $(CC) $(c_flags) $(missing_syscalls_flags)
  76. missing-syscalls: scripts/checksyscalls.sh $(offsets-file) FORCE
  77. $(call cmd,syscalls)
  78. #####
  79. # 5) Generate constants for Python GDB integration
  80. #
  81. extra-$(CONFIG_GDB_SCRIPTS) += build_constants_py
  82. build_constants_py: $(obj)/$(timeconst-file) $(obj)/$(bounds-file)
  83. @$(MAKE) $(build)=scripts/gdb/linux $@
  84. # Keep these three files during make clean
  85. no-clean-files := $(bounds-file) $(offsets-file) $(timeconst-file)