1 ## SPDX-License-Identifier: BSD-3-Clause
3 ifneq ($(words $(CURDIR
)),1)
4 $(error Error
: Path to the main directory cannot contain spaces
)
8 srck
:= $(top
)/util
/kconfig
10 override obj
:= $(subst $(top
)/,,$(abspath
$(obj
)))
11 xcompile ?
= $(obj
)/xcompile
12 objutil ?
= $(obj
)/util
13 objk
:= $(objutil
)/kconfig
14 absobj
:= $(abspath
$(obj
))
18 VBOOT_HOST_BUILD ?
= $(abspath
$(objutil
)/vboot_lib
)
20 COREBOOT_EXPORTS
:= COREBOOT_EXPORTS
21 COREBOOT_EXPORTS
+= top src srck obj objutil objk
23 DOTCONFIG ?
= $(top
)/.config
24 KCONFIG_CONFIG
= $(DOTCONFIG
)
25 KCONFIG_AUTOADS
:= $(obj
)/cb-config.ads
26 KCONFIG_RUSTCCFG
:= $(obj
)/cb-config.rustcfg
27 KCONFIG_AUTOHEADER
:= $(obj
)/config.h
28 KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
29 KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
30 KCONFIG_SPLITCONFIG
:= $(obj
)/config
/
31 KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
32 KCONFIG_NEGATIVES
:= 1
34 KCONFIG_WARN_UNKNOWN_SYMBOLS
:= 1
35 KCONFIG_PACKAGE
:= CB.Config
36 KCONFIG_MAKEFILE_REAL ?
= $(objk
)/Makefile.real
38 COREBOOT_EXPORTS
+= KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
39 COREBOOT_EXPORTS
+= KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
40 COREBOOT_EXPORTS
+= KCONFIG_NEGATIVES
41 ifeq ($(filter %config
,$(MAKECMDGOALS
)),)
42 COREBOOT_EXPORTS
+= KCONFIG_WERROR
44 COREBOOT_EXPORTS
+= KCONFIG_WARN_UNKNOWN_SYMBOLS
45 COREBOOT_EXPORTS
+= KCONFIG_AUTOADS KCONFIG_PACKAGE
46 COREBOOT_EXPORTS
+= KCONFIG_RUSTCCFG
48 # Make does not offer a recursive wildcard function, so here's one:
49 rwildcard
=$(wildcard $1$2) $(foreach d
,$(wildcard $1*),$(call rwildcard
,$d/,$2))
50 SYMLINK_LIST
= $(call rwildcard
,site-local
/,symlink.txt
)
53 # Directory containing the toplevel Makefile.mk
57 KBUILD_DEFCONFIG
:= configs
/defconfig
58 UNAME_RELEASE
:= $(shell uname
-r
)
59 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
60 HAVE_KCONFIG_MAKEFILE_REAL
:= $(wildcard $(KCONFIG_MAKEFILE_REAL
))
61 MAKEFLAGS
+= -rR
--no-print-directory
63 # Make is silent per default, but 'make V=1' will show all compiler calls.
69 quiet_errors
:= 2>/dev
/null
73 # Disable implicit/built-in rules to make Makefile errors fail fast.
79 HOSTPKG_CONFIG ?
= pkg-config
80 COREBOOT_EXPORTS
+= HOSTPKG_CONFIG
82 PREPROCESS_ONLY
:= -E
-P
-x assembler-with-cpp
-undef
-I .
84 export $(COREBOOT_EXPORTS
)
89 @echo
'*** coreboot platform targets ***'
90 @echo
' Use "make [target] V=1" for extra build debug information'
91 @echo
' all - Build coreboot'
92 @echo
' clean - Remove coreboot build artifacts'
93 @echo
' distclean - Remove build artifacts and config files'
94 @echo
' sphinx - Build sphinx documentation for coreboot'
95 @echo
' sphinx-lint - Build sphinx documentation for coreboot with warnings as errors'
96 @echo
' filelist - Show files used in current build'
97 @echo
' printall - print makefile info for debugging'
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.mk
107 # The cases where we don't need fully populated $(obj) lists:
108 # 1. when no .config exists
109 # 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
110 # 3. when make config (in any flavour) is run
111 # 4. when make distclean is run
112 # Don't waste time on reading all Makefile.incs in these cases
113 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
116 ifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL
)),)
117 ifneq ($(MAKECMDGOALS
),tools
)
121 ifneq ($(MAKECMDGOALS
),)
122 ifneq ($(filter %config
%clean cross
% clang iasl lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
125 ifneq ($(filter %clean lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
131 ifneq ($(filter help
%, $(MAKECMDGOALS
)), )
135 ifneq ($(filter %-test %-tests
%coverage-report
, $(MAKECMDGOALS
)),)
136 ifneq ($(filter-out %-test %-tests
%coverage-report
, $(MAKECMDGOALS
)),)
137 $(error Cannot mix unit-tests targets with other targets
)
144 # When building the "tools" target, the BUILD_ALL_TOOLS variable needs
145 # to be set before reading the tools' Makefiles
146 ifneq ($(filter tools
, $(MAKECMDGOALS
)), )
150 $(xcompile
): util
/xcompile
/xcompile
152 $< $(XGCCPATH
) > $@.tmp
153 \mv
-f
$@.tmp
$@
2> /dev
/null
156 ifeq ($(NOCOMPILE
),1)
157 # We also don't use .xcompile in the no-compile situations, so
158 # provide some reasonable defaults.
159 HOSTCC ?
= $(if
$(shell type gcc
2>/dev
/null
),gcc
,cc)
162 include $(TOPLEVEL
)/Makefile.mk
163 include $(TOPLEVEL
)/payloads
/Makefile.mk
164 include $(TOPLEVEL
)/util
/testing
/Makefile.mk
165 -include $(TOPLEVEL
)/site-local
/Makefile.mk
166 -include $(TOPLEVEL
)/site-local
/Makefile.inc
167 include $(TOPLEVEL
)/tests
/Makefile.mk
169 @echo
"Error: Trying to build, but NOCOMPILE is set." >&2
170 @echo
" Please file a bug with the following information:"
171 @echo
"- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
172 @echo
"- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
173 @echo
"- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
178 ifneq ($(UNIT_TEST
),1)
182 # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
183 # wait for make to generate the file.
184 $(if
$(wildcard $(xcompile
)),, $(shell \
185 mkdir
-p
$(dir $(xcompile
)) && \
186 util
/xcompile
/xcompile
$(XGCCPATH
) > $(xcompile
) ||
rm -f
$(xcompile
)))
190 ifneq ($(XCOMPILE_COMPLETE
),1)
191 $(shell rm -f
$(xcompile
))
192 $(error
$(xcompile
) deleted because it
's invalid. \
193 Restarting the build should fix that, or explain the problem)
196 # reproducible builds
200 ifneq ($(NOCOMPILE),1)
201 SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's
/^.
define COREBOOT_BUILD_EPOCH\
>.
*"\(.*\)".
*/\
1/p
')
203 # don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
205 export LANG LC_ALL TZ SOURCE_DATE_EPOCH
207 ifneq ($(UNIT_TEST
),1)
211 strip_quotes
= $(strip $(subst ",,$(subst \",,$(1))))
212 # fix makefile syntax highlighting after strip macro \" "))
214 ifneq ($(NOCOMPILE
),1)
215 $(shell rm -f
$(CCACHE_STATSLOG
))
218 # The primary target needs to be here before we include the
221 real-all
: real-target
223 # must come rather early
228 $(KCONFIG_AUTOHEADER
): $(KCONFIG_CONFIG
) $(objutil
)/kconfig
/conf
232 $(KCONFIG_AUTOCONFIG
): $(KCONFIG_AUTOHEADER
)
235 $(KCONFIG_AUTOADS
): $(KCONFIG_CONFIG
) $(KCONFIG_AUTOHEADER
) $(objutil
)/kconfig
/toada
236 $(objutil
)/kconfig
/toada CB.Config
<$< >$@
238 $(obj
)/%/$(notdir $(KCONFIG_AUTOADS
)): $(KCONFIG_AUTOADS
)
241 # Add a new class of source/object files to the build system
243 $(eval
$(1)-srcs
:=) \
244 $(eval
$(1)-objs
:=) \
245 $(eval classes
+=$(1))
247 # Special classes are managed types with special behaviour
248 # On parse time, for each entry in variable $(1)-y
249 # a handler $(1)-handler is executed with the arguments:
250 # * $(1): directory the parser is in
251 # * $(2): current entry
254 $(eval special-classes
+=$(1))
256 # Converts one or more source file paths to their corresponding build/ paths.
257 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
260 # $2 file path (list)
262 $(patsubst $(obj
)/%,$(obj
)/$(1)/%,\
263 $(patsubst $(obj
)/$(1)/%,$(obj
)/%,\
264 $(patsubst 3rdparty
/%,$(obj
)/%,\
265 $(patsubst src
/%,$(obj
)/%,\
266 $(patsubst %.ads
,%.o
,\
267 $(patsubst %.adb
,%.o
,\
270 $(subst .
$(1),,$(2))))))))))
272 # Converts one or more source file paths to the corresponding build/ paths
273 # of their Ada library information (.ali) files.
275 # $2 file path (list)
277 $(patsubst $(obj
)/%,$(obj
)/$(1)/%,\
278 $(patsubst $(obj
)/$(1)/%,$(obj
)/%,\
279 $(patsubst 3rdparty
/%,$(obj
)/%,\
280 $(patsubst src
/%,$(obj
)/%,\
281 $(patsubst %.ads
,%.ali
,\
282 $(patsubst %.adb
,%.ali
,\
284 $(filter %.ads
%.adb
,$(2)))))))))
286 # Clean -y variables, include Makefile.mk & Makefile.inc
287 # Add paths to files in X-y to X-srcs
288 # Add subdirs-y to subdirs
290 $(if
$(wildcard $(1)), \
291 $(foreach class
,classes subdirs
$(classes
) $(special-classes
), $(eval
$(class
)-y
:=)) \
292 $(eval
-include $(1)) \
293 $(foreach class
,$(classes-y
), $(call add-class
,$(class
))) \
294 $(foreach special
,$(special-classes
), \
295 $(foreach item
,$($(special
)-y
), $(call
$(special
)-handler
,$(dir $(1)),$(item
)))) \
296 $(foreach class
,$(classes
), \
297 $(eval
$(class
)-srcs
+= \
298 $$(subst $(absobj
)/,$(obj
)/, \
300 $$(abspath
$$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class
)-y
)))))))) \
301 $(eval subdirs
+=$$(subst $(CURDIR
)/,,$$(wildcard $$(abspath
$$(addprefix $(dir $(1)),$$(subdirs-y
)))))))
303 # For each path in $(subdirs) call includemakefiles
304 # Repeat until subdirs is empty
305 # TODO: Remove Makefile.inc support
307 $(eval cursubdirs
:=$(subdirs
)) \
309 $(foreach dir,$(cursubdirs
), \
310 $(eval
$(call includemakefiles
,$(dir)/Makefile.mk
))) \
311 $(foreach dir,$(cursubdirs
), \
312 $(eval
$(call includemakefiles
,$(dir)/Makefile.inc
))) \
313 $(if
$(subdirs
),$(eval
$(call evaluate_subdirs
)))
315 # collect all object files eligible for building
319 # Don't iterate through Makefiles under src/ when building tests
320 ifneq ($(UNIT_TEST
),1)
321 $(eval
$(call evaluate_subdirs
))
323 include $(TOPLEVEL
)/tests
/Makefile.mk
326 ifeq ($(FAILBUILD
),1)
327 $(error cannot continue build
)
330 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
331 $(eval
$(postinclude-hooks
))
333 # Eliminate duplicate mentions of source files in a class
334 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:=$(sort $($(class
)-srcs
))))
336 ifeq ($(CONFIG_IWYU
),y
)
338 SAVE_IWYU_OUTPUT
:= 2>&1 | grep
"should\|\#include\|---\|include-list\|^[[:blank:]]\?\'" | tee
-a
$$(obj
)/iwyu.txt
341 # Build Kconfig .ads if necessary
342 ifeq ($(CONFIG_ROMSTAGE_ADA
),y
)
343 romstage-srcs
+= $(obj
)/romstage
/$(notdir $(KCONFIG_AUTOADS
))
345 ifeq ($(CONFIG_RAMSTAGE_ADA
),y
)
346 ramstage-srcs
+= $(obj
)/ramstage
/$(notdir $(KCONFIG_AUTOADS
))
349 # To track dependencies, we need all Ada specification (.ads) files in
350 # *-srcs. Extract / filter all specification files that have a matching
351 # body (.adb) file here (specifications without a body are valid sources
353 $(foreach class
,$(classes
),$(eval
$(class
)-extra-specs
:= \
355 $(addprefix %/,$(patsubst %.adb
,%.ads
,$(notdir $(filter %.adb
,$($(class
)-srcs
))))), \
356 $(filter %.ads
,$($(class
)-srcs
)))))
357 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:= \
358 $(filter-out $($(class
)-extra-specs
),$($(class
)-srcs
))))
360 $(foreach class
,$(classes
),$(eval
$(class
)-objs
:=$(call src-to-obj
,$(class
),$($(class
)-srcs
))))
361 $(foreach class
,$(classes
),$(eval
$(class
)-alis
:=$(call src-to-ali
,$(class
),$($(class
)-srcs
))))
364 $(foreach class
,$(classes
),$(eval
$(class
)-ada-dirs
:=$(sort $(dir $(filter %.ads
%.adb
,$($(class
)-srcs
)) $($(class
)-extra-specs
)))))
366 # Save all objs before processing them (for dependency inclusion)
367 originalobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
369 # Call post-processors if they're defined
370 $(foreach class
,$(classes
),\
371 $(if
$(value
$(class
)-postprocess
),$(eval
$(call
$(class
)-postprocess
,$($(class
)-objs
)))))
373 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
374 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
375 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
377 # Reads dependencies from an Ada library information (.ali) file
378 # Only basenames (with suffix) are preserved so we have to look the
379 # paths up in $($(stage)-srcs).
382 create_ada_deps
=$$(if
$(2),\
385 $$(addprefix %/,$$(shell sed
-ne
's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev
/null
)), \
386 $$($(1)-srcs
) $$($(1)-extra-specs
)))
388 # macro to define template macros that are used by use_template macro
389 define create_cc_template
391 # $2 source suffix (c, S, ld, ...)
392 # $3 additional compiler flags
393 # $4 additional dependencies
394 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
395 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
396 ifn
$(EMPTY
)eq
($(filter ads adb
,$(2)),)
397 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $$(call create_ada_deps
,$1,$$(call src-to-ali
,$1,$$(1).
$2)) $(4)
398 @printf
" GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
400 $$$$(ADAFLAGS_
$(1)) $$$$(addprefix -I
,$$$$($(1)-ada-dirs
)) \
401 $(3) -c
-o
$$$$@
$$$$<
403 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $(KCONFIG_AUTOHEADER
) $(4)
404 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
406 -MMD
$$$$(CPPFLAGS_
$(1)) $$$$(CFLAGS_
$(1)) -MT
$$$$(@
) \
407 $(3) -c
-o
$$$$@
$$$$< $(SAVE_IWYU_OUTPUT
)
413 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
414 $(foreach class
,$(classes
), \
415 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
416 $(eval
$(class
)-$(type
)-ccopts
+= $(generic-
$(type
)-ccopts
) $($(class
)-generic-ccopts
)) \
417 $(if
$(generic-objs_
$(type
)_template_gen
),$(eval
$(call generic-objs_
$(type
)_template_gen
,$(class
))),\
418 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
))))))
420 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
421 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
423 # To supported complex package initializations, we need to call the
424 # emitted code explicitly. gnatbind gathers all the calls for us
425 # and exports them as a procedure $(stage)_adainit(). Every stage that
426 # uses Ada code has to call it!
427 define gnatbind_template
429 $$(obj
)/$(1)/b__
$(1).adb
: $$$$(filter-out $$(obj
)/$(1)/b__
$(1).ali
,$$$$($(1)-alis
))
430 @printf
" BIND $$(subst $$(obj)/,,$$@)\n"
431 # We have to give gnatbind a simple filename (without leading
432 # path components) so just cd there.
434 $$(GNATBIND_
$(1)) -a
-n \
435 --RTS
=$$(absobj
)/libgnat-
$$(ARCH-
$(1)-y
)/ \
436 -L
$(1)_ada
-o
$$(notdir $$@
) \
437 $$(subst $$(dir $$@
),,$$^
)
438 $$(obj
)/$(1)/b__
$(1).o
: $$(obj
)/$(1)/b__
$(1).adb
439 @printf
" GCC $$(subst $$(obj)/,,$$@)\n"
440 $(GCC_
$(1)) $$(ADAFLAGS_
$(1)) -c
-o
$$@
$$<
441 $(1)-objs
+= $$(obj
)/$(1)/b__
$(1).o
442 $($(1)-alis
): %.ali
: %.o
;
445 $(eval
$(foreach class
,$(filter-out libgnat-
%,$(classes
)), \
446 $(if
$($(class
)-alis
),$(call gnatbind_template
,$(class
)))))
448 DEPENDENCIES
+= $(addsuffix .d
,$(basename $(allobjs
)))
449 -include $(DEPENDENCIES
)
452 @
$(foreach class
,$(classes
), echo
$(class
)-objs
: $($(class
)-objs
) | tr
' ' '\n'; echo
; )
453 @echo alldirs
: $(alldirs
) | tr
' ' '\n'; echo
454 @echo allsrcs
: $(allsrcs
) | tr
' ' '\n'; echo
455 @echo DEPENDENCIES
: $(DEPENDENCIES
) | tr
' ' '\n'; echo
456 @
$(foreach class
,$(special-classes
),echo
$(class
):'$($(class))' | tr
' ' '\n'; echo
; )
460 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
463 $(obj
)/project_filelist.txt
:
464 if
[ -z
"$(wildcard $(obj)/coreboot.rom)" ]; then \
465 echo
"*** Error: Project must be built before generating file list ***"; \
468 find
$(obj
) -path
"$(obj)/util" -prune
-o
-path
"$(obj)/external" -prune
-o
-name
"*.d" -exec cat
{} \
; | \
469 sed
"s|$(top)/||" | sed
's/[:\\]/ /g' | sed
's/ /\n/g' |
sort | uniq | \
470 grep
-v
'\.o$$' > $(obj
)/project_filelist.txt
472 filelist
: $(obj
)/project_filelist.txt
473 printf
"\nFiles used in build:\n"
474 cat
$(obj
)/project_filelist.txt
476 #works with either exuberant ctags or ctags.emacs
477 ctags-project
: clean-ctags
$(obj
)/project_filelist.txt
478 cat
$(obj
)/project_filelist.txt | \
481 cscope-project
: clean-cscope
$(obj
)/project_filelist.txt
482 cat
$(obj
)/project_filelist.txt | xargs cscope
-b
488 $(MAKE
) -C Documentation sphinx
491 $(MAKE
) SPHINXOPTS
=-W
-C Documentation sphinx
494 @echo
"Creating Symbolic Links.."; \
495 for link in
$(SYMLINK_LIST
); do \
496 SYMLINK
=`cat $$link`; \
497 REALPATH
=`realpath $$link`; \
498 if
[ -L
"$$SYMLINK" ]; then \
500 elif
[ ! -e
"$$SYMLINK" ]; then \
501 echo
-e
"\tLINK $$SYMLINK -> $$(dirname $$REALPATH)"; \
502 ln
-s
$$(dirname
$$REALPATH) $$SYMLINK; \
504 echo
-e
"\tFAILED: $$SYMLINK exists"; \
509 @echo
"Deleting symbolic link";\
510 EXISTING_SYMLINKS
=`find -L ./src -xtype l | grep -v 3rdparty`; \
511 for link in
$$EXISTING_SYMLINKS; do \
512 echo
-e
"\tUNLINK $$link"; \
517 rm -rf
$(obj
) .xcompile
519 clean: clean-for-update clean-utils clean-payloads
529 $(foreach tool
, $(TOOLLIST
), \
530 $(MAKE
) -C util
/$(tool
) clean MFLAGS
= MAKEFLAGS
= ;)
533 $(foreach tool
, $(TOOLLIST
), \
534 $(MAKE
) -C util
/$(tool
) distclean MFLAGS
= MAKEFLAGS
= ; \
535 rm -f
/util
/$(tool
)/junit.xml
;)
537 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
538 rm -f .config .config.old ..config.tmp
* .kconfig.d .tmpconfig
* .ccwrap .xcompile
539 rm -rf coreboot-builds coreboot-builds-chromeos
540 rm -f abuild
*.xml junit.xml
* util
/lint
/junit.xml
542 .PHONY
: $(PHONY
) clean clean-for-update clean-cscope cscope
distclean sphinx sphinx-lint
543 .PHONY
: ctags-project cscope-project clean-ctags symlink clean-symlink