Makefile.headersinst 3.0 KB

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