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_AUTOHEADER
:= $(obj
)/config.h
27 KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
28 KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
29 KCONFIG_SPLITCONFIG
:= $(obj
)/config
/
30 KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
31 KCONFIG_NEGATIVES
:= 1
33 KCONFIG_PACKAGE
:= CB.Config
34 KCONFIG_MAKEFILE_REAL ?
= $(objk
)/Makefile.real
36 COREBOOT_EXPORTS
+= KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
37 COREBOOT_EXPORTS
+= KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
38 COREBOOT_EXPORTS
+= KCONFIG_NEGATIVES KCONFIG_STRICT
39 COREBOOT_EXPORTS
+= KCONFIG_AUTOADS KCONFIG_PACKAGE
41 # Make does not offer a recursive wildcard function, so here's one:
42 rwildcard
=$(wildcard $1$2) $(foreach d
,$(wildcard $1*),$(call rwildcard
,$d/,$2))
43 SYMLINK_LIST
= $(call rwildcard
,site-local
/,symlink.txt
)
46 # directory containing the toplevel Makefile.inc
50 KBUILD_DEFCONFIG
:= configs
/defconfig
51 UNAME_RELEASE
:= $(shell uname
-r
)
52 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
53 HAVE_KCONFIG_MAKEFILE_REAL
:= $(wildcard $(KCONFIG_MAKEFILE_REAL
))
54 MAKEFLAGS
+= -rR
--no-print-directory
56 # Make is silent per default, but 'make V=1' will show all compiler calls.
62 quiet_errors
:= 2>/dev
/null
66 # Disable implicit/built-in rules to make Makefile errors fail fast.
72 PREPROCESS_ONLY
:= -E
-P
-x assembler-with-cpp
-undef
-I .
74 export $(COREBOOT_EXPORTS
)
79 @echo
'*** coreboot platform targets ***'
80 @echo
' Use "make [target] V=1" for extra build debug information'
81 @echo
' all - Build coreboot'
82 @echo
' clean - Remove coreboot build artifacts'
83 @echo
' distclean - Remove build artifacts and config files'
84 @echo
' sphinx - Build sphinx documentation for coreboot'
85 @echo
' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
86 @echo
' filelist - Show files used in current build'
87 @echo
' printall - print makefile info for debugging'
88 @echo
' gitconfig - set up git to submit patches to coreboot'
89 @echo
' ctags / ctags-project - make ctags file for all of coreboot or current board'
90 @echo
' cscope / cscope-project - make cscope.out file for coreboot or current board'
93 # This include must come _before_ the pattern rules below!
94 # Order _does_ matter for pattern rules.
95 include $(srck
)/Makefile.inc
97 # The cases where we don't need fully populated $(obj) lists:
98 # 1. when no .config exists
99 # 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
100 # 3. when make config (in any flavour) is run
101 # 4. when make distclean is run
102 # Don't waste time on reading all Makefile.incs in these cases
103 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
106 ifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL
)),)
107 ifneq ($(MAKECMDGOALS
),tools
)
111 ifneq ($(MAKECMDGOALS
),)
112 ifneq ($(filter %config
%clean cross
% clang iasl lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
115 ifneq ($(filter %clean lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
121 ifneq ($(filter help
%, $(MAKECMDGOALS
)), )
125 ifneq ($(filter %-test %-tests
%coverage-report
, $(MAKECMDGOALS
)),)
126 ifneq ($(filter-out %-test %-tests
%coverage-report
, $(MAKECMDGOALS
)),)
127 $(error Cannot mix unit-tests targets with other targets
)
134 $(xcompile
): util
/xcompile
/xcompile
136 $< $(XGCCPATH
) > $@.tmp
137 \mv
-f
$@.tmp
$@
2> /dev
/null
140 ifeq ($(NOCOMPILE
),1)
141 # We also don't use .xcompile in the no-compile situations, so
142 # provide some reasonable defaults.
143 HOSTCC ?
= $(if
$(shell type gcc
2>/dev
/null
),gcc
,cc)
146 include $(TOPLEVEL
)/Makefile.inc
147 include $(TOPLEVEL
)/payloads
/Makefile.inc
148 include $(TOPLEVEL
)/util
/testing
/Makefile.inc
149 -include $(TOPLEVEL
)/site-local
/Makefile.inc
150 include $(TOPLEVEL
)/tests
/Makefile.inc
152 @echo
"Error: Trying to build, but NOCOMPILE is set." >&2
153 @echo
" Please file a bug with the following information:"
154 @echo
"- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
155 @echo
"- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
156 @echo
"- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
160 ifneq ($(UNIT_TEST
),1)
164 # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
165 # wait for make to generate the file.
166 $(if
$(wildcard $(xcompile
)),, $(shell \
167 mkdir
-p
$(dir $(xcompile
)) && \
168 util
/xcompile
/xcompile
$(XGCCPATH
) > $(xcompile
) ||
rm -f
$(xcompile
)))
172 ifneq ($(XCOMPILE_COMPLETE
),1)
173 $(shell rm -f
$(xcompile
))
174 $(error
$(xcompile
) deleted because it
's invalid. \
175 Restarting the build should fix that, or explain the problem)
178 # reproducible builds
182 ifneq ($(NOCOMPILE),1)
183 SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's
/^.
define COREBOOT_BUILD_EPOCH\
>.
*"\(.*\)".
*/\
1/p
')
185 # don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
187 export LANG LC_ALL TZ SOURCE_DATE_EPOCH
189 ifneq ($(CONFIG_MMX
),y
)
190 CFLAGS_x86_32
+= -mno-mmx
193 ifneq ($(UNIT_TEST
),1)
194 include toolchain.inc
197 strip_quotes
= $(strip $(subst ",,$(subst \",,$(1))))
198 # fix makefile syntax highlighting after strip macro \" "))
200 # The primary target needs to be here before we include the
203 real-all
: real-target
205 # must come rather early
210 $(KCONFIG_AUTOHEADER
): $(KCONFIG_CONFIG
) $(objutil
)/kconfig
/conf
214 $(KCONFIG_AUTOCONFIG
): $(KCONFIG_AUTOHEADER
)
217 $(KCONFIG_AUTOADS
): $(KCONFIG_CONFIG
) $(KCONFIG_AUTOHEADER
) $(objutil
)/kconfig
/toada
218 $(objutil
)/kconfig
/toada CB.Config
<$< >$@
220 $(obj
)/%/$(notdir $(KCONFIG_AUTOADS
)): $(KCONFIG_AUTOADS
)
223 # Add a new class of source/object files to the build system
225 $(eval
$(1)-srcs
:=) \
226 $(eval
$(1)-objs
:=) \
227 $(eval classes
+=$(1))
229 # Special classes are managed types with special behaviour
230 # On parse time, for each entry in variable $(1)-y
231 # a handler $(1)-handler is executed with the arguments:
232 # * $(1): directory the parser is in
233 # * $(2): current entry
236 $(eval special-classes
+=$(1))
238 # Converts one or more source file paths to their corresponding build/ paths.
239 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
242 # $2 file path (list)
244 $(patsubst $(obj
)/%,$(obj
)/$(1)/%,\
245 $(patsubst $(obj
)/$(1)/%,$(obj
)/%,\
246 $(patsubst 3rdparty
/%,$(obj
)/%,\
247 $(patsubst src
/%,$(obj
)/%,\
248 $(patsubst %.ads
,%.o
,\
249 $(patsubst %.adb
,%.o
,\
252 $(subst .
$(1),,$(2))))))))))
254 # Converts one or more source file paths to the corresponding build/ paths
255 # of their Ada library information (.ali) files.
257 # $2 file path (list)
259 $(patsubst $(obj
)/%,$(obj
)/$(1)/%,\
260 $(patsubst $(obj
)/$(1)/%,$(obj
)/%,\
261 $(patsubst 3rdparty
/%,$(obj
)/%,\
262 $(patsubst src
/%,$(obj
)/%,\
263 $(patsubst %.ads
,%.ali
,\
264 $(patsubst %.adb
,%.ali
,\
266 $(filter %.ads
%.adb
,$(2)))))))))
268 # Clean -y variables, include Makefile.inc
269 # Add paths to files in X-y to X-srcs
270 # Add subdirs-y to subdirs
272 $(foreach class
,classes subdirs
$(classes
) $(special-classes
), $(eval
$(class
)-y
:=)) \
273 $(eval
-include $(1)) \
274 $(foreach class
,$(classes-y
), $(call add-class
,$(class
))) \
275 $(foreach special
,$(special-classes
), \
276 $(foreach item
,$($(special
)-y
), $(call
$(special
)-handler
,$(dir $(1)),$(item
)))) \
277 $(foreach class
,$(classes
), \
278 $(eval
$(class
)-srcs
+= \
279 $$(subst $(absobj
)/,$(obj
)/, \
281 $$(abspath
$$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class
)-y
)))))))) \
282 $(eval subdirs
+=$$(subst $(CURDIR
)/,,$$(wildcard $$(abspath
$$(addprefix $(dir $(1)),$$(subdirs-y
))))))
284 # For each path in $(subdirs) call includemakefiles
285 # Repeat until subdirs is empty
287 $(eval cursubdirs
:=$(subdirs
)) \
289 $(foreach dir,$(cursubdirs
), \
290 $(eval
$(call includemakefiles
,$(dir)/Makefile.inc
))) \
291 $(if
$(subdirs
),$(eval
$(call evaluate_subdirs
)))
293 # collect all object files eligible for building
297 # Don't iterate through Makefile.incs under src/ when building tests
298 ifneq ($(UNIT_TEST
),1)
299 $(eval
$(call evaluate_subdirs
))
301 include $(TOPLEVEL
)/tests
/Makefile.inc
304 ifeq ($(FAILBUILD
),1)
305 $(error cannot continue build
)
308 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
309 $(eval
$(postinclude-hooks
))
311 # Eliminate duplicate mentions of source files in a class
312 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:=$(sort $($(class
)-srcs
))))
314 # Build Kconfig .ads if necessary
315 ifeq ($(CONFIG_RAMSTAGE_ADA
),y
)
316 ramstage-srcs
+= $(obj
)/ramstage
/$(notdir $(KCONFIG_AUTOADS
))
319 # To track dependencies, we need all Ada specification (.ads) files in
320 # *-srcs. Extract / filter all specification files that have a matching
321 # body (.adb) file here (specifications without a body are valid sources
323 $(foreach class
,$(classes
),$(eval
$(class
)-extra-specs
:= \
325 $(addprefix %/,$(patsubst %.adb
,%.ads
,$(notdir $(filter %.adb
,$($(class
)-srcs
))))), \
326 $(filter %.ads
,$($(class
)-srcs
)))))
327 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:= \
328 $(filter-out $($(class
)-extra-specs
),$($(class
)-srcs
))))
330 $(foreach class
,$(classes
),$(eval
$(class
)-objs
:=$(call src-to-obj
,$(class
),$($(class
)-srcs
))))
331 $(foreach class
,$(classes
),$(eval
$(class
)-alis
:=$(call src-to-ali
,$(class
),$($(class
)-srcs
))))
334 $(foreach class
,$(classes
),$(eval
$(class
)-ada-dirs
:=$(sort $(dir $(filter %.ads
%.adb
,$($(class
)-srcs
)) $($(class
)-extra-specs
)))))
336 # Save all objs before processing them (for dependency inclusion)
337 originalobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
339 # Call post-processors if they're defined
340 $(foreach class
,$(classes
),\
341 $(if
$(value
$(class
)-postprocess
),$(eval
$(call
$(class
)-postprocess
,$($(class
)-objs
)))))
343 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
344 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
345 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
347 # Reads dependencies from an Ada library information (.ali) file
348 # Only basenames (with suffix) are preserved so we have to look the
349 # paths up in $($(stage)-srcs).
352 create_ada_deps
=$$(if
$(2),\
355 $$(addprefix %/,$$(shell sed
-ne
's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev
/null
)), \
356 $$($(1)-srcs
) $$($(1)-extra-specs
)))
358 # macro to define template macros that are used by use_template macro
359 define create_cc_template
361 # $2 source suffix (c, S, ld, ...)
362 # $3 additional compiler flags
363 # $4 additional dependencies
364 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
365 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
366 ifn
$(EMPTY
)eq
($(filter ads adb
,$(2)),)
367 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $$(call create_ada_deps
,$1,$$(call src-to-ali
,$1,$$(1).
$2)) $(4)
368 @printf
" GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
370 $$$$(ADAFLAGS_
$(1)) $$$$(addprefix -I
,$$$$($(1)-ada-dirs
)) \
371 $(3) -c
-o
$$$$@
$$$$<
373 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $(KCONFIG_AUTOHEADER
) $(4)
374 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
376 -MMD
$$$$(CPPFLAGS_
$(1)) $$$$(CFLAGS_
$(1)) -MT
$$$$(@
) \
377 $(3) -c
-o
$$$$@
$$$$<
383 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
384 $(foreach class
,$(classes
), \
385 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
386 $(eval
$(class
)-$(type
)-ccopts
+= $(generic-
$(type
)-ccopts
) $($(class
)-generic-ccopts
)) \
387 $(if
$(generic-objs_
$(type
)_template_gen
),$(eval
$(call generic-objs_
$(type
)_template_gen
,$(class
))),\
388 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
))))))
390 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
391 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
393 # To supported complex package initializations, we need to call the
394 # emitted code explicitly. gnatbind gathers all the calls for us
395 # and exports them as a procedure $(stage)_adainit(). Every stage that
396 # uses Ada code has to call it!
397 define gnatbind_template
399 $$(obj
)/$(1)/b__
$(1).adb
: $$$$(filter-out $$(obj
)/$(1)/b__
$(1).ali
,$$$$($(1)-alis
))
400 @printf
" BIND $$(subst $$(obj)/,,$$@)\n"
401 # We have to give gnatbind a simple filename (without leading
402 # path components) so just cd there.
404 $$(GNATBIND_
$(1)) -a
-n \
405 --RTS
=$$(absobj
)/libgnat-
$$(ARCH-
$(1)-y
)/ \
406 -L
$(1)_ada
-o
$$(notdir $$@
) \
407 $$(subst $$(dir $$@
),,$$^
)
408 $$(obj
)/$(1)/b__
$(1).o
: $$(obj
)/$(1)/b__
$(1).adb
409 @printf
" GCC $$(subst $$(obj)/,,$$@)\n"
410 $(GCC_
$(1)) $$(ADAFLAGS_
$(1)) -c
-o
$$@
$$<
411 $(1)-objs
+= $$(obj
)/$(1)/b__
$(1).o
412 $($(1)-alis
): %.ali
: %.o
;
415 $(eval
$(foreach class
,$(filter-out libgnat-
%,$(classes
)), \
416 $(if
$($(class
)-alis
),$(call gnatbind_template
,$(class
)))))
418 DEPENDENCIES
+= $(addsuffix .d
,$(basename $(allobjs
)))
419 -include $(DEPENDENCIES
)
422 @
$(foreach class
,$(classes
), echo
$(class
)-objs
: $($(class
)-objs
) | tr
' ' '\n'; echo
; )
423 @echo alldirs
: $(alldirs
) | tr
' ' '\n'; echo
424 @echo allsrcs
: $(allsrcs
) | tr
' ' '\n'; echo
425 @echo DEPENDENCIES
: $(DEPENDENCIES
) | tr
' ' '\n'; echo
426 @
$(foreach class
,$(special-classes
),echo
$(class
):'$($(class))' | tr
' ' '\n'; echo
; )
430 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
433 $(obj
)/project_filelist.txt
:
434 if
[ -z
"$(wildcard $(obj)/coreboot.rom)" ]; then \
435 echo
"*** Error: Project must be built before generating file list ***"; \
438 find
$(obj
) -path
"$(obj)/util" -prune
-o
-name
"*.d" -exec cat
{} \
; | \
439 sed
"s|$(top)/||" | sed
's/[:\\]/ /g' | sed
's/ /\n/g' |
sort | uniq | \
440 grep
-v
'\.o$$' > $(obj
)/project_filelist.txt
442 filelist
: $(obj
)/project_filelist.txt
443 printf
"\nFiles used in build:\n"
444 cat
$(obj
)/project_filelist.txt
446 #works with either exuberant ctags or ctags.emacs
447 ctags-project
: clean-ctags
$(obj
)/project_filelist.txt
448 cat
$(obj
)/project_filelist.txt | \
451 cscope-project
: clean-cscope
$(obj
)/project_filelist.txt
452 cat
$(obj
)/project_filelist.txt | xargs cscope
-b
458 $(MAKE
) -C Documentation
-f Makefile.sphinx html
461 $(MAKE
) SPHINXOPTS
=-W
-C Documentation
-f Makefile.sphinx html
464 @echo
"Creating Symbolic Links.."; \
465 for link in
$(SYMLINK_LIST
); do \
466 SYMLINK
=`cat $$link`; \
467 REALPATH
=`realpath $$link`; \
468 if
[ -L
"$$SYMLINK" ]; then \
470 elif
[ ! -e
"$$SYMLINK" ]; then \
471 echo
-e
"\tLINK $$SYMLINK -> $$(dirname $$REALPATH)"; \
472 ln
-s
$$(dirname
$$REALPATH) $$SYMLINK; \
474 echo
-e
"\tFAILED: $$SYMLINK exists"; \
479 @echo
"Deleting symbolic link";\
480 EXISTING_SYMLINKS
=`find -L ./src -xtype l | grep -v 3rdparty`; \
481 for link in
$$EXISTING_SYMLINKS; do \
482 echo
-e
"\tUNLINK $$link"; \
487 rm -rf
$(obj
) .xcompile
489 clean: clean-for-update clean-utils clean-payloads
499 $(foreach tool
, $(TOOLLIST
), \
500 $(MAKE
) -C util
/$(tool
) clean MFLAGS
= MAKEFLAGS
= ;)
503 $(foreach tool
, $(TOOLLIST
), \
504 $(MAKE
) -C util
/$(tool
) distclean MFLAGS
= MAKEFLAGS
= ; \
505 rm -f
/util
/$(tool
)/junit.xml
;)
507 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
508 rm -f .config .config.old ..config.tmp
* .kconfig.d .tmpconfig
* .ccwrap .xcompile
509 rm -rf coreboot-builds coreboot-builds-chromeos
510 rm -f abuild
*.xml junit.xml
* util
/lint
/junit.xml
512 .PHONY
: $(PHONY
) clean clean-for-update clean-cscope cscope
distclean sphinx sphinx-lint
513 .PHONY
: ctags-project cscope-project clean-ctags symlink clean-symlink