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 export top
:= $(CURDIR
)
35 export srck
:= $(top
)/util
/kconfig
37 override obj
:= $(subst $(top
)/,,$(abspath
$(obj
)))
39 export objutil ?
= $(obj
)/util
40 export objk
:= $(objutil
)/kconfig
41 absobj
:= $(abspath
$(obj
))
44 export KCONFIG_AUTOHEADER
:= $(obj
)/config.h
45 export KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
46 export KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
47 export KCONFIG_SPLITCONFIG
:= $(obj
)/config
48 export KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
49 export KCONFIG_NEGATIVES
:= 1
50 export KCONFIG_STRICT
:= 1
52 # directory containing the toplevel Makefile.inc
56 KBUILD_DEFCONFIG
:= configs
/defconfig
57 UNAME_RELEASE
:= $(shell uname
-r
)
58 DOTCONFIG ?
= $(top
)/.config
59 KCONFIG_CONFIG
= $(DOTCONFIG
)
61 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
62 MAKEFLAGS
+= -rR
--no-print-directory
64 # Make is silent per default, but 'make V=1' will show all compiler calls.
72 # Disable implicit/built-in rules to make Makefile errors fail fast.
75 HOSTCC
:= $(if
$(shell type gcc
2>/dev
/null
),gcc
,cc)
80 PREPROCESS_ONLY
:= -E
-P
-x assembler-with-cpp
-undef
-I .
83 DOXYGEN_OUTPUT_DIR
:= doxygen
88 @echo
'*** coreboot platform targets ***'
89 @echo
' Use "make [target] V=1" for extra build debug information'
90 @echo
' all - Build coreboot'
91 @echo
' clean - Remove coreboot build artifacts'
92 @echo
' distclean - Remove build artifacts and config files'
93 @echo
' doxygen - Build doxygen documentation for coreboot'
94 @echo
' doxyplatform - Build doxygen documentation for the current platform'
95 @echo
' what-jenkins-does - Run platform build tests (Use CPUS=# for more cores)'
96 @echo
' printall - print makefile info for debugging'
97 @echo
' lint / lint-stable - run coreboot lint tools (all / minimal)'
98 @echo
' gitconfig - set up git to submit patches to coreboot'
99 @echo
' ctags / ctags-project - make ctags file for all of coreboot or current board'
100 @echo
' cscope / cscope-project - make cscope.out file for coreboot or current board'
103 # This include must come _before_ the pattern rules below!
104 # Order _does_ matter for pattern rules.
105 include $(srck
)/Makefile
107 # Three cases where we don't need fully populated $(obj) lists:
108 # 1. when no .config exists
109 # 2. when make config (in any flavour) is run
110 # 3. when make distclean is run
111 # Don't waste time on reading all Makefile.incs in these cases
112 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
115 ifneq ($(MAKECMDGOALS
),)
116 ifneq ($(filter %config
%clean cross
% clang iasl gnumake lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
119 ifeq ($(MAKECMDGOALS
), %clean)
124 ifeq ($(NOCOMPILE
),1)
125 include $(TOPLEVEL
)/Makefile.inc
126 include $(TOPLEVEL
)/payloads
/Makefile.inc
128 @echo
"Error: Expected config file ($(DOTCONFIG)) not present." >&2
129 @echo
"Please specify a config file or run 'make menuconfig' to" >&2
130 @echo
"generate a new config file." >&2
136 # in addition to the dependency below, create the file if it doesn't exist
137 # to silence stupid warnings about a file that would be generated anyway.
138 $(if
$(wildcard .xcompile
)$(NOCOMPILE
),,$(eval
$(shell util
/xcompile
/xcompile
$(XGCCPATH
) > .xcompile ||
rm -f .xcompile
)))
140 .xcompile
: util
/xcompile
/xcompile
142 $< $(XGCCPATH
) > $@.tmp
143 \mv
-f
$@.tmp
$@
2> /dev
/null
148 ifneq ($(XCOMPILE_COMPLETE
),1)
149 $(shell rm -f .xcompile
)
150 $(error .xcompile deleted because it
's invalid. \
151 Restarting the build should fix that, or explain the problem)
154 ifneq ($(CONFIG_MMX),y)
155 CFLAGS_x86_32 += -mno-mmx
158 include toolchain.inc
160 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
161 # fix makefile syntax highlighting after strip macro \" "))
163 # The primary target needs to be here before we include the
166 real-all: real-target
168 # must come rather early
171 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
174 # Add a new class of source/object files to the build system
176 $(eval $(1)-srcs:=) \
177 $(eval $(1)-objs:=) \
178 $(eval classes+=$(1))
180 # Special classes are managed types with special behaviour
181 # On parse time, for each entry in variable $(1)-y
182 # a handler $(1)-handler is executed with the arguments:
183 # * $(1): directory the parser is in
184 # * $(2): current entry
187 $(eval special-classes+=$(1))
189 # Converts one or more source file paths to their corresponding build/ paths.
190 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
193 # $2 file path (list)
195 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
196 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
197 $(patsubst 3rdparty/%,$(obj)/%,\
198 $(patsubst src/%,$(obj)/%,\
199 $(patsubst %.ads,%.o,\
200 $(patsubst %.adb,%.o,\
203 $(subst .$(1),,$(2))))))))))
205 # Converts one or more source file paths to the corresponding build/ paths
206 # of their Ada library information (.ali) files.
208 # $2 file path (list)
210 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
211 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
212 $(patsubst 3rdparty/%,$(obj)/%,\
213 $(patsubst src/%,$(obj)/%,\
214 $(patsubst %.ads,%.ali,\
215 $(patsubst %.adb,%.ali,\
217 $(filter %.ads %.adb,$(2)))))))))
219 # Clean -y variables, include Makefile.inc
220 # Add paths to files in X-y to X-srcs
221 # Add subdirs-y to subdirs
223 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
224 $(eval -include $(1)) \
225 $(foreach class,$(classes-y), $(call add-class,$(class))) \
226 $(foreach class,$(classes), \
227 $(eval $(class)-srcs+= \
228 $$(subst $(absobj)/,$(obj)/, \
230 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
231 $(foreach special,$(special-classes), \
232 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
233 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
235 # For each path in $(subdirs) call includemakefiles
236 # Repeat until subdirs is empty
238 $(eval cursubdirs:=$(subdirs)) \
240 $(foreach dir,$(cursubdirs), \
241 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
242 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
244 # collect all object files eligible for building
247 $(eval $(call evaluate_subdirs))
248 ifeq ($(FAILBUILD),1)
249 $(error cannot continue build)
252 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
253 $(eval $(postinclude-hooks))
255 # Eliminate duplicate mentions of source files in a class
256 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
258 # To track dependencies, we need all Ada specification (.ads) files in
259 # *-srcs. Extract / filter all specification files that have a matching
260 # body (.adb) file here (specifications without a body are valid sources
262 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
264 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
265 $(filter %.ads,$($(class)-srcs)))))
266 $(foreach class,$(classes),$(eval $(class)-srcs := \
267 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
269 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
270 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
273 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
275 # Save all objs before processing them (for dependency inclusion)
276 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
278 # Call post-processors if they're defined
279 $(foreach class
,$(classes
),\
280 $(if
$(value
$(class
)-postprocess
),$(eval
$(call
$(class
)-postprocess
,$($(class
)-objs
)))))
282 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
283 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
284 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
286 # Reads dependencies from an Ada library information (.ali) file
287 # Only basenames (with suffix) are preserved so we have to look the
288 # paths up in $($(stage)-srcs).
291 create_ada_deps
=$$(if
$(2),\
294 $$(addprefix %/,$$(shell sed
-ne
's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev
/null
)), \
295 $$($(1)-srcs
) $$($(1)-extra-specs
)))
297 # macro to define template macros that are used by use_template macro
298 define create_cc_template
300 # $2 source suffix (c, S, ld, ...)
301 # $3 additional compiler flags
302 # $4 additional dependencies
303 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
304 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
305 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $$(call create_ada_deps
,$1,$$(call src-to-ali
,$1,$$(1).
$2)) $(KCONFIG_AUTOHEADER
) $(4)
306 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
308 $$(if
$$(filter-out ads adb
,$(2)), \
309 -MMD
$$$$(CPPFLAGS_
$(1)) $$$$(CFLAGS_
$(1)) -MT
$$$$(@
), \
310 $$$$(ADAFLAGS_
$(1)) $$$$(addprefix -I
,$$$$($(1)-ada-dirs
))) \
311 $(3) -c
-o
$$$$@
$$$$<
316 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
317 $(foreach class
,$(classes
), \
318 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
319 $(eval
$(class
)-$(type
)-ccopts
+= $(generic-
$(type
)-ccopts
) $($(class
)-generic-ccopts
)) \
320 $(if
$(generic-objs_
$(type
)_template_gen
),$(eval
$(call generic-objs_
$(type
)_template_gen
,$(class
))),\
321 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
))))))
323 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
324 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
326 # To supported complex package initializations, we need to call the
327 # emitted code explicitly. gnatbind gathers all the calls for us
328 # and exports them as a procedure $(stage)_adainit(). Every stage that
329 # uses Ada code has to call it!
330 define gnatbind_template
332 $$(obj
)/$(1)/b__
$(1).adb
: $$$$(filter-out $$(obj
)/$(1)/b__
$(1).ali
,$$$$($(1)-alis
))
333 @printf
" BIND $$(subst $$(obj)/,,$$@)\n"
334 # We have to give gnatbind a simple filename (without leading
335 # path components) so just cd there.
337 $$(GNATBIND_
$(1)) -a
-n \
338 --RTS
=$$(absobj
)/libgnat-
$$(ARCH-
$(1)-y
)/ \
339 -L
$(1)_ada
-o
$$(notdir $$@
) \
340 $$(subst $$(dir $$@
),,$$^
)
341 $$(obj
)/$(1)/b__
$(1).o
: $$(obj
)/$(1)/b__
$(1).adb
342 @printf
" CC $$(subst $$(obj)/,,$$@)\n"
343 $(CC_
$(1)) $$(ADAFLAGS_
$(1)) -c
-o
$$@
$$<
344 $(1)-objs
+= $$(obj
)/$(1)/b__
$(1).o
345 $($(1)-alis
): %.ali
: %.o
;
348 $(eval
$(foreach class
,$(filter-out libgnat-
%,$(classes
)), \
349 $(if
$($(class
)-alis
),$(call gnatbind_template
,$(class
)))))
351 DEPENDENCIES
+= $(addsuffix .d
,$(basename $(allobjs
)))
352 -include $(DEPENDENCIES
)
355 @
$(foreach class
,$(classes
), echo
$(class
)-objs
: $($(class
)-objs
) | tr
' ' '\n'; echo
; )
356 @echo alldirs
: $(alldirs
) | tr
' ' '\n'; echo
357 @echo allsrcs
: $(allsrcs
) | tr
' ' '\n'; echo
358 @echo DEPENDENCIES
: $(DEPENDENCIES
) | tr
' ' '\n'; echo
359 @
$(foreach class
,$(special-classes
),echo
$(class
):'$($(class))' | tr
' ' '\n'; echo
; )
363 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
366 $(obj
)/project_filelist.txt
: all
367 find
$(obj
) -name
"*.d" -exec cat
{} \
; | \
368 sed
's/[:\\]/ /g' | sed
's/ /\n/g' |
sort | uniq | \
369 grep
-v
'\.o$$' > $(obj
)/project_filelist.txt
372 $(MAKE
) $(obj
)/project_filelist.txt
373 printf
"\nFiles used in build:\n"
374 cat
$(obj
)/project_filelist.txt
376 #works with either exuberant ctags or ctags.emacs
377 ctags-project
: clean-ctags
$(obj
)/project_filelist.txt
378 cat
$(obj
)/project_filelist.txt | \
381 cscope-project
: clean-cscope
$(obj
)/project_filelist.txt
382 cat
$(obj
)/project_filelist.txt | xargs cscope
-b
389 $(DOXYGEN
) Documentation
/Doxyfile.coreboot
392 $(DOXYGEN
) Documentation
/Doxyfile.coreboot_simple
394 doxyplatform doxygen_platform
: $(obj
)/project_filelist.txt
396 echo
"Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
397 export DOXYGEN_OUTPUT_DIR
="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
398 mkdir
-p
"$$DOXYGEN_OUTPUT_DIR"; \
399 export DOXYFILES
="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
400 export DOXYGEN_PLATFORM
="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
401 $(DOXYGEN
) Documentation
/doxygen
/Doxyfile.coreboot_platform
403 doxyclean
: doxygen-clean
405 rm -rf
$(DOXYGEN_OUTPUT_DIR
)
407 clean-for-update
: doxygen-clean clean-for-update-target
408 rm -rf
$(obj
) .xcompile
410 clean: clean-for-update clean-target
419 distclean: clean clean-ctags clean-cscope distclean-payloads
420 rm -f .config .config.old ..config.tmp
* .kconfig.d .tmpconfig
* .ccwrap .xcompile
422 .PHONY
: $(PHONY
) clean clean-for-update clean-cscope cscope
distclean doxygen doxy doxygen_simple
423 .PHONY
: ctags-project cscope-project clean-ctags