Makefile.autoconf 4.5 KB

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