Makefile.headersinst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. install := $(INSTALL_HDR_PATH)/$(_dst)
  26. header-y := $(sort $(header-y) $(unifdef-y))
  27. subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
  28. header-y := $(filter-out %/, $(header-y))
  29. # stamp files for header checks
  30. check-y := $(patsubst %,.check.%,$(header-y) $(objhdr-y))
  31. # Work out what needs to be removed
  32. oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
  33. unwanted := $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
  34. oldcheckstamps := $(patsubst $(install)/%,%,$(wildcard $(install)/.check.*.h))
  35. unwanted += $(filter-out $(check-y),$(oldcheckstamps))
  36. # Prefix them all with full paths to $(INSTALL_HDR_PATH)
  37. header-y := $(patsubst %,$(install)/%,$(header-y))
  38. objhdr-y := $(patsubst %,$(install)/%,$(objhdr-y))
  39. check-y := $(patsubst %,$(install)/%,$(check-y))
  40. quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  41. cmd_o_hdr_install = cp $(patsubst $(install)/%,$(objtree)/$(obj)/%,$@) \
  42. $(install)
  43. quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  44. cmd_unifdef = $(UNIFDEF) $(patsubst $(install)/%,$(srctree)/$(obj)/%,$@)\
  45. | $(HDRSED) > $@ || :
  46. quiet_cmd_check = CHECK $(patsubst $(install)/.check.%,$(_dst)/%,$@)
  47. cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
  48. $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
  49. quiet_cmd_remove = REMOVE $(_dst)/$@
  50. cmd_remove = rm -f $(install)/$@
  51. quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  52. cmd_mkdir = mkdir -p $@
  53. .PHONY: __headersinst __headerscheck
  54. ifdef HDRCHECK
  55. __headerscheck: $(subdir-y) $(check-y)
  56. @true
  57. $(check-y) : $(install)/.check.%.h : $(install)/%.h
  58. $(call cmd,check)
  59. # Other dependencies for $(check-y)
  60. include /dev/null $(wildcard $(check-y))
  61. # but leave $(check-y) as .PHONY for now until those
  62. # deps are actually correct.
  63. .PHONY: $(check-y)
  64. else
  65. # Rules for installing headers
  66. __headersinst: $(subdir-y) $(header-y) $(objhdr-y)
  67. @true
  68. $(objhdr-y) $(subdir-y) $(header-y): | $(install) $(unwanted)
  69. $(install):
  70. $(call cmd,mkdir)
  71. # Rules for removing unwanted header files
  72. .PHONY: $(unwanted)
  73. $(unwanted):
  74. $(call cmd,remove)
  75. # Install generated files
  76. $(objhdr-y): $(install)/%.h: $(objtree)/$(obj)/%.h $(kbuild-file)
  77. $(call cmd,o_hdr_install)
  78. # Unifdef header files and install them
  79. $(header-y): $(install)/%.h: $(srctree)/$(obj)/%.h $(kbuild-file)
  80. $(call cmd,unifdef)
  81. endif
  82. hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
  83. # Recursion
  84. .PHONY: $(subdir-y)
  85. $(subdir-y):
  86. $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@