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 objutil ?
= $(obj
)/util
12 objk
:= $(objutil
)/kconfig
13 absobj
:= $(abspath
$(obj
))
15 VBOOT_HOST_BUILD ?
= $(abspath
$(objutil
)/vboot_lib
)
17 COREBOOT_EXPORTS
:= COREBOOT_EXPORTS
18 COREBOOT_EXPORTS
+= top src srck obj objutil objk
24 COREBOOT_EXPORTS
+= LANG LC_ALL TZ
26 DOTCONFIG ?
= $(top
)/.config
27 KCONFIG_CONFIG
= $(DOTCONFIG
)
28 KCONFIG_AUTOADS
:= $(obj
)/cb-config.ads
29 KCONFIG_AUTOHEADER
:= $(obj
)/config.h
30 KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
31 KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
32 KCONFIG_SPLITCONFIG
:= $(obj
)/config
33 KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
34 KCONFIG_NEGATIVES
:= 1
36 KCONFIG_PACKAGE
:= CB.Config
38 COREBOOT_EXPORTS
+= KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
39 COREBOOT_EXPORTS
+= KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
40 COREBOOT_EXPORTS
+= KCONFIG_NEGATIVES KCONFIG_STRICT
41 COREBOOT_EXPORTS
+= KCONFIG_AUTOADS KCONFIG_PACKAGE
43 # directory containing the toplevel Makefile.inc
47 KBUILD_DEFCONFIG
:= configs
/defconfig
48 UNAME_RELEASE
:= $(shell uname
-r
)
49 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
50 MAKEFLAGS
+= -rR
--no-print-directory
52 # Make is silent per default, but 'make V=1' will show all compiler calls.
61 # Disable implicit/built-in rules to make Makefile errors fail fast.
67 PREPROCESS_ONLY
:= -E
-P
-x assembler-with-cpp
-undef
-I .
70 DOXYGEN_OUTPUT_DIR
:= doxygen
72 export $(COREBOOT_EXPORTS
)
77 @echo
'*** coreboot platform targets ***'
78 @echo
' Use "make [target] V=1" for extra build debug information'
79 @echo
' all - Build coreboot'
80 @echo
' clean - Remove coreboot build artifacts'
81 @echo
' distclean - Remove build artifacts and config files'
82 @echo
' doxygen - Build doxygen documentation for coreboot'
83 @echo
' doxyplatform - Build doxygen documentation for the current platform'
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 # Three cases where we don't need fully populated $(obj) lists:
98 # 1. when no .config exists
99 # 2. when make config (in any flavour) is run
100 # 3. when make distclean is run
101 # Don't waste time on reading all Makefile.incs in these cases
102 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
105 ifneq ($(MAKECMDGOALS
),)
106 ifneq ($(filter %config
%clean cross
% clang iasl lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
109 ifneq ($(filter %clean lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
114 ifneq ($(filter %-test %-tests
,$(MAKECMDGOALS
)),)
115 ifneq ($(filter-out %-test %-tests
, $(MAKECMDGOALS
)),)
116 $(error Cannot mix unit-tests targets with other targets
)
122 .xcompile
: util
/xcompile
/xcompile
124 $< $(XGCCPATH
) > $@.tmp
125 \mv
-f
$@.tmp
$@
2> /dev
/null
128 ifeq ($(NOCOMPILE
),1)
129 # We also don't use .xcompile in the no-compile situations, so
130 # provide some reasonable defaults.
131 HOSTCC ?
= $(if
$(shell type gcc
2>/dev
/null
),gcc
,cc)
134 include $(TOPLEVEL
)/Makefile.inc
135 include $(TOPLEVEL
)/payloads
/Makefile.inc
136 include $(TOPLEVEL
)/util
/testing
/Makefile.inc
137 -include $(TOPLEVEL
)/site-local
/Makefile.inc
139 @echo
"Error: Expected config file ($(DOTCONFIG)) not present." >&2
140 @echo
"Please specify a config file or run 'make menuconfig' to" >&2
141 @echo
"generate a new config file." >&2
145 ifneq ($(UNIT_TEST
),1)
149 # in addition to the dependency below, create the file if it doesn't exist
150 # to silence stupid warnings about a file that would be generated anyway.
151 $(if
$(wildcard .xcompile
)$(NOCOMPILE
),,$(eval
$(shell util
/xcompile
/xcompile
$(XGCCPATH
) > .xcompile ||
rm -f .xcompile
)))
155 ifneq ($(XCOMPILE_COMPLETE
),1)
156 $(shell rm -f .xcompile
)
157 $(error .xcompile deleted because it
's invalid. \
158 Restarting the build should fix that, or explain the problem)
161 ifneq ($(CONFIG_MMX),y)
162 CFLAGS_x86_32 += -mno-mmx
165 ifneq ($(UNIT_TEST),1)
166 include toolchain.inc
169 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
170 # fix makefile syntax highlighting after strip macro \" "))
172 # The primary target needs to be here before we include the
175 real-all: real-target
177 # must come rather early
181 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
184 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
187 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
188 $(objutil)/kconfig/toada CB.Config <$< >$@
190 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
193 # Add a new class of source/object files to the build system
195 $(eval $(1)-srcs:=) \
196 $(eval $(1)-objs:=) \
197 $(eval classes+=$(1))
199 # Special classes are managed types with special behaviour
200 # On parse time, for each entry in variable $(1)-y
201 # a handler $(1)-handler is executed with the arguments:
202 # * $(1): directory the parser is in
203 # * $(2): current entry
206 $(eval special-classes+=$(1))
208 # Converts one or more source file paths to their corresponding build/ paths.
209 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
212 # $2 file path (list)
214 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
215 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
216 $(patsubst 3rdparty/%,$(obj)/%,\
217 $(patsubst src/%,$(obj)/%,\
218 $(patsubst %.ads,%.o,\
219 $(patsubst %.adb,%.o,\
222 $(subst .$(1),,$(2))))))))))
224 # Converts one or more source file paths to the corresponding build/ paths
225 # of their Ada library information (.ali) files.
227 # $2 file path (list)
229 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
230 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
231 $(patsubst 3rdparty/%,$(obj)/%,\
232 $(patsubst src/%,$(obj)/%,\
233 $(patsubst %.ads,%.ali,\
234 $(patsubst %.adb,%.ali,\
236 $(filter %.ads %.adb,$(2)))))))))
238 # Clean -y variables, include Makefile.inc
239 # Add paths to files in X-y to X-srcs
240 # Add subdirs-y to subdirs
242 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
243 $(eval -include $(1)) \
244 $(foreach class,$(classes-y), $(call add-class,$(class))) \
245 $(foreach special,$(special-classes), \
246 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
247 $(foreach class,$(classes), \
248 $(eval $(class)-srcs+= \
249 $$(subst $(absobj)/,$(obj)/, \
251 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
252 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
254 # For each path in $(subdirs) call includemakefiles
255 # Repeat until subdirs is empty
257 $(eval cursubdirs:=$(subdirs)) \
259 $(foreach dir,$(cursubdirs), \
260 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
261 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
263 # collect all object files eligible for building
267 # Don't iterate through Makefile.incs under src
/ when building tests
268 ifneq ($(UNIT_TEST
),1)
269 $(eval
$(call evaluate_subdirs
))
271 include $(TOPLEVEL
)/tests
/Makefile.inc
274 ifeq ($(FAILBUILD
),1)
275 $(error cannot continue build
)
278 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
279 $(eval
$(postinclude-hooks
))
281 # Eliminate duplicate mentions of source files in a class
282 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:=$(sort $($(class
)-srcs
))))
284 # Build Kconfig .ads if necessary
285 ifeq ($(CONFIG_RAMSTAGE_ADA
),y
)
286 ramstage-srcs
+= $(obj
)/ramstage
/$(notdir $(KCONFIG_AUTOADS
))
289 # To track dependencies, we need all Ada specification (.ads) files in
290 # *-srcs. Extract / filter all specification files that have a matching
291 # body (.adb) file here (specifications without a body are valid sources
293 $(foreach class
,$(classes
),$(eval
$(class
)-extra-specs
:= \
295 $(addprefix %/,$(patsubst %.adb
,%.ads
,$(notdir $(filter %.adb
,$($(class
)-srcs
))))), \
296 $(filter %.ads
,$($(class
)-srcs
)))))
297 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:= \
298 $(filter-out $($(class
)-extra-specs
),$($(class
)-srcs
))))
300 $(foreach class
,$(classes
),$(eval
$(class
)-objs
:=$(call src-to-obj
,$(class
),$($(class
)-srcs
))))
301 $(foreach class
,$(classes
),$(eval
$(class
)-alis
:=$(call src-to-ali
,$(class
),$($(class
)-srcs
))))
304 $(foreach class
,$(classes
),$(eval
$(class
)-ada-dirs
:=$(sort $(dir $(filter %.ads
%.adb
,$($(class
)-srcs
)) $($(class
)-extra-specs
)))))
306 # Save all objs before processing them (for dependency inclusion)
307 originalobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
309 # Call post-processors if they're defined
310 $(foreach class
,$(classes
),\
311 $(if
$(value
$(class
)-postprocess
),$(eval
$(call
$(class
)-postprocess
,$($(class
)-objs
)))))
313 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
314 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
315 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
317 # Reads dependencies from an Ada library information (.ali) file
318 # Only basenames (with suffix) are preserved so we have to look the
319 # paths up in $($(stage)-srcs).
322 create_ada_deps
=$$(if
$(2),\
325 $$(addprefix %/,$$(shell sed
-ne
's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev
/null
)), \
326 $$($(1)-srcs
) $$($(1)-extra-specs
)))
328 # macro to define template macros that are used by use_template macro
329 define create_cc_template
331 # $2 source suffix (c, S, ld, ...)
332 # $3 additional compiler flags
333 # $4 additional dependencies
334 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
335 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
336 ifn
$(EMPTY
)eq
($(filter ads adb
,$(2)),)
337 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $$(call create_ada_deps
,$1,$$(call src-to-ali
,$1,$$(1).
$2)) $(4)
338 @printf
" GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
340 $$$$(ADAFLAGS_
$(1)) $$$$(addprefix -I
,$$$$($(1)-ada-dirs
)) \
341 $(3) -c
-o
$$$$@
$$$$<
343 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $(KCONFIG_AUTOHEADER
) $(4)
344 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
346 -MMD
$$$$(CPPFLAGS_
$(1)) $$$$(CFLAGS_
$(1)) -MT
$$$$(@
) \
347 $(3) -c
-o
$$$$@
$$$$<
353 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
354 $(foreach class
,$(classes
), \
355 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
356 $(eval
$(class
)-$(type
)-ccopts
+= $(generic-
$(type
)-ccopts
) $($(class
)-generic-ccopts
)) \
357 $(if
$(generic-objs_
$(type
)_template_gen
),$(eval
$(call generic-objs_
$(type
)_template_gen
,$(class
))),\
358 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
))))))
360 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
361 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
363 # To supported complex package initializations, we need to call the
364 # emitted code explicitly. gnatbind gathers all the calls for us
365 # and exports them as a procedure $(stage)_adainit(). Every stage that
366 # uses Ada code has to call it!
367 define gnatbind_template
369 $$(obj
)/$(1)/b__
$(1).adb
: $$$$(filter-out $$(obj
)/$(1)/b__
$(1).ali
,$$$$($(1)-alis
))
370 @printf
" BIND $$(subst $$(obj)/,,$$@)\n"
371 # We have to give gnatbind a simple filename (without leading
372 # path components) so just cd there.
374 $$(GNATBIND_
$(1)) -a
-n \
375 --RTS
=$$(absobj
)/libgnat-
$$(ARCH-
$(1)-y
)/ \
376 -L
$(1)_ada
-o
$$(notdir $$@
) \
377 $$(subst $$(dir $$@
),,$$^
)
378 $$(obj
)/$(1)/b__
$(1).o
: $$(obj
)/$(1)/b__
$(1).adb
379 @printf
" GCC $$(subst $$(obj)/,,$$@)\n"
380 $(GCC_
$(1)) $$(ADAFLAGS_
$(1)) -c
-o
$$@
$$<
381 $(1)-objs
+= $$(obj
)/$(1)/b__
$(1).o
382 $($(1)-alis
): %.ali
: %.o
;
385 $(eval
$(foreach class
,$(filter-out libgnat-
%,$(classes
)), \
386 $(if
$($(class
)-alis
),$(call gnatbind_template
,$(class
)))))
388 DEPENDENCIES
+= $(addsuffix .d
,$(basename $(allobjs
)))
389 -include $(DEPENDENCIES
)
392 @
$(foreach class
,$(classes
), echo
$(class
)-objs
: $($(class
)-objs
) | tr
' ' '\n'; echo
; )
393 @echo alldirs
: $(alldirs
) | tr
' ' '\n'; echo
394 @echo allsrcs
: $(allsrcs
) | tr
' ' '\n'; echo
395 @echo DEPENDENCIES
: $(DEPENDENCIES
) | tr
' ' '\n'; echo
396 @
$(foreach class
,$(special-classes
),echo
$(class
):'$($(class))' | tr
' ' '\n'; echo
; )
400 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
403 $(obj
)/project_filelist.txt
:
404 if
[ -z
"$(wildcard $(obj)/coreboot.rom)" ]; then \
405 echo
"*** Error: Project must be built before generating file list ***"; \
408 find
$(obj
) -path
"$(obj)/util" -prune
-o
-name
"*.d" -exec cat
{} \
; | \
409 sed
"s|$(top)/||" | sed
's/[:\\]/ /g' | sed
's/ /\n/g' |
sort | uniq | \
410 grep
-v
'\.o$$' > $(obj
)/project_filelist.txt
412 filelist
: $(obj
)/project_filelist.txt
413 printf
"\nFiles used in build:\n"
414 cat
$(obj
)/project_filelist.txt
416 #works with either exuberant ctags or ctags.emacs
417 ctags-project
: clean-ctags
$(obj
)/project_filelist.txt
418 cat
$(obj
)/project_filelist.txt | \
421 cscope-project
: clean-cscope
$(obj
)/project_filelist.txt
422 cat
$(obj
)/project_filelist.txt | xargs cscope
-b
428 $(MAKE
) -C Documentation
-f Makefile.sphinx html
431 $(MAKE
) SPHINXOPTS
=-W
-C Documentation
-f Makefile.sphinx html
435 $(DOXYGEN
) Documentation
/Doxyfile.coreboot
438 $(DOXYGEN
) Documentation
/Doxyfile.coreboot_simple
440 doxyplatform doxygen_platform
: $(obj
)/project_filelist.txt
442 echo
"Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
443 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' )"; \
444 mkdir
-p
"$$DOXYGEN_OUTPUT_DIR"; \
445 export DOXYFILES
="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
446 export DOXYGEN_PLATFORM
="$(call strip_quotes, $(CONFIG_MAINBOARD_DIR)) \($(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER))\) version $(KERNELVERSION)"; \
447 $(DOXYGEN
) Documentation
/doxygen
/Doxyfile.coreboot_platform
449 doxyclean
: doxygen-clean
451 rm -rf
$(DOXYGEN_OUTPUT_DIR
)
453 clean-for-update
: doxygen-clean clean-for-update-target
454 rm -rf
$(obj
) .xcompile
456 clean: clean-for-update clean-target clean-utils
466 $(foreach tool
, $(TOOLLIST
), \
467 $(MAKE
) -C util
/$(tool
) clean MFLAGS
= MAKEFLAGS
= ;)
470 $(foreach tool
, $(TOOLLIST
), \
471 $(MAKE
) -C util
/$(tool
) distclean MFLAGS
= MAKEFLAGS
= ; \
472 rm -f
/util
/$(tool
)/junit.xml
;)
474 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
475 rm -f .config .config.old ..config.tmp
* .kconfig.d .tmpconfig
* .ccwrap .xcompile
476 rm -rf coreboot-builds coreboot-builds-chromeos
477 rm -f abuild
*.xml junit.xml
* util
/lint
/junit.xml
479 .PHONY
: $(PHONY
) clean clean-for-update clean-cscope cscope
distclean doxygen doxy doxygen_simple sphinx sphinx-lint
480 .PHONY
: ctags-project cscope-project clean-ctags