Makefile.headersinst 3.3 KB

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