2 ## This file is part of the depthcharge project.
4 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
5 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
6 ## Copyright 2012 Google Inc.
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; version 2 of the License.
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
20 export src ?= $(shell pwd)
21 export srck ?= $(src)/util/kconfig
22 export obj ?= $(src)/build
23 export objk ?= $(obj)/util/kconfig
25 export KERNELVERSION := 0.1.0
27 export KCONFIG_AUTOHEADER := $(obj)/config.h
28 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
29 export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
30 export KCONFIG_SPLITCONFIG := $(obj)/config
31 export KCONFIG_TRISTATE := $(obj)/tristate.conf
32 export KCONFIG_NEGATIVES := 1
33 export KCONFIG_STRICT := 1
35 export KCONFIG_CONFIG = $(DOTCONFIG)
40 KBUILD_DEFCONFIG := $(src)/board/$(BOARD)/defconfig
42 UNAME_RELEASE := $(shell uname -r)
43 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
44 MAKEFLAGS += -rR --no-print-directory
46 # Make is silent per default, but 'make V=1' will show all compiler calls.
54 HOSTCFLAGS := -I$(srck) -I$(objk)
55 HOSTCXXFLAGS := -I$(srck) -I$(objk)
58 # libpayload's xcompile script checks for this config flag to decide which
60 CONFIG_LP_COMPILER_GCC=y
61 include $(LIBPAYLOAD_DIR)/libpayload.xcompile
63 LIBPAYLOAD_DIR ?= ../libpayload/install/libpayload
66 ifeq ($(strip $(HAVE_DOTCONFIG)),)
74 ifeq ($(CONFIG_ARCH_X86),y)
77 ifeq ($(CONFIG_ARCH_ARM),y)
80 ifeq ($(CONFIG_ARCH_ARM_V8),y)
86 ifeq ($(CONFIG_ARCH_MIPS),y)
91 ifeq ($(CONFIG_LDSCRIPT_ARCH),y)
92 LDSCRIPT := $(src)/src/arch/$(ARCH_DIR)/depthcharge.ldscript
93 ifeq ("$(wildcard $(LDSCRIPT))","")
94 $(error $(LDSCRIPT): no such file.)
97 LDSCRIPT := $(src)/src/image/depthcharge.ldscript
100 ARCH_TO_TOOLCHAIN_x86 := i386
101 ARCH_TO_TOOLCHAIN_arm := arm
102 ARCH_TO_TOOLCHAIN_arm64 := arm64
103 ARCH_TO_TOOLCHAIN_mips := mipsel
105 toolchain := $(ARCH_TO_TOOLCHAIN_$(ARCH))
107 # libpayload's xcompile adapted the coreboot naming scheme, which is different
108 # in some places. If the names above don't work, use another set.
109 ifeq ($(CC_$(toolchain)),)
110 new_toolchain_name_i386 := x86_32
111 new_toolchain_name_mipsel := mips
113 toolchain := $(new_toolchain_name_$(toolchain))
116 CC:=$(firstword $(CC_$(toolchain)))
117 XCC := CC=$(CC) $(LIBPAYLOAD_DIR)/bin/lpgcc
118 AS = $(LIBPAYLOAD_DIR)/bin/lpas
119 OBJCOPY ?= $(OBJCOPY_$(toolchain))
120 STRIP ?= $(STRIP_$(toolchain))
122 include $(src)/src/arch/$(ARCH_DIR)/build_vars
124 INCLUDES = -I$(obj) -I$(src)/src/ -I$(src)/src/arch/$(ARCH_DIR)/includes/ \
125 -I$(VB_SOURCE)/firmware/include
126 ABI_FLAGS := $(ARCH_ABI_FLAGS) -ffreestanding -fno-builtin \
127 -fno-stack-protector -fomit-frame-pointer
128 LINK_FLAGS = $(ARCH_LINK_FLAGS) $(ABI_FLAGS) -fuse-ld=bfd \
129 -Wl,-T,$(LDSCRIPT) -Wl,--gc-sections -Wl,-Map=$@.map
130 CFLAGS := $(ARCH_CFLAGS) -Wall -Werror $(INCLUDES) -std=gnu99 \
131 $(ABI_FLAGS) -ffunction-sections -fdata-sections -ggdb3
133 ifneq ($(SOURCE_DEBUG),)
140 @echo 'You must specify one of the following targets to build:'
142 @echo ' depthcharge_unified - Build unified depthcharge (with no'
143 @echo ' firmware selection, for use with EFS)'
144 @echo ' netboot_unified - Build netboot binary'
145 @echo ' fastboot_bin - Build fastboot binary'
146 @echo ' dev_unified - Build unified developer binary (with'
147 @echo ' (EFS) vboot, netboot and gdb)'
148 @echo ' dts - Preprocess fmap.dts file'
149 @echo ' clean - Delete final output binaries'
150 @echo ' distclean - Delete whole build directory'
154 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
157 strip_quotes = $(subst ",,$(subst \",,$(1)))
159 # Add a new class of source/object files to the build system
161 $(eval $(1)-srcs:=) \
162 $(eval $(1)-objs:=) \
163 $(eval classes+=$(1))
165 # Special classes are managed types with special behaviour
166 # On parse time, for each entry in variable $(1)-y
167 # a handler $(1)-handler is executed with the arguments:
168 # * $(1): directory the parser is in
169 # * $(2): current entry
172 $(eval special-classes+=$(1))
174 # Clean -y variables, include Makefile.inc
175 # Add paths to files in X-y to X-srcs
176 # Add subdirs-y to subdirs
178 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
179 $(eval -include $(1)) \
180 $(foreach class,$(classes-y), $(call add-class,$(class))) \
181 $(foreach class,$(classes), \
182 $(eval $(class)-srcs+= \
184 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
185 $(foreach special,$(special-classes), \
186 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
187 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
189 # For each path in $(subdirs) call includemakefiles
190 # Repeat until subdirs is empty
192 $(eval cursubdirs:=$(subdirs)) \
194 $(foreach dir,$(cursubdirs), \
195 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
196 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
198 # collect all object files eligible for building
200 $(eval $(call evaluate_subdirs))
202 # Eliminate duplicate mentions of source files in a class
203 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
205 src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
206 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
208 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
209 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
210 alldirs:=$(sort $(abspath $(dir $(allobjs))))
213 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
214 @echo alldirs:=$(alldirs)
215 @echo allsrcs=$(allsrcs)
216 @echo DEPENDENCIES=$(DEPENDENCIES)
217 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
218 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
221 $(shell mkdir -p $(obj) $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
224 # macro to define template macros that are used by use_template macro
225 define create_cc_template
227 # $2 source suffix (c, S)
228 # $3 additional compiler flags
229 # $4 additional dependencies
230 ifn$(EMPTY)def $(1)-objs_$(2)_template
231 de$(EMPTY)fine $(1)-objs_$(2)_template
232 $(obj)/$$(1).$(1).o: src/$$(1).$(2) $(KCONFIG_AUTOHEADER) $(4)
233 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
234 $(Q)$(XCC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
239 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
240 $(foreach class,$(classes), \
241 $(foreach type,$(call filetypes-of-class,$(class)), \
242 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
244 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
245 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
247 # Kconfig options intended for the linker.
248 $(foreach option,$(link_config_options), \
249 $(eval LINK_FLAGS += -Wl,--defsym=$(option)=$$(CONFIG_$(option))))
251 DEPENDENCIES = $(allobjs:.o=.d)
252 -include $(DEPENDENCIES)
254 DTS_DIR := $(src)/board/$(BOARD)
255 DTS_CPPFLAGS := -x assembler-with-cpp
256 $(obj)/%.dts : $(DTS_DIR)/%.dts $(KCONFIG_AUTOHEADER)
257 $(HOSTCC) -E -P $(DTS_CPPFLAGS) --include $(KCONFIG_AUTOHEADER) $< -o $@
261 $(Q)mkdir -p $(obj)/util/kconfig/lxdialog
264 $(Q)rm -rf $(obj)/*.elf $(obj)/*.o
268 $(Q)rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
270 include util/kconfig/Makefile
272 .PHONY: $(PHONY) prepare clean distclean