Makefile.headersinst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 := 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. .PHONY: __headersinst
  23. __headersinst:
  24. ifeq (,$(patsubst include/asm/%,,$(obj)/))
  25. # For producing the generated stuff in include/asm for biarch builds, include
  26. # both sets of Kbuild files; we'll generate anything which is mentioned in
  27. # _either_ arch, and recurse into subdirectories which are mentioned in either
  28. # arch. Since some directories may exist in one but not the other, we must
  29. # use '-include'.
  30. GENASM := 1
  31. archasm := $(subst include/asm,asm-$(ARCH),$(obj))
  32. altarchasm := $(subst include/asm,asm-$(ALTARCH),$(obj))
  33. -include $(srctree)/include/$(archasm)/Kbuild
  34. -include $(srctree)/include/$(altarchasm)/Kbuild
  35. else
  36. include $(srctree)/$(obj)/Kbuild
  37. endif
  38. include scripts/Kbuild.include
  39. # If this is include/asm-$(ARCH) and there's no $(ALTARCH), then
  40. # override $(_dst) so that we install to include/asm directly.
  41. ifeq ($(obj)$(ALTARCH),include/asm-$(ARCH))
  42. _dst := include/asm
  43. endif
  44. header-y := $(sort $(header-y))
  45. unifdef-y := $(sort $(unifdef-y))
  46. subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
  47. header-y := $(filter-out %/, $(header-y))
  48. header-y := $(filter-out $(unifdef-y),$(header-y))
  49. ifdef ALTARCH
  50. ifeq ($(obj),include/asm-$(ARCH))
  51. altarch-y := altarch-dir
  52. endif
  53. endif
  54. # Make the definitions visible for recursive make invocations
  55. export ALTARCH
  56. export ARCHDEF
  57. export ALTARCHDEF
  58. quiet_cmd_o_hdr_install = INSTALL $(_dst)/$@
  59. cmd_o_hdr_install = cp $(objtree)/$(obj)/$@ $(INSTALL_HDR_PATH)/$(_dst)
  60. quiet_cmd_headers_install = INSTALL $(_dst)/$@
  61. cmd_headers_install = $(HDRSED) $(srctree)/$(obj)/$@ \
  62. > $(INSTALL_HDR_PATH)/$(_dst)/$@
  63. quiet_cmd_unifdef = UNIFDEF $(_dst)/$@
  64. cmd_unifdef = $(UNIFDEF) $(srctree)/$(obj)/$@ | $(HDRSED) \
  65. > $(INSTALL_HDR_PATH)/$(_dst)/$@ || :
  66. quiet_cmd_mkdir = MKDIR $@
  67. cmd_mkdir = mkdir -p $(INSTALL_HDR_PATH)/$@
  68. quiet_cmd_gen = GEN $(_dst)/$@
  69. cmd_gen = \
  70. STUBDEF=__ASM_STUB_`echo $@ | tr a-z. A-Z_`; \
  71. (echo "/* File autogenerated by 'make headers_install' */" ; \
  72. echo "\#ifndef $$STUBDEF" ; \
  73. echo "\#define $$STUBDEF" ; \
  74. echo "\# if $(ARCHDEF)" ; \
  75. if [ -r $(srctree)/include/$(archasm)/$@ ]; then \
  76. echo "\# include <$(archasm)/$@>" ; \
  77. else \
  78. echo "\# error $(archasm)/$@ does not exist in" \
  79. "the $(ARCH) architecture" ; \
  80. fi ; \
  81. echo "\# elif $(ALTARCHDEF)" ; \
  82. if [ -r $(srctree)/include/$(altarchasm)/$@ ]; then \
  83. echo "\# include <$(altarchasm)/$@>" ; \
  84. else \
  85. echo "\# error $(altarchasm)/$@ does not exist in" \
  86. "the $(ALTARCH) architecture" ; \
  87. fi ; \
  88. echo "\# else" ; \
  89. echo "\# warning This machine appears to be" \
  90. "neither $(ARCH) nor $(ALTARCH)." ; \
  91. echo "\# endif" ; \
  92. echo "\#endif /* $$STUBDEF */" ; \
  93. ) > $(INSTALL_HDR_PATH)/$(_dst)/$@
  94. __headersinst: $(subdir-y) $(header-y) $(unifdef-y) $(altarch-y) $(objhdr-y)
  95. .PHONY: $(header-y) $(unifdef-y) $(subdir-y)
  96. # Rules for installing headers
  97. $(objhdr-y) $(subdir-y) $(header-y) $(unifdef-y): $(_dst)
  98. .PHONY: $(_dst)
  99. $(_dst):
  100. $(call cmd,mkdir)
  101. ifdef GENASM
  102. $(objhdr-y) $(header-y) $(unifdef-y):
  103. $(call cmd,gen)
  104. else
  105. $(objhdr-y):
  106. $(call cmd,o_hdr_install)
  107. $(header-y):
  108. $(call cmd,headers_install)
  109. $(unifdef-y):
  110. $(call cmd,unifdef)
  111. endif
  112. hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
  113. .PHONY: altarch-dir
  114. altarch-dir:
  115. $(Q)$(MAKE) $(hdrinst)=include/asm-$(ALTARCH) dst=include/asm-$(ALTARCH)
  116. $(Q)$(MAKE) $(hdrinst)=include/asm dst=include/asm
  117. # Recursion
  118. $(subdir-y):
  119. $(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)