Makefile.headersinst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # ==========================================================================
  2. # Installing headers
  3. #
  4. # All headers under include/uapi, include/generated/uapi,
  5. # arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
  6. # exported.
  7. # They are preprocessed to remove __KERNEL__ section of the file.
  8. #
  9. # ==========================================================================
  10. PHONY := __headers
  11. __headers:
  12. include scripts/Kbuild.include
  13. srcdir := $(srctree)/$(obj)
  14. # When make is run under a fakechroot environment, the function
  15. # $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular
  16. # files. So, we are using a combination of sort/dir/wildcard which works
  17. # with fakechroot.
  18. subdirs := $(patsubst $(srcdir)/%/,%,\
  19. $(filter-out $(srcdir)/,\
  20. $(sort $(dir $(wildcard $(srcdir)/*/)))))
  21. # Recursion
  22. __headers: $(subdirs)
  23. .PHONY: $(subdirs)
  24. $(subdirs):
  25. $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@
  26. # Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi.
  27. # We have only sub-directories there.
  28. skip-inst := $(if $(filter %/uapi,$(obj)),1)
  29. ifeq ($(skip-inst),)
  30. # Kbuild file is optional
  31. kbuild-file := $(srctree)/$(obj)/Kbuild
  32. -include $(kbuild-file)
  33. installdir := $(INSTALL_HDR_PATH)/$(dst)
  34. gendir := $(objtree)/$(subst include/,include/generated/,$(obj))
  35. header-files := $(notdir $(wildcard $(srcdir)/*.h))
  36. header-files += $(notdir $(wildcard $(srcdir)/*.agh))
  37. header-files := $(filter-out $(no-export-headers), $(header-files))
  38. genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
  39. genhdr-files := $(filter-out $(header-files), $(genhdr-files))
  40. # files used to track state of install/check
  41. install-file := $(installdir)/.install
  42. check-file := $(installdir)/.check
  43. # all headers files for this dir
  44. all-files := $(header-files) $(genhdr-files)
  45. output-files := $(addprefix $(installdir)/, $(all-files))
  46. ifneq ($(mandatory-y),)
  47. missing := $(filter-out $(all-files),$(mandatory-y))
  48. ifneq ($(missing),)
  49. $(error Some mandatory headers ($(missing)) are missing in $(obj))
  50. endif
  51. endif
  52. # Work out what needs to be removed
  53. oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
  54. unwanted := $(filter-out $(all-files),$(oldheaders))
  55. # Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
  56. unwanted-file := $(addprefix $(installdir)/, $(unwanted))
  57. printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
  58. quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
  59. file$(if $(word 2, $(all-files)),s))
  60. cmd_install = \
  61. $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
  62. $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
  63. touch $@
  64. quiet_cmd_remove = REMOVE $(unwanted)
  65. cmd_remove = rm -f $(unwanted-file)
  66. quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
  67. # Headers list can be pretty long, xargs helps to avoid
  68. # the "Argument list too long" error.
  69. cmd_check = for f in $(all-files); do \
  70. echo "$(installdir)/$${f}"; done \
  71. | xargs \
  72. $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
  73. touch $@
  74. ifndef HDRCHECK
  75. # Rules for installing headers
  76. __headers: $(install-file)
  77. @:
  78. targets += $(install-file)
  79. $(install-file): scripts/headers_install.sh \
  80. $(addprefix $(srcdir)/,$(header-files)) \
  81. $(addprefix $(gendir)/,$(genhdr-files)) FORCE
  82. $(if $(unwanted),$(call cmd,remove),)
  83. $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
  84. $(call if_changed,install)
  85. else
  86. __headers: $(check-file)
  87. @:
  88. targets += $(check-file)
  89. $(check-file): scripts/headers_check.pl $(output-files) FORCE
  90. $(call if_changed,check)
  91. endif
  92. targets := $(wildcard $(sort $(targets)))
  93. cmd_files := $(wildcard \
  94. $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  95. ifneq ($(cmd_files),)
  96. include $(cmd_files)
  97. endif
  98. endif # skip-inst
  99. .PHONY: $(PHONY)
  100. PHONY += FORCE
  101. FORCE: ;