Makefile.headersinst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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:]]\+/ /g" \
  13. -e "s/(__user[[:space:]]\+/ (/g" \
  14. -e "s/[[:space:]]__force[[:space:]]\+/ /g" \
  15. -e "s/(__force[[:space:]]\+/ (/g" \
  16. -e "s/[[:space:]]__iomem[[:space:]]\+/ /g" \
  17. -e "s/(__iomem[[:space:]]\+/ (/g" \
  18. -e "s/[[:space:]]__attribute_const__[[:space:]]\+/\ /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))
  46. unifdef-y := $(sort $(unifdef-y))
  47. subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
  48. header-y := $(filter-out %/, $(header-y))
  49. header-y := $(filter-out $(unifdef-y),$(header-y))
  50. # stamp files for header checks
  51. check-y := $(patsubst %,.check.%,$(header-y) $(unifdef-y) $(objhdr-y))
  52. # Work out what needs to be removed
  53. oldheaders := $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/*.h))
  54. unwanted := $(filter-out $(header-y) $(unifdef-y) $(objhdr-y),$(oldheaders))
  55. oldcheckstamps := $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/.check.*.h))
  56. unwanted += $(filter-out $(check-y),$(oldcheckstamps))
  57. # Prefix them all with full paths to $(INSTALL_HDR_PATH)
  58. header-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(header-y))
  59. unifdef-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(unifdef-y))
  60. objhdr-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(objhdr-y))
  61. check-y := $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(check-y))
  62. ifdef ALTARCH
  63. ifeq ($(obj),include/asm-$(ARCH))
  64. altarch-y := altarch-dir
  65. endif
  66. endif
  67. # Make the definitions visible for recursive make invocations
  68. export ALTARCH
  69. export ARCHDEF
  70. export ALTARCHDEF
  71. quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  72. cmd_o_hdr_install = cp $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(objtree)/$(obj)/%,$@) \
  73. $(INSTALL_HDR_PATH)/$(_dst)
  74. quiet_cmd_headers_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  75. cmd_headers_install = $(HDRSED) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
  76. > $@
  77. quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  78. cmd_unifdef = $(UNIFDEF) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
  79. | $(HDRSED) > $@ || :
  80. quiet_cmd_check = CHECK $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/.check.%,$(_dst)/%,$@)
  81. cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
  82. $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
  83. quiet_cmd_remove = REMOVE $(_dst)/$@
  84. cmd_remove = rm -f $(INSTALL_HDR_PATH)/$(_dst)/$@
  85. quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  86. cmd_mkdir = mkdir -p $@
  87. quiet_cmd_gen = GEN $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
  88. cmd_gen = \
  89. FNAME=$(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$@) \
  90. STUBDEF=__ASM_STUB_`echo $$FNAME | tr a-z.- A-Z__`; \
  91. (echo "/* File autogenerated by 'make headers_install' */" ; \
  92. echo "\#ifndef $$STUBDEF" ; \
  93. echo "\#define $$STUBDEF" ; \
  94. echo "\# if $(ARCHDEF)" ; \
  95. if [ -r $(subst /$(_dst)/,/include/$(archasm)/,$@) ]; then \
  96. echo "\# include <$(archasm)/$$FNAME>" ; \
  97. else \
  98. echo "\# error $(archasm)/$$FNAME does not exist in" \
  99. "the $(ARCH) architecture" ; \
  100. fi ; \
  101. echo "\# elif $(ALTARCHDEF)" ; \
  102. if [ -r $(subst /$(_dst)/,/include/$(altarchasm)/,$@) ]; then \
  103. echo "\# include <$(altarchasm)/$$FNAME>" ; \
  104. else \
  105. echo "\# error $(altarchasm)/$$FNAME does not exist in" \
  106. "the $(ALTARCH) architecture" ; \
  107. fi ; \
  108. echo "\# else" ; \
  109. echo "\# warning This machine appears to be" \
  110. "neither $(ARCH) nor $(ALTARCH)." ; \
  111. echo "\# endif" ; \
  112. echo "\#endif /* $$STUBDEF */" ; \
  113. ) > $@
  114. .PHONY: __headersinst __headerscheck
  115. ifdef HDRCHECK
  116. __headerscheck: $(subdir-y) $(check-y)
  117. @true
  118. $(check-y) : $(INSTALL_HDR_PATH)/$(_dst)/.check.%.h : $(INSTALL_HDR_PATH)/$(_dst)/%.h
  119. $(call cmd,check)
  120. # Other dependencies for $(check-y)
  121. -include /dev/null $(check-y)
  122. # ... but leave $(check-y) as .PHONY for now until those deps are actually correct.
  123. .PHONY: $(check-y)
  124. else
  125. # Rules for installing headers
  126. __headersinst: $(subdir-y) $(header-y) $(unifdef-y) $(altarch-y) $(objhdr-y)
  127. @true
  128. $(objhdr-y) $(subdir-y) $(header-y) $(unifdef-y): | $(INSTALL_HDR_PATH)/$(_dst) $(unwanted)
  129. $(INSTALL_HDR_PATH)/$(_dst):
  130. $(call cmd,mkdir)
  131. .PHONY: $(unwanted)
  132. $(unwanted):
  133. $(call cmd,remove)
  134. ifdef GENASM
  135. $(objhdr-y) $(header-y) $(unifdef-y): $(KBUILDFILES)
  136. $(call cmd,gen)
  137. else
  138. $(objhdr-y) : $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(objtree)/$(obj)/%.h $(KBUILDFILES)
  139. $(call cmd,o_hdr_install)
  140. $(header-y) : $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
  141. $(call cmd,headers_install)
  142. $(unifdef-y) : $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(KBUILDFILES)
  143. $(call cmd,unifdef)
  144. endif
  145. endif
  146. hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
  147. .PHONY: altarch-dir
  148. # All the files in the normal arch dir must be created first, since we test
  149. # for their existence.
  150. altarch-dir: $(subdir-y) $(header-y) $(unifdef-y) $(objhdr-y)
  151. $(Q)$(MAKE) $(hdrinst)=include/asm-$(ALTARCH) dst=include/asm-$(ALTARCH)
  152. $(Q)$(MAKE) $(hdrinst)=include/asm dst=include/asm$(BIASMDIR)
  153. # Recursion
  154. .PHONY: $(subdir-y)
  155. $(subdir-y):
  156. $(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)