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
))
16 VBOOT_HOST_BUILD ?
= $(abspath
$(objutil
)/vboot_lib
)
18 COREBOOT_EXPORTS
:= COREBOOT_EXPORTS
19 COREBOOT_EXPORTS
+= top src srck obj objutil objk
25 COREBOOT_EXPORTS
+= LANG LC_ALL TZ
27 DOTCONFIG ?
= $(top
)/.config
28 KCONFIG_CONFIG
= $(DOTCONFIG
)
29 KCONFIG_AUTOADS
:= $(obj
)/cb-config.ads
30 KCONFIG_AUTOHEADER
:= $(obj
)/config.h
31 KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
32 KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
33 KCONFIG_SPLITCONFIG
:= $(obj
)/config
34 KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
35 KCONFIG_NEGATIVES
:= 1
37 KCONFIG_PACKAGE
:= CB.Config
39 COREBOOT_EXPORTS
+= KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
40 COREBOOT_EXPORTS
+= KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
41 COREBOOT_EXPORTS
+= KCONFIG_NEGATIVES KCONFIG_STRICT
42 COREBOOT_EXPORTS
+= KCONFIG_AUTOADS KCONFIG_PACKAGE
44 # directory containing the toplevel Makefile.inc
48 KBUILD_DEFCONFIG
:= configs
/defconfig
49 UNAME_RELEASE
:= $(shell uname
-r
)
50 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
51 MAKEFLAGS
+= -rR
--no-print-directory
53 # Make is silent per default, but 'make V=1' will show all compiler calls.
62 # Disable implicit/built-in rules to make Makefile errors fail fast.
68 PREPROCESS_ONLY
:= -E
-P
-x assembler-with-cpp
-undef
-I .
71 DOXYGEN_OUTPUT_DIR
:= doxygen
73 export $(COREBOOT_EXPORTS
)
78 @echo
'*** coreboot platform targets ***'
79 @echo
' Use "make [target] V=1" for extra build debug information'
80 @echo
' all - Build coreboot'
81 @echo
' clean - Remove coreboot build artifacts'
82 @echo
' distclean - Remove build artifacts and config files'
83 @echo
' doxygen - Build doxygen documentation for coreboot'
84 @echo
' doxyplatform - Build doxygen documentation for the current platform'
85 @echo
' sphinx - Build sphinx documentation for coreboot'
86 @echo
' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
87 @echo
' filelist - Show files used in current build'
88 @echo
' printall - print makefile info for debugging'
89 @echo
' gitconfig - set up git to submit patches to coreboot'
90 @echo
' ctags / ctags-project - make ctags file for all of coreboot or current board'
91 @echo
' cscope / cscope-project - make cscope.out file for coreboot or current board'
94 # This include must come _before_ the pattern rules below!
95 # Order _does_ matter for pattern rules.
96 include $(srck
)/Makefile.inc
98 # Three cases where we don't need fully populated $(obj) lists:
99 # 1. when no .config exists
100 # 2. when make config (in any flavour) is run
101 # 3. when make distclean is run
102 # Don't waste time on reading all Makefile.incs in these cases
103 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
106 ifneq ($(MAKECMDGOALS
),)
107 ifneq ($(filter %config
%clean cross
% clang iasl lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
110 ifneq ($(filter %clean lint
% help
% what-jenkins-does
,$(MAKECMDGOALS
)),)
115 ifneq ($(filter %-test %-tests
,$(MAKECMDGOALS
)),)
116 ifneq ($(filter-out %-test %-tests
, $(MAKECMDGOALS
)),)
117 $(error Cannot mix unit-tests targets with other targets
)
123 $(xcompile
): util
/xcompile
/xcompile
125 $< $(XGCCPATH
) > $@.tmp
126 \mv
-f
$@.tmp
$@
2> /dev
/null
129 ifeq ($(NOCOMPILE
),1)
130 # We also don't use .xcompile in the no-compile situations, so
131 # provide some reasonable defaults.
132 HOSTCC ?
= $(if
$(shell type gcc
2>/dev
/null
),gcc
,cc)
135 include $(TOPLEVEL
)/Makefile.inc
136 include $(TOPLEVEL
)/payloads
/Makefile.inc
137 include $(TOPLEVEL
)/util
/testing
/Makefile.inc
138 -include $(TOPLEVEL
)/site-local
/Makefile.inc
140 @echo
"Error: Expected config file ($(DOTCONFIG)) not present." >&2
141 @echo
"Please specify a config file or run 'make menuconfig' to" >&2
142 @echo
"generate a new config file." >&2
146 ifneq ($(UNIT_TEST
),1)
150 # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
151 # wait for make to generate the file.
152 $(if
$(wildcard $(xcompile
)),, $(shell \
153 mkdir
-p
$(dir $(xcompile
)) && \
154 util
/xcompile
/xcompile
$(XGCCPATH
) > $(xcompile
) ||
rm -f
$(xcompile
)))
158 ifneq ($(XCOMPILE_COMPLETE
),1)
159 $(shell rm -f
$(xcompile
))
160 $(error
$(xcompile
) deleted because it
's invalid. \
161 Restarting the build should fix that, or explain the problem)
164 ifneq ($(CONFIG_MMX),y)
165 CFLAGS_x86_32 += -mno-mmx
168 ifneq ($(UNIT_TEST),1)
169 include toolchain.inc
172 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
173 # fix makefile syntax highlighting after strip macro \" "))
175 # The primary target needs to be here before we include the
178 real-all: real-target
180 # must come rather early
184 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
187 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
190 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
191 $(objutil)/kconfig/toada CB.Config <$< >$@
193 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
196 # Add a new class of source/object files to the build system
198 $(eval $(1)-srcs:=) \
199 $(eval $(1)-objs:=) \
200 $(eval classes+=$(1))
202 # Special classes are managed types with special behaviour
203 # On parse time, for each entry in variable $(1)-y
204 # a handler $(1)-handler is executed with the arguments:
205 # * $(1): directory the parser is in
206 # * $(2): current entry
209 $(eval special-classes+=$(1))
211 # Converts one or more source file paths to their corresponding build/ paths.
212 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
215 # $2 file path (list)
217 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
218 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
219 $(patsubst 3rdparty/%,$(obj)/%,\
220 $(patsubst src/%,$(obj)/%,\
221 $(patsubst %.ads,%.o,\
222 $(patsubst %.adb,%.o,\
225 $(subst .$(1),,$(2))))))))))
227 # Converts one or more source file paths to the corresponding build/ paths
228 # of their Ada library information (.ali) files.
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,%.ali,\
237 $(patsubst %.adb,%.ali,\
239 $(filter %.ads %.adb,$(2)))))))))
241 # Clean -y variables, include Makefile.inc
242 # Add paths to files in X-y to X-srcs
243 # Add subdirs-y to subdirs
245 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
246 $(eval -include $(1)) \
247 $(foreach class,$(classes-y), $(call add-class,$(class))) \
248 $(foreach special,$(special-classes), \
249 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
250 $(foreach class,$(classes), \
251 $(eval $(class)-srcs+= \
252 $$(subst $(absobj)/,$(obj)/, \
254 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
255 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
257 # For each path in $(subdirs) call includemakefiles
258 # Repeat until subdirs is empty
260 $(eval cursubdirs:=$(subdirs)) \
262 $(foreach dir,$(cursubdirs), \
263 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
264 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
266 # collect all object files eligible for building
270 # Don't iterate through Makefile.incs under src
/ when building tests
271 ifneq ($(UNIT_TEST
),1)
272 $(eval
$(call evaluate_subdirs
))
274 include $(TOPLEVEL
)/tests
/Makefile.inc
277 ifeq ($(FAILBUILD
),1)
278 $(error cannot continue build
)
281 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
282 $(eval
$(postinclude-hooks
))
284 # Eliminate duplicate mentions of source files in a class
285 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:=$(sort $($(class
)-srcs
))))
287 # Build Kconfig .ads if necessary
288 ifeq ($(CONFIG_RAMSTAGE_ADA
),y
)
289 ramstage-srcs
+= $(obj
)/ramstage
/$(notdir $(KCONFIG_AUTOADS
))
292 # To track dependencies, we need all Ada specification (.ads) files in
293 # *-srcs. Extract / filter all specification files that have a matching
294 # body (.adb) file here (specifications without a body are valid sources
296 $(foreach class
,$(classes
),$(eval
$(class
)-extra-specs
:= \
298 $(addprefix %/,$(patsubst %.adb
,%.ads
,$(notdir $(filter %.adb
,$($(class
)-srcs
))))), \
299 $(filter %.ads
,$($(class
)-srcs
)))))
300 $(foreach class
,$(classes
),$(eval
$(class
)-srcs
:= \
301 $(filter-out $($(class
)-extra-specs
),$($(class
)-srcs
))))
303 $(foreach class
,$(classes
),$(eval
$(class
)-objs
:=$(call src-to-obj
,$(class
),$($(class
)-srcs
))))
304 $(foreach class
,$(classes
),$(eval
$(class
)-alis
:=$(call src-to-ali
,$(class
),$($(class
)-srcs
))))
307 $(foreach class
,$(classes
),$(eval
$(class
)-ada-dirs
:=$(sort $(dir $(filter %.ads
%.adb
,$($(class
)-srcs
)) $($(class
)-extra-specs
)))))
309 # Save all objs before processing them (for dependency inclusion)
310 originalobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
312 # Call post-processors if they're defined
313 $(foreach class
,$(classes
),\
314 $(if
$(value
$(class
)-postprocess
),$(eval
$(call
$(class
)-postprocess
,$($(class
)-objs
)))))
316 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
317 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
318 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
320 # Reads dependencies from an Ada library information (.ali) file
321 # Only basenames (with suffix) are preserved so we have to look the
322 # paths up in $($(stage)-srcs).
325 create_ada_deps
=$$(if
$(2),\
328 $$(addprefix %/,$$(shell sed
-ne
's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev
/null
)), \
329 $$($(1)-srcs
) $$($(1)-extra-specs
)))
331 # macro to define template macros that are used by use_template macro
332 define create_cc_template
334 # $2 source suffix (c, S, ld, ...)
335 # $3 additional compiler flags
336 # $4 additional dependencies
337 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
338 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
339 ifn
$(EMPTY
)eq
($(filter ads adb
,$(2)),)
340 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $$(call create_ada_deps
,$1,$$(call src-to-ali
,$1,$$(1).
$2)) $(4)
341 @printf
" GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
343 $$$$(ADAFLAGS_
$(1)) $$$$(addprefix -I
,$$$$($(1)-ada-dirs
)) \
344 $(3) -c
-o
$$$$@
$$$$<
346 $$(call src-to-obj
,$1,$$(1).
$2): $$(1).
$2 $(KCONFIG_AUTOHEADER
) $(4)
347 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
349 -MMD
$$$$(CPPFLAGS_
$(1)) $$$$(CFLAGS_
$(1)) -MT
$$$$(@
) \
350 $(3) -c
-o
$$$$@
$$$$<
356 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
357 $(foreach class
,$(classes
), \
358 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
359 $(eval
$(class
)-$(type
)-ccopts
+= $(generic-
$(type
)-ccopts
) $($(class
)-generic-ccopts
)) \
360 $(if
$(generic-objs_
$(type
)_template_gen
),$(eval
$(call generic-objs_
$(type
)_template_gen
,$(class
))),\
361 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
))))))
363 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
364 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
366 # To supported complex package initializations, we need to call the
367 # emitted code explicitly. gnatbind gathers all the calls for us
368 # and exports them as a procedure $(stage)_adainit(). Every stage that
369 # uses Ada code has to call it!
370 define gnatbind_template
372 $$(obj
)/$(1)/b__
$(1).adb
: $$$$(filter-out $$(obj
)/$(1)/b__
$(1).ali
,$$$$($(1)-alis
))
373 @printf
" BIND $$(subst $$(obj)/,,$$@)\n"
374 # We have to give gnatbind a simple filename (without leading
375 # path components) so just cd there.
377 $$(GNATBIND_
$(1)) -a
-n \
378 --RTS
=$$(absobj
)/libgnat-
$$(ARCH-
$(1)-y
)/ \
379 -L
$(1)_ada
-o
$$(notdir $$@
) \
380 $$(subst $$(dir $$@
),,$$^
)
381 $$(obj
)/$(1)/b__
$(1).o
: $$(obj
)/$(1)/b__
$(1).adb
382 @printf
" GCC $$(subst $$(obj)/,,$$@)\n"
383 $(GCC_
$(1)) $$(ADAFLAGS_
$(1)) -c
-o
$$@
$$<
384 $(1)-objs
+= $$(obj
)/$(1)/b__
$(1).o
385 $($(1)-alis
): %.ali
: %.o
;
388 $(eval
$(foreach class
,$(filter-out libgnat-
%,$(classes
)), \
389 $(if
$($(class
)-alis
),$(call gnatbind_template
,$(class
)))))
391 DEPENDENCIES
+= $(addsuffix .d
,$(basename $(allobjs
)))
392 -include $(DEPENDENCIES
)
395 @
$(foreach class
,$(classes
), echo
$(class
)-objs
: $($(class
)-objs
) | tr
' ' '\n'; echo
; )
396 @echo alldirs
: $(alldirs
) | tr
' ' '\n'; echo
397 @echo allsrcs
: $(allsrcs
) | tr
' ' '\n'; echo
398 @echo DEPENDENCIES
: $(DEPENDENCIES
) | tr
' ' '\n'; echo
399 @
$(foreach class
,$(special-classes
),echo
$(class
):'$($(class))' | tr
' ' '\n'; echo
; )
403 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
406 $(obj
)/project_filelist.txt
:
407 if
[ -z
"$(wildcard $(obj)/coreboot.rom)" ]; then \
408 echo
"*** Error: Project must be built before generating file list ***"; \
411 find
$(obj
) -path
"$(obj)/util" -prune
-o
-name
"*.d" -exec cat
{} \
; | \
412 sed
"s|$(top)/||" | sed
's/[:\\]/ /g' | sed
's/ /\n/g' |
sort | uniq | \
413 grep
-v
'\.o$$' > $(obj
)/project_filelist.txt
415 filelist
: $(obj
)/project_filelist.txt
416 printf
"\nFiles used in build:\n"
417 cat
$(obj
)/project_filelist.txt
419 #works with either exuberant ctags or ctags.emacs
420 ctags-project
: clean-ctags
$(obj
)/project_filelist.txt
421 cat
$(obj
)/project_filelist.txt | \
424 cscope-project
: clean-cscope
$(obj
)/project_filelist.txt
425 cat
$(obj
)/project_filelist.txt | xargs cscope
-b
431 $(MAKE
) -C Documentation
-f Makefile.sphinx html
434 $(MAKE
) SPHINXOPTS
=-W
-C Documentation
-f Makefile.sphinx html
438 $(DOXYGEN
) Documentation
/Doxyfile.coreboot
441 $(DOXYGEN
) Documentation
/Doxyfile.coreboot_simple
443 doxyplatform doxygen_platform
: $(obj
)/project_filelist.txt
445 echo
"Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
446 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' )"; \
447 mkdir
-p
"$$DOXYGEN_OUTPUT_DIR"; \
448 export DOXYFILES
="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
449 export DOXYGEN_PLATFORM
="$(call strip_quotes, $(CONFIG_MAINBOARD_DIR)) \($(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER))\) version $(KERNELVERSION)"; \
450 $(DOXYGEN
) Documentation
/doxygen
/Doxyfile.coreboot_platform
452 doxyclean
: doxygen-clean
454 rm -rf
$(DOXYGEN_OUTPUT_DIR
)
456 clean-for-update
: doxygen-clean clean-for-update-target
457 rm -rf
$(obj
) .xcompile
459 clean: clean-for-update clean-target clean-utils
469 $(foreach tool
, $(TOOLLIST
), \
470 $(MAKE
) -C util
/$(tool
) clean MFLAGS
= MAKEFLAGS
= ;)
473 $(foreach tool
, $(TOOLLIST
), \
474 $(MAKE
) -C util
/$(tool
) distclean MFLAGS
= MAKEFLAGS
= ; \
475 rm -f
/util
/$(tool
)/junit.xml
;)
477 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
478 rm -f .config .config.old ..config.tmp
* .kconfig.d .tmpconfig
* .ccwrap .xcompile
479 rm -rf coreboot-builds coreboot-builds-chromeos
480 rm -f abuild
*.xml junit.xml
* util
/lint
/junit.xml
482 .PHONY
: $(PHONY
) clean clean-for-update clean-cscope cscope
distclean doxygen doxy doxygen_simple sphinx sphinx-lint
483 .PHONY
: ctags-project cscope-project clean-ctags