Makefile.headersinst 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. include scripts/Kbuild.include
  15. install := $(INSTALL_HDR_PATH)/$(_dst)
  16. header-y := $(sort $(header-y) $(unifdef-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 = $(PERL) $< $(srctree)/$(obj) $(install) $(header-y); \
  36. $(PERL) $< $(objtree)/$(obj) $(install) $(objhdr-y); \
  37. touch $@
  38. quiet_cmd_remove = REMOVE $(unwanted)
  39. cmd_remove = rm -f $(unwanted-file)
  40. quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
  41. cmd_check = $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH) \
  42. $(addprefix $(install)/, $(all-files)); \
  43. touch $@
  44. PHONY += __headersinst __headerscheck
  45. ifndef HDRCHECK
  46. # Rules for installing headers
  47. __headersinst: $(subdirs) $(install-file)
  48. @:
  49. targets += $(install-file)
  50. $(install-file): scripts/headers_install.pl $(input-files) FORCE
  51. $(if $(unwanted),$(call cmd,remove),)
  52. $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
  53. $(call if_changed,install)
  54. else
  55. __headerscheck: $(subdirs) $(check-file)
  56. @:
  57. targets += $(check-file)
  58. $(check-file): scripts/headers_check.pl $(output-files) FORCE
  59. $(call if_changed,check)
  60. endif
  61. # Recursion
  62. hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
  63. .PHONY: $(subdirs)
  64. $(subdirs):
  65. $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
  66. targets := $(wildcard $(sort $(targets)))
  67. cmd_files := $(wildcard \
  68. $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  69. ifneq ($(cmd_files),)
  70. include $(cmd_files)
  71. endif
  72. .PHONY: $(PHONY)
  73. PHONY += FORCE
  74. FORCE: ;