3 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
4 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
5 ## Copyright (C) 2009-2010 coresystems GmbH
6 ## Copyright (C) 2011 secunet Security Networks AG
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted provided that the following conditions
11 ## 1. Redistributions of source code must retain the above copyright
12 ## notice, this list of conditions and the following disclaimer.
13 ## 2. Redistributions in binary form must reproduce the above copyright
14 ## notice, this list of conditions and the following disclaimer in the
15 ## documentation and/or other materials provided with the distribution.
16 ## 3. The name of the author may not be used to endorse or promote products
17 ## derived from this software without specific prior written permission.
19 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 ifneq ($(words $(CURDIR
)),1)
33 $(error Error
: Path to the main directory cannot contain spaces
)
37 srck
:= $(top
)/util
/kconfig
39 override obj
:= $(subst $(top
)/,,$(abspath
$(obj
)))
40 objutil ?
= $(obj
)/util
41 objk
:= $(objutil
)/kconfig
42 absobj
:= $(abspath
$(obj
))
44 VBOOT_HOST_BUILD ?
= $(abspath
$(objutil
)/vboot_lib
)
46 COREBOOT_EXPORTS
:= COREBOOT_EXPORTS
47 COREBOOT_EXPORTS
+= top src srck obj objutil objk
53 COREBOOT_EXPORTS
+= LANG LC_ALL TZ
55 DOTCONFIG ?
= $(top
)/.config
56 KCONFIG_CONFIG
= $(DOTCONFIG
)
57 KCONFIG_AUTOADS
:= $(obj
)/cb-config.ads
58 KCONFIG_AUTOHEADER
:= $(obj
)/config.h
59 KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
60 KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
61 KCONFIG_SPLITCONFIG
:= $(obj
)/config
62 KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
63 KCONFIG_NEGATIVES
:= 1
65 KCONFIG_PACKAGE
:= CB.Config
67 COREBOOT_EXPORTS
+= KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
68 COREBOOT_EXPORTS
+= KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
69 COREBOOT_EXPORTS
+= KCONFIG_NEGATIVES KCONFIG_STRICT
70 COREBOOT_EXPORTS
+= KCONFIG_AUTOADS KCONFIG_PACKAGE
72 # directory containing the toplevel Makefile.inc
76 KBUILD_DEFCONFIG
:= configs
/defconfig
77 UNAME_RELEASE
:= $(shell uname
-r
)
78 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
79 MAKEFLAGS
+= -rR
--no-print-directory
81 # Make is silent per default, but 'make V=1' will show all compiler calls.
90 # Disable implicit/built-in rules to make Makefile errors fail fast.
93 HOSTCC
:= $(if
$(shell type gcc
2>/dev
/null
),gcc
,cc)
98 PREPROCESS_ONLY
:= -E
-P
-x assembler-with-cpp
-undef
-I .
101 DOXYGEN_OUTPUT_DIR
:= doxygen
103 export $(COREBOOT_EXPORTS
)
108 @echo
'*** coreboot platform targets ***'
109 @echo
' Use "make [target] V=1" for extra build debug information'
110 @echo
' all - Build coreboot'
111 @echo
' clean - Remove coreboot build artifacts'
112 @echo
' distclean - Remove build artifacts and config files'
113 @echo
' doxygen - Build doxygen documentation for coreboot'
114 @echo
' doxyplatform - Build doxygen documentation for the current platform'
115 @echo
' filelist - Show files used in current build'
116 @echo
' printall - print makefile info for debugging'
117 @echo
' gitconfig - set up git to submit patches to coreboot'
118 @echo
' ctags / ctags-project - make ctags file for all of coreboot or current board'
119 @echo
' cscope / cscope-project - make cscope.out file for coreboot or current board'
122 # This include must come _before_ the pattern rules below!
123 # Order _does_ matter for pattern rules.
124 include $(srck
)/Makefile.inc
126 # Three cases where we don't need fully populated $(obj) lists:
127 # 1. when no .config exists
128 # 2. when make config (in any flavour) is run
129 # 3. when make distclean is run
130 # Don't waste time on reading all Makefile.incs in these cases
131 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
134 ifneq ($(MAKECMDGOALS
),)
135 ifneq ($(filter %config
%clean cross
% clang iasl gnumake lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
138 ifneq ($(filter %clean lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
143 ifneq ($(filter %-test %-tests
,$(MAKECMDGOALS
)),)
144 ifneq ($(filter-out %-test %-tests
, $(MAKECMDGOALS
)),)
145 $(error Cannot mix unit-tests targets with other targets
)
151 .xcompile
: util
/xcompile
/xcompile
153 $< $(XGCCPATH
) > $@.tmp
154 \mv
-f
$@.tmp
$@
2> /dev
/null
157 ifeq ($(NOCOMPILE
),1)
158 include $(TOPLEVEL
)/Makefile.inc
159 include $(TOPLEVEL
)/payloads
/Makefile.inc
160 include $(TOPLEVEL
)/util
/testing
/Makefile.inc
161 -include $(TOPLEVEL
)/site-local
/Makefile.inc
163 @echo
"Error: Expected config file ($(DOTCONFIG)) not present." >&2
164 @echo
"Please specify a config file or run 'make menuconfig' to" >&2
165 @echo
"generate a new config file." >&2
169 ifneq ($(UNIT_TEST
),1)
173 # in addition to the dependency below, create the file if it doesn't exist
174 # to silence stupid warnings about a file that would be generated anyway.
175 $(if
$(wildcard .xcompile
)$(NOCOMPILE
),,$(eval
$(shell util
/xcompile
/xcompile
$(XGCCPATH
) > .xcompile ||
rm -f .xcompile
)))
179 ifneq ($(XCOMPILE_COMPLETE
),1)
180 $(shell rm -f .xcompile
)
181 $(error .xcompile deleted because it
's invalid. \
182 Restarting the build should fix that, or explain the problem)
185 ifneq ($(CONFIG_MMX),y)
186 CFLAGS_x86_32 += -mno-mmx
189 ifneq ($(UNIT_TEST),1)
190 include toolchain.inc
193 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
194 # fix makefile syntax highlighting after strip macro \" "))
196 # The primary target needs to be here before we include the
199 real-all: real-target
201 # must come rather early
205 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
208 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
211 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
212 $(objutil)/kconfig/toada CB.Config <$< >$@
214 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
217 # Add a new class of source/object files to the build system
219 $(eval $(1)-srcs:=) \
220 $(eval $(1)-objs:=) \
221 $(eval classes+=$(1))
223 # Special classes are managed types with special behaviour
224 # On parse time, for each entry in variable $(1)-y
225 # a handler $(1)-handler is executed with the arguments:
226 # * $(1): directory the parser is in
227 # * $(2): current entry
230 $(eval special-classes+=$(1))
232 # Converts one or more source file paths to their corresponding build/ paths.
233 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
236 # $2 file path (list)
238 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
239 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
240 $(patsubst 3rdparty/%,$(obj)/%,\
241 $(patsubst src/%,$(obj)/%,\
242 $(patsubst %.ads,%.o,\
243 $(patsubst %.adb,%.o,\
246 $(subst .$(1),,$(2))))))))))
248 # Converts one or more source file paths to the corresponding build/ paths
249 # of their Ada library information (.ali) files.
251 # $2 file path (list)
253 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
254 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
255 $(patsubst 3rdparty/%,$(obj)/%,\
256 $(patsubst src/%,$(obj)/%,\
257 $(patsubst %.ads,%.ali,\
258 $(patsubst %.adb,%.ali,\
260 $(filter %.ads %.adb,$(2)))))))))
262 # Clean -y variables, include Makefile.inc
263 # Add paths to files in X-y to X-srcs
264 # Add subdirs-y to subdirs
266 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
267 $(eval -include $(1)) \
268 $(foreach class,$(classes-y), $(call add-class,$(class))) \
269 $(foreach special,$(special-classes), \
270 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
271 $(foreach class,$(classes), \
272 $(eval $(class)-srcs+= \
273 $$(subst $(absobj)/,$(obj)/, \
275 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
276 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
278 # For each path in $(subdirs) call includemakefiles
279 # Repeat until subdirs is empty
281 $(eval cursubdirs:=$(subdirs)) \
283 $(foreach dir,$(cursubdirs), \
284 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
285 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
287 # collect all object files eligible for building
291 # Don't iterate through Makefile.incs under src
/ when building tests
292 ifneq ($(UNIT_TEST
),1)
293 $(eval
$(call evaluate_subdirs
))
295 include $(TOPLEVEL
)/tests
/Makefile.inc
298 ifeq ($(FAILBUILD
),1)
299 $(error cannot continue build
)
302 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
303 $(eval
$(postinclude-hooks
))
305 # Eliminate duplicate mentions of source files in a class
306 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:=$(sort $($(class
)-srcs
))))
308 # Build Kconfig .ads if necessary
309 ifeq ($(CONFIG_RAMSTAGE_ADA
),y
)
310 ramstage-srcs
+= $(obj
)/ramstage
/$(notdir $(KCONFIG_AUTOADS
))
313 # To track dependencies, we need all Ada specification (.ads) files in
314 # *-srcs. Extract / filter all specification files that have a matching
315 # body (.adb) file here (specifications without a body are valid sources
317 $(foreach class
,$(classes
),$(eval
$(class
)-extra-specs
:= \
319 $(addprefix %/,$(patsubst %.adb
,%.ads
,$(notdir $(filter %.adb
,$($(class
)-srcs
))))), \
320 $(filter %.ads
,$($(class
)-srcs
)))))
321 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:= \
322 $(filter-out $($(class
)-extra-specs
),$($(class
)-srcs
))))
324 $(foreach class
,$(classes
),$(eval
$(class
)-objs
:=$(call src-to-obj
,$(class
),$($(class
)-srcs
))))
325 $(foreach class
,$(classes
),$(eval
$(class
)-alis
:=$(call src-to-ali
,$(class
),$($(class
)-srcs
))))
328 $(foreach class
,$(classes
),$(eval
$(class
)-ada-dirs
:=$(sort $(dir $(filter %.ads
%.adb
,$($(class
)-srcs
)) $($(class
)-extra-specs
)))))
330 # Save all objs before processing them (for dependency inclusion)
331 originalobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
333 # Call post-processors if they're defined
334 $(foreach class
,$(classes
),\
335 $(if
$(value
$(class
)-postprocess
),$(eval
$(call
$(class
)-postprocess
,$($(class
)-objs
)))))
337 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
338 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
339 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
341 # Reads dependencies from an Ada library information (.ali) file
342 # Only basenames (with suffix) are preserved so we have to look the
343 # paths up in $($(stage)-srcs).
346 create_ada_deps
=$$(if
$(2),\
349 $$(addprefix %/,$$(shell sed
-ne
's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev
/null
)), \
350 $$($(1)-srcs
) $$($(1)-extra-specs
)))
352 # macro to define template macros that are used by use_template macro
353 define create_cc_template
355 # $2 source suffix (c, S, ld, ...)
356 # $3 additional compiler flags
357 # $4 additional dependencies
358 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
359 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
360 ifn
$(EMPTY
)eq
($(filter ads adb
,$(2)),)
361 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $$(call create_ada_deps
,$1,$$(call src-to-ali
,$1,$$(1).
$2)) $(4)
362 @printf
" GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
364 $$$$(ADAFLAGS_
$(1)) $$$$(addprefix -I
,$$$$($(1)-ada-dirs
)) \
365 $(3) -c
-o
$$$$@
$$$$<
367 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $(KCONFIG_AUTOHEADER
) $(4)
368 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
370 -MMD
$$$$(CPPFLAGS_
$(1)) $$$$(CFLAGS_
$(1)) -MT
$$$$(@
) \
371 $(3) -c
-o
$$$$@
$$$$<
377 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
378 $(foreach class
,$(classes
), \
379 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
380 $(eval
$(class
)-$(type
)-ccopts
+= $(generic-
$(type
)-ccopts
) $($(class
)-generic-ccopts
)) \
381 $(if
$(generic-objs_
$(type
)_template_gen
),$(eval
$(call generic-objs_
$(type
)_template_gen
,$(class
))),\
382 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
))))))
384 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
385 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
387 # To supported complex package initializations, we need to call the
388 # emitted code explicitly. gnatbind gathers all the calls for us
389 # and exports them as a procedure $(stage)_adainit(). Every stage that
390 # uses Ada code has to call it!
391 define gnatbind_template
393 $$(obj
)/$(1)/b__
$(1).adb
: $$$$(filter-out $$(obj
)/$(1)/b__
$(1).ali
,$$$$($(1)-alis
))
394 @printf
" BIND $$(subst $$(obj)/,,$$@)\n"
395 # We have to give gnatbind a simple filename (without leading
396 # path components) so just cd there.
398 $$(GNATBIND_
$(1)) -a
-n \
399 --RTS
=$$(absobj
)/libgnat-
$$(ARCH-
$(1)-y
)/ \
400 -L
$(1)_ada
-o
$$(notdir $$@
) \
401 $$(subst $$(dir $$@
),,$$^
)
402 $$(obj
)/$(1)/b__
$(1).o
: $$(obj
)/$(1)/b__
$(1).adb
403 @printf
" GCC $$(subst $$(obj)/,,$$@)\n"
404 $(GCC_
$(1)) $$(ADAFLAGS_
$(1)) -c
-o
$$@
$$<
405 $(1)-objs
+= $$(obj
)/$(1)/b__
$(1).o
406 $($(1)-alis
): %.ali
: %.o
;
409 $(eval
$(foreach class
,$(filter-out libgnat-
%,$(classes
)), \
410 $(if
$($(class
)-alis
),$(call gnatbind_template
,$(class
)))))
412 DEPENDENCIES
+= $(addsuffix .d
,$(basename $(allobjs
)))
413 -include $(DEPENDENCIES
)
416 @
$(foreach class
,$(classes
), echo
$(class
)-objs
: $($(class
)-objs
) | tr
' ' '\n'; echo
; )
417 @echo alldirs
: $(alldirs
) | tr
' ' '\n'; echo
418 @echo allsrcs
: $(allsrcs
) | tr
' ' '\n'; echo
419 @echo DEPENDENCIES
: $(DEPENDENCIES
) | tr
' ' '\n'; echo
420 @
$(foreach class
,$(special-classes
),echo
$(class
):'$($(class))' | tr
' ' '\n'; echo
; )
424 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
427 $(obj
)/project_filelist.txt
:
428 if
[ -z
"$(wildcard $(obj)/coreboot.rom)" ]; then \
429 echo
"*** Error: Project must be built before generating file list ***"; \
432 find
$(obj
) -path
"$(obj)/util" -prune
-o
-name
"*.d" -exec cat
{} \
; | \
433 sed
"s|$(top)/||" | sed
's/[:\\]/ /g' | sed
's/ /\n/g' |
sort | uniq | \
434 grep
-v
'\.o$$' > $(obj
)/project_filelist.txt
436 filelist
: $(obj
)/project_filelist.txt
437 printf
"\nFiles used in build:\n"
438 cat
$(obj
)/project_filelist.txt
440 #works with either exuberant ctags or ctags.emacs
441 ctags-project
: clean-ctags
$(obj
)/project_filelist.txt
442 cat
$(obj
)/project_filelist.txt | \
445 cscope-project
: clean-cscope
$(obj
)/project_filelist.txt
446 cat
$(obj
)/project_filelist.txt | xargs cscope
-b
453 $(DOXYGEN
) Documentation
/Doxyfile.coreboot
456 $(DOXYGEN
) Documentation
/Doxyfile.coreboot_simple
458 doxyplatform doxygen_platform
: $(obj
)/project_filelist.txt
460 echo
"Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
461 export DOXYGEN_OUTPUT_DIR
="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
462 mkdir
-p
"$$DOXYGEN_OUTPUT_DIR"; \
463 export DOXYFILES
="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
464 export DOXYGEN_PLATFORM
="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
465 $(DOXYGEN
) Documentation
/doxygen
/Doxyfile.coreboot_platform
467 doxyclean
: doxygen-clean
469 rm -rf
$(DOXYGEN_OUTPUT_DIR
)
471 clean-for-update
: doxygen-clean clean-for-update-target
472 rm -rf
$(obj
) .xcompile
474 clean: clean-for-update clean-target clean-utils
484 $(foreach tool
, $(TOOLLIST
), \
485 $(MAKE
) -C util
/$(tool
) clean MFLAGS
= MAKEFLAGS
= ;)
488 $(foreach tool
, $(TOOLLIST
), \
489 $(MAKE
) -C util
/$(tool
) distclean MFLAGS
= MAKEFLAGS
= ; \
490 rm -f
/util
/$(tool
)/junit.xml
;)
492 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
493 rm -f .config .config.old ..config.tmp
* .kconfig.d .tmpconfig
* .ccwrap .xcompile
494 rm -rf coreboot-builds coreboot-builds-chromeos
495 rm -f abuild
*.xml junit.xml
* util
/lint
/junit.xml
497 .PHONY
: $(PHONY
) clean clean-for-update clean-cscope cscope
distclean doxygen doxy doxygen_simple
498 .PHONY
: ctags-project cscope-project clean-ctags