Makefile.headersinst 3.7 KB

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