Makefile.headersinst 3.0 KB

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