xref: /openbmc/u-boot/scripts/Makefile.autoconf (revision 07b34278)
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_cmd_defaults.h\>;			\
78	echo \#include \<config_defaults.h\>;				\
79	echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>;		\
80	echo \#include \<asm/config.h\>;				\
81	echo \#include \<config_fallbacks.h\>;				\
82	echo \#include \<config_uncmd_spl.h\>; )
83endef
84
85include/config.h: scripts/Makefile.autoconf create_symlink FORCE
86	$(call filechk,config_h)
87
88# symbolic links
89PHONY += create_symlink
90create_symlink:
91ifneq ($(KBUILD_SRC),)
92	$(Q)mkdir -p include/asm
93endif
94	$(Q)ln -fsn $(srctree)/arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU)) \
95		$(if $(KBUILD_SRC),,arch/$(ARCH)/)include/asm/arch
96
97PHONY += FORCE
98FORCE:
99
100.PHONY: $(PHONY)
101