Makefile.headersinst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. # called may set destination dir (when installing to asm/)
  10. _dst := $(or $(destination-y),$(dst),$(obj))
  11. # generated header directory
  12. gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
  13. kbuild-file := $(srctree)/$(obj)/Kbuild
  14. include $(kbuild-file)
  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-files := $(foreach hdr, $(header-y), \
  38. $(or \
  39. $(wildcard $(srcdir)/$(hdr)), \
  40. $(wildcard $(oldsrcdir)/$(hdr)), \
  41. $(error Missing UAPI file $(srcdir)/$(hdr)) \
  42. )) \
  43. $(foreach hdr, $(genhdr-y), \
  44. $(or \
  45. $(wildcard $(gendir)/$(hdr)), \
  46. $(error Missing generated UAPI file $(gendir)/$(hdr)) \
  47. ))
  48. # Work out what needs to be removed
  49. oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
  50. unwanted := $(filter-out $(all-files),$(oldheaders))
  51. # Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
  52. unwanted-file := $(addprefix $(installdir)/, $(unwanted))
  53. printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
  54. quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
  55. file$(if $(word 2, $(all-files)),s))
  56. cmd_install = \
  57. $(PERL) $< $(installdir) $(SRCARCH) $(input-files); \
  58. for F in $(wrapper-files); do \
  59. echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
  60. done; \
  61. touch $@
  62. quiet_cmd_remove = REMOVE $(unwanted)
  63. cmd_remove = rm -f $(unwanted-file)
  64. quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
  65. # Headers list can be pretty long, xargs helps to avoid
  66. # the "Argument list too long" error.
  67. cmd_check = for f in $(all-files); do \
  68. echo "$(installdir)/$${f}"; done \
  69. | xargs \
  70. $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
  71. touch $@
  72. PHONY += __headersinst __headerscheck
  73. ifndef HDRCHECK
  74. # Rules for installing headers
  75. __headersinst: $(subdirs) $(install-file)
  76. @:
  77. targets += $(install-file)
  78. $(install-file): scripts/headers_install.pl $(input-files) FORCE
  79. $(if $(unwanted),$(call cmd,remove),)
  80. $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
  81. $(call if_changed,install)
  82. else
  83. __headerscheck: $(subdirs) $(check-file)
  84. @:
  85. targets += $(check-file)
  86. $(check-file): scripts/headers_check.pl $(output-files) FORCE
  87. $(call if_changed,check)
  88. endif
  89. # Recursion
  90. hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
  91. .PHONY: $(subdirs)
  92. $(subdirs):
  93. $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
  94. targets := $(wildcard $(sort $(targets)))
  95. cmd_files := $(wildcard \
  96. $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  97. ifneq ($(cmd_files),)
  98. include $(cmd_files)
  99. endif
  100. .PHONY: $(PHONY)
  101. PHONY += FORCE
  102. FORCE: ;