Makefile.headersinst 4.7 KB

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