Makefile.autoconf 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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: 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. $(CPP) $(c_flags) $2 -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && { \
  51. sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp | \
  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. rm $@.tmp; \
  59. } || { \
  60. rm $@.tmp; false; \
  61. }
  62. include/autoconf.mk: FORCE
  63. $(call cmd,autoconf)
  64. spl/include/autoconf.mk: FORCE
  65. $(Q)mkdir -p $(dir $@)
  66. $(call cmd,autoconf,-DCONFIG_SPL_BUILD)
  67. tpl/include/autoconf.mk: FORCE
  68. $(Q)mkdir -p $(dir $@)
  69. $(call cmd,autoconf,-DCONFIG_SPL_BUILD -DCONFIG_TPL_BUILD)
  70. include/autoconf.mk include/autoconf.mk.dep \
  71. spl/include/autoconf.mk tpl/include/autoconf.mk: include/config.h
  72. # include/config.h
  73. # Prior to Kconfig, it was generated by mkconfig. Now it is created here.
  74. define filechk_config_h
  75. (echo "/* Automatically generated - do not edit */"; \
  76. for i in $$(echo $(CONFIG_SYS_EXTRA_OPTIONS) | sed 's/,/ /g'); do \
  77. echo \#define CONFIG_$$i \
  78. | sed '/=/ {s/=/ /;q; } ; { s/$$/ 1/; }'; \
  79. done; \
  80. echo \#define CONFIG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
  81. echo \#include \<config_defaults.h\>; \
  82. echo \#include \<config_uncmd_spl.h\>; \
  83. echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>; \
  84. echo \#include \<asm/config.h\>; \
  85. echo \#include \<config_fallbacks.h\>;)
  86. endef
  87. include/config.h: scripts/Makefile.autoconf create_symlink FORCE
  88. $(call filechk,config_h)
  89. # symbolic links
  90. # If arch/$(ARCH)/mach-$(SOC)/include/mach exists,
  91. # make a symbolic link to that directory.
  92. # Otherwise, create a symbolic link to arch/$(ARCH)/include/asm/arch-$(SOC).
  93. PHONY += create_symlink
  94. create_symlink:
  95. ifdef CONFIG_CREATE_ARCH_SYMLINK
  96. ifneq ($(KBUILD_SRC),)
  97. $(Q)mkdir -p include/asm
  98. $(Q)if [ -d $(KBUILD_SRC)/arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
  99. dest=arch/$(ARCH)/mach-$(SOC)/include/mach; \
  100. else \
  101. dest=arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU)); \
  102. fi; \
  103. ln -fsn $(KBUILD_SRC)/$$dest include/asm/arch
  104. else
  105. $(Q)if [ -d arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
  106. dest=../../mach-$(SOC)/include/mach; \
  107. else \
  108. dest=arch-$(if $(SOC),$(SOC),$(CPU)); \
  109. fi; \
  110. ln -fsn $$dest arch/$(ARCH)/include/asm/arch
  111. endif
  112. endif
  113. PHONY += FORCE
  114. FORCE:
  115. .PHONY: $(PHONY)