Makefile.headersinst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_check = CHECK $(_dst)/$@
  67. cmd_check = $(srctree)/scripts/hdrcheck.sh \
  68. $(INSTALL_HDR_PATH)/include \
  69. $(INSTALL_HDR_PATH)/$(_dst)/$@
  70. quiet_cmd_mkdir = MKDIR $@
  71. cmd_mkdir = mkdir -p $(INSTALL_HDR_PATH)/$@
  72. quiet_cmd_gen = GEN $(_dst)/$@
  73. cmd_gen = \
  74. STUBDEF=__ASM_STUB_`echo $@ | tr a-z. A-Z_`; \
  75. (echo "/* File autogenerated by 'make headers_install' */" ; \
  76. echo "\#ifndef $$STUBDEF" ; \
  77. echo "\#define $$STUBDEF" ; \
  78. echo "\# if $(ARCHDEF)" ; \
  79. if [ -r $(srctree)/include/$(archasm)/$@ ]; then \
  80. echo "\# include <$(archasm)/$@>" ; \
  81. else \
  82. echo "\# error $(archasm)/$@ does not exist in" \
  83. "the $(ARCH) architecture" ; \
  84. fi ; \
  85. echo "\# elif $(ALTARCHDEF)" ; \
  86. if [ -r $(srctree)/include/$(altarchasm)/$@ ]; then \
  87. echo "\# include <$(altarchasm)/$@>" ; \
  88. else \
  89. echo "\# error $(altarchasm)/$@ does not exist in" \
  90. "the $(ALTARCH) architecture" ; \
  91. fi ; \
  92. echo "\# else" ; \
  93. echo "\# warning This machine appears to be" \
  94. "neither $(ARCH) nor $(ALTARCH)." ; \
  95. echo "\# endif" ; \
  96. echo "\#endif /* $$STUBDEF */" ; \
  97. ) > $(INSTALL_HDR_PATH)/$(_dst)/$@
  98. __headersinst: $(subdir-y) $(header-y) $(unifdef-y) $(altarch-y) $(objhdr-y)
  99. .PHONY: $(header-y) $(unifdef-y) $(subdir-y)
  100. ifdef HDRCHECK
  101. # Rules for checking headers
  102. $(objhdr-y) $(header-y) $(unifdef-y):
  103. $(call cmd,check)
  104. else
  105. # Rules for installing headers
  106. $(objhdr-y) $(subdir-y) $(header-y) $(unifdef-y): $(_dst)
  107. .PHONY: $(_dst)
  108. $(_dst):
  109. $(call cmd,mkdir)
  110. ifdef GENASM
  111. $(objhdr-y) $(header-y) $(unifdef-y):
  112. $(call cmd,gen)
  113. else
  114. $(objhdr-y):
  115. $(call cmd,o_hdr_install)
  116. $(header-y):
  117. $(call cmd,headers_install)
  118. $(unifdef-y):
  119. $(call cmd,unifdef)
  120. endif
  121. endif
  122. hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
  123. .PHONY: altarch-dir
  124. altarch-dir:
  125. $(Q)$(MAKE) $(hdrinst)=include/asm-$(ALTARCH) dst=include/asm-$(ALTARCH)
  126. $(Q)$(MAKE) $(hdrinst)=include/asm dst=include/asm
  127. # Recursion
  128. $(subdir-y):
  129. $(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)