blob: 0b3ffa08bfa9651c6c9ee485c0f3d7c1ba4005a8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0
Masahiro Yamada60bb7342014-07-30 14:08:17 +09002# 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
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090011__all: include/autoconf.mk include/autoconf.mk.dep
12
13ifeq ($(shell grep -q '^CONFIG_SPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
14__all: spl/include/autoconf.mk
15endif
16
17ifeq ($(shell grep -q '^CONFIG_TPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
18__all: tpl/include/autoconf.mk
19endif
20
21include include/config/auto.conf
Masahiro Yamada60bb7342014-07-30 14:08:17 +090022
23include scripts/Kbuild.include
24
25# Need to define CC and CPP again here in case the top Makefile did not
26# include config.mk. Some architectures expect CROSS_COMPILE to be defined
27# in arch/$(ARCH)/config.mk
28CC = $(CROSS_COMPILE)gcc
29CPP = $(CC) -E
30
31include config.mk
32
33UBOOTINCLUDE := \
Masahiro Yamada60bb7342014-07-30 14:08:17 +090034 -Iinclude \
35 $(if $(KBUILD_SRC), -I$(srctree)/include) \
36 -I$(srctree)/arch/$(ARCH)/include \
37 -include $(srctree)/include/linux/kconfig.h
38
39c_flags := $(KBUILD_CFLAGS) $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) \
40 $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
41
42quiet_cmd_autoconf_dep = GEN $@
43 cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M -MP $(c_flags) \
44 -MQ include/config/auto.conf $(srctree)/include/common.h > $@ || { \
45 rm $@; false; \
46 }
Masahiro Yamada16a65212016-09-26 13:05:00 +090047include/autoconf.mk.dep: include/config.h FORCE
Masahiro Yamada60bb7342014-07-30 14:08:17 +090048 $(call cmd,autoconf_dep)
49
50# We are migrating from board headers to Kconfig little by little.
51# In the interim, we use both of
52# - include/config/auto.conf (generated by Kconfig)
53# - include/autoconf.mk (used in the U-Boot conventional configuration)
54# The following rule creates autoconf.mk
55# include/config/auto.conf is grepped in order to avoid duplication of the
56# same CONFIG macros
57quiet_cmd_autoconf = GEN $@
58 cmd_autoconf = \
Masahiro Yamadad8d53342016-09-26 13:05:01 +090059 sed -n -f $(srctree)/tools/scripts/define2mk.sed $< | \
Masahiro Yamada60bb7342014-07-30 14:08:17 +090060 while read line; do \
Joe Hershberger765442b2015-05-19 13:21:18 -050061 if [ -n "${KCONFIG_IGNORE_DUPLICATES}" ] || \
62 ! grep -q "$${line%=*}=" include/config/auto.conf; then \
Masahiro Yamada60bb7342014-07-30 14:08:17 +090063 echo "$$line"; \
Angelo Dureghello483c8862021-11-05 16:20:24 +010064 fi; \
Masahiro Yamadad8d53342016-09-26 13:05:01 +090065 done > $@
66
67quiet_cmd_u_boot_cfg = CFG $@
68 cmd_u_boot_cfg = \
69 $(CPP) $(c_flags) $2 -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && { \
Patrick Delaunay51412e12021-11-08 10:21:21 +010070 grep 'define CONFIG_' $@.tmp | \
Simon Glass4cf5d612022-01-22 05:07:26 -070071 sed '/define CONFIG_IS_ENABLED(/d;/define CONFIG_IF_ENABLED_INT(/d;/define CONFIG_VAL(/d;' > $@; \
Masahiro Yamadad8d53342016-09-26 13:05:01 +090072 rm $@.tmp; \
73 } || { \
74 rm $@.tmp; false; \
Masahiro Yamada60bb7342014-07-30 14:08:17 +090075 }
76
Masahiro Yamadad8d53342016-09-26 13:05:01 +090077u-boot.cfg: include/config.h FORCE
78 $(call cmd,u_boot_cfg)
79
80spl/u-boot.cfg: include/config.h FORCE
81 $(Q)mkdir -p $(dir $@)
82 $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD)
83
84tpl/u-boot.cfg: include/config.h FORCE
85 $(Q)mkdir -p $(dir $@)
86 $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD -DCONFIG_TPL_BUILD)
87
88include/autoconf.mk: u-boot.cfg
Masahiro Yamada60bb7342014-07-30 14:08:17 +090089 $(call cmd,autoconf)
90
Masahiro Yamadad8d53342016-09-26 13:05:01 +090091spl/include/autoconf.mk: spl/u-boot.cfg
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090092 $(Q)mkdir -p $(dir $@)
Masahiro Yamadad8d53342016-09-26 13:05:01 +090093 $(call cmd,autoconf)
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090094
Masahiro Yamadad8d53342016-09-26 13:05:01 +090095tpl/include/autoconf.mk: tpl/u-boot.cfg
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090096 $(Q)mkdir -p $(dir $@)
Masahiro Yamadad8d53342016-09-26 13:05:01 +090097 $(call cmd,autoconf)
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090098
Masahiro Yamada60bb7342014-07-30 14:08:17 +090099# include/config.h
100# Prior to Kconfig, it was generated by mkconfig. Now it is created here.
101define filechk_config_h
102 (echo "/* Automatically generated - do not edit */"; \
Tom Rinia23179e2022-04-02 18:18:57 -0400103 for i in $$(echo $(CONFIG_SYS_EXTRA_OPTIONS) | sed 's/,/ /g'); do \
104 echo \#define CONFIG_$$i \
105 | sed '/=/ {s/=/ /;q; } ; { s/$$/ 1/; }'; \
106 done; \
Masahiro Yamada60bb7342014-07-30 14:08:17 +0900107 echo \#define CONFIG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
Masahiro Yamada72fb32b2015-02-24 22:26:20 +0900108 echo \#include \<config_uncmd_spl.h\>; \
Masahiro Yamada60bb7342014-07-30 14:08:17 +0900109 echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>; \
110 echo \#include \<asm/config.h\>; \
Patrick Delaunay88fbc5b2017-01-27 11:00:40 +0100111 echo \#include \<linux/kconfig.h\>; \
Masahiro Yamada72fb32b2015-02-24 22:26:20 +0900112 echo \#include \<config_fallbacks.h\>;)
Masahiro Yamada60bb7342014-07-30 14:08:17 +0900113endef
114
115include/config.h: scripts/Makefile.autoconf create_symlink FORCE
116 $(call filechk,config_h)
117
118# symbolic links
Masahiro Yamada2fa3dd92015-02-20 17:04:12 +0900119# If arch/$(ARCH)/mach-$(SOC)/include/mach exists,
120# make a symbolic link to that directory.
121# Otherwise, create a symbolic link to arch/$(ARCH)/include/asm/arch-$(SOC).
Masahiro Yamada60bb7342014-07-30 14:08:17 +0900122PHONY += create_symlink
123create_symlink:
Masahiro Yamada58654502015-07-15 20:59:29 +0900124ifdef CONFIG_CREATE_ARCH_SYMLINK
Masahiro Yamada60bb7342014-07-30 14:08:17 +0900125ifneq ($(KBUILD_SRC),)
126 $(Q)mkdir -p include/asm
Masahiro Yamada2fa3dd92015-02-20 17:04:12 +0900127 $(Q)if [ -d $(KBUILD_SRC)/arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
128 dest=arch/$(ARCH)/mach-$(SOC)/include/mach; \
129 else \
130 dest=arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU)); \
131 fi; \
132 ln -fsn $(KBUILD_SRC)/$$dest include/asm/arch
Masahiro Yamada4e1c3c72014-10-30 11:06:11 +0900133else
Masahiro Yamada2fa3dd92015-02-20 17:04:12 +0900134 $(Q)if [ -d arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
135 dest=../../mach-$(SOC)/include/mach; \
136 else \
137 dest=arch-$(if $(SOC),$(SOC),$(CPU)); \
138 fi; \
139 ln -fsn $$dest arch/$(ARCH)/include/asm/arch
Masahiro Yamada60bb7342014-07-30 14:08:17 +0900140endif
Masahiro Yamada58654502015-07-15 20:59:29 +0900141endif
Masahiro Yamada60bb7342014-07-30 14:08:17 +0900142
143PHONY += FORCE
144FORCE:
145
146.PHONY: $(PHONY)