xref: /openbmc/u-boot/scripts/Makefile.autoconf (revision afee3fb8)
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# obj is "include" or "spl/include" or "tpl/include"
11# for non-SPL, SPL, TPL, respectively
12include $(obj)/config/auto.conf
13
14include scripts/Kbuild.include
15
16# Need to define CC and CPP again here in case the top Makefile did not
17# include config.mk.  Some architectures expect CROSS_COMPILE to be defined
18# in arch/$(ARCH)/config.mk
19CC		= $(CROSS_COMPILE)gcc
20CPP		= $(CC) -E
21
22include config.mk
23
24UBOOTINCLUDE    := \
25		-I$(obj) \
26		-Iinclude \
27		$(if $(KBUILD_SRC), -I$(srctree)/include) \
28		-I$(srctree)/arch/$(ARCH)/include \
29		-include $(srctree)/include/linux/kconfig.h
30
31c_flags := $(KBUILD_CFLAGS) $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) \
32					$(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
33
34quiet_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	}
39include/autoconf.mk.dep: FORCE
40	$(call cmd,autoconf_dep)
41
42# We are migrating from board headers to Kconfig little by little.
43# In the interim, we use both of
44#  - include/config/auto.conf (generated by Kconfig)
45#  - include/autoconf.mk      (used in the U-Boot conventional configuration)
46# The following rule creates autoconf.mk
47# include/config/auto.conf is grepped in order to avoid duplication of the
48# same CONFIG macros
49quiet_cmd_autoconf = GEN     $@
50      cmd_autoconf = \
51	$(CPP) $(c_flags) -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && {	\
52		sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp |		\
53		while read line; do							\
54			if ! grep -q "$${line%=*}=" $(obj)/config/auto.conf; then	\
55				echo "$$line";						\
56			fi								\
57		done > $@;								\
58		rm $@.tmp;								\
59	} || {										\
60		rm $@.tmp; false;							\
61	}
62
63$(obj)/autoconf.mk: FORCE
64	$(call cmd,autoconf)
65
66include/autoconf.mk include/autoconf.mk.dep: include/config.h
67
68# include/config.h
69# Prior to Kconfig, it was generated by mkconfig. Now it is created here.
70define filechk_config_h
71	(echo "/* Automatically generated - do not edit */";		\
72	for i in $$(echo $(CONFIG_SYS_EXTRA_OPTIONS) | sed 's/,/ /g'); do \
73		echo \#define CONFIG_$$i				\
74		| sed '/=/ {s/=/	/;q; } ; { s/$$/	1/; }'; \
75	done;								\
76	echo \#define CONFIG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
77	echo \#include \<config_defaults.h\>;				\
78	echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>;		\
79	echo \#include \<asm/config.h\>;				\
80	echo \#include \<config_fallbacks.h\>;				\
81	echo \#include \<config_uncmd_spl.h\>; )
82endef
83
84include/config.h: scripts/Makefile.autoconf create_symlink FORCE
85	$(call filechk,config_h)
86
87# symbolic links
88PHONY += create_symlink
89create_symlink:
90ifneq ($(KBUILD_SRC),)
91	$(Q)mkdir -p include/asm
92	$(Q)ln -fsn $(KBUILD_SRC)/arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU)) \
93		include/asm/arch
94else
95	$(Q)ln -fsn arch-$(if $(SOC),$(SOC),$(CPU)) \
96		arch/$(ARCH)/include/asm/arch
97endif
98
99PHONY += FORCE
100FORCE:
101
102.PHONY: $(PHONY)
103