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
35 COREBOOT_EXPORTS
+= KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
36 COREBOOT_EXPORTS
+= KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
37 COREBOOT_EXPORTS
+= KCONFIG_NEGATIVES KCONFIG_STRICT
38 COREBOOT_EXPORTS
+= KCONFIG_AUTOADS KCONFIG_PACKAGE
40 # directory containing the toplevel Makefile.inc
44 KBUILD_DEFCONFIG
:= configs
/defconfig
45 UNAME_RELEASE
:= $(shell uname
-r
)
46 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
47 MAKEFLAGS
+= -rR
--no-print-directory
49 # Make is silent per default, but 'make V=1' will show all compiler calls.
55 quiet_errors
:= 2>/dev
/null
59 # Disable implicit/built-in rules to make Makefile errors fail fast.
65 PREPROCESS_ONLY
:= -E
-P
-x assembler-with-cpp
-undef
-I .
68 DOXYGEN_OUTPUT_DIR
:= doxygen
70 export $(COREBOOT_EXPORTS
)
75 @echo
'*** coreboot platform targets ***'
76 @echo
' Use "make [target] V=1" for extra build debug information'
77 @echo
' all - Build coreboot'
78 @echo
' clean - Remove coreboot build artifacts'
79 @echo
' distclean - Remove build artifacts and config files'
80 @echo
' doxygen - Build doxygen documentation for coreboot'
81 @echo
' doxyplatform - Build doxygen documentation for the current platform'
82 @echo
' sphinx - Build sphinx documentation for coreboot'
83 @echo
' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
84 @echo
' filelist - Show files used in current build'
85 @echo
' printall - print makefile info for debugging'
86 @echo
' gitconfig - set up git to submit patches to coreboot'
87 @echo
' ctags / ctags-project - make ctags file for all of coreboot or current board'
88 @echo
' cscope / cscope-project - make cscope.out file for coreboot or current board'
91 # This include must come _before_ the pattern rules below!
92 # Order _does_ matter for pattern rules.
93 include $(srck
)/Makefile.inc
95 # Three cases where we don't need fully populated $(obj) lists:
96 # 1. when no .config exists
97 # 2. when make config (in any flavour) is run
98 # 3. when make distclean is run
99 # Don't waste time on reading all Makefile.incs in these cases
100 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
103 ifneq ($(MAKECMDGOALS
),)
104 ifneq ($(filter %config
%clean cross
% clang iasl lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
107 ifneq ($(filter %clean lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
113 ifneq ($(filter help
%, $(MAKECMDGOALS
)), )
117 ifneq ($(filter %-test %-tests
%coverage-report
, $(MAKECMDGOALS
)),)
118 ifneq ($(filter-out %-test %-tests
%coverage-report
, $(MAKECMDGOALS
)),)
119 $(error Cannot mix unit-tests targets with other targets
)
126 $(xcompile
): util
/xcompile
/xcompile
128 $< $(XGCCPATH
) > $@.tmp
129 \mv
-f
$@.tmp
$@
2> /dev
/null
132 ifeq ($(NOCOMPILE
),1)
133 # We also don't use .xcompile in the no-compile situations, so
134 # provide some reasonable defaults.
135 HOSTCC ?
= $(if
$(shell type gcc
2>/dev
/null
),gcc
,cc)
138 include $(TOPLEVEL
)/Makefile.inc
139 include $(TOPLEVEL
)/payloads
/Makefile.inc
140 include $(TOPLEVEL
)/util
/testing
/Makefile.inc
141 -include $(TOPLEVEL
)/site-local
/Makefile.inc
142 include $(TOPLEVEL
)/tests
/Makefile.inc
144 @echo
"Error: Expected config file ($(DOTCONFIG)) not present." >&2
145 @echo
"Please specify a config file or run 'make menuconfig' to" >&2
146 @echo
"generate a new config file." >&2
150 ifneq ($(UNIT_TEST
),1)
154 # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
155 # wait for make to generate the file.
156 $(if
$(wildcard $(xcompile
)),, $(shell \
157 mkdir
-p
$(dir $(xcompile
)) && \
158 util
/xcompile
/xcompile
$(XGCCPATH
) > $(xcompile
) ||
rm -f
$(xcompile
)))
162 ifneq ($(XCOMPILE_COMPLETE
),1)
163 $(shell rm -f
$(xcompile
))
164 $(error
$(xcompile
) deleted because it
's invalid. \
165 Restarting the build should fix that, or explain the problem)
168 # reproducible builds
172 ifneq ($(NOCOMPILE),1)
173 SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's
/^.
define COREBOOT_BUILD_EPOCH\
>.
*"\(.*\)".
*/\
1/p
')
175 # don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
177 export LANG LC_ALL TZ SOURCE_DATE_EPOCH
179 ifneq ($(CONFIG_MMX
),y
)
180 CFLAGS_x86_32
+= -mno-mmx
183 ifneq ($(UNIT_TEST
),1)
184 include toolchain.inc
187 strip_quotes
= $(strip $(subst ",,$(subst \",,$(1))))
188 # fix makefile syntax highlighting after strip macro \" "))
190 # The primary target needs to be here before we include the
193 real-all
: real-target
195 # must come rather early
199 $(KCONFIG_AUTOHEADER
): $(KCONFIG_CONFIG
) $(objutil
)/kconfig
/conf
203 $(KCONFIG_AUTOCONFIG
): $(KCONFIG_AUTOHEADER
)
206 $(KCONFIG_AUTOADS
): $(KCONFIG_CONFIG
) $(KCONFIG_AUTOHEADER
) $(objutil
)/kconfig
/toada
207 $(objutil
)/kconfig
/toada CB.Config
<$< >$@
209 $(obj
)/%/$(notdir $(KCONFIG_AUTOADS
)): $(KCONFIG_AUTOADS
)
212 # Add a new class of source/object files to the build system
214 $(eval
$(1)-srcs
:=) \
215 $(eval
$(1)-objs
:=) \
216 $(eval classes
+=$(1))
218 # Special classes are managed types with special behaviour
219 # On parse time, for each entry in variable $(1)-y
220 # a handler $(1)-handler is executed with the arguments:
221 # * $(1): directory the parser is in
222 # * $(2): current entry
225 $(eval special-classes
+=$(1))
227 # Converts one or more source file paths to their corresponding build/ paths.
228 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
231 # $2 file path (list)
233 $(patsubst $(obj
)/%,$(obj
)/$(1)/%,\
234 $(patsubst $(obj
)/$(1)/%,$(obj
)/%,\
235 $(patsubst 3rdparty
/%,$(obj
)/%,\
236 $(patsubst src
/%,$(obj
)/%,\
237 $(patsubst %.ads
,%.o
,\
238 $(patsubst %.adb
,%.o
,\
241 $(subst .
$(1),,$(2))))))))))
243 # Converts one or more source file paths to the corresponding build/ paths
244 # of their Ada library information (.ali) files.
246 # $2 file path (list)
248 $(patsubst $(obj
)/%,$(obj
)/$(1)/%,\
249 $(patsubst $(obj
)/$(1)/%,$(obj
)/%,\
250 $(patsubst 3rdparty
/%,$(obj
)/%,\
251 $(patsubst src
/%,$(obj
)/%,\
252 $(patsubst %.ads
,%.ali
,\
253 $(patsubst %.adb
,%.ali
,\
255 $(filter %.ads
%.adb
,$(2)))))))))
257 # Clean -y variables, include Makefile.inc
258 # Add paths to files in X-y to X-srcs
259 # Add subdirs-y to subdirs
261 $(foreach class
,classes subdirs
$(classes
) $(special-classes
), $(eval
$(class
)-y
:=)) \
262 $(eval
-include $(1)) \
263 $(foreach class
,$(classes-y
), $(call add-class
,$(class
))) \
264 $(foreach special
,$(special-classes
), \
265 $(foreach item
,$($(special
)-y
), $(call
$(special
)-handler
,$(dir $(1)),$(item
)))) \
266 $(foreach class
,$(classes
), \
267 $(eval
$(class
)-srcs
+= \
268 $$(subst $(absobj
)/,$(obj
)/, \
270 $$(abspath
$$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class
)-y
)))))))) \
271 $(eval subdirs
+=$$(subst $(CURDIR
)/,,$$(wildcard $$(abspath
$$(addprefix $(dir $(1)),$$(subdirs-y
))))))
273 # For each path in $(subdirs) call includemakefiles
274 # Repeat until subdirs is empty
276 $(eval cursubdirs
:=$(subdirs
)) \
278 $(foreach dir,$(cursubdirs
), \
279 $(eval
$(call includemakefiles
,$(dir)/Makefile.inc
))) \
280 $(if
$(subdirs
),$(eval
$(call evaluate_subdirs
)))
282 # collect all object files eligible for building
286 # Don't iterate through Makefile.incs under src/ when building tests
287 ifneq ($(UNIT_TEST
),1)
288 $(eval
$(call evaluate_subdirs
))
290 include $(TOPLEVEL
)/tests
/Makefile.inc
293 ifeq ($(FAILBUILD
),1)
294 $(error cannot continue build
)
297 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
298 $(eval
$(postinclude-hooks
))
300 # Eliminate duplicate mentions of source files in a class
301 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:=$(sort $($(class
)-srcs
))))
303 # Build Kconfig .ads if necessary
304 ifeq ($(CONFIG_RAMSTAGE_ADA
),y
)
305 ramstage-srcs
+= $(obj
)/ramstage
/$(notdir $(KCONFIG_AUTOADS
))
308 # To track dependencies, we need all Ada specification (.ads) files in
309 # *-srcs. Extract / filter all specification files that have a matching
310 # body (.adb) file here (specifications without a body are valid sources
312 $(foreach class
,$(classes
),$(eval
$(class
)-extra-specs
:= \
314 $(addprefix %/,$(patsubst %.adb
,%.ads
,$(notdir $(filter %.adb
,$($(class
)-srcs
))))), \
315 $(filter %.ads
,$($(class
)-srcs
)))))
316 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:= \
317 $(filter-out $($(class
)-extra-specs
),$($(class
)-srcs
))))
319 $(foreach class
,$(classes
),$(eval
$(class
)-objs
:=$(call src-to-obj
,$(class
),$($(class
)-srcs
))))
320 $(foreach class
,$(classes
),$(eval
$(class
)-alis
:=$(call src-to-ali
,$(class
),$($(class
)-srcs
))))
323 $(foreach class
,$(classes
),$(eval
$(class
)-ada-dirs
:=$(sort $(dir $(filter %.ads
%.adb
,$($(class
)-srcs
)) $($(class
)-extra-specs
)))))
325 # Save all objs before processing them (for dependency inclusion)
326 originalobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
328 # Call post-processors if they're defined
329 $(foreach class
,$(classes
),\
330 $(if
$(value
$(class
)-postprocess
),$(eval
$(call
$(class
)-postprocess
,$($(class
)-objs
)))))
332 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
333 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
334 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
336 # Reads dependencies from an Ada library information (.ali) file
337 # Only basenames (with suffix) are preserved so we have to look the
338 # paths up in $($(stage)-srcs).
341 create_ada_deps
=$$(if
$(2),\
344 $$(addprefix %/,$$(shell sed
-ne
's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev
/null
)), \
345 $$($(1)-srcs
) $$($(1)-extra-specs
)))
347 # macro to define template macros that are used by use_template macro
348 define create_cc_template
350 # $2 source suffix (c, S, ld, ...)
351 # $3 additional compiler flags
352 # $4 additional dependencies
353 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
354 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
355 ifn
$(EMPTY
)eq
($(filter ads adb
,$(2)),)
356 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $$(call create_ada_deps
,$1,$$(call src-to-ali
,$1,$$(1).
$2)) $(4)
357 @printf
" GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
359 $$$$(ADAFLAGS_
$(1)) $$$$(addprefix -I
,$$$$($(1)-ada-dirs
)) \
360 $(3) -c
-o
$$$$@
$$$$<
362 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $(KCONFIG_AUTOHEADER
) $(4)
363 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
365 -MMD
$$$$(CPPFLAGS_
$(1)) $$$$(CFLAGS_
$(1)) -MT
$$$$(@
) \
366 $(3) -c
-o
$$$$@
$$$$<
372 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
373 $(foreach class
,$(classes
), \
374 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
375 $(eval
$(class
)-$(type
)-ccopts
+= $(generic-
$(type
)-ccopts
) $($(class
)-generic-ccopts
)) \
376 $(if
$(generic-objs_
$(type
)_template_gen
),$(eval
$(call generic-objs_
$(type
)_template_gen
,$(class
))),\
377 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
))))))
379 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
380 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
382 # To supported complex package initializations, we need to call the
383 # emitted code explicitly. gnatbind gathers all the calls for us
384 # and exports them as a procedure $(stage)_adainit(). Every stage that
385 # uses Ada code has to call it!
386 define gnatbind_template
388 $$(obj
)/$(1)/b__
$(1).adb
: $$$$(filter-out $$(obj
)/$(1)/b__
$(1).ali
,$$$$($(1)-alis
))
389 @printf
" BIND $$(subst $$(obj)/,,$$@)\n"
390 # We have to give gnatbind a simple filename (without leading
391 # path components) so just cd there.
393 $$(GNATBIND_
$(1)) -a
-n \
394 --RTS
=$$(absobj
)/libgnat-
$$(ARCH-
$(1)-y
)/ \
395 -L
$(1)_ada
-o
$$(notdir $$@
) \
396 $$(subst $$(dir $$@
),,$$^
)
397 $$(obj
)/$(1)/b__
$(1).o
: $$(obj
)/$(1)/b__
$(1).adb
398 @printf
" GCC $$(subst $$(obj)/,,$$@)\n"
399 $(GCC_
$(1)) $$(ADAFLAGS_
$(1)) -c
-o
$$@
$$<
400 $(1)-objs
+= $$(obj
)/$(1)/b__
$(1).o
401 $($(1)-alis
): %.ali
: %.o
;
404 $(eval
$(foreach class
,$(filter-out libgnat-
%,$(classes
)), \
405 $(if
$($(class
)-alis
),$(call gnatbind_template
,$(class
)))))
407 DEPENDENCIES
+= $(addsuffix .d
,$(basename $(allobjs
)))
408 -include $(DEPENDENCIES
)
411 @
$(foreach class
,$(classes
), echo
$(class
)-objs
: $($(class
)-objs
) | tr
' ' '\n'; echo
; )
412 @echo alldirs
: $(alldirs
) | tr
' ' '\n'; echo
413 @echo allsrcs
: $(allsrcs
) | tr
' ' '\n'; echo
414 @echo DEPENDENCIES
: $(DEPENDENCIES
) | tr
' ' '\n'; echo
415 @
$(foreach class
,$(special-classes
),echo
$(class
):'$($(class))' | tr
' ' '\n'; echo
; )
419 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
422 $(obj
)/project_filelist.txt
:
423 if
[ -z
"$(wildcard $(obj)/coreboot.rom)" ]; then \
424 echo
"*** Error: Project must be built before generating file list ***"; \
427 find
$(obj
) -path
"$(obj)/util" -prune
-o
-name
"*.d" -exec cat
{} \
; | \
428 sed
"s|$(top)/||" | sed
's/[:\\]/ /g' | sed
's/ /\n/g' |
sort | uniq | \
429 grep
-v
'\.o$$' > $(obj
)/project_filelist.txt
431 filelist
: $(obj
)/project_filelist.txt
432 printf
"\nFiles used in build:\n"
433 cat
$(obj
)/project_filelist.txt
435 #works with either exuberant ctags or ctags.emacs
436 ctags-project
: clean-ctags
$(obj
)/project_filelist.txt
437 cat
$(obj
)/project_filelist.txt | \
440 cscope-project
: clean-cscope
$(obj
)/project_filelist.txt
441 cat
$(obj
)/project_filelist.txt | xargs cscope
-b
447 $(MAKE
) -C Documentation
-f Makefile.sphinx html
450 $(MAKE
) SPHINXOPTS
=-W
-C Documentation
-f Makefile.sphinx html
454 $(DOXYGEN
) Documentation
/Doxyfile.coreboot
457 $(DOXYGEN
) Documentation
/Doxyfile.coreboot_simple
459 doxyplatform doxygen_platform
: $(obj
)/project_filelist.txt
461 echo
"Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
462 export DOXYGEN_OUTPUT_DIR
="$$( echo $(DOXYGEN_OUTPUT_DIR)/$(call strip_quotes, $(CONFIG_MAINBOARD_VENDOR))_$(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER)) | sed 's|[^A-Za-z0-9/]|_|g' )"; \
463 mkdir
-p
"$$DOXYGEN_OUTPUT_DIR"; \
464 export DOXYFILES
="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
465 export DOXYGEN_PLATFORM
="$(call strip_quotes, $(CONFIG_MAINBOARD_DIR)) \($(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER))\) version $(KERNELVERSION)"; \
466 $(DOXYGEN
) Documentation
/doxygen
/Doxyfile.coreboot_platform
468 doxyclean
: doxygen-clean
470 rm -rf
$(DOXYGEN_OUTPUT_DIR
)
472 clean-for-update
: doxygen-clean clean-for-update-target
473 rm -rf
$(obj
) .xcompile
475 clean: clean-for-update clean-target clean-utils
485 $(foreach tool
, $(TOOLLIST
), \
486 $(MAKE
) -C util
/$(tool
) clean MFLAGS
= MAKEFLAGS
= ;)
489 $(foreach tool
, $(TOOLLIST
), \
490 $(MAKE
) -C util
/$(tool
) distclean MFLAGS
= MAKEFLAGS
= ; \
491 rm -f
/util
/$(tool
)/junit.xml
;)
493 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
494 rm -f .config .config.old ..config.tmp
* .kconfig.d .tmpconfig
* .ccwrap .xcompile
495 rm -rf coreboot-builds coreboot-builds-chromeos
496 rm -f abuild
*.xml junit.xml
* util
/lint
/junit.xml
498 .PHONY
: $(PHONY
) clean clean-for-update clean-cscope cscope
distclean doxygen doxy doxygen_simple sphinx sphinx-lint
499 .PHONY
: ctags-project cscope-project clean-ctags