Makefile.headersinst 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # ==========================================================================
  2. # Installing headers
  3. #
  4. # header-y files will be installed verbatim
  5. # unifdef-y are the files where unifdef will be run before installing files
  6. # objhdr-y are generated files that will be installed verbatim
  7. #
  8. # ==========================================================================
  9. UNIFDEF := scripts/unifdef -U__KERNEL__
  10. # Eliminate the contents of (and inclusions of) compiler.h
  11. HDRSED := sed -e "s/ inline / __inline__ /g" \
  12. -e "s/[[:space:]]__user[[:space:]]\{1,\}/ /g" \
  13. -e "s/(__user[[:space:]]\{1,\}/ (/g" \
  14. -e "s/[[:space:]]__force[[:space:]]\{1,\}/ /g" \
  15. -e "s/(__force[[:space:]]\{1,\}/ (/g" \
  16. -e "s/[[:space:]]__iomem[[:space:]]\{1,\}/ /g" \
  17. -e "s/(__iomem[[:space:]]\{1,\}/ (/g" \
  18. -e "s/[[:space:]]__attribute_const__[[:space:]]\{1,\}/\ /g" \
  19. -e "s/[[:space:]]__attribute_const__$$//" \
  20. -e "/^\#include <linux\/compiler.h>/d"
  21. _dst := $(if $(dst),$(dst),$(obj))
  22. ifeq (,$(patsubst include/asm/%,,$(obj)/))
  23. # For producing the generated stuff in include/asm for biarch builds, include
  24. # both sets of Kbuild files; we'll generate anything which is mentioned in
  25. # _either_ arch, and recurse into subdirectories which are mentioned in either
  26. # arch. Since some directories may exist in one but not the other, we must
  27. # use $(wildcard...).
  28. GENASM := 1
  29. archasm := $(subst include/asm,asm-$(ARCH),$(obj))
  30. altarchasm := $(subst include/asm,asm-$(ALTARCH),$(obj))
  31. KBUILDFILES := $(wildcard $(srctree)/include/$(archasm)/Kbuild $(srctree)/include/$(altarchasm)/Kbuild)
  32. else
  33. KBUILDFILES := $(srctree)/$(obj)/Kbuild
  34. endif
  35. include $(KBUILDFILES)
  36. include scripts/Kbuild.include
  37. # If this is include/asm-$(ARCH) and there's no $(ALTARCH), then
  38. # override $(_dst) so that we install to include/asm directly.
  39. # Unless $(BIASMDIR) is set, in which case we're probably doing
  40. # a 'headers_install_all' build and we should keep the -$(ARCH)
  41. # in the directory name.
  42. ifeq ($(obj)$(ALTARCH),include/asm-$(ARCH)$(BIASMDIR))
  43. _dst := include/asm
  44. endif
  45. header-y := $(sort $(header-y) $(unifdef-y))
  46. subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
  47. header-y := $(filter-out %/, $(header-y))
  48. # stamp files for header checks
  49. check-y := $(patsubst %,.check.%,$(header-y) $(objhdr-y))
  50. # Work out what needs to be removed
  51. oldheaders := $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/*.h))
  52. unwanted := $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
  53. oldcheckstamps := $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/.check.*.h))
  54. unwanted += $(filter-out $(check-y),$(oldcheckstamps))
  55. # Prefix them all with full paths to $(INSTALL_HDR_PATH)
  56. header-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(header-y))
  57. objhdr-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(objhdr-y))
  58. check-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(check-y))
  59. ifdef ALTARCH
  60. ifeq ($(obj),include/asm-$(ARCH))
  61. altarch-y := altarch-dir
  62. endif
  63. endif
  64. # Make the definitions visible for recursive make invocations
  65. export ALTARCH
  66. export ARCHDEF
  67. export ALTARCHDEF
  68. quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  69. cmd_o_hdr_install = cp $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(objtree)/$(obj)/%,$@) \
  70. $(INSTALL_HDR_PATH)/$(_dst)
  71. quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  72. cmd_unifdef = $(UNIFDEF) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
  73. | $(HDRSED) > $@ || :
  74. quiet_cmd_check = CHECK $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/.check.%,$(_dst)/%,$@)
  75. cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
  76. $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
  77. quiet_cmd_remove = REMOVE $(_dst)/$@
  78. cmd_remove = rm -f $(INSTALL_HDR_PATH)/$(_dst)/$@
  79. quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  80. cmd_mkdir = mkdir -p $@
  81. quiet_cmd_gen = GEN $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  82. cmd_gen = \
  83. FNAME=$(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$@); \
  84. STUBDEF=__ASM_STUB_`echo $$FNAME | tr a-z.- A-Z__`; \
  85. (echo "/* File autogenerated by 'make headers_install' */" ; \
  86. echo "\#ifndef $$STUBDEF" ; \
  87. echo "\#define $$STUBDEF" ; \
  88. echo "\# if $(ARCHDEF)" ; \
  89. if [ -r $(subst /$(_dst)/,/include/$(archasm)/,$@) ]; then \
  90. echo "\# include <$(archasm)/$$FNAME>" ; \
  91. else \
  92. echo "\# error $(archasm)/$$FNAME does not exist in" \
  93. "the $(ARCH) architecture" ; \
  94. fi ; \
  95. echo "\# elif $(ALTARCHDEF)" ; \
  96. if [ -r $(subst /$(_dst)/,/include/$(altarchasm)/,$@) ]; then \
  97. echo "\# include <$(altarchasm)/$$FNAME>" ; \
  98. else \
  99. echo "\# error $(altarchasm)/$$FNAME does not exist in" \
  100. "the $(ALTARCH) architecture" ; \
  101. fi ; \
  102. echo "\# else" ; \
  103. echo "\# warning This machine appears to be" \
  104. "neither $(ARCH) nor $(ALTARCH)." ; \
  105. echo "\# endif" ; \
  106. echo "\#endif /* $$STUBDEF */" ; \
  107. ) > $@
  108. .PHONY: __headersinst __headerscheck
  109. ifdef HDRCHECK
  110. __headerscheck: $(subdir-y) $(check-y)
  111. @true
  112. $(check-y) : $(INSTALL_HDR_PATH)/$(_dst)/.check.%.h : $(INSTALL_HDR_PATH)/$(_dst)/%.h
  113. $(call cmd,check)
  114. # Other dependencies for $(check-y)
  115. include /dev/null $(wildcard $(check-y))
  116. # ... but leave $(check-y) as .PHONY for now until those deps are actually correct.
  117. .PHONY: $(check-y)
  118. else
  119. # Rules for installing headers
  120. __headersinst: $(subdir-y) $(header-y) $(altarch-y) $(objhdr-y)
  121. @true
  122. $(objhdr-y) $(subdir-y) $(header-y): | $(INSTALL_HDR_PATH)/$(_dst) $(unwanted)
  123. $(INSTALL_HDR_PATH)/$(_dst):
  124. $(call cmd,mkdir)
  125. .PHONY: $(unwanted)
  126. $(unwanted):
  127. $(call cmd,remove)
  128. ifdef GENASM
  129. $(objhdr-y) $(header-y): $(KBUILDFILES)
  130. $(call cmd,gen)
  131. else
  132. $(objhdr-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(objtree)/$(obj)/%.h $(KBUILDFILES)
  133. $(call cmd,o_hdr_install)
  134. $(header-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
  135. $(call cmd,unifdef)
  136. endif
  137. endif
  138. hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
  139. .PHONY: altarch-dir
  140. # All the files in the normal arch dir must be created first, since we test
  141. # for their existence.
  142. altarch-dir: $(subdir-y) $(header-y) $(objhdr-y)
  143. $(Q)$(MAKE) $(hdrinst)=include/asm-$(ALTARCH) dst=include/asm-$(ALTARCH)
  144. $(Q)$(MAKE) $(hdrinst)=include/asm dst=include/asm$(BIASMDIR)
  145. # Recursion
  146. .PHONY: $(subdir-y)
  147. $(subdir-y):
  148. $(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)