xref: /openbmc/u-boot/scripts/Makefile.autoconf (revision bf494d7e)
1# SPDX-License-Identifier: GPL-2.0
2# 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
11__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
22
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    := \
34		-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	}
47include/autoconf.mk.dep: include/config.h FORCE
48	$(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 = \
59		sed -n -f $(srctree)/tools/scripts/define2mk.sed $< |			\
60		while read line; do							\
61			if [ -n "${KCONFIG_IGNORE_DUPLICATES}" ] ||			\
62			   ! grep -q "$${line%=*}=" include/config/auto.conf; then	\
63				echo "$$line";						\
64			fi								\
65		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 && { \
70		grep 'define CONFIG_' $@.tmp > $@;			\
71		rm $@.tmp;						\
72	} || {								\
73		rm $@.tmp; false;					\
74	}
75
76u-boot.cfg: include/config.h FORCE
77	$(call cmd,u_boot_cfg)
78
79spl/u-boot.cfg: include/config.h FORCE
80	$(Q)mkdir -p $(dir $@)
81	$(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD)
82
83tpl/u-boot.cfg: include/config.h FORCE
84	$(Q)mkdir -p $(dir $@)
85	$(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD -DCONFIG_TPL_BUILD)
86
87include/autoconf.mk: u-boot.cfg
88	$(call cmd,autoconf)
89
90spl/include/autoconf.mk: spl/u-boot.cfg
91	$(Q)mkdir -p $(dir $@)
92	$(call cmd,autoconf)
93
94tpl/include/autoconf.mk: tpl/u-boot.cfg
95	$(Q)mkdir -p $(dir $@)
96	$(call cmd,autoconf)
97
98# include/config.h
99# Prior to Kconfig, it was generated by mkconfig. Now it is created here.
100define filechk_config_h
101	(echo "/* Automatically generated - do not edit */";		\
102	for i in $$(echo $(CONFIG_SYS_EXTRA_OPTIONS) | sed 's/,/ /g'); do \
103		echo \#define CONFIG_$$i				\
104		| sed '/=/ {s/=/	/;q; } ; { s/$$/	1/; }'; \
105	done;								\
106	echo \#define CONFIG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
107	echo \#include \<config_defaults.h\>;				\
108	echo \#include \<config_uncmd_spl.h\>;				\
109	echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>;		\
110	echo \#include \<asm/config.h\>;				\
111	echo \#include \<linux/kconfig.h\>;				\
112	echo \#include \<config_fallbacks.h\>;)
113endef
114
115include/config.h: scripts/Makefile.autoconf create_symlink FORCE
116	$(call filechk,config_h)
117
118# symbolic links
119# 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).
122PHONY += create_symlink
123create_symlink:
124ifdef CONFIG_CREATE_ARCH_SYMLINK
125ifneq ($(KBUILD_SRC),)
126	$(Q)mkdir -p include/asm
127	$(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
133else
134	$(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
140endif
141endif
142
143PHONY += FORCE
144FORCE:
145
146.PHONY: $(PHONY)
147