Makefile.headersinst 4.0 KB

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