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 COREBOOT_EXPORTS
+= LANG LC_ALL TZ
29 DOTCONFIG ?
= $(top
)/.config
30 KCONFIG_CONFIG
= $(DOTCONFIG
)
31 KCONFIG_AUTOADS
:= $(obj
)/cb-config.ads
32 KCONFIG_AUTOHEADER
:= $(obj
)/config.h
33 KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
34 KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
35 KCONFIG_SPLITCONFIG
:= $(obj
)/config
36 KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
37 KCONFIG_NEGATIVES
:= 1
39 KCONFIG_PACKAGE
:= CB.Config
41 COREBOOT_EXPORTS
+= KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
42 COREBOOT_EXPORTS
+= KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
43 COREBOOT_EXPORTS
+= KCONFIG_NEGATIVES KCONFIG_STRICT
44 COREBOOT_EXPORTS
+= KCONFIG_AUTOADS KCONFIG_PACKAGE
46 # directory containing the toplevel Makefile.inc
50 KBUILD_DEFCONFIG
:= configs
/defconfig
51 UNAME_RELEASE
:= $(shell uname
-r
)
52 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
53 MAKEFLAGS
+= -rR
--no-print-directory
55 # Make is silent per default, but 'make V=1' will show all compiler calls.
64 # Disable implicit/built-in rules to make Makefile errors fail fast.
70 PREPROCESS_ONLY
:= -E
-P
-x assembler-with-cpp
-undef
-I .
73 DOXYGEN_OUTPUT_DIR
:= doxygen
75 export $(COREBOOT_EXPORTS
)
80 @echo
'*** coreboot platform targets ***'
81 @echo
' Use "make [target] V=1" for extra build debug information'
82 @echo
' all - Build coreboot'
83 @echo
' clean - Remove coreboot build artifacts'
84 @echo
' distclean - Remove build artifacts and config files'
85 @echo
' doxygen - Build doxygen documentation for coreboot'
86 @echo
' doxyplatform - Build doxygen documentation for the current platform'
87 @echo
' sphinx - Build sphinx documentation for coreboot'
88 @echo
' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
89 @echo
' filelist - Show files used in current build'
90 @echo
' printall - print makefile info for debugging'
91 @echo
' gitconfig - set up git to submit patches to coreboot'
92 @echo
' ctags / ctags-project - make ctags file for all of coreboot or current board'
93 @echo
' cscope / cscope-project - make cscope.out file for coreboot or current board'
96 # This include must come _before_ the pattern rules below!
97 # Order _does_ matter for pattern rules.
98 include $(srck
)/Makefile.inc
100 # Three cases where we don't need fully populated $(obj) lists:
101 # 1. when no .config exists
102 # 2. when make config (in any flavour) is run
103 # 3. when make distclean is run
104 # Don't waste time on reading all Makefile.incs in these cases
105 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
108 ifneq ($(MAKECMDGOALS
),)
109 ifneq ($(filter %config
%clean cross
% clang iasl lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
112 ifneq ($(filter %clean lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
117 ifneq ($(filter %-test %-tests
,$(MAKECMDGOALS
)),)
118 ifneq ($(filter-out %-test %-tests
, $(MAKECMDGOALS
)),)
119 $(error Cannot mix unit-tests targets with other targets
)
125 $(xcompile
): util
/xcompile
/xcompile
127 $< $(XGCCPATH
) > $@.tmp
128 \mv
-f
$@.tmp
$@
2> /dev
/null
131 ifeq ($(NOCOMPILE
),1)
132 # We also don't use .xcompile in the no-compile situations, so
133 # provide some reasonable defaults.
134 HOSTCC ?
= $(if
$(shell type gcc
2>/dev
/null
),gcc
,cc)
137 include $(TOPLEVEL
)/Makefile.inc
138 include $(TOPLEVEL
)/payloads
/Makefile.inc
139 include $(TOPLEVEL
)/util
/testing
/Makefile.inc
140 -include $(TOPLEVEL
)/site-local
/Makefile.inc
142 @echo
"Error: Expected config file ($(DOTCONFIG)) not present." >&2
143 @echo
"Please specify a config file or run 'make menuconfig' to" >&2
144 @echo
"generate a new config file." >&2
148 ifneq ($(UNIT_TEST
),1)
152 # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
153 # wait for make to generate the file.
154 $(if
$(wildcard $(xcompile
)),, $(shell \
155 mkdir
-p
$(dir $(xcompile
)) && \
156 util
/xcompile
/xcompile
$(XGCCPATH
) > $(xcompile
) ||
rm -f
$(xcompile
)))
160 ifneq ($(XCOMPILE_COMPLETE
),1)
161 $(shell rm -f
$(xcompile
))
162 $(error
$(xcompile
) deleted because it
's invalid. \
163 Restarting the build should fix that, or explain the problem)
166 ifneq ($(CONFIG_MMX),y)
167 CFLAGS_x86_32 += -mno-mmx
170 ifneq ($(UNIT_TEST),1)
171 include toolchain.inc
174 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
175 # fix makefile syntax highlighting after strip macro \" "))
177 # The primary target needs to be here before we include the
180 real-all: real-target
182 # must come rather early
186 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
189 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
192 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
193 $(objutil)/kconfig/toada CB.Config <$< >$@
195 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
198 # Add a new class of source/object files to the build system
200 $(eval $(1)-srcs:=) \
201 $(eval $(1)-objs:=) \
202 $(eval classes+=$(1))
204 # Special classes are managed types with special behaviour
205 # On parse time, for each entry in variable $(1)-y
206 # a handler $(1)-handler is executed with the arguments:
207 # * $(1): directory the parser is in
208 # * $(2): current entry
211 $(eval special-classes+=$(1))
213 # Converts one or more source file paths to their corresponding build/ paths.
214 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
217 # $2 file path (list)
219 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
220 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
221 $(patsubst 3rdparty/%,$(obj)/%,\
222 $(patsubst src/%,$(obj)/%,\
223 $(patsubst %.ads,%.o,\
224 $(patsubst %.adb,%.o,\
227 $(subst .$(1),,$(2))))))))))
229 # Converts one or more source file paths to the corresponding build/ paths
230 # of their Ada library information (.ali) files.
232 # $2 file path (list)
234 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
235 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
236 $(patsubst 3rdparty/%,$(obj)/%,\
237 $(patsubst src/%,$(obj)/%,\
238 $(patsubst %.ads,%.ali,\
239 $(patsubst %.adb,%.ali,\
241 $(filter %.ads %.adb,$(2)))))))))
243 # Clean -y variables, include Makefile.inc
244 # Add paths to files in X-y to X-srcs
245 # Add subdirs-y to subdirs
247 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
248 $(eval -include $(1)) \
249 $(foreach class,$(classes-y), $(call add-class,$(class))) \
250 $(foreach special,$(special-classes), \
251 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
252 $(foreach class,$(classes), \
253 $(eval $(class)-srcs+= \
254 $$(subst $(absobj)/,$(obj)/, \
256 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
257 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
259 # For each path in $(subdirs) call includemakefiles
260 # Repeat until subdirs is empty
262 $(eval cursubdirs:=$(subdirs)) \
264 $(foreach dir,$(cursubdirs), \
265 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
266 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
268 # collect all object files eligible for building
272 # Don't iterate through Makefile.incs under src
/ when building tests
273 ifneq ($(UNIT_TEST
),1)
274 $(eval
$(call evaluate_subdirs
))
276 include $(TOPLEVEL
)/tests
/Makefile.inc
279 ifeq ($(FAILBUILD
),1)
280 $(error cannot continue build
)
283 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
284 $(eval
$(postinclude-hooks
))
286 # Eliminate duplicate mentions of source files in a class
287 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:=$(sort $($(class
)-srcs
))))
289 # Build Kconfig .ads if necessary
290 ifeq ($(CONFIG_RAMSTAGE_ADA
),y
)
291 ramstage-srcs
+= $(obj
)/ramstage
/$(notdir $(KCONFIG_AUTOADS
))
294 # To track dependencies, we need all Ada specification (.ads) files in
295 # *-srcs. Extract / filter all specification files that have a matching
296 # body (.adb) file here (specifications without a body are valid sources
298 $(foreach class
,$(classes
),$(eval
$(class
)-extra-specs
:= \
300 $(addprefix %/,$(patsubst %.adb
,%.ads
,$(notdir $(filter %.adb
,$($(class
)-srcs
))))), \
301 $(filter %.ads
,$($(class
)-srcs
)))))
302 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:= \
303 $(filter-out $($(class
)-extra-specs
),$($(class
)-srcs
))))
305 $(foreach class
,$(classes
),$(eval
$(class
)-objs
:=$(call src-to-obj
,$(class
),$($(class
)-srcs
))))
306 $(foreach class
,$(classes
),$(eval
$(class
)-alis
:=$(call src-to-ali
,$(class
),$($(class
)-srcs
))))
309 $(foreach class
,$(classes
),$(eval
$(class
)-ada-dirs
:=$(sort $(dir $(filter %.ads
%.adb
,$($(class
)-srcs
)) $($(class
)-extra-specs
)))))
311 # Save all objs before processing them (for dependency inclusion)
312 originalobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
314 # Call post-processors if they're defined
315 $(foreach class
,$(classes
),\
316 $(if
$(value
$(class
)-postprocess
),$(eval
$(call
$(class
)-postprocess
,$($(class
)-objs
)))))
318 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
319 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
320 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
322 # Reads dependencies from an Ada library information (.ali) file
323 # Only basenames (with suffix) are preserved so we have to look the
324 # paths up in $($(stage)-srcs).
327 create_ada_deps
=$$(if
$(2),\
330 $$(addprefix %/,$$(shell sed
-ne
's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev
/null
)), \
331 $$($(1)-srcs
) $$($(1)-extra-specs
)))
333 # macro to define template macros that are used by use_template macro
334 define create_cc_template
336 # $2 source suffix (c, S, ld, ...)
337 # $3 additional compiler flags
338 # $4 additional dependencies
339 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
340 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
341 ifn
$(EMPTY
)eq
($(filter ads adb
,$(2)),)
342 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $$(call create_ada_deps
,$1,$$(call src-to-ali
,$1,$$(1).
$2)) $(4)
343 @printf
" GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
345 $$$$(ADAFLAGS_
$(1)) $$$$(addprefix -I
,$$$$($(1)-ada-dirs
)) \
346 $(3) -c
-o
$$$$@
$$$$<
348 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $(KCONFIG_AUTOHEADER
) $(4)
349 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
351 -MMD
$$$$(CPPFLAGS_
$(1)) $$$$(CFLAGS_
$(1)) -MT
$$$$(@
) \
352 $(3) -c
-o
$$$$@
$$$$<
358 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
359 $(foreach class
,$(classes
), \
360 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
361 $(eval
$(class
)-$(type
)-ccopts
+= $(generic-
$(type
)-ccopts
) $($(class
)-generic-ccopts
)) \
362 $(if
$(generic-objs_
$(type
)_template_gen
),$(eval
$(call generic-objs_
$(type
)_template_gen
,$(class
))),\
363 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
))))))
365 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
366 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
368 # To supported complex package initializations, we need to call the
369 # emitted code explicitly. gnatbind gathers all the calls for us
370 # and exports them as a procedure $(stage)_adainit(). Every stage that
371 # uses Ada code has to call it!
372 define gnatbind_template
374 $$(obj
)/$(1)/b__
$(1).adb
: $$$$(filter-out $$(obj
)/$(1)/b__
$(1).ali
,$$$$($(1)-alis
))
375 @printf
" BIND $$(subst $$(obj)/,,$$@)\n"
376 # We have to give gnatbind a simple filename (without leading
377 # path components) so just cd there.
379 $$(GNATBIND_
$(1)) -a
-n \
380 --RTS
=$$(absobj
)/libgnat-
$$(ARCH-
$(1)-y
)/ \
381 -L
$(1)_ada
-o
$$(notdir $$@
) \
382 $$(subst $$(dir $$@
),,$$^
)
383 $$(obj
)/$(1)/b__
$(1).o
: $$(obj
)/$(1)/b__
$(1).adb
384 @printf
" GCC $$(subst $$(obj)/,,$$@)\n"
385 $(GCC_
$(1)) $$(ADAFLAGS_
$(1)) -c
-o
$$@
$$<
386 $(1)-objs
+= $$(obj
)/$(1)/b__
$(1).o
387 $($(1)-alis
): %.ali
: %.o
;
390 $(eval
$(foreach class
,$(filter-out libgnat-
%,$(classes
)), \
391 $(if
$($(class
)-alis
),$(call gnatbind_template
,$(class
)))))
393 DEPENDENCIES
+= $(addsuffix .d
,$(basename $(allobjs
)))
394 -include $(DEPENDENCIES
)
397 @
$(foreach class
,$(classes
), echo
$(class
)-objs
: $($(class
)-objs
) | tr
' ' '\n'; echo
; )
398 @echo alldirs
: $(alldirs
) | tr
' ' '\n'; echo
399 @echo allsrcs
: $(allsrcs
) | tr
' ' '\n'; echo
400 @echo DEPENDENCIES
: $(DEPENDENCIES
) | tr
' ' '\n'; echo
401 @
$(foreach class
,$(special-classes
),echo
$(class
):'$($(class))' | tr
' ' '\n'; echo
; )
405 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
408 $(obj
)/project_filelist.txt
:
409 if
[ -z
"$(wildcard $(obj)/coreboot.rom)" ]; then \
410 echo
"*** Error: Project must be built before generating file list ***"; \
413 find
$(obj
) -path
"$(obj)/util" -prune
-o
-name
"*.d" -exec cat
{} \
; | \
414 sed
"s|$(top)/||" | sed
's/[:\\]/ /g' | sed
's/ /\n/g' |
sort | uniq | \
415 grep
-v
'\.o$$' > $(obj
)/project_filelist.txt
417 filelist
: $(obj
)/project_filelist.txt
418 printf
"\nFiles used in build:\n"
419 cat
$(obj
)/project_filelist.txt
421 #works with either exuberant ctags or ctags.emacs
422 ctags-project
: clean-ctags
$(obj
)/project_filelist.txt
423 cat
$(obj
)/project_filelist.txt | \
426 cscope-project
: clean-cscope
$(obj
)/project_filelist.txt
427 cat
$(obj
)/project_filelist.txt | xargs cscope
-b
433 $(MAKE
) -C Documentation
-f Makefile.sphinx html
436 $(MAKE
) SPHINXOPTS
=-W
-C Documentation
-f Makefile.sphinx html
440 $(DOXYGEN
) Documentation
/Doxyfile.coreboot
443 $(DOXYGEN
) Documentation
/Doxyfile.coreboot_simple
445 doxyplatform doxygen_platform
: $(obj
)/project_filelist.txt
447 echo
"Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
448 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' )"; \
449 mkdir
-p
"$$DOXYGEN_OUTPUT_DIR"; \
450 export DOXYFILES
="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
451 export DOXYGEN_PLATFORM
="$(call strip_quotes, $(CONFIG_MAINBOARD_DIR)) \($(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER))\) version $(KERNELVERSION)"; \
452 $(DOXYGEN
) Documentation
/doxygen
/Doxyfile.coreboot_platform
454 doxyclean
: doxygen-clean
456 rm -rf
$(DOXYGEN_OUTPUT_DIR
)
458 clean-for-update
: doxygen-clean clean-for-update-target
459 rm -rf
$(obj
) .xcompile
461 clean: clean-for-update clean-target clean-utils
471 $(foreach tool
, $(TOOLLIST
), \
472 $(MAKE
) -C util
/$(tool
) clean MFLAGS
= MAKEFLAGS
= ;)
475 $(foreach tool
, $(TOOLLIST
), \
476 $(MAKE
) -C util
/$(tool
) distclean MFLAGS
= MAKEFLAGS
= ; \
477 rm -f
/util
/$(tool
)/junit.xml
;)
479 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
480 rm -f .config .config.old ..config.tmp
* .kconfig.d .tmpconfig
* .ccwrap .xcompile
481 rm -rf coreboot-builds coreboot-builds-chromeos
482 rm -f abuild
*.xml junit.xml
* util
/lint
/junit.xml
484 .PHONY
: $(PHONY
) clean clean-for-update clean-cscope cscope
distclean doxygen doxy doxygen_simple sphinx sphinx-lint
485 .PHONY
: ctags-project cscope-project clean-ctags