blob: f054081c98959ccbfd0cbd3acbd660fd2b40637c [file] [log] [blame]
Masahiro Yamada60bb7342014-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.
9
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090010__all: include/autoconf.mk include/autoconf.mk.dep
11
12ifeq ($(shell grep -q '^CONFIG_SPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
13__all: spl/include/autoconf.mk
14endif
15
16ifeq ($(shell grep -q '^CONFIG_TPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
17__all: tpl/include/autoconf.mk
18endif
19
20include include/config/auto.conf
Masahiro Yamada60bb7342014-07-30 14:08:17 +090021
22include scripts/Kbuild.include
23
24# Need to define CC and CPP again here in case the top Makefile did not
25# include config.mk. Some architectures expect CROSS_COMPILE to be defined
26# in arch/$(ARCH)/config.mk
27CC = $(CROSS_COMPILE)gcc
28CPP = $(CC) -E
29
30include config.mk
31
32UBOOTINCLUDE := \
Masahiro Yamada60bb7342014-07-30 14:08:17 +090033 -Iinclude \
34 $(if $(KBUILD_SRC), -I$(srctree)/include) \
35 -I$(srctree)/arch/$(ARCH)/include \
36 -include $(srctree)/include/linux/kconfig.h
37
38c_flags := $(KBUILD_CFLAGS) $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) \
39 $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
40
41quiet_cmd_autoconf_dep = GEN $@
42 cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M -MP $(c_flags) \
43 -MQ include/config/auto.conf $(srctree)/include/common.h > $@ || { \
44 rm $@; false; \
45 }
46include/autoconf.mk.dep: FORCE
47 $(call cmd,autoconf_dep)
48
49# We are migrating from board headers to Kconfig little by little.
50# In the interim, we use both of
51# - include/config/auto.conf (generated by Kconfig)
52# - include/autoconf.mk (used in the U-Boot conventional configuration)
53# The following rule creates autoconf.mk
54# include/config/auto.conf is grepped in order to avoid duplication of the
55# same CONFIG macros
56quiet_cmd_autoconf = GEN $@
57 cmd_autoconf = \
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090058 $(CPP) $(c_flags) $2 -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && { \
Masahiro Yamada60bb7342014-07-30 14:08:17 +090059 sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp | \
60 while read line; do \
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090061 if ! grep -q "$${line%=*}=" include/config/auto.conf; then \
Masahiro Yamada60bb7342014-07-30 14:08:17 +090062 echo "$$line"; \
63 fi \
64 done > $@; \
65 rm $@.tmp; \
66 } || { \
67 rm $@.tmp; false; \
68 }
69
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090070include/autoconf.mk: FORCE
Masahiro Yamada60bb7342014-07-30 14:08:17 +090071 $(call cmd,autoconf)
72
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090073spl/include/autoconf.mk: FORCE
74 $(Q)mkdir -p $(dir $@)
75 $(call cmd,autoconf,-DCONFIG_SPL_BUILD)
76
77tpl/include/autoconf.mk: FORCE
78 $(Q)mkdir -p $(dir $@)
79 $(call cmd,autoconf,-DCONFIG_SPL_BUILD -DCONFIG_TPL_BUILD)
80
81include/autoconf.mk include/autoconf.mk.dep \
82 spl/include/autoconf.mk tpl/include/autoconf.mk: include/config.h
Masahiro Yamada60bb7342014-07-30 14:08:17 +090083
84# include/config.h
85# Prior to Kconfig, it was generated by mkconfig. Now it is created here.
86define filechk_config_h
87 (echo "/* Automatically generated - do not edit */"; \
88 for i in $$(echo $(CONFIG_SYS_EXTRA_OPTIONS) | sed 's/,/ /g'); do \
89 echo \#define CONFIG_$$i \
90 | sed '/=/ {s/=/ /;q; } ; { s/$$/ 1/; }'; \
91 done; \
92 echo \#define CONFIG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
Masahiro Yamada60bb7342014-07-30 14:08:17 +090093 echo \#include \<config_defaults.h\>; \
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090094 echo \#include \<config_uncmd_spl.h\>; \
Masahiro Yamada60bb7342014-07-30 14:08:17 +090095 echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>; \
96 echo \#include \<asm/config.h\>; \
Masahiro Yamada72fb32b2015-02-24 22:26:20 +090097 echo \#include \<config_fallbacks.h\>;)
Masahiro Yamada60bb7342014-07-30 14:08:17 +090098endef
99
100include/config.h: scripts/Makefile.autoconf create_symlink FORCE
101 $(call filechk,config_h)
102
103# symbolic links
Masahiro Yamada2fa3dd92015-02-20 17:04:12 +0900104# If arch/$(ARCH)/mach-$(SOC)/include/mach exists,
105# make a symbolic link to that directory.
106# Otherwise, create a symbolic link to arch/$(ARCH)/include/asm/arch-$(SOC).
Masahiro Yamada60bb7342014-07-30 14:08:17 +0900107PHONY += create_symlink
108create_symlink:
109ifneq ($(KBUILD_SRC),)
110 $(Q)mkdir -p include/asm
Masahiro Yamada2fa3dd92015-02-20 17:04:12 +0900111 $(Q)if [ -d $(KBUILD_SRC)/arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
112 dest=arch/$(ARCH)/mach-$(SOC)/include/mach; \
113 else \
114 dest=arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU)); \
115 fi; \
116 ln -fsn $(KBUILD_SRC)/$$dest include/asm/arch
Masahiro Yamada4e1c3c72014-10-30 11:06:11 +0900117else
Masahiro Yamada2fa3dd92015-02-20 17:04:12 +0900118 $(Q)if [ -d arch/$(ARCH)/mach-$(SOC)/include/mach ]; then \
119 dest=../../mach-$(SOC)/include/mach; \
120 else \
121 dest=arch-$(if $(SOC),$(SOC),$(CPU)); \
122 fi; \
123 ln -fsn $$dest arch/$(ARCH)/include/asm/arch
Masahiro Yamada60bb7342014-07-30 14:08:17 +0900124endif
Masahiro Yamada60bb7342014-07-30 14:08:17 +0900125
126PHONY += FORCE
127FORCE:
128
129.PHONY: $(PHONY)