Makefile.headersinst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # ==========================================================================
  2. # Installing headers
  3. #
  4. # header-y files will be installed verbatim
  5. # unifdef-y are the files where unifdef will be run before installing files
  6. # objhdr-y are generated files that will be installed verbatim
  7. #
  8. # ==========================================================================
  9. UNIFDEF := scripts/unifdef -U__KERNEL__
  10. # Eliminate the contents of (and inclusions of) compiler.h
  11. HDRSED := sed -e "s/ inline / __inline__ /g" \
  12. -e "s/[[:space:]]__user[[:space:]]\{1,\}/ /g" \
  13. -e "s/(__user[[:space:]]\{1,\}/ (/g" \
  14. -e "s/[[:space:]]__force[[:space:]]\{1,\}/ /g" \
  15. -e "s/(__force[[:space:]]\{1,\}/ (/g" \
  16. -e "s/[[:space:]]__iomem[[:space:]]\{1,\}/ /g" \
  17. -e "s/(__iomem[[:space:]]\{1,\}/ (/g" \
  18. -e "s/[[:space:]]__attribute_const__[[:space:]]\{1,\}/\ /g" \
  19. -e "s/[[:space:]]__attribute_const__$$//" \
  20. -e "/^\#include <linux\/compiler.h>/d"
  21. _dst := $(if $(dst),$(dst),$(obj))
  22. kbuild-file := $(srctree)/$(obj)/Kbuild
  23. include $(kbuild-file)
  24. include scripts/Kbuild.include
  25. # If this is include/asm-$(ARCH) then override $(_dst) so that
  26. # we install to include/asm directly.
  27. # Unless $(BIASMDIR) is set, in which case we're probably doing
  28. # a 'headers_install_all' build and we should keep the -$(ARCH)
  29. # in the directory name.
  30. ifeq ($(obj),include/asm-$(ARCH)$(BIASMDIR))
  31. _dst := include/asm
  32. endif
  33. header-y := $(sort $(header-y) $(unifdef-y))
  34. subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
  35. header-y := $(filter-out %/, $(header-y))
  36. # stamp files for header checks
  37. check-y := $(patsubst %,.check.%,$(header-y) $(objhdr-y))
  38. # Work out what needs to be removed
  39. oldheaders := $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/*.h))
  40. unwanted := $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
  41. oldcheckstamps := $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/.check.*.h))
  42. unwanted += $(filter-out $(check-y),$(oldcheckstamps))
  43. # Prefix them all with full paths to $(INSTALL_HDR_PATH)
  44. header-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(header-y))
  45. objhdr-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(objhdr-y))
  46. check-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(check-y))
  47. quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  48. cmd_o_hdr_install = cp $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(objtree)/$(obj)/%,$@) \
  49. $(INSTALL_HDR_PATH)/$(_dst)
  50. quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  51. cmd_unifdef = $(UNIFDEF) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
  52. | $(HDRSED) > $@ || :
  53. quiet_cmd_check = CHECK $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/.check.%,$(_dst)/%,$@)
  54. cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
  55. $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
  56. quiet_cmd_remove = REMOVE $(_dst)/$@
  57. cmd_remove = rm -f $(INSTALL_HDR_PATH)/$(_dst)/$@
  58. quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  59. cmd_mkdir = mkdir -p $@
  60. .PHONY: __headersinst __headerscheck
  61. ifdef HDRCHECK
  62. __headerscheck: $(subdir-y) $(check-y)
  63. @true
  64. $(check-y) : $(INSTALL_HDR_PATH)/$(_dst)/.check.%.h : $(INSTALL_HDR_PATH)/$(_dst)/%.h
  65. $(call cmd,check)
  66. # Other dependencies for $(check-y)
  67. include /dev/null $(wildcard $(check-y))
  68. # ... but leave $(check-y) as .PHONY for now until those deps are actually correct.
  69. .PHONY: $(check-y)
  70. else
  71. # Rules for installing headers
  72. __headersinst: $(subdir-y) $(header-y) $(objhdr-y)
  73. @true
  74. $(objhdr-y) $(subdir-y) $(header-y): | $(INSTALL_HDR_PATH)/$(_dst) $(unwanted)
  75. $(INSTALL_HDR_PATH)/$(_dst):
  76. $(call cmd,mkdir)
  77. .PHONY: $(unwanted)
  78. $(unwanted):
  79. $(call cmd,remove)
  80. $(objhdr-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(objtree)/$(obj)/%.h $(kbuild-file)
  81. $(call cmd,o_hdr_install)
  82. $(header-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(kbuild-file)
  83. $(call cmd,unifdef)
  84. endif
  85. hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
  86. # Recursion
  87. .PHONY: $(subdir-y)
  88. $(subdir-y):
  89. $(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)