Makefile.headersinst 4.4 KB

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