blob: 2f85eb9599148145cf9b3d38b3acbb0d0b2bbe85 [file] [log] [blame]
Masahiro Yamada51148792014-07-30 14:08:17 +09001# 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.
Tom Rinif32c8642016-01-14 18:24:44 -05009#
10# SPDX-License-Identifier: GPL-2.0
11#
Masahiro Yamada51148792014-07-30 14:08:17 +090012
Masahiro Yamadae02ee252015-02-24 22:26:20 +090013__all: include/autoconf.mk include/autoconf.mk.dep
14
15ifeq ($(shell grep -q '^CONFIG_SPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
16__all: spl/include/autoconf.mk
17endif
18
19ifeq ($(shell grep -q '^CONFIG_TPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
20__all: tpl/include/autoconf.mk
21endif
22
23include include/config/auto.conf
Masahiro Yamada51148792014-07-30 14:08:17 +090024
25include scripts/Kbuild.include
26
27# Need to define CC and CPP again here in case the top Makefile did not
28# include config.mk. Some architectures expect CROSS_COMPILE to be defined
29# in arch/$(ARCH)/config.mk
30CC = $(CROSS_COMPILE)gcc
31CPP = $(CC) -E
32
33include config.mk
34
35UBOOTINCLUDE := \
Masahiro Yamada51148792014-07-30 14:08:17 +090036 -Iinclude \
37 $(if $(KBUILD_SRC), -I$(srctree)/include) \
38 -I$(srctree)/arch/$(ARCH)/include \
39 -include $(srctree)/include/linux/kconfig.h
40
41c_flags := $(KBUILD_CFLAGS) $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) \
42 $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
43
44quiet_cmd_autoconf_dep = GEN $@
45 cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M -MP $(c_flags) \
46 -MQ include/config/auto.conf $(srctree)/include/common.h > $@ || { \
47 rm $@; false; \
48 }
Masahiro Yamada14069922016-09-26 13:05:00 +090049include/autoconf.mk.dep: include/config.h FORCE
Masahiro Yamada51148792014-07-30 14:08:17 +090050 $(call cmd,autoconf_dep)
51
52# We are migrating from board headers to Kconfig little by little.
53# In the interim, we use both of
54# - include/config/auto.conf (generated by Kconfig)
55# - include/autoconf.mk (used in the U-Boot conventional configuration)
56# The following rule creates autoconf.mk
57# include/config/auto.conf is grepped in order to avoid duplication of the
58# same CONFIG macros
59quiet_cmd_autoconf = GEN $@
60 cmd_autoconf = \
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090061 sed -n -f $(srctree)/tools/scripts/define2mk.sed $< | \
Masahiro Yamada51148792014-07-30 14:08:17 +090062 while read line; do \
Joe Hershberger7740f652015-05-19 13:21:18 -050063 if [ -n "${KCONFIG_IGNORE_DUPLICATES}" ] || \
64 ! grep -q "$${line%=*}=" include/config/auto.conf; then \
Masahiro Yamada51148792014-07-30 14:08:17 +090065 echo "$$line"; \
66 fi \
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090067 done > $@
68
69quiet_cmd_u_boot_cfg = CFG $@
70 cmd_u_boot_cfg = \
71 $(CPP) $(c_flags) $2 -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && { \
72 grep 'define CONFIG_' $@.tmp > $@; \
73 rm $@.tmp; \
74 } || { \
75 rm $@.tmp; false; \
Masahiro Yamada51148792014-07-30 14:08:17 +090076 }
77
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090078u-boot.cfg: include/config.h FORCE
79 $(call cmd,u_boot_cfg)
80
81spl/u-boot.cfg: include/config.h FORCE
82 $(Q)mkdir -p $(dir $@)
83 $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD)
84
85tpl/u-boot.cfg: include/config.h FORCE
86 $(Q)mkdir -p $(dir $@)
87 $(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD -DCONFIG_TPL_BUILD)
88
89include/autoconf.mk: u-boot.cfg
Masahiro Yamada51148792014-07-30 14:08:17 +090090 $(call cmd,autoconf)
91
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090092spl/include/autoconf.mk: spl/u-boot.cfg
Masahiro Yamadae02ee252015-02-24 22:26:20 +090093 $(Q)mkdir -p $(dir $@)
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090094 $(call cmd,autoconf)
Masahiro Yamadae02ee252015-02-24 22:26:20 +090095
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090096tpl/include/autoconf.mk: tpl/u-boot.cfg
Masahiro Yamadae02ee252015-02-24 22:26:20 +090097 $(Q)mkdir -p $(dir $@)
Masahiro Yamadae19b0fb2016-09-26 13:05:01 +090098 $(call cmd,autoconf)
Masahiro Yamadae02ee252015-02-24 22:26:20 +090099
Masahiro Yamada51148792014-07-30 14:08:17 +0900100# include/config.h
101# Prior to Kconfig, it was generated by mkconfig. Now it is created here.
102define filechk_config_h
103 (echo "/* Automatically generated - do not edit */"; \
104 for i in $$(echo $(CONFIG_SYS_EXTRA_OPTIONS) | sed 's/,/ /g'); do \
105 echo \#define CONFIG_$$i \
106 | sed '/=/ {s/=/ /;q; } ; { s/$$/ 1/; }'; \
107 done; \
108 echo \#define CONFIG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
Masahiro Yamada51148792014-07-30 14:08:17 +0900109 echo \#include \<config_defaults.h\>; \
Masahiro Yamadae02ee252015-02-24 22:26:20 +0900110 echo \#include \<config_uncmd_spl.h\>; \
Masahiro Yamada51148792014-07-30 14:08:17 +0900111 echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>; \
112 echo \#include \<asm/config.h\>; \
Masahiro Yamadae02ee252015-02-24 22:26:20 +0900113 echo \#include \<config_fallbacks.h\>;)
Masahiro Yamada51148792014-07-30 14:08:17 +0900114endef
115
116include/config.h: scripts/Makefile.autoconf create_symlink FORCE
117 $(call filechk,config_h)
118
119# symbolic links
Masahiro Yamada0e7368c2015-02-20 17:04:12 +0900120# If arch/$(ARCH)/mach-$(SOC)/include/mach exists,
121# make a symbolic link to that directory.
122# Otherwise, create a symbolic link to arch/$(ARCH)/include/asm/arch-$(SOC).
Masahiro Yamada51148792014-07-30 14:08:17 +0900123PHONY += create_symlink
124create_symlink:
Masahiro Yamadaa350c6a2015-07-15 20:59:29 +0900125ifdef CONFIG_CREATE_ARCH_SYMLINK
Masahiro Yamada51148792014-07-30 14:08:17 +0900126ifneq ($(KBUILD_SRC),)
127 $(Q)mkdir -p include/asm
Masahiro Yamada0e7368c2015-02-20 17:04:12 +0900128 $(Q)if [ -d $(KBUILD_SRC)/arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
129 dest=arch/$(ARCH)/mach-$(SOC)/include/mach; \
130 else \
131 dest=arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU)); \
132 fi; \
133 ln -fsn $(KBUILD_SRC)/$$dest include/asm/arch
Masahiro Yamadaffe29eb2014-10-30 11:06:11 +0900134else
Masahiro Yamada0e7368c2015-02-20 17:04:12 +0900135 $(Q)if [ -d arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
136 dest=../../mach-$(SOC)/include/mach; \
137 else \
138 dest=arch-$(if $(SOC),$(SOC),$(CPU)); \
139 fi; \
140 ln -fsn $$dest arch/$(ARCH)/include/asm/arch
Masahiro Yamada51148792014-07-30 14:08:17 +0900141endif
Masahiro Yamadaa350c6a2015-07-15 20:59:29 +0900142endif
Masahiro Yamada51148792014-07-30 14:08:17 +0900143
144PHONY += FORCE
145FORCE:
146
147.PHONY: $(PHONY)