Makefile.headersinst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # ==========================================================================
  2. # Installing headers
  3. #
  4. # All headers under include/uapi, include/generated/uapi,
  5. # arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
  6. # exported.
  7. # They are preprocessed to remove __KERNEL__ section of the file.
  8. #
  9. # ==========================================================================
  10. PHONY := __headers
  11. __headers:
  12. include scripts/Kbuild.include
  13. srcdir := $(srctree)/$(obj)
  14. subdirs := $(patsubst $(srcdir)/%/.,%,$(wildcard $(srcdir)/*/.))
  15. # caller may set destination dir (when installing to asm/)
  16. _dst := $(if $(dst),$(dst),$(obj))
  17. # Recursion
  18. __headers: $(subdirs)
  19. .PHONY: $(subdirs)
  20. $(subdirs):
  21. $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
  22. # Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi.
  23. # We have only sub-directories there.
  24. skip-inst := $(if $(filter %/uapi,$(obj)),1)
  25. ifeq ($(skip-inst),)
  26. # generated header directory
  27. gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
  28. # Kbuild file is optional
  29. kbuild-file := $(srctree)/$(obj)/Kbuild
  30. -include $(kbuild-file)
  31. old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
  32. ifneq ($(wildcard $(old-kbuild-file)),)
  33. include $(old-kbuild-file)
  34. endif
  35. installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
  36. gendir := $(objtree)/$(gen)
  37. header-files := $(notdir $(wildcard $(srcdir)/*.h))
  38. header-files += $(notdir $(wildcard $(srcdir)/*.agh))
  39. header-files := $(filter-out $(no-export-headers), $(header-files))
  40. genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
  41. genhdr-files := $(filter-out $(header-files), $(genhdr-files))
  42. # files used to track state of install/check
  43. install-file := $(installdir)/.install
  44. check-file := $(installdir)/.check
  45. # generic-y list all files an architecture uses from asm-generic
  46. # Use this to build a list of headers which require a wrapper
  47. generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
  48. wrapper-files := $(filter $(generic-files), $(generic-y))
  49. wrapper-files := $(filter-out $(header-files), $(wrapper-files))
  50. # all headers files for this dir
  51. all-files := $(header-files) $(genhdr-files) $(wrapper-files)
  52. output-files := $(addprefix $(installdir)/, $(all-files))
  53. ifneq ($(mandatory-y),)
  54. missing := $(filter-out $(all-files),$(mandatory-y))
  55. ifneq ($(missing),)
  56. $(error Some mandatory headers ($(missing)) are missing in $(obj))
  57. endif
  58. endif
  59. # Work out what needs to be removed
  60. oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
  61. unwanted := $(filter-out $(all-files),$(oldheaders))
  62. # Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
  63. unwanted-file := $(addprefix $(installdir)/, $(unwanted))
  64. printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
  65. quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
  66. file$(if $(word 2, $(all-files)),s))
  67. cmd_install = \
  68. $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
  69. $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
  70. for F in $(wrapper-files); do \
  71. echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
  72. done; \
  73. touch $@
  74. quiet_cmd_remove = REMOVE $(unwanted)
  75. cmd_remove = rm -f $(unwanted-file)
  76. quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
  77. # Headers list can be pretty long, xargs helps to avoid
  78. # the "Argument list too long" error.
  79. cmd_check = for f in $(all-files); do \
  80. echo "$(installdir)/$${f}"; done \
  81. | xargs \
  82. $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
  83. touch $@
  84. ifndef HDRCHECK
  85. # Rules for installing headers
  86. __headers: $(install-file)
  87. @:
  88. targets += $(install-file)
  89. $(install-file): scripts/headers_install.sh \
  90. $(addprefix $(srcdir)/,$(header-files)) \
  91. $(addprefix $(gendir)/,$(genhdr-files)) FORCE
  92. $(if $(unwanted),$(call cmd,remove),)
  93. $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
  94. $(call if_changed,install)
  95. else
  96. __headers: $(check-file)
  97. @:
  98. targets += $(check-file)
  99. $(check-file): scripts/headers_check.pl $(output-files) FORCE
  100. $(call if_changed,check)
  101. endif
  102. targets := $(wildcard $(sort $(targets)))
  103. cmd_files := $(wildcard \
  104. $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  105. ifneq ($(cmd_files),)
  106. include $(cmd_files)
  107. endif
  108. endif # skip-inst
  109. .PHONY: $(PHONY)
  110. PHONY += FORCE
  111. FORCE: ;