mb/google/brya/var/ghost: Pull EN_PP3300_TCHSCR high
[coreboot.git] / Makefile
blob6bdd44a8562e216eff2cf123a3b527553e0e62bb
1 ## SPDX-License-Identifier: BSD-3-Clause
3 ifneq ($(words $(CURDIR)),1)
4 $(error Error: Path to the main directory cannot contain spaces)
5 endif
6 top := $(CURDIR)
7 src := src
8 srck := $(top)/util/kconfig
9 obj ?= build
10 override obj := $(subst $(top)/,,$(abspath $(obj)))
11 xcompile ?= $(obj)/xcompile
12 objutil ?= $(obj)/util
13 objk := $(objutil)/kconfig
14 absobj := $(abspath $(obj))
16 additional-dirs :=
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
32 KCONFIG_STRICT := 1
33 KCONFIG_PACKAGE := CB.Config
34 KCONFIG_MAKEFILE_REAL ?= $(objk)/Makefile.real
36 COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
37 COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
38 COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
39 COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
41 # directory containing the toplevel Makefile.inc
42 TOPLEVEL := .
44 CONFIG_SHELL := sh
45 KBUILD_DEFCONFIG := configs/defconfig
46 UNAME_RELEASE := $(shell uname -r)
47 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
48 HAVE_KCONFIG_MAKEFILE_REAL := $(wildcard $(KCONFIG_MAKEFILE_REAL))
49 MAKEFLAGS += -rR --no-print-directory
51 # Make is silent per default, but 'make V=1' will show all compiler calls.
52 Q:=@
53 ifneq ($(V),1)
54 ifneq ($(Q),)
55 .SILENT:
56 MAKEFLAGS += -s
57 quiet_errors := 2>/dev/null
58 endif
59 endif
61 # Disable implicit/built-in rules to make Makefile errors fail fast.
62 .SUFFIXES:
64 HOSTCFLAGS := -g
65 HOSTCXXFLAGS := -g
67 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
69 export $(COREBOOT_EXPORTS)
71 all: real-all
73 help_coreboot help::
74 @echo '*** coreboot platform targets ***'
75 @echo ' Use "make [target] V=1" for extra build debug information'
76 @echo ' all - Build coreboot'
77 @echo ' clean - Remove coreboot build artifacts'
78 @echo ' distclean - Remove build artifacts and config files'
79 @echo ' sphinx - Build sphinx documentation for coreboot'
80 @echo ' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
81 @echo ' filelist - Show files used in current build'
82 @echo ' printall - print makefile info for debugging'
83 @echo ' gitconfig - set up git to submit patches to coreboot'
84 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
85 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
86 @echo
88 # This include must come _before_ the pattern rules below!
89 # Order _does_ matter for pattern rules.
90 include $(srck)/Makefile.inc
92 # The cases where we don't need fully populated $(obj) lists:
93 # 1. when no .config exists
94 # 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
95 # 3. when make config (in any flavour) is run
96 # 4. when make distclean is run
97 # Don't waste time on reading all Makefile.incs in these cases
98 ifeq ($(strip $(HAVE_DOTCONFIG)),)
99 NOCOMPILE:=1
100 endif
101 ifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL)),)
102 ifneq ($(MAKECMDGOALS),tools)
103 NOCOMPILE:=1
104 endif
105 endif
106 ifneq ($(MAKECMDGOALS),)
107 ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
108 NOCOMPILE:=1
109 endif
110 ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
111 NOMKDIR:=1
112 UNIT_TEST:=1
113 endif
114 endif
116 ifneq ($(filter help%, $(MAKECMDGOALS)), )
117 NOCOMPILE:=1
118 UNIT_TEST:=1
119 else
120 ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
121 ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
122 $(error Cannot mix unit-tests targets with other targets)
123 endif
124 UNIT_TEST:=1
125 NOCOMPILE:=
126 endif
127 endif
129 $(xcompile): util/xcompile/xcompile
130 rm -f $@
131 $< $(XGCCPATH) > $@.tmp
132 \mv -f $@.tmp $@ 2> /dev/null
133 rm -f $@.tmp
135 ifeq ($(NOCOMPILE),1)
136 # We also don't use .xcompile in the no-compile situations, so
137 # provide some reasonable defaults.
138 HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
139 HOSTCXX ?= g++
141 include $(TOPLEVEL)/Makefile.inc
142 include $(TOPLEVEL)/payloads/Makefile.inc
143 include $(TOPLEVEL)/util/testing/Makefile.inc
144 -include $(TOPLEVEL)/site-local/Makefile.inc
145 include $(TOPLEVEL)/tests/Makefile.inc
146 real-all:
147 @echo "Error: Trying to build, but NOCOMPILE is set." >&2
148 @echo " Please file a bug with the following information:"
149 @echo "- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
150 @echo "- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
151 @echo "- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
152 @exit 1
153 else
155 ifneq ($(UNIT_TEST),1)
156 include $(DOTCONFIG)
157 endif
159 # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
160 # wait for make to generate the file.
161 $(if $(wildcard $(xcompile)),, $(shell \
162 mkdir -p $(dir $(xcompile)) && \
163 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
165 include $(xcompile)
167 ifneq ($(XCOMPILE_COMPLETE),1)
168 $(shell rm -f $(xcompile))
169 $(error $(xcompile) deleted because it's invalid. \
170 Restarting the build should fix that, or explain the problem)
171 endif
173 # reproducible builds
174 LANG:=C
175 LC_ALL:=C
176 TZ:=UTC0
177 ifneq ($(NOCOMPILE),1)
178 SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
179 endif
180 # don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
181 # are reproducible
182 export LANG LC_ALL TZ SOURCE_DATE_EPOCH
184 ifneq ($(CONFIG_MMX),y)
185 CFLAGS_x86_32 += -mno-mmx
186 endif
188 ifneq ($(UNIT_TEST),1)
189 include toolchain.inc
190 endif
192 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
193 # fix makefile syntax highlighting after strip macro \" "))
195 # The primary target needs to be here before we include the
196 # other files
198 real-all: real-target
200 # must come rather early
201 .SECONDARY:
202 .SECONDEXPANSION:
203 .DELETE_ON_ERROR:
205 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
206 $(MAKE) olddefconfig
207 $(MAKE) syncconfig
209 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
210 true
212 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
213 $(objutil)/kconfig/toada CB.Config <$< >$@
215 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
216 cp $< $@
218 # Add a new class of source/object files to the build system
219 add-class= \
220 $(eval $(1)-srcs:=) \
221 $(eval $(1)-objs:=) \
222 $(eval classes+=$(1))
224 # Special classes are managed types with special behaviour
225 # On parse time, for each entry in variable $(1)-y
226 # a handler $(1)-handler is executed with the arguments:
227 # * $(1): directory the parser is in
228 # * $(2): current entry
229 add-special-class= \
230 $(eval $(1):=) \
231 $(eval special-classes+=$(1))
233 # Converts one or more source file paths to their corresponding build/ paths.
234 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
235 # their name.
236 # $1 stage name
237 # $2 file path (list)
238 src-to-obj=\
239 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
240 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
241 $(patsubst 3rdparty/%,$(obj)/%,\
242 $(patsubst src/%,$(obj)/%,\
243 $(patsubst %.ads,%.o,\
244 $(patsubst %.adb,%.o,\
245 $(patsubst %.c,%.o,\
246 $(patsubst %.S,%.o,\
247 $(subst .$(1),,$(2))))))))))
249 # Converts one or more source file paths to the corresponding build/ paths
250 # of their Ada library information (.ali) files.
251 # $1 stage name
252 # $2 file path (list)
253 src-to-ali=\
254 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
255 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
256 $(patsubst 3rdparty/%,$(obj)/%,\
257 $(patsubst src/%,$(obj)/%,\
258 $(patsubst %.ads,%.ali,\
259 $(patsubst %.adb,%.ali,\
260 $(subst .$(1),,\
261 $(filter %.ads %.adb,$(2)))))))))
263 # Clean -y variables, include Makefile.inc
264 # Add paths to files in X-y to X-srcs
265 # Add subdirs-y to subdirs
266 includemakefiles= \
267 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
268 $(eval -include $(1)) \
269 $(foreach class,$(classes-y), $(call add-class,$(class))) \
270 $(foreach special,$(special-classes), \
271 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
272 $(foreach class,$(classes), \
273 $(eval $(class)-srcs+= \
274 $$(subst $(absobj)/,$(obj)/, \
275 $$(subst $(top)/,, \
276 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
277 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
279 # For each path in $(subdirs) call includemakefiles
280 # Repeat until subdirs is empty
281 evaluate_subdirs= \
282 $(eval cursubdirs:=$(subdirs)) \
283 $(eval subdirs:=) \
284 $(foreach dir,$(cursubdirs), \
285 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
286 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
288 # collect all object files eligible for building
289 subdirs:=$(TOPLEVEL)
290 postinclude-hooks :=
292 # Don't iterate through Makefile.incs under src/ when building tests
293 ifneq ($(UNIT_TEST),1)
294 $(eval $(call evaluate_subdirs))
295 else
296 include $(TOPLEVEL)/tests/Makefile.inc
297 endif
299 ifeq ($(FAILBUILD),1)
300 $(error cannot continue build)
301 endif
303 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
304 $(eval $(postinclude-hooks))
306 # Eliminate duplicate mentions of source files in a class
307 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
309 # Build Kconfig .ads if necessary
310 ifeq ($(CONFIG_RAMSTAGE_ADA),y)
311 ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
312 endif
314 # To track dependencies, we need all Ada specification (.ads) files in
315 # *-srcs. Extract / filter all specification files that have a matching
316 # body (.adb) file here (specifications without a body are valid sources
317 # in Ada).
318 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
319 $(filter \
320 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
321 $(filter %.ads,$($(class)-srcs)))))
322 $(foreach class,$(classes),$(eval $(class)-srcs := \
323 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
325 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
326 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
328 # For Ada includes
329 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
331 # Save all objs before processing them (for dependency inclusion)
332 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
334 # Call post-processors if they're defined
335 $(foreach class,$(classes),\
336 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
338 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
339 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
340 alldirs:=$(sort $(abspath $(dir $(allobjs))))
342 # Reads dependencies from an Ada library information (.ali) file
343 # Only basenames (with suffix) are preserved so we have to look the
344 # paths up in $($(stage)-srcs).
345 # $1 stage name
346 # $2 ali file
347 create_ada_deps=$$(if $(2),\
348 gnat.adc \
349 $$(filter \
350 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
351 $$($(1)-srcs) $$($(1)-extra-specs)))
353 # macro to define template macros that are used by use_template macro
354 define create_cc_template
355 # $1 obj class
356 # $2 source suffix (c, S, ld, ...)
357 # $3 additional compiler flags
358 # $4 additional dependencies
359 ifn$(EMPTY)def $(1)-objs_$(2)_template
360 de$(EMPTY)fine $(1)-objs_$(2)_template
361 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
362 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
363 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
364 $(GCC_$(1)) \
365 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
366 $(3) -c -o $$$$@ $$$$<
367 el$(EMPTY)se
368 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
369 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
370 $(CC_$(1)) \
371 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
372 $(3) -c -o $$$$@ $$$$<
373 end$(EMPTY)if
374 en$(EMPTY)def
375 end$(EMPTY)if
376 endef
378 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
379 $(foreach class,$(classes), \
380 $(foreach type,$(call filetypes-of-class,$(class)), \
381 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
382 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
383 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
385 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
386 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
388 # To supported complex package initializations, we need to call the
389 # emitted code explicitly. gnatbind gathers all the calls for us
390 # and exports them as a procedure $(stage)_adainit(). Every stage that
391 # uses Ada code has to call it!
392 define gnatbind_template
393 # $1 class
394 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
395 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
396 # We have to give gnatbind a simple filename (without leading
397 # path components) so just cd there.
398 cd $$(dir $$@) && \
399 $$(GNATBIND_$(1)) -a -n \
400 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
401 -L$(1)_ada -o $$(notdir $$@) \
402 $$(subst $$(dir $$@),,$$^)
403 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
404 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
405 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
406 $(1)-objs += $$(obj)/$(1)/b__$(1).o
407 $($(1)-alis): %.ali: %.o ;
408 endef
410 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
411 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
413 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
414 -include $(DEPENDENCIES)
416 printall:
417 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
418 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
419 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
420 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
421 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
422 endif
424 ifndef NOMKDIR
425 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
426 endif
428 $(obj)/project_filelist.txt:
429 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
430 echo "*** Error: Project must be built before generating file list ***"; \
431 exit 1; \
433 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
434 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
435 grep -v '\.o$$' > $(obj)/project_filelist.txt
437 filelist: $(obj)/project_filelist.txt
438 printf "\nFiles used in build:\n"
439 cat $(obj)/project_filelist.txt
441 #works with either exuberant ctags or ctags.emacs
442 ctags-project: clean-ctags $(obj)/project_filelist.txt
443 cat $(obj)/project_filelist.txt | \
444 xargs ctags -o tags
446 cscope-project: clean-cscope $(obj)/project_filelist.txt
447 cat $(obj)/project_filelist.txt | xargs cscope -b
449 cscope:
450 cscope -bR
452 sphinx:
453 $(MAKE) -C Documentation -f Makefile.sphinx html
455 sphinx-lint:
456 $(MAKE) SPHINXOPTS=-W -C Documentation -f Makefile.sphinx html
458 clean-for-update:
459 rm -rf $(obj) .xcompile
461 clean: clean-for-update clean-utils clean-payloads
462 rm -f .ccwrap
464 clean-cscope:
465 rm -f cscope.out
467 clean-ctags:
468 rm -f tags
470 clean-utils:
471 $(foreach tool, $(TOOLLIST), \
472 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
474 distclean-utils:
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 sphinx sphinx-lint
485 .PHONY: ctags-project cscope-project clean-ctags