Makefile.headersinst 4.3 KB

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