blob: 3fa4d50f1ea74edb3c9ce433ff883d4fdb25e127 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0
Masahiro Yamada51148792014-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 Yamadae02ee252015-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
Simon Glassf86ca5a2022-04-30 00:56:52 -060021ifeq ($(shell grep -q '^CONFIG_VPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
22__all: vpl/include/autoconf.mk
23endif
24
Masahiro Yamadae02ee252015-02-24 22:26:20 +090025include include/config/auto.conf
Masahiro Yamada51148792014-07-30 14:08:17 +090026
27include scripts/Kbuild.include
28
29# Need to define CC and CPP again here in case the top Makefile did not
30# include config.mk. Some architectures expect CROSS_COMPILE to be defined
31# in arch/$(ARCH)/config.mk
32CC = $(CROSS_COMPILE)gcc
33CPP = $(CC) -E
34
35include config.mk
36
37UBOOTINCLUDE := \
Masahiro Yamada51148792014-07-30 14:08:17 +090038 -Iinclude \
39 $(if $(KBUILD_SRC), -I$(srctree)/include) \
40 -I$(srctree)/arch/$(ARCH)/include \
41 -include $(srctree)/include/linux/kconfig.h
42
43c_flags := $(KBUILD_CFLAGS) $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) \
44 $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
45
46quiet_cmd_autoconf_dep = GEN $@
47 cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M -MP $(c_flags) \
48 -MQ include/config/auto.conf $(srctree)/include/common.h > $@ || { \
49 rm $@; false; \
50 }
Masahiro Yamada14069922016-09-26 13:05:00 +090051include/autoconf.mk.dep: include/config.h FORCE
Masahiro Yamada51148792014-07-30 14:08:17 +090052 $(call cmd,autoconf_dep)
53
54# We are migrating from board headers to Kconfig little by little.
55# In the interim, we use both of
56# - include/config/auto.conf (generated by Kconfig)
57# - include/autoconf.mk (used in the U-Boot conventional configuration)
58# The following rule creates autoconf.mk
59# include/config/auto.conf is grepped in order to avoid duplication of the
60# same CONFIG macros
61quiet_cmd_autoconf = GEN $@
62 cmd_autoconf = \
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090063 sed -n -f $(srctree)/tools/scripts/define2mk.sed $< | \
Masahiro Yamada51148792014-07-30 14:08:17 +090064 while read line; do \
Joe Hershberger7740f652015-05-19 13:21:18 -050065 if [ -n "${KCONFIG_IGNORE_DUPLICATES}" ] || \
66 ! grep -q "$${line%=*}=" include/config/auto.conf; then \
Masahiro Yamada51148792014-07-30 14:08:17 +090067 echo "$$line"; \
Angelo Dureghello51301022021-11-05 16:20:24 +010068 fi; \
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090069 done > $@
70
71quiet_cmd_u_boot_cfg = CFG $@
72 cmd_u_boot_cfg = \
73 $(CPP) $(c_flags) $2 -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && { \
Patrick Delaunayff062762021-11-08 10:21:21 +010074 grep 'define CONFIG_' $@.tmp | \
Simon Glass097ff012022-01-22 05:07:26 -070075 sed '/define CONFIG_IS_ENABLED(/d;/define CONFIG_IF_ENABLED_INT(/d;/define CONFIG_VAL(/d;' > $@; \
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090076 rm $@.tmp; \
77 } || { \
78 rm $@.tmp; false; \
Masahiro Yamada51148792014-07-30 14:08:17 +090079 }
80
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090081u-boot.cfg: include/config.h FORCE
82 $(call cmd,u_boot_cfg)
83
84spl/u-boot.cfg: include/config.h FORCE
85 $(Q)mkdir -p $(dir $@)
86 $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD)
87
88tpl/u-boot.cfg: include/config.h FORCE
89 $(Q)mkdir -p $(dir $@)
90 $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD -DCONFIG_TPL_BUILD)
91
Simon Glassf86ca5a2022-04-30 00:56:52 -060092vpl/u-boot.cfg: include/config.h FORCE
93 $(Q)mkdir -p $(dir $@)
94 $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD -DCONFIG_VPL_BUILD)
95
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090096include/autoconf.mk: u-boot.cfg
Masahiro Yamada51148792014-07-30 14:08:17 +090097 $(call cmd,autoconf)
98
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090099spl/include/autoconf.mk: spl/u-boot.cfg
Masahiro Yamadae02ee252015-02-24 22:26:20 +0900100 $(Q)mkdir -p $(dir $@)
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +0900101 $(call cmd,autoconf)
Masahiro Yamadae02ee252015-02-24 22:26:20 +0900102
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +0900103tpl/include/autoconf.mk: tpl/u-boot.cfg
Masahiro Yamadae02ee252015-02-24 22:26:20 +0900104 $(Q)mkdir -p $(dir $@)
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +0900105 $(call cmd,autoconf)
Masahiro Yamadae02ee252015-02-24 22:26:20 +0900106
Simon Glassf86ca5a2022-04-30 00:56:52 -0600107vpl/include/autoconf.mk: vpl/u-boot.cfg
108 $(Q)mkdir -p $(dir $@)
109 $(call cmd,autoconf)
110
Masahiro Yamada51148792014-07-30 14:08:17 +0900111# include/config.h
112# Prior to Kconfig, it was generated by mkconfig. Now it is created here.
113define filechk_config_h
114 (echo "/* Automatically generated - do not edit */"; \
115 for i in $$(echo $(CONFIG_SYS_EXTRA_OPTIONS) | sed 's/,/ /g'); do \
116 echo \#define CONFIG_$$i \
117 | sed '/=/ {s/=/ /;q; } ; { s/$$/ 1/; }'; \
118 done; \
119 echo \#define CONFIG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
Masahiro Yamadae02ee252015-02-24 22:26:20 +0900120 echo \#include \<config_uncmd_spl.h\>; \
Masahiro Yamada51148792014-07-30 14:08:17 +0900121 echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>; \
122 echo \#include \<asm/config.h\>; \
Patrick Delaunay4ac96342017-01-27 11:00:40 +0100123 echo \#include \<linux/kconfig.h\>; \
Masahiro Yamadae02ee252015-02-24 22:26:20 +0900124 echo \#include \<config_fallbacks.h\>;)
Masahiro Yamada51148792014-07-30 14:08:17 +0900125endef
126
127include/config.h: scripts/Makefile.autoconf create_symlink FORCE
128 $(call filechk,config_h)
129
130# symbolic links
Masahiro Yamada0e7368c2015-02-20 17:04:12 +0900131# If arch/$(ARCH)/mach-$(SOC)/include/mach exists,
132# make a symbolic link to that directory.
133# Otherwise, create a symbolic link to arch/$(ARCH)/include/asm/arch-$(SOC).
Masahiro Yamada51148792014-07-30 14:08:17 +0900134PHONY += create_symlink
135create_symlink:
Masahiro Yamadaa350c6a2015-07-15 20:59:29 +0900136ifdef CONFIG_CREATE_ARCH_SYMLINK
Masahiro Yamada51148792014-07-30 14:08:17 +0900137ifneq ($(KBUILD_SRC),)
138 $(Q)mkdir -p include/asm
Masahiro Yamada0e7368c2015-02-20 17:04:12 +0900139 $(Q)if [ -d $(KBUILD_SRC)/arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
140 dest=arch/$(ARCH)/mach-$(SOC)/include/mach; \
141 else \
142 dest=arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU)); \
143 fi; \
144 ln -fsn $(KBUILD_SRC)/$$dest include/asm/arch
Masahiro Yamadaffe29eb2014-10-30 11:06:11 +0900145else
Masahiro Yamada0e7368c2015-02-20 17:04:12 +0900146 $(Q)if [ -d arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
147 dest=../../mach-$(SOC)/include/mach; \
148 else \
149 dest=arch-$(if $(SOC),$(SOC),$(CPU)); \
150 fi; \
151 ln -fsn $$dest arch/$(ARCH)/include/asm/arch
Masahiro Yamada51148792014-07-30 14:08:17 +0900152endif
Masahiro Yamadaa350c6a2015-07-15 20:59:29 +0900153endif
Masahiro Yamada51148792014-07-30 14:08:17 +0900154
155PHONY += FORCE
156FORCE:
157
158.PHONY: $(PHONY)