Makefile.autoconf 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # SPDX-License-Identifier: GPL-2.0
  2. # This helper makefile is used for creating
  3. # - symbolic links (arch/$ARCH/include/asm/arch
  4. # - include/autoconf.mk, {spl,tpl}/include/autoconf.mk
  5. # - include/config.h
  6. #
  7. # When our migration to Kconfig is done
  8. # (= When we move all CONFIGs from header files to Kconfig)
  9. # this makefile can be deleted.
  10. __all: include/autoconf.mk include/autoconf.mk.dep
  11. ifeq ($(shell grep -q '^CONFIG_SPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
  12. __all: spl/include/autoconf.mk
  13. endif
  14. ifeq ($(shell grep -q '^CONFIG_TPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
  15. __all: tpl/include/autoconf.mk
  16. endif
  17. ifeq ($(shell grep -q '^CONFIG_PPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
  18. __all: ppl/include/autoconf.mk
  19. endif
  20. include include/config/auto.conf
  21. include scripts/Kbuild.include
  22. # Need to define CC and CPP again here in case the top Makefile did not
  23. # include config.mk. Some architectures expect CROSS_COMPILE to be defined
  24. # in arch/$(ARCH)/config.mk
  25. CC = $(CROSS_COMPILE)gcc
  26. CPP = $(CC) -E
  27. include config.mk
  28. UBOOTINCLUDE := \
  29. -Iinclude \
  30. $(if $(KBUILD_SRC), -I$(srctree)/include) \
  31. -I$(srctree)/arch/$(ARCH)/include \
  32. -include $(srctree)/include/linux/kconfig.h
  33. c_flags := $(KBUILD_CFLAGS) $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) \
  34. $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
  35. quiet_cmd_autoconf_dep = GEN $@
  36. cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M -MP $(c_flags) \
  37. -MQ include/config/auto.conf $(srctree)/include/common.h > $@ || { \
  38. rm $@; false; \
  39. }
  40. include/autoconf.mk.dep: include/config.h FORCE
  41. $(call cmd,autoconf_dep)
  42. # We are migrating from board headers to Kconfig little by little.
  43. # In the interim, we use both of
  44. # - include/config/auto.conf (generated by Kconfig)
  45. # - include/autoconf.mk (used in the U-Boot conventional configuration)
  46. # The following rule creates autoconf.mk
  47. # include/config/auto.conf is grepped in order to avoid duplication of the
  48. # same CONFIG macros
  49. quiet_cmd_autoconf = GEN $@
  50. cmd_autoconf = \
  51. sed -n -f $(srctree)/tools/scripts/define2mk.sed $< | \
  52. while read line; do \
  53. if [ -n "${KCONFIG_IGNORE_DUPLICATES}" ] || \
  54. ! grep -q "$${line%=*}=" include/config/auto.conf; then \
  55. echo "$$line"; \
  56. fi \
  57. done > $@
  58. quiet_cmd_u_boot_cfg = CFG $@
  59. cmd_u_boot_cfg = \
  60. $(CPP) $(c_flags) $2 -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && { \
  61. grep 'define CONFIG_' $@.tmp > $@; \
  62. rm $@.tmp; \
  63. } || { \
  64. rm $@.tmp; false; \
  65. }
  66. u-boot.cfg: include/config.h FORCE
  67. $(call cmd,u_boot_cfg)
  68. spl/u-boot.cfg: include/config.h FORCE
  69. $(Q)mkdir -p $(dir $@)
  70. $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD)
  71. tpl/u-boot.cfg: include/config.h FORCE
  72. $(Q)mkdir -p $(dir $@)
  73. $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD -DCONFIG_TPL_BUILD)
  74. ppl/u-boot.cfg: include/config.h FORCE
  75. $(Q)mkdir -p $(dir $@)
  76. $(call cmd,u_boot_cfg,-DCONFIG_PPL_BUILD)
  77. include/autoconf.mk: u-boot.cfg
  78. $(call cmd,autoconf)
  79. spl/include/autoconf.mk: spl/u-boot.cfg
  80. $(Q)mkdir -p $(dir $@)
  81. $(call cmd,autoconf)
  82. tpl/include/autoconf.mk: tpl/u-boot.cfg
  83. $(Q)mkdir -p $(dir $@)
  84. $(call cmd,autoconf)
  85. ppl/include/autoconf.mk: ppl/u-boot.cfg
  86. $(Q)mkdir -p $(dir $@)
  87. $(call cmd,autoconf)
  88. # include/config.h
  89. # Prior to Kconfig, it was generated by mkconfig. Now it is created here.
  90. define filechk_config_h
  91. (echo "/* Automatically generated - do not edit */"; \
  92. for i in $$(echo $(CONFIG_SYS_EXTRA_OPTIONS) | sed 's/,/ /g'); do \
  93. echo \#define CONFIG_$$i \
  94. | sed '/=/ {s/=/ /;q; } ; { s/$$/ 1/; }'; \
  95. done; \
  96. echo \#define CONFIG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
  97. echo \#include \<config_defaults.h\>; \
  98. echo \#include \<config_uncmd_spl.h\>; \
  99. echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>; \
  100. echo \#include \<asm/config.h\>; \
  101. echo \#include \<linux/kconfig.h\>; \
  102. echo \#include \<config_fallbacks.h\>;)
  103. endef
  104. include/config.h: scripts/Makefile.autoconf create_symlink FORCE
  105. $(call filechk,config_h)
  106. # symbolic links
  107. # If arch/$(ARCH)/mach-$(SOC)/include/mach exists,
  108. # make a symbolic link to that directory.
  109. # Otherwise, create a symbolic link to arch/$(ARCH)/include/asm/arch-$(SOC).
  110. PHONY += create_symlink
  111. create_symlink:
  112. ifdef CONFIG_CREATE_ARCH_SYMLINK
  113. ifneq ($(KBUILD_SRC),)
  114. $(Q)mkdir -p include/asm
  115. $(Q)if [ -d $(KBUILD_SRC)/arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
  116. dest=arch/$(ARCH)/mach-$(SOC)/include/mach; \
  117. else \
  118. dest=arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU)); \
  119. fi; \
  120. ln -fsn $(KBUILD_SRC)/$$dest include/asm/arch
  121. else
  122. $(Q)if [ -d arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
  123. dest=../../mach-$(SOC)/include/mach; \
  124. else \
  125. dest=arch-$(if $(SOC),$(SOC),$(CPU)); \
  126. fi; \
  127. ln -fsn $$dest arch/$(ARCH)/include/asm/arch
  128. endif
  129. endif
  130. PHONY += FORCE
  131. FORCE:
  132. .PHONY: $(PHONY)