Makefile.headersinst 4.7 KB

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