Makefile.headersinst 3.2 KB

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