Makefile.autoconf 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_VPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
  18. __all: vpl/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. sed '/define CONFIG_IS_ENABLED(/d;/define CONFIG_IF_ENABLED_INT(/d;/define CONFIG_VAL(/d;' > $@; \
  63. rm $@.tmp; \
  64. } || { \
  65. rm $@.tmp; false; \
  66. }
  67. u-boot.cfg: include/config.h FORCE
  68. $(call cmd,u_boot_cfg)
  69. spl/u-boot.cfg: include/config.h FORCE
  70. $(Q)mkdir -p $(dir $@)
  71. $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD)
  72. tpl/u-boot.cfg: include/config.h FORCE
  73. $(Q)mkdir -p $(dir $@)
  74. $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD -DCONFIG_TPL_BUILD)
  75. vpl/u-boot.cfg: include/config.h FORCE
  76. $(Q)mkdir -p $(dir $@)
  77. $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD -DCONFIG_VPL_BUILD)
  78. include/autoconf.mk: u-boot.cfg
  79. $(call cmd,autoconf)
  80. spl/include/autoconf.mk: spl/u-boot.cfg
  81. $(Q)mkdir -p $(dir $@)
  82. $(call cmd,autoconf)
  83. tpl/include/autoconf.mk: tpl/u-boot.cfg
  84. $(Q)mkdir -p $(dir $@)
  85. $(call cmd,autoconf)
  86. vpl/include/autoconf.mk: vpl/u-boot.cfg
  87. $(Q)mkdir -p $(dir $@)
  88. $(call cmd,autoconf)
  89. # include/config.h
  90. # Prior to Kconfig, it was generated by mkconfig. Now it is created here.
  91. define filechk_config_h
  92. (echo "/* Automatically generated - do not edit */"; \
  93. echo \#define CFG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
  94. echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>; \
  95. echo \#include \<asm/config.h\>; \
  96. echo \#include \<linux/kconfig.h\>; \
  97. echo \#include \<config_fallbacks.h\>;)
  98. endef
  99. include/config.h: scripts/Makefile.autoconf create_symlink FORCE
  100. $(call filechk,config_h)
  101. # symbolic links
  102. # If arch/$(ARCH)/mach-$(SOC)/include/mach exists,
  103. # make a symbolic link to that directory.
  104. # Otherwise, create a symbolic link to arch/$(ARCH)/include/asm/arch-$(SOC).
  105. PHONY += create_symlink
  106. create_symlink:
  107. ifdef CONFIG_CREATE_ARCH_SYMLINK
  108. ifneq ($(KBUILD_SRC),)
  109. $(Q)mkdir -p include/asm
  110. $(Q)if [ -d $(KBUILD_SRC)/arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
  111. dest=arch/$(ARCH)/mach-$(SOC)/include/mach; \
  112. else \
  113. dest=arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU)); \
  114. fi; \
  115. ln -fsn $(KBUILD_SRC)/$$dest include/asm/arch
  116. else
  117. $(Q)if [ -d arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
  118. dest=../../mach-$(SOC)/include/mach; \
  119. else \
  120. dest=arch-$(if $(SOC),$(SOC),$(CPU)); \
  121. fi; \
  122. ln -fsn $$dest arch/$(ARCH)/include/asm/arch
  123. endif
  124. endif
  125. PHONY += FORCE
  126. FORCE:
  127. .PHONY: $(PHONY)