Makefile.headersinst 4.0 KB

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