Makefile.autoconf 4.5 KB

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