2 ## This file is part of the coreboot project.
4 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
5 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
6 ## Copyright (C) 2009-2010 coresystems GmbH
7 ## Copyright (C) 2011 secunet Security Networks AG
9 ## Redistribution and use in source and binary forms, with or without
10 ## modification, are permitted provided that the following conditions
12 ## 1. Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## 2. Redistributions in binary form must reproduce the above copyright
15 ## notice, this list of conditions and the following disclaimer in the
16 ## documentation and/or other materials provided with the distribution.
17 ## 3. The name of the author may not be used to endorse or promote products
18 ## derived from this software without specific prior written permission.
20 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 # in addition to the dependency below, create the file if it doesn't exist
34 # to silence stupid warnings about a file that would be generated anyway.
35 $(if
$(wildcard .xcompile
),,$(eval
$(shell util
/xcompile
/xcompile
$(XGCCPATH
) > .xcompile ||
rm -f .xcompile
)))
37 .xcompile
: util
/xcompile
/xcompile
39 $< $(XGCCPATH
) > $@.tmp
40 \mv
-f
$@.tmp
$@
2> /dev
/null
42 export top
:= $(CURDIR
)
44 export srck
:= $(top
)/util
/kconfig
46 override obj
:= $(subst $(top
)/,,$(abspath
$(obj
)))
48 export objutil ?
= $(obj
)/util
49 export objk
:= $(objutil
)/kconfig
50 absobj
:= $(abspath
$(obj
))
53 export KCONFIG_AUTOHEADER
:= $(obj
)/config.h
54 export KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
55 export KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
56 export KCONFIG_SPLITCONFIG
:= $(obj
)/config
57 export KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
58 export KCONFIG_NEGATIVES
:= 1
60 # directory containing the toplevel Makefile.inc
64 KBUILD_DEFCONFIG
:= configs
/defconfig
65 UNAME_RELEASE
:= $(shell uname
-r
)
67 KCONFIG_CONFIG
= $(DOTCONFIG
)
69 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
70 MAKEFLAGS
+= -rR
--no-print-directory
72 # Make is silent per default, but 'make V=1' will show all compiler calls.
80 # Disable implicit/built-in rules to make Makefile errors fail fast.
83 HOSTCC
:= $(if
$(shell type gcc
2>/dev
/null
), gcc
, cc)
88 PREPROCESS_ONLY
:= -E
-P
-x assembler-with-cpp
-undef
-I .
91 DOXYGEN_OUTPUT_DIR
:= doxygen
95 # This include must come _before_ the pattern rules below!
96 # Order _does_ matter for pattern rules.
97 include $(srck
)/Makefile
99 # Three cases where we don't need fully populated $(obj) lists:
100 # 1. when no .config exists
101 # 2. when make config (in any flavour) is run
102 # 3. when make distclean is run
103 # Don't waste time on reading all Makefile.incs in these cases
104 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
107 ifneq ($(MAKECMDGOALS
),)
108 ifneq ($(filter %config
%clean cross
% lint
% what-jenkins-does
,$(MAKECMDGOALS
)),)
111 ifeq ($(MAKECMDGOALS
), %clean)
116 ifeq ($(NOCOMPILE
),1)
117 include $(TOPLEVEL
)/Makefile.inc
122 include $(HAVE_DOTCONFIG
)
126 ifneq ($(XCOMPILE_COMPLETE
),1)
127 $(shell rm -f .xcompile
)
128 $(error .xcompile deleted because it
's invalid. \
129 Restarting the build should fix that, or explain the problem)
132 ifneq ($(CONFIG_MMX),y)
133 CFLAGS_x86_32 += -mno-mmx
136 include toolchain.inc
138 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
140 # The primary target needs to be here before we include the
143 real-all: real-target
145 # must come rather early
148 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
151 # Add a new class of source/object files to the build system
153 $(eval $(1)-srcs:=) \
154 $(eval $(1)-objs:=) \
155 $(eval classes+=$(1))
157 # Special classes are managed types with special behaviour
158 # On parse time, for each entry in variable $(1)-y
159 # a handler $(1)-handler is executed with the arguments:
160 # * $(1): directory the parser is in
161 # * $(2): current entry
164 $(eval special-classes+=$(1))
166 # Clean -y variables, include Makefile.inc
167 # Add paths to files in X-y to X-srcs
168 # Add subdirs-y to subdirs
170 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
171 $(eval -include $(1)) \
172 $(foreach class,$(classes-y), $(call add-class,$(class))) \
173 $(foreach class,$(classes), \
174 $(eval $(class)-srcs+= \
175 $$(subst $(absobj)/,$(obj)/, \
177 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
178 $(foreach special,$(special-classes), \
179 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
180 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
182 # For each path in $(subdirs) call includemakefiles
183 # Repeat until subdirs is empty
185 $(eval cursubdirs:=$(subdirs)) \
187 $(foreach dir,$(cursubdirs), \
188 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
189 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
191 # collect all object files eligible for building
193 $(eval $(call evaluate_subdirs))
194 ifeq ($(FAILBUILD),1)
195 $(error cannot continue build)
198 # Eliminate duplicate mentions of source files in a class
199 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
201 # Converts one or more source file paths to their corresponding build/ paths.
202 # Only .c and .S get converted to .o, other files (like .ld) keep their name.
204 # $2 file path (list)
205 src-to-obj=$(foreach file,$(2),$(subst .$(1),,$(basename $(patsubst src/%,$(obj)/%,$(file)))).$(1)$(patsubst %.c,%.o,$(patsubst %.S,%.o,$(suffix $(file)))))
207 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
209 # Save all objs before processing them (for dependency inclusion)
210 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
212 # Call post-processors if they're defined
213 $(foreach class
,$(classes
),\
214 $(if
$(value
$(class
)-postprocess
),$(eval
$(call
$(class
)-postprocess
,$($(class
)-objs
)))))
216 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
217 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
218 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
220 # macro to define template macros that are used by use_template macro
221 define create_cc_template
223 # $2 source suffix (c, S, ld, ...)
224 # $3 additional compiler flags
225 # $4 additional dependencies
226 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
227 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
228 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $(KCONFIG_AUTOHEADER
) $(4)
229 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
230 $(CC_
$(1)) -MMD
$$$$(CPPFLAGS_
$(1)) $$$$(CFLAGS_
$(1)) -MT
$$$$(@
) $(3) -c
-o
$$$$@
$$$$<
235 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
236 $(foreach class
,$(classes
), \
237 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
238 $(eval
$(class
)-$(type
)-ccopts
+= $(generic-
$(type
)-ccopts
) $($(class
)-generic-ccopts
)) \
239 $(if
$(generic-objs_
$(type
)_template_gen
),$(eval
$(call generic-objs_
$(type
)_template_gen
,$(class
))),\
240 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
))))))
242 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
243 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
245 DEPENDENCIES
+= $(addsuffix .d
,$(basename $(allobjs
)))
246 -include $(DEPENDENCIES
)
249 @
$(foreach class
,$(classes
),echo
$(class
)-objs
:=$($(class
)-objs
); )
250 @echo alldirs
:=$(alldirs
)
251 @echo allsrcs
=$(allsrcs
)
252 @echo DEPENDENCIES
=$(DEPENDENCIES
)
253 @
$(foreach class
,$(special-classes
),echo
$(class
):='$($(class))'; )
258 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
261 $(obj
)/project_filelist.txt
: all
262 find
$(obj
) -name
"*.d" -exec cat
{} \
; | \
263 sed
's/[:\\]/ /g' | sed
's/ /\n/g' |
sort | uniq | \
264 grep
-v
'\.o$$' > $(obj
)/project_filelist.txt
266 #works with either exuberant ctags or ctags.emacs
267 ctags-project
: clean-ctags
$(obj
)/project_filelist.txt
268 cat
$(obj
)/project_filelist.txt | \
271 cscope-project
: clean-cscope
$(obj
)/project_filelist.txt
272 cat
$(obj
)/project_filelist.txt | xargs cscope
-b
279 $(DOXYGEN
) Documentation
/Doxyfile.coreboot
282 $(DOXYGEN
) Documentation
/Doxyfile.coreboot_simple
284 doxyclean
: doxygen-clean
286 rm -rf
$(DOXYGEN_OUTPUT_DIR
)
288 clean-for-update
: doxygen-clean clean-for-update-target
289 rm -rf
$(obj
) .xcompile
291 clean: clean-for-update clean-target
300 distclean: clean clean-ctags clean-cscope
301 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig
* .ccwrap .xcompile
303 .PHONY
: $(PHONY
) clean clean-for-update clean-cscope cscope
distclean doxygen doxy doxygen_simple
304 .PHONY
: ctags-project cscope-project clean-ctags