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
27 ifneq ($(NOCOMPILE
),1)
28 SOURCE_DATE_EPOCH
:= $(shell $(top
)/util
/genbuild_h
/genbuild_h.sh . | sed
-n
's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
30 # don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
32 export LANG LC_ALL TZ SOURCE_DATE_EPOCH
34 DOTCONFIG ?
= $(top
)/.config
35 KCONFIG_CONFIG
= $(DOTCONFIG
)
36 KCONFIG_AUTOADS
:= $(obj
)/cb-config.ads
37 KCONFIG_AUTOHEADER
:= $(obj
)/config.h
38 KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
39 KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
40 KCONFIG_SPLITCONFIG
:= $(obj
)/config
/
41 KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
42 KCONFIG_NEGATIVES
:= 1
44 KCONFIG_PACKAGE
:= CB.Config
46 COREBOOT_EXPORTS
+= KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
47 COREBOOT_EXPORTS
+= KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
48 COREBOOT_EXPORTS
+= KCONFIG_NEGATIVES KCONFIG_STRICT
49 COREBOOT_EXPORTS
+= KCONFIG_AUTOADS KCONFIG_PACKAGE
51 # directory containing the toplevel Makefile.inc
55 KBUILD_DEFCONFIG
:= configs
/defconfig
56 UNAME_RELEASE
:= $(shell uname
-r
)
57 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
58 MAKEFLAGS
+= -rR
--no-print-directory
60 # Make is silent per default, but 'make V=1' will show all compiler calls.
69 # Disable implicit/built-in rules to make Makefile errors fail fast.
75 PREPROCESS_ONLY
:= -E
-P
-x assembler-with-cpp
-undef
-I .
78 DOXYGEN_OUTPUT_DIR
:= doxygen
80 export $(COREBOOT_EXPORTS
)
85 @echo
'*** coreboot platform targets ***'
86 @echo
' Use "make [target] V=1" for extra build debug information'
87 @echo
' all - Build coreboot'
88 @echo
' clean - Remove coreboot build artifacts'
89 @echo
' distclean - Remove build artifacts and config files'
90 @echo
' doxygen - Build doxygen documentation for coreboot'
91 @echo
' doxyplatform - Build doxygen documentation for the current platform'
92 @echo
' sphinx - Build sphinx documentation for coreboot'
93 @echo
' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
94 @echo
' filelist - Show files used in current build'
95 @echo
' printall - print makefile info for debugging'
96 @echo
' gitconfig - set up git to submit patches to coreboot'
97 @echo
' ctags / ctags-project - make ctags file for all of coreboot or current board'
98 @echo
' cscope / cscope-project - make cscope.out file for coreboot or current board'
101 # This include must come _before_ the pattern rules below!
102 # Order _does_ matter for pattern rules.
103 include $(srck
)/Makefile.inc
105 # Three cases where we don't need fully populated $(obj) lists:
106 # 1. when no .config exists
107 # 2. when make config (in any flavour) is run
108 # 3. when make distclean is run
109 # Don't waste time on reading all Makefile.incs in these cases
110 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
113 ifneq ($(MAKECMDGOALS
),)
114 ifneq ($(filter %config
%clean cross
% clang iasl lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
117 ifneq ($(filter %clean lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
123 ifneq ($(filter help
%, $(MAKECMDGOALS
)), )
127 ifneq ($(filter %-test %-tests
%coverage-report
, $(MAKECMDGOALS
)),)
128 ifneq ($(filter-out %-test %-tests
%coverage-report
, $(MAKECMDGOALS
)),)
129 $(error Cannot mix unit-tests targets with other targets
)
136 $(xcompile
): util
/xcompile
/xcompile
138 $< $(XGCCPATH
) > $@.tmp
139 \mv
-f
$@.tmp
$@
2> /dev
/null
142 ifeq ($(NOCOMPILE
),1)
143 # We also don't use .xcompile in the no-compile situations, so
144 # provide some reasonable defaults.
145 HOSTCC ?
= $(if
$(shell type gcc
2>/dev
/null
),gcc
,cc)
148 include $(TOPLEVEL
)/Makefile.inc
149 include $(TOPLEVEL
)/payloads
/Makefile.inc
150 include $(TOPLEVEL
)/util
/testing
/Makefile.inc
151 -include $(TOPLEVEL
)/site-local
/Makefile.inc
152 include $(TOPLEVEL
)/tests
/Makefile.inc
154 @echo
"Error: Expected config file ($(DOTCONFIG)) not present." >&2
155 @echo
"Please specify a config file or run 'make menuconfig' to" >&2
156 @echo
"generate a new config file." >&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 ifneq ($(CONFIG_MMX),y)
179 CFLAGS_x86_32 += -mno-mmx
182 ifneq ($(UNIT_TEST),1)
183 include toolchain.inc
186 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
187 # fix makefile syntax highlighting after strip macro \" "))
189 # The primary target needs to be here before we include the
192 real-all: real-target
194 # must come rather early
198 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
202 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
205 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
206 $(objutil)/kconfig/toada CB.Config <$< >$@
208 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
211 # Add a new class of source/object files to the build system
213 $(eval $(1)-srcs:=) \
214 $(eval $(1)-objs:=) \
215 $(eval classes+=$(1))
217 # Special classes are managed types with special behaviour
218 # On parse time, for each entry in variable $(1)-y
219 # a handler $(1)-handler is executed with the arguments:
220 # * $(1): directory the parser is in
221 # * $(2): current entry
224 $(eval special-classes+=$(1))
226 # Converts one or more source file paths to their corresponding build/ paths.
227 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
230 # $2 file path (list)
232 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
233 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
234 $(patsubst 3rdparty/%,$(obj)/%,\
235 $(patsubst src/%,$(obj)/%,\
236 $(patsubst %.ads,%.o,\
237 $(patsubst %.adb,%.o,\
240 $(subst .$(1),,$(2))))))))))
242 # Converts one or more source file paths to the corresponding build/ paths
243 # of their Ada library information (.ali) files.
245 # $2 file path (list)
247 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
248 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
249 $(patsubst 3rdparty/%,$(obj)/%,\
250 $(patsubst src/%,$(obj)/%,\
251 $(patsubst %.ads,%.ali,\
252 $(patsubst %.adb,%.ali,\
254 $(filter %.ads %.adb,$(2)))))))))
256 # Clean -y variables, include Makefile.inc
257 # Add paths to files in X-y to X-srcs
258 # Add subdirs-y to subdirs
260 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
261 $(eval -include $(1)) \
262 $(foreach class,$(classes-y), $(call add-class,$(class))) \
263 $(foreach special,$(special-classes), \
264 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
265 $(foreach class,$(classes), \
266 $(eval $(class)-srcs+= \
267 $$(subst $(absobj)/,$(obj)/, \
269 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
270 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
272 # For each path in $(subdirs) call includemakefiles
273 # Repeat until subdirs is empty
275 $(eval cursubdirs:=$(subdirs)) \
277 $(foreach dir,$(cursubdirs), \
278 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
279 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
281 # collect all object files eligible for building
285 # Don't iterate through Makefile.incs under src
/ when building tests
286 ifneq ($(UNIT_TEST
),1)
287 $(eval
$(call evaluate_subdirs
))
289 include $(TOPLEVEL
)/tests
/Makefile.inc
292 ifeq ($(FAILBUILD
),1)
293 $(error cannot continue build
)
296 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
297 $(eval
$(postinclude-hooks
))
299 # Eliminate duplicate mentions of source files in a class
300 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:=$(sort $($(class
)-srcs
))))
302 # Build Kconfig .ads if necessary
303 ifeq ($(CONFIG_RAMSTAGE_ADA
),y
)
304 ramstage-srcs
+= $(obj
)/ramstage
/$(notdir $(KCONFIG_AUTOADS
))
307 # To track dependencies, we need all Ada specification (.ads) files in
308 # *-srcs. Extract / filter all specification files that have a matching
309 # body (.adb) file here (specifications without a body are valid sources
311 $(foreach class
,$(classes
),$(eval
$(class
)-extra-specs
:= \
313 $(addprefix %/,$(patsubst %.adb
,%.ads
,$(notdir $(filter %.adb
,$($(class
)-srcs
))))), \
314 $(filter %.ads
,$($(class
)-srcs
)))))
315 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:= \
316 $(filter-out $($(class
)-extra-specs
),$($(class
)-srcs
))))
318 $(foreach class
,$(classes
),$(eval
$(class
)-objs
:=$(call src-to-obj
,$(class
),$($(class
)-srcs
))))
319 $(foreach class
,$(classes
),$(eval
$(class
)-alis
:=$(call src-to-ali
,$(class
),$($(class
)-srcs
))))
322 $(foreach class
,$(classes
),$(eval
$(class
)-ada-dirs
:=$(sort $(dir $(filter %.ads
%.adb
,$($(class
)-srcs
)) $($(class
)-extra-specs
)))))
324 # Save all objs before processing them (for dependency inclusion)
325 originalobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
327 # Call post-processors if they're defined
328 $(foreach class
,$(classes
),\
329 $(if
$(value
$(class
)-postprocess
),$(eval
$(call
$(class
)-postprocess
,$($(class
)-objs
)))))
331 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
332 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
333 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
335 # Reads dependencies from an Ada library information (.ali) file
336 # Only basenames (with suffix) are preserved so we have to look the
337 # paths up in $($(stage)-srcs).
340 create_ada_deps
=$$(if
$(2),\
343 $$(addprefix %/,$$(shell sed
-ne
's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev
/null
)), \
344 $$($(1)-srcs
) $$($(1)-extra-specs
)))
346 # macro to define template macros that are used by use_template macro
347 define create_cc_template
349 # $2 source suffix (c, S, ld, ...)
350 # $3 additional compiler flags
351 # $4 additional dependencies
352 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
353 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
354 ifn
$(EMPTY
)eq
($(filter ads adb
,$(2)),)
355 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $$(call create_ada_deps
,$1,$$(call src-to-ali
,$1,$$(1).
$2)) $(4)
356 @printf
" GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
358 $$$$(ADAFLAGS_
$(1)) $$$$(addprefix -I
,$$$$($(1)-ada-dirs
)) \
359 $(3) -c
-o
$$$$@
$$$$<
361 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $(KCONFIG_AUTOHEADER
) $(4)
362 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
364 -MMD
$$$$(CPPFLAGS_
$(1)) $$$$(CFLAGS_
$(1)) -MT
$$$$(@
) \
365 $(3) -c
-o
$$$$@
$$$$<
371 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
372 $(foreach class
,$(classes
), \
373 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
374 $(eval
$(class
)-$(type
)-ccopts
+= $(generic-
$(type
)-ccopts
) $($(class
)-generic-ccopts
)) \
375 $(if
$(generic-objs_
$(type
)_template_gen
),$(eval
$(call generic-objs_
$(type
)_template_gen
,$(class
))),\
376 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
))))))
378 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
379 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
381 # To supported complex package initializations, we need to call the
382 # emitted code explicitly. gnatbind gathers all the calls for us
383 # and exports them as a procedure $(stage)_adainit(). Every stage that
384 # uses Ada code has to call it!
385 define gnatbind_template
387 $$(obj
)/$(1)/b__
$(1).adb
: $$$$(filter-out $$(obj
)/$(1)/b__
$(1).ali
,$$$$($(1)-alis
))
388 @printf
" BIND $$(subst $$(obj)/,,$$@)\n"
389 # We have to give gnatbind a simple filename (without leading
390 # path components) so just cd there.
392 $$(GNATBIND_
$(1)) -a
-n \
393 --RTS
=$$(absobj
)/libgnat-
$$(ARCH-
$(1)-y
)/ \
394 -L
$(1)_ada
-o
$$(notdir $$@
) \
395 $$(subst $$(dir $$@
),,$$^
)
396 $$(obj
)/$(1)/b__
$(1).o
: $$(obj
)/$(1)/b__
$(1).adb
397 @printf
" GCC $$(subst $$(obj)/,,$$@)\n"
398 $(GCC_
$(1)) $$(ADAFLAGS_
$(1)) -c
-o
$$@
$$<
399 $(1)-objs
+= $$(obj
)/$(1)/b__
$(1).o
400 $($(1)-alis
): %.ali
: %.o
;
403 $(eval
$(foreach class
,$(filter-out libgnat-
%,$(classes
)), \
404 $(if
$($(class
)-alis
),$(call gnatbind_template
,$(class
)))))
406 DEPENDENCIES
+= $(addsuffix .d
,$(basename $(allobjs
)))
407 -include $(DEPENDENCIES
)
410 @
$(foreach class
,$(classes
), echo
$(class
)-objs
: $($(class
)-objs
) | tr
' ' '\n'; echo
; )
411 @echo alldirs
: $(alldirs
) | tr
' ' '\n'; echo
412 @echo allsrcs
: $(allsrcs
) | tr
' ' '\n'; echo
413 @echo DEPENDENCIES
: $(DEPENDENCIES
) | tr
' ' '\n'; echo
414 @
$(foreach class
,$(special-classes
),echo
$(class
):'$($(class))' | tr
' ' '\n'; echo
; )
418 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
421 $(obj
)/project_filelist.txt
:
422 if
[ -z
"$(wildcard $(obj)/coreboot.rom)" ]; then \
423 echo
"*** Error: Project must be built before generating file list ***"; \
426 find
$(obj
) -path
"$(obj)/util" -prune
-o
-name
"*.d" -exec cat
{} \
; | \
427 sed
"s|$(top)/||" | sed
's/[:\\]/ /g' | sed
's/ /\n/g' |
sort | uniq | \
428 grep
-v
'\.o$$' > $(obj
)/project_filelist.txt
430 filelist
: $(obj
)/project_filelist.txt
431 printf
"\nFiles used in build:\n"
432 cat
$(obj
)/project_filelist.txt
434 #works with either exuberant ctags or ctags.emacs
435 ctags-project
: clean-ctags
$(obj
)/project_filelist.txt
436 cat
$(obj
)/project_filelist.txt | \
439 cscope-project
: clean-cscope
$(obj
)/project_filelist.txt
440 cat
$(obj
)/project_filelist.txt | xargs cscope
-b
446 $(MAKE
) -C Documentation
-f Makefile.sphinx html
449 $(MAKE
) SPHINXOPTS
=-W
-C Documentation
-f Makefile.sphinx html
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
="$$( echo $(DOXYGEN_OUTPUT_DIR)/$(call strip_quotes, $(CONFIG_MAINBOARD_VENDOR))_$(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER)) | sed 's|[^A-Za-z0-9/]|_|g' )"; \
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
="$(call strip_quotes, $(CONFIG_MAINBOARD_DIR)) \($(call strip_quotes, $(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 sphinx sphinx-lint
498 .PHONY
: ctags-project cscope-project clean-ctags